Skip to content

Commit 4979476

Browse files
committed
fix: Update c2pa.py code
1 parent 8dd6568 commit 4979476

File tree

1 file changed

+3
-34
lines changed

1 file changed

+3
-34
lines changed

src/c2pa/c2pa.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,6 @@ 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-
352339
# Set up function prototypes not attached to an API object
353340
_setup_function(_lib.c2pa_version, [], ctypes.c_void_p)
354341
_setup_function(_lib.c2pa_error, [], ctypes.c_void_p)
@@ -1137,11 +1124,12 @@ def flush_callback(ctx):
11371124
self._flush_cb = FlushCallback(flush_callback)
11381125

11391126
# Create a dummy context since Python callbacks don't use it
1140-
self._dummy_context = _lib.c2pa_create_dummy_context()
1127+
# We create a small buffer and cast it to a StreamContext pointer
1128+
self._dummy_context = ctypes.create_string_buffer(1) # Create a 1-byte buffer
11411129

11421130
# Create the stream
11431131
self._stream = _lib.c2pa_create_stream(
1144-
self._dummy_context, # context
1132+
ctypes.cast(self._dummy_context, ctypes.POINTER(StreamContext)), # context
11451133
self._read_cb,
11461134
self._seek_cb,
11471135
self._write_cb,
@@ -1186,15 +1174,6 @@ def __del__(self):
11861174
self._stream = None
11871175
self._closed = True
11881176
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
11981177
except Exception:
11991178
# Destructors must not raise exceptions
12001179
pass
@@ -1225,16 +1204,6 @@ def close(self):
12251204
finally:
12261205
self._stream = None
12271206

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
12381207

12391208
# Clean up callbacks
12401209
for attr in ['_read_cb', '_seek_cb', '_write_cb', '_flush_cb']:

0 commit comments

Comments
 (0)