python: Add special macros for error handling

Can only be used on clang or gcc but I think the library already
requires them.
This commit is contained in:
igo95862 2021-04-03 17:37:33 +03:00 committed by Nick Black
parent e044699603
commit 45318ac2e7

View File

@ -135,3 +135,20 @@ typedef struct
PyObject_HEAD;
struct palette256 palette256;
} Palette256Object;
static inline void PyObject_cleanup(PyObject **object)
{
Py_XDECREF(*object);
}
#define CLEANUP_PY_OBJ __attribute__((cleanup(PyObject_cleanup)))
#define PY_CHECK(py_function) \
({ \
PyObject *new_object = py_function; \
if (new_object == NULL) \
{ \
return NULL; \
} \
new_object; \
})