From fde9e3b46192a065ec622da1395c48015df3cf32 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 7 Mar 2021 18:54:57 +0100 Subject: Handle hashes of data types as Py_ssize_t values from Python bindings. --- plugins/pychrysalide/analysis/type.c | 2 +- tests/analysis/type.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/pychrysalide/analysis/type.c b/plugins/pychrysalide/analysis/type.c index 303d188..86a0ffb 100644 --- a/plugins/pychrysalide/analysis/type.c +++ b/plugins/pychrysalide/analysis/type.c @@ -243,7 +243,7 @@ static guint py_data_type_hash_wrapper(const GDataType *type) if (pyret != NULL) { if (PyLong_Check(pyret)) - result = PyLong_AsUnsignedLong(pyret); + result = PyLong_AsSsize_t(pyret); } Py_XDECREF(pyret); diff --git a/tests/analysis/type.py b/tests/analysis/type.py index b690a55..405659e 100644 --- a/tests/analysis/type.py +++ b/tests/analysis/type.py @@ -107,3 +107,18 @@ class TestDataType(ChrysalideTestCase): tp = MyUserType('random') self.assertEqual(tp.hash, hash('random') & ((1 << 32) - 1)) + + class MyOutOfRangeUserType(DataType): + + hard_coded_hash = -8752470794866657507 + + def __init__(self, name): + super(MyOutOfRangeUserType, self).__init__() + self._name = name + + def _hash(self): + return self.hard_coded_hash + + tp = MyOutOfRangeUserType('out-of-range') + + self.assertEqual(tp.hash, MyOutOfRangeUserType.hard_coded_hash & ((1 << 32) - 1)) -- cgit v0.11.2-87-g4458