From eb407ec9d3bc87eeee517dd6698b86ffca351e50 Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 26 Aug 2023 22:11:11 -0400 Subject: [PATCH 1/2] Add missing hash function to type hint file --- Cargo.toml | 2 +- include/common/RabbitizerVersion.h | 2 +- pyproject.toml | 2 +- rabbitizer/Enum.pyi | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e976c77..27d1bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "rabbitizer" # Version should be synced with include/common/RabbitizerVersion.h -version = "1.7.6" +version = "1.7.7" edition = "2021" authors = ["Anghelo Carvajal "] description = "MIPS instruction decoder" diff --git a/include/common/RabbitizerVersion.h b/include/common/RabbitizerVersion.h index ad13303..2b55d68 100644 --- a/include/common/RabbitizerVersion.h +++ b/include/common/RabbitizerVersion.h @@ -14,7 +14,7 @@ extern "C" { // Header version #define RAB_VERSION_MAJOR 1 #define RAB_VERSION_MINOR 7 -#define RAB_VERSION_PATCH 6 +#define RAB_VERSION_PATCH 7 #define RAB_VERSION_STR RAB_STRINGIFY(RAB_VERSION_MAJOR) "." RAB_STRINGIFY(RAB_VERSION_MINOR) "." RAB_STRINGIFY(RAB_VERSION_PATCH) diff --git a/pyproject.toml b/pyproject.toml index 25d82dc..2a0f4bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ [project] name = "rabbitizer" # Version should be synced with include/common/RabbitizerVersion.h -version = "1.7.6" +version = "1.7.7" description = "MIPS instruction decoder" # license = "MIT" readme = "README.md" diff --git a/rabbitizer/Enum.pyi b/rabbitizer/Enum.pyi index 1ca25b9..c7285a2 100644 --- a/rabbitizer/Enum.pyi +++ b/rabbitizer/Enum.pyi @@ -20,5 +20,7 @@ class Enum: def __gt__(self, __o: object) -> bool: ... def __ge__(self, __o: object) -> bool: ... + def __hash__(self) -> int: ... + def __repr__(self) -> str: ... def __str__(self) -> str: ... From ed678cfeb6e4dd7b822b719cd79d7819d8d62f75 Mon Sep 17 00:00:00 2001 From: angie Date: Sat, 26 Aug 2023 23:16:22 -0400 Subject: [PATCH 2/2] Use proper hash function --- rabbitizer/enums/rabbitizer_type_Enum.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/rabbitizer/enums/rabbitizer_type_Enum.c b/rabbitizer/enums/rabbitizer_type_Enum.c index 7474ce7..e966f1b 100644 --- a/rabbitizer/enums/rabbitizer_type_Enum.c +++ b/rabbitizer/enums/rabbitizer_type_Enum.c @@ -91,15 +91,21 @@ static PyGetSetDef rabbitizer_type_Enum_getsetters[] = { }; -// Crappy hash Py_hash_t rabbitizer_type_Enum_hash(PyRabbitizerEnum *self) { - Py_hash_t hash = PyObject_Hash(self->enumType); + PyObject *tuple = PyTuple_Pack(2, self->enumType, PyLong_FromLong(self->value)); + Py_hash_t hash; + + if (tuple == NULL) { + return -1; + } + + hash = PyObject_Hash(tuple); if (hash == -1) { return -1; } - return hash + self->value; + return hash; } // Checks for the 6 basic comparisons (==, !=, <, <=, >, >=) @@ -140,8 +146,8 @@ PyObject *rabbitizer_type_Enum_richcompare(PyRabbitizerEnum *self, PyObject *oth switch (op) { case Py_EQ: if ((self->value) == (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; case Py_NE: if ((self->value) != (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; - case Py_LT: if ((self->value) < (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; - case Py_GT: if ((self->value) > (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; + case Py_LT: if ((self->value) < (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; + case Py_GT: if ((self->value) > (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; case Py_LE: if ((self->value) <= (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; case Py_GE: if ((self->value) >= (otherValue)) Py_RETURN_TRUE; Py_RETURN_FALSE; default: @@ -158,7 +164,7 @@ static PyObject *rabbitizer_type_Enum___reduce__(PyRabbitizerEnum *self, UNUSED PyObject *name; PyObject *value; - enumType = self->enumType; + enumType = self->enumType; Py_INCREF(enumType); name = self->name; Py_INCREF(name);