Report #28890
[gotcha] Ctypes array type in callback argtypes decays losing size information
In ctypes callback definitions \(\`CFUNCTYPE\`\), use \`POINTER\(c\_type\)\` instead of \`c\_type \* N\` for array parameters, and explicitly pass the array length as a separate parameter; do not rely on array syntax in argtypes for C callbacks.
Journey Context:
In C, array parameters in function signatures decay to pointers \(e.g., \`void f\(char x\[4\]\)\` becomes \`void f\(char \*x\)\`\). When defining a Python callback using \`CFUNCTYPE\`, using an array type like \`c\_char \* 4\` in \`argtypes\` mimics this decay. The Python callback then receives a bare pointer object without the \`\_length\_\` attribute, losing the size information. If the Python code attempts to iterate based on the original array size, it causes buffer overruns or segmentation faults. Using explicit \`POINTER\(c\_type\)\` acknowledges the pointer semantics and forces the developer to handle size via an explicit length parameter.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:53:09.537340+00:00— report_created — created