[SyneRBI/SIRF] swig: Handle wrapper (Issue #1384)

0 views
Skip to first unread message

Casper da Costa-Luis

unread,
Mar 23, 2026, 11:26:09 AMMar 23
to SyneRBI/SIRF, Subscribed
casperdcl created an issue (SyneRBI/SIRF#1384)

I'd recommend an intermediate wrapper which does:

  • check_status
  • typed data extraction
  • destruction

which can be used e.g. as:

 def get_STIR_version_string():
     """Returns STIR engine version as Python str."""
-    handle = pystir.cSTIR_STIR_version_string()
-    check_status(handle)
-    version = pyiutil.charDataFromHandle(handle)
-    pyiutil.deleteDataHandle(handle)
-    return version
+    handle = Handle(pystir.cSTIR_STIR_version_string())
+    return str(handle)
Implementation
class Handle:
    def __init__(self, handle, check_stack=None):
        check_status(handle, stack=check_stack)
        self.handle = handle

    def __int__(self):
        return pyiutil.intDataFromHandle(self.handle)

    def __bool__(self):
        return pyiutil.boolDataFromHandle(self.handle)

    def __float__(self, double=False):
        return (pyiutil.doubleDataFromHandle if double else pyiutil.floatDataFromHandle)(self.handle)

    def __str__(self):
        return pyiutil.charDataFromHandle(self.handle)

    def __abs__(self):
        return pyiutil.size_tDataFromHandle(self.handle)

    def __complex__(self, double=False):
        if double:
            return pyiutil.doubleReDataFromHandle(self.handle) + 1.j * pyiutil.doubleImDataFromHandle(self.handle)
        return pyiutil.floatReDataFromHandle(self.handle) + 1.j * pyiutil.floatImDataFromHandle(self.handle)

    def __del__(self):
        if self.handle is not None:
            pyiutil.deleteDataHandle(self.handle)

Related to #1377

/CC @evgueni-ovtchinnikov @paskino @KrisThielemans


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1384@github.com>

Kris Thielemans

unread,
Mar 23, 2026, 11:50:41 AMMar 23
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1384)

sounds cool


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issues/1384/4111666344@github.com>

Casper da Costa-Luis

unread,
Mar 27, 2026, 1:11:46 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

Closed #1384 as completed via fdcd949.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/issue/1384/issue_event/23979474488@github.com>

Reply all
Reply to author
Forward
0 new messages