From 8f1bc5944b849f3ad0cbbd5972d5ab9948ed4d57 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sat, 2 May 2020 11:01:35 -0400 Subject: Fix up equality operators and had hash operators --- python/callingconvention.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'python/callingconvention.py') diff --git a/python/callingconvention.py b/python/callingconvention.py index c6e5895a..66569a96 100644 --- a/python/callingconvention.py +++ b/python/callingconvention.py @@ -159,15 +159,24 @@ class CallingConvention(object): if self.handle is not None: core.BNFreeCallingConvention(self.handle) - def __eq__(self, value): - if not isinstance(value, CallingConvention): - return False - return ctypes.addressof(self.handle.contents) == ctypes.addressof(value.handle.contents) + def __repr__(self): + return "" % (self.arch.name, self.name) + + def __str__(self): + return self.name + + def __eq__(self, other): + if not isinstance(other, self.__class__): + return NotImplemented + return ctypes.addressof(self.handle.contents) == ctypes.addressof(other.handle.contents) - def __ne__(self, value): - if not isinstance(value, CallingConvention): - return True - return ctypes.addressof(self.handle.contents) != ctypes.addressof(value.handle.contents) + def __ne__(self, other): + if not isinstance(other, self.__class__): + return NotImplemented + return not (self == other) + + def __hash__(self): + return hash(ctypes.addressof(self.handle.contents)) def _get_caller_saved_regs(self, ctxt, count): try: @@ -364,12 +373,6 @@ class CallingConvention(object): result[0].index = in_var[0].index result[0].storage = in_var[0].storage - def __repr__(self): - return "" % (self.arch.name, self.name) - - def __str__(self): - return self.name - def perform_get_incoming_reg_value(self, reg, func): reg_stack = self.arch.get_reg_stack_for_reg(reg) if reg_stack is not None: -- cgit v1.3.1