diff options
author | Daniel Elstner <daniel.kitta@gmail.com> | 2015-10-05 01:53:43 +0200 |
---|---|---|
committer | Daniel Elstner <daniel.kitta@gmail.com> | 2015-10-06 23:25:36 +0200 |
commit | 201a85a8ea071d37f4fda2668c0a1c488d852f4e (patch) | |
tree | f407560b61fc126291ee932d6c897a80dea79a30 /type_logic.c | |
parent | bd0e7d2e71e7a05b2bb0686a86a75b8fcb92fd54 (diff) | |
download | libsigrokdecode-201a85a8ea071d37f4fda2668c0a1c488d852f4e.tar.gz libsigrokdecode-201a85a8ea071d37f4fda2668c0a1c488d852f4e.zip |
Python: Restrict code to stable ABI subset
Limit usage of the Python C API to the stable ABI subset as defined
by PEP 384. This removes some type definitions and functions which
libsigrokdecode made use of. Convert all affected code to suitable
API alternatives. Also fix a few leaks that became apparent while
working on the code.
The most visible change is that PyTypeObject is now an opaque type.
Thus, the custom Decoder and srd_logic types are now created on the
heap via an alternative API. Unfortunately, since tp_name is now
inaccessible, type names had to be removed from the log output.
Stack traces after Python exceptions are now formatted by calling
into Python, since the trace object C API is no longer available.
Diffstat (limited to 'type_logic.c')
-rw-r--r-- | type_logic.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/type_logic.c b/type_logic.c index 0b11339..d126d7b 100644 --- a/type_logic.c +++ b/type_logic.c @@ -73,14 +73,25 @@ static PyObject *srd_logic_iternext(PyObject *self) return logic->sample; } -/** @cond PRIVATE */ -SRD_PRIV PyTypeObject srd_logic_type = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "srd_logic", - .tp_basicsize = sizeof(srd_logic), - .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_doc = "Sigrokdecode logic sample object", - .tp_iter = srd_logic_iter, - .tp_iternext = srd_logic_iternext, -}; -/** @endcond */ +/** Create the srd_logic type. + * @return The new type object. + * @private + */ +SRD_PRIV PyObject *srd_logic_type_new(void) +{ + PyType_Spec spec; + PyType_Slot slots[] = { + { Py_tp_doc, "sigrokdecode logic sample object" }, + { Py_tp_iter, (void *)&srd_logic_iter }, + { Py_tp_iternext, (void *)&srd_logic_iternext }, + { Py_tp_new, (void *)&PyType_GenericNew }, + { 0, NULL } + }; + spec.name = "srd_logic"; + spec.basicsize = sizeof(srd_logic); + spec.itemsize = 0; + spec.flags = Py_TPFLAGS_DEFAULT; + spec.slots = slots; + + return PyType_FromSpec(&spec); +} |