Skip to content

Commit d069e47

Browse files
committed
Fix scalar unpacking in the C API example bridges
The managed input bridge unpacked four scalars, but only kwargs become scalars: InputAdapterDef strips push_mode from the tail and AdapterDef strips the manager from the head, leaving (typ, interval_ms, push_group). That raised ValueError on macOS in test_cpp_examples. The managed output bridge had the same miscount, masked rather than raised: scalars is (prefix,), so `scalars[1] if len(scalars) > 1 else ""` always took the else branch and the manager's prefix was silently discarded on every call. Replace the defensive index lookups with strict unpacking in all four bridges so a future mismatch fails loudly instead of substituting a default. Verified the delivered tuples for each of the four adapter definitions against csp's wiring layer. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
1 parent 6858ca2 commit d069e47

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

  • examples/05_cpp/4_c_api_adapter/exampleadapter

examples/05_cpp/4_c_api_adapter/exampleadapter/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ def _create_managed_input_adapter(mgr_capsule, engine, pytype, push_mode, scalar
124124
"""
125125
Bridge function for managed input adapter.
126126
127-
scalars are positional, in the order declared by _managed_input_adapter_def:
128-
(manager, ts_type, interval_ms, push_group)
127+
scalars are positional, in the order the kwargs are declared by
128+
_managed_input_adapter_def: (typ, interval_ms, push_group). The manager is a
129+
separate positional argument to input_adapter_def, so it is delivered as
130+
mgr_capsule rather than as a scalar.
129131
"""
130-
_, _, interval_ms, push_group = scalars
132+
_, interval_ms, push_group = scalars
131133

132134
capsule = _exampleadapterimpl._example_input_adapter(interval_ms=interval_ms)
133135

@@ -138,10 +140,10 @@ def _create_managed_output_adapter(mgr_capsule, engine, scalars):
138140
"""
139141
Bridge function for managed output adapter.
140142
141-
scalars: (ExampleAdapterManager, prefix)
143+
The manager is delivered as mgr_capsule rather than as a scalar, and the ts
144+
input is not a scalar, so scalars is just (prefix,).
142145
"""
143-
# Extract prefix from scalars
144-
prefix = scalars[1] if len(scalars) > 1 else ""
146+
(prefix,) = scalars
145147
if prefix is None:
146148
prefix = ""
147149

@@ -211,12 +213,9 @@ def _create_standalone_input_adapter(mgr, engine, pytype, push_mode, scalars):
211213
"""
212214
Bridge function for standalone input adapter.
213215
214-
For standalone adapters without a manager, scalars contains:
215-
- scalars[0]: typ (the Python type, e.g., int)
216-
- scalars[1]: interval_ms (int)
216+
There is no manager, so scalars is (typ, interval_ms).
217217
"""
218-
# Extract interval_ms from scalars (second element, after typ)
219-
interval_ms = scalars[1] if len(scalars) > 1 else 100
218+
_, interval_ms = scalars
220219

221220
# Create the VTable capsule
222221
capsule = _exampleadapterimpl._example_input_adapter(interval_ms=interval_ms)
@@ -228,9 +227,10 @@ def _create_standalone_input_adapter(mgr, engine, pytype, push_mode, scalars):
228227
def _create_standalone_output_adapter(mgr, engine, scalars):
229228
"""
230229
Bridge function for standalone output adapter.
230+
231+
The ts input is not a scalar, so scalars is just (prefix,).
231232
"""
232-
# Extract prefix from scalars
233-
prefix = scalars[0] if scalars else None
233+
(prefix,) = scalars
234234
# Convert None to empty string as the C function expects a string
235235
if prefix is None:
236236
prefix = ""

0 commit comments

Comments
 (0)