From 21e0949a9843494e5d7492a28004c7805a947eec Mon Sep 17 00:00:00 2001 From: "Carl D. Roth" Date: Mon, 16 Oct 2017 11:36:31 -0700 Subject: [PATCH] Add weakref wrapper for partially-malloc'd struct data --- .../onlp/module/python/onlp/onlp/aim_weakref.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/base/any/onlp/src/onlp/module/python/onlp/onlp/aim_weakref.py b/packages/base/any/onlp/src/onlp/module/python/onlp/onlp/aim_weakref.py index 5c6e7246..e639de57 100644 --- a/packages/base/any/onlp/src/onlp/module/python/onlp/onlp/aim_weakref.py +++ b/packages/base/any/onlp/src/onlp/module/python/onlp/onlp/aim_weakref.py @@ -80,3 +80,17 @@ class AimPointer(ctypes.c_void_p): # XXX roth -- casting may be necessary track_for_finalization(self, aimPtr, self.deletePointer) + +class AimStruct(ctypes.Structure): + """Manage an AIM struct with internally-allocated data.""" + + @classmethod + def deleteStruct(cls, aimPtr): + """Override this with the proper delete semantics.""" + raise NotImplementedError + + def __init__(self): + + super(ctypes.Structure, self).__init__() + + track_for_finalization(self, self, self.deleteStruct)