Skip to content

Commit e750fb9

Browse files
committed
[Python] Fix exceptions from __del__ during interpreter shutdown
`StructureType`, `EnumerationType`, and `NamedTypeReferenceType` called `super(Class, self)` in `__del__`. The interpreter nulls that module-global class name during teardown, so finalizers running at shutdown raised a `TypeError`. Switch to zero-arg `super()` here and across the rest of the Python API.
1 parent 06c0905 commit e750fb9

16 files changed

Lines changed: 36 additions & 36 deletions

python/architecture.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,7 +2687,7 @@ def fastcall_calling_convention(self, cc: 'callingconvention.CallingConvention')
26872687

26882688
class CoreArchitecture(Architecture):
26892689
def __init__(self, handle: core.BNArchitecture):
2690-
super(CoreArchitecture, self).__init__()
2690+
super().__init__()
26912691

26922692
self.handle = core.handle_of_type(handle, core.BNArchitecture)
26932693
self.name = core.BNGetArchitectureName(self.handle)
@@ -3361,7 +3361,7 @@ def get_flags_required_for_flag_condition(
33613361
class ArchitectureHook(CoreArchitecture):
33623362
def __init__(self, base_arch: 'Architecture'):
33633363
self._base_arch = base_arch
3364-
super(ArchitectureHook, self).__init__(base_arch.handle)
3364+
super().__init__(base_arch.handle)
33653365

33663366
# To improve performance of simpler hooks, use null callback for functions that are not being overridden
33673367
if self.get_associated_arch_by_address.__code__ == CoreArchitecture.get_associated_arch_by_address.__code__:

python/binaryview.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class BinaryDataNotification:
280280
281281
>>> class NotifyTest(binaryninja.BinaryDataNotification):
282282
... def __init__(self):
283-
... super(NotifyTest, self).__init__(binaryninja.NotificationType.NotificationBarrier | binaryninja.NotificationType.FunctionLifetime | binaryninja.NotificationType.FunctionUpdated)
283+
... super().__init__(binaryninja.NotificationType.NotificationBarrier | binaryninja.NotificationType.FunctionLifetime | binaryninja.NotificationType.FunctionUpdated)
284284
... self.received_event = False
285285
... def notification_barrier(self, view: 'BinaryView') -> int:
286286
... has_events = self.received_event
@@ -12228,7 +12228,7 @@ def auto_discovered(self) -> bool:
1222812228

1222912229
class DataVariable(CoreDataVariable):
1223012230
def __init__(self, view: BinaryView, address: int, type: '_types.Type', auto_discovered: bool):
12231-
super(DataVariable, self).__init__(address, type, auto_discovered)
12231+
super().__init__(address, type, auto_discovered)
1223212232
self.view = view
1223312233
self._accessor = TypedDataAccessor(self.type, self.address, self.view, self.view.endianness)
1223412234

@@ -12324,7 +12324,7 @@ def components(self) -> List[component.Component]:
1232412324

1232512325
class DataVariableAndName(CoreDataVariable):
1232612326
def __init__(self, addr: int, var_type: '_types.Type', var_name: str, auto_discovered: bool) -> None:
12327-
super(DataVariableAndName, self).__init__(addr, var_type, auto_discovered)
12327+
super().__init__(addr, var_type, auto_discovered)
1232812328
self.name = var_name
1232912329

1233012330
def __repr__(self) -> str:

python/constantrenderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def render_constant_pointer(
205205

206206
class CoreConstantRenderer(ConstantRenderer):
207207
def __init__(self, handle: core.BNConstantRenderer):
208-
super(CoreConstantRenderer, self).__init__(handle=handle)
208+
super().__init__(handle=handle)
209209
if type(self) is CoreConstantRenderer:
210210
global _renderer_cache
211211
_renderer_cache[ctypes.addressof(handle.contents)] = self

python/deprecation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, function, deprecated_in, removed_in, details=""):
6767
self.deprecated_in = deprecated_in
6868
self.removed_in = removed_in
6969
self.details = details
70-
super(DeprecatedWarning, self).__init__(function, deprecated_in,
70+
super().__init__(function, deprecated_in,
7171
removed_in, details)
7272

7373
def __str__(self):

python/downloadprovider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def create_instance(self):
370370

371371
class PythonDownloadInstance(DownloadInstance):
372372
def __init__(self, provider):
373-
super(PythonDownloadInstance, self).__init__(provider)
373+
super().__init__(provider)
374374

375375
def perform_destroy_instance(self):
376376
pass
@@ -466,7 +466,7 @@ class PythonDownloadProvider(DownloadProvider):
466466

467467
class PythonDownloadInstance(DownloadInstance):
468468
def __init__(self, provider):
469-
super(PythonDownloadInstance, self).__init__(provider)
469+
super().__init__(provider)
470470

471471
def perform_destroy_instance(self):
472472
pass

python/flowgraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def remove_render_layer(self, layer: 'binaryninja.RenderLayer'):
921921

922922
class CoreFlowGraph(FlowGraph):
923923
def __init__(self, handle):
924-
super(CoreFlowGraph, self).__init__(handle)
924+
super().__init__(handle)
925925

926926
def update(self):
927927
graph = core.BNUpdateFlowGraph(self.handle)

python/highlevelil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5186,7 +5186,7 @@ class HighLevelILBasicBlock(basicblock.BasicBlock):
51865186
def __init__(
51875187
self, handle: core.BNBasicBlockHandle, owner: HighLevelILFunction, view: Optional['binaryview.BinaryView']
51885188
):
5189-
super(HighLevelILBasicBlock, self).__init__(handle, view)
5189+
super().__init__(handle, view)
51905190
self._il_function = owner
51915191

51925192
def __iter__(self) -> Generator[HighLevelILInstruction, None, None]:

python/languagerepresentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ def __repr__(self):
872872

873873
class CoreLanguageRepresentationFunctionType(LanguageRepresentationFunctionType):
874874
def __init__(self, handle: core.BNLanguageRepresentationFunctionTypeHandle):
875-
super(CoreLanguageRepresentationFunctionType, self).__init__(handle=handle)
875+
super().__init__(handle=handle)
876876
if type(self) is CoreLanguageRepresentationFunctionType:
877877
global _language_cache
878878
_language_cache[ctypes.addressof(handle.contents)] = self

python/lineformatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def __repr__(self):
247247

248248
class CoreLineFormatter(LineFormatter):
249249
def __init__(self, handle: core.BNLineFormatter):
250-
super(CoreLineFormatter, self).__init__(handle=handle)
250+
super().__init__(handle=handle)
251251
if type(self) is CoreLineFormatter:
252252
global _formatter_cache
253253
_formatter_cache[ctypes.addressof(handle.contents)] = self

python/lowlevelil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6678,7 +6678,7 @@ class LowLevelILBasicBlock(basicblock.BasicBlock):
66786678
def __init__(
66796679
self, handle: core.BNBasicBlockHandle, owner: LowLevelILFunction, view: Optional['binaryview.BinaryView']
66806680
):
6681-
super(LowLevelILBasicBlock, self).__init__(handle, view)
6681+
super().__init__(handle, view)
66826682
self._il_function = owner
66836683

66846684
def __hash__(self):

0 commit comments

Comments
 (0)