Skip to content

Commit 8dd6568

Browse files
committed
fix: 1
1 parent d3bb12c commit 8dd6568

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/c2pa/c2pa.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ def _setup_function(func, argtypes, restype=None):
336336
None
337337
)
338338

339+
# Add dummy context functions
340+
_setup_function(
341+
_lib.c2pa_create_dummy_context,
342+
[],
343+
ctypes.POINTER(StreamContext)
344+
)
345+
346+
_setup_function(
347+
_lib.c2pa_free_dummy_context,
348+
[ctypes.POINTER(StreamContext)],
349+
None
350+
)
351+
339352
# Set up function prototypes not attached to an API object
340353
_setup_function(_lib.c2pa_version, [], ctypes.c_void_p)
341354
_setup_function(_lib.c2pa_error, [], ctypes.c_void_p)
@@ -1123,9 +1136,12 @@ def flush_callback(ctx):
11231136
self._write_cb = WriteCallback(write_callback)
11241137
self._flush_cb = FlushCallback(flush_callback)
11251138

1139+
# Create a dummy context since Python callbacks don't use it
1140+
self._dummy_context = _lib.c2pa_create_dummy_context()
1141+
11261142
# Create the stream
11271143
self._stream = _lib.c2pa_create_stream(
1128-
None, # context
1144+
self._dummy_context, # context
11291145
self._read_cb,
11301146
self._seek_cb,
11311147
self._write_cb,
@@ -1170,6 +1186,15 @@ def __del__(self):
11701186
self._stream = None
11711187
self._closed = True
11721188
self._initialized = False
1189+
1190+
# Clean up dummy context
1191+
if hasattr(self, '_dummy_context') and self._dummy_context:
1192+
try:
1193+
_lib.c2pa_free_dummy_context(self._dummy_context)
1194+
except Exception:
1195+
pass
1196+
finally:
1197+
self._dummy_context = None
11731198
except Exception:
11741199
# Destructors must not raise exceptions
11751200
pass
@@ -1200,6 +1225,17 @@ def close(self):
12001225
finally:
12011226
self._stream = None
12021227

1228+
# Clean up dummy context
1229+
if hasattr(self, '_dummy_context') and self._dummy_context:
1230+
try:
1231+
_lib.c2pa_free_dummy_context(self._dummy_context)
1232+
except Exception as e:
1233+
logger.error(
1234+
Stream._ERROR_MESSAGES['callback_error'].format(
1235+
'dummy_context', str(e)))
1236+
finally:
1237+
self._dummy_context = None
1238+
12031239
# Clean up callbacks
12041240
for attr in ['_read_cb', '_seek_cb', '_write_cb', '_flush_cb']:
12051241
if hasattr(self, attr):

0 commit comments

Comments
 (0)