Add Modules/_testcapi/util.h header (GH-108774)

It contains common macros used in C API tests.
This commit is contained in:
Serhiy Storchaka 2023-09-01 21:42:42 +03:00 committed by GitHub
parent 578ebc5d5f
commit 0e01fac315
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 49 additions and 94 deletions

View file

@ -43,16 +43,8 @@
// Several parts of this module are broken out into files in _testcapi/.
// Include definitions from there.
#include "_testcapi/parts.h"
#include "_testcapi/util.h"
#define NULLABLE(x) do { if (x == Py_None) x = NULL; } while (0);
#define RETURN_INT(value) do { \
int _ret = (value); \
if (_ret == -1) { \
return NULL; \
} \
return PyLong_FromLong(_ret); \
} while (0)
// Forward declarations
static struct PyModuleDef _testcapimodule;
@ -1333,19 +1325,13 @@ static PyObject *
test_PyBuffer_SizeFromFormat(PyObject *self, PyObject *args)
{
const char *format;
Py_ssize_t result;
if (!PyArg_ParseTuple(args, "s:test_PyBuffer_SizeFromFormat",
&format)) {
return NULL;
}
result = PyBuffer_SizeFromFormat(format);
if (result == -1) {
return NULL;
}
return PyLong_FromSsize_t(result);
RETURN_SIZE(PyBuffer_SizeFromFormat(format));
}
/* Test that the fatal error from not having a current thread doesn't