Content-Length: 270956 | pFad | https://github.com/pythonnet/pythonnet/issues/676

30 PyObject.GetHashCode overflow bug · Issue #676 · pythonnet/pythonnet · GitHub
Skip to content

PyObject.GetHashCode overflow bug #676

@GSPP

Description

@GSPP

PyObject.GetHashCode() can throw an OverflowException because IntPtr.ToInt32() does throw. See

return Runtime.PyObject_Hash(obj).ToInt32();
. I suggest fixing this by xoring the high and low parts of that IntPtr together. Like this:

var ulongVal = (ulong)ptr;
return (int)((uint)ulongVal ^ (uint)(ulongVal >> 32));

This happened to me when inserting into a dictionary using tensorflow objects as keys:

new Dictionary<dynamic, dynamic>() { { x, 1.0 }, { y, 1.0 }, }

Environment

  • Pythonnet version: 2.3
  • Python version: 3.5
  • Operating System: Windows 7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/pythonnet/pythonnet/issues/676

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy