From 549ccc3570fa6a38293092fbc40172ec2830bd2b Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Sun, 24 May 2026 22:07:53 +0200 Subject: [PATCH] Code clean up --- class_parser.py | 38 ++++++++++++++++++-------------------- dpkg/changelog | 4 ++-- pyproject.toml | 2 +- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/class_parser.py b/class_parser.py index d608319..48e93d6 100644 --- a/class_parser.py +++ b/class_parser.py @@ -225,7 +225,7 @@ DEBUG = False # The pytsk3 version. -VERSION = "20260519" +VERSION = "20260524" # These functions are used to manage library memory. FREE = "aff4_free" @@ -544,14 +544,11 @@ class Module(BaseCodeGenerator): * Pre-3.12 support has been retained for Python 3.10 and 3.11 compatibility. */ void pytsk_fetch_error(void) {{ -#if PY_VERSION_HEX >= 0x030C0000 - PyObject *raised_exception = NULL; -#else +#if PY_VERSION_HEX < 0x030C0000 PyObject *exception_traceback = NULL; PyObject *exception_type = NULL; - PyObject *exception_value = NULL; #endif - PyObject *exception_repr = NULL; + PyObject *exception_value = NULL; PyObject *string_object = NULL; char *str_c = NULL; char *error_str = NULL; @@ -562,17 +559,15 @@ class Module(BaseCodeGenerator): /* Fetch the exception state and convert it to a string. */ #if PY_VERSION_HEX >= 0x030C0000 - raised_exception = PyErr_GetRaisedException(); - exception_repr = raised_exception; + exception_value = PyErr_GetRaisedException(); #else PyErr_Fetch(&exception_type, &exception_value, &exception_traceback); - exception_repr = exception_value; #endif /* NULL on the legacy path means PyErr_SetNone(type) raised without a value, e.g. * KeyboardInterrupt); on the modern path means no exception was actually set. */ - if(exception_repr == NULL) {{ + if(exception_value == NULL) {{ if(error_str != NULL) {{ const char *placeholder = "Python exception raised without value"; size_t placeholder_len = strlen(placeholder); @@ -584,13 +579,13 @@ class Module(BaseCodeGenerator): }} *error_type = ERuntimeError; #if PY_VERSION_HEX >= 0x030C0000 - PyErr_SetRaisedException(raised_exception); + PyErr_SetRaisedException(exception_value); #else PyErr_Restore(exception_type, exception_value, exception_traceback); #endif return; }} - string_object = PyObject_Repr(exception_repr); + string_object = PyObject_Repr(exception_value); if(string_object != NULL) {{ utf8_string_object = PyUnicode_AsUTF8String(string_object); @@ -620,7 +615,7 @@ class Module(BaseCodeGenerator): *error_type = ERuntimeError; }} #if PY_VERSION_HEX >= 0x030C0000 - PyErr_SetRaisedException(raised_exception); + PyErr_SetRaisedException(exception_value); #else PyErr_Restore(exception_type, exception_value, exception_traceback); #endif @@ -777,14 +772,15 @@ class Module(BaseCodeGenerator): }} #ifdef Py_GIL_DISABLED - /* Declare this module safe for free-threaded Python - * Without this call, CPython force-enables - * the GIL for our module at import time on - * free-threaded builds, which would serialize every - * pytsk3 call and defeat the point of free-threading. - * The symbol is only declared when Py_GIL_DISABLED is set + /* Declare this module safe for free-threaded Python. Without this call, CPython + * force-enables the GIL for our module at import time on free-threaded builds, + * which would serialize every pytsk3 call and defeat the point of free-threading. + * The symbol is only declared when Py_GIL_DISABLED is set. */ - PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); + if( PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED) != 0) {{ + Py_DecRef(module); + return(NULL); + }} #endif d = PyModule_GetDict(module); @@ -1023,6 +1019,8 @@ def write(self, out): "on_error:\n" " PyGILState_Release(gil_state);\n" "\n" + " Py_DecRef(module);\n" + "\n" " return NULL;\n" "}\n" "\n" diff --git a/dpkg/changelog b/dpkg/changelog index 20219f1..8d76422 100644 --- a/dpkg/changelog +++ b/dpkg/changelog @@ -1,5 +1,5 @@ -pytsk3 (20260519-1) unstable; urgency=low +pytsk3 (20260524-1) unstable; urgency=low * Auto-generated - -- Joachim Metz Tue, 19 May 2026 20:44:24 +0200 + -- Joachim Metz Sun, 24 May 2026 19:48:56 -0100 diff --git a/pyproject.toml b/pyproject.toml index 3e7376c..a106011 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pytsk3" -version = "20260519" +version = "20260524" description = "Python bindings for the SleuthKit" authors = [ { name = "Michael Cohen", email = "scudette@gmail.com" },