summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_testcapi/util.h')
-rw-r--r--Modules/_testcapi/util.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/_testcapi/util.h b/Modules/_testcapi/util.h
new file mode 100644
index 0000000..05ccb12
--- /dev/null
+++ b/Modules/_testcapi/util.h
@@ -0,0 +1,25 @@
+#define NULLABLE(x) do { \
+ if (x == Py_None) { \
+ x = NULL; \
+ } \
+ } while (0);
+
+#define RETURN_INT(value) do { \
+ int _ret = (value); \
+ if (_ret == -1) { \
+ assert(PyErr_Occurred()); \
+ return NULL; \
+ } \
+ assert(!PyErr_Occurred()); \
+ return PyLong_FromLong(_ret); \
+ } while (0)
+
+#define RETURN_SIZE(value) do { \
+ Py_ssize_t _ret = (value); \
+ if (_ret == -1) { \
+ assert(PyErr_Occurred()); \
+ return NULL; \
+ } \
+ assert(!PyErr_Occurred()); \
+ return PyLong_FromSsize_t(_ret); \
+ } while (0)