Python bindings (weaseljson.py) omit on_key_data and misalign the C callbacks struct #6

Closed
opened 2026-06-17 23:39:55 +00:00 by weaselbot · 0 comments
Member

The C WeaselJsonCallbacks struct in include/weaseljson.h orders its function pointers as:
on_begin_object, on_end_object, on_string_data, on_key_data, on_begin_array, on_end_array, on_number_data, on_true_literal, on_false_literal, on_null_literal.

weaseljson.py defines WeaselJsonCallbacks._fields_ (lines 13-30) with only nine entries and places on_begin_array where on_key_data should be, completely omitting the key callback. This misaligns the ctypes struct with the C layout, so any JSON document containing object keys reads an incorrect function pointer and/or routes key data to the wrong Python callback.

Additional gaps:

  • WeaselJsonCallbacksBase (lines 33-58) has no on_key_data method.
  • The module-level c_callbacks object built from the global callback wrappers (around line 150) does not include an on_key_data wrapper.

Consequences:

  • Python users cannot implement key handling.
  • Parsing objects is likely to crash or silently deliver key bytes through on_string_data.

Expected: WeaselJsonCallbacks should contain on_key_data in the correct position, WeaselJsonCallbacksBase should expose on_key_data(self, data, done), and a corresponding ctypes wrapper should be added to c_callbacks.

The C `WeaselJsonCallbacks` struct in `include/weaseljson.h` orders its function pointers as: `on_begin_object`, `on_end_object`, `on_string_data`, `on_key_data`, `on_begin_array`, `on_end_array`, `on_number_data`, `on_true_literal`, `on_false_literal`, `on_null_literal`. `weaseljson.py` defines `WeaselJsonCallbacks._fields_` (lines 13-30) with only nine entries and places `on_begin_array` where `on_key_data` should be, completely omitting the key callback. This misaligns the ctypes struct with the C layout, so any JSON document containing object keys reads an incorrect function pointer and/or routes key data to the wrong Python callback. Additional gaps: - `WeaselJsonCallbacksBase` (lines 33-58) has no `on_key_data` method. - The module-level `c_callbacks` object built from the global callback wrappers (around line 150) does not include an `on_key_data` wrapper. Consequences: - Python users cannot implement key handling. - Parsing objects is likely to crash or silently deliver key bytes through `on_string_data`. Expected: `WeaselJsonCallbacks` should contain `on_key_data` in the correct position, `WeaselJsonCallbacksBase` should expose `on_key_data(self, data, done)`, and a corresponding ctypes wrapper should be added to `c_callbacks`.
weaselbot was assigned by andrew 2026-06-18 14:05:37 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#6