File dp_state_pyhelp.h¶
FileList > inc > dp_state_pyhelp.h
Go to the source code of this file
Macros¶
| Type | Name |
|---|---|
| define | DP_PY_STATE_METHODS (FNPFX, SELF_T, HANDLE_EXPR, CPFX) |
Macro Definition Documentation¶
define DP_PY_STATE_METHODS¶
dp_state_pyhelp.h — the state bytes interface for hand-written (no_generate) CPython bindings.
jm's serializable flag generates the Python triplet (state_bytes / get_state / set_state) for every jm-managed object. A no_generate module (e.g. ddc_fn) owns its binding by hand, so jm cannot generate it there — this macro provides the same three methods so the hand-written face is byte-identical in behaviour and cannot drift from jm's output.
Include from a *_ext.c translation unit (after Python.h). Instantiate with the PyObject struct type, an expression yielding the live C handle (or NULL when closed/destroyed), and the C object prefix, e.g.:
DP_PY_STATE_METHODS(Ddcr, DdcrObject, (self->closed ? NULL : self->h), ddcr)
then add to the type's PyMethodDef table:
{"state_bytes", (PyCFunction)Ddcr_state_bytes, METH_NOARGS, "Serialized state size in bytes."}, {"get_state", (PyCFunction)Ddcr_get_state, METH_NOARGS, "Serialize the engine's mutable state to bytes."}, {"set_state", (PyCFunction)Ddcr_set_state, METH_O, "Restore mutable state from a get_state() blob."},
The C triplet (<pfx>_state_bytes/get_state/set_state) must follow the standard ABI (see dp_state.h): set_state returns DP_OK (0) or a negative error. set_state here enforces an exact size match, mirroring jm.
The documentation for this class was generated from the following file native/inc/dp_state_pyhelp.h