diff options
author | Petr Viktorin <encukou@gmail.com> | 2022-08-17 11:48:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 11:48:43 (GMT) |
commit | 0f2b469ce1a6f123ad9e151b1771651b3e1d2de6 (patch) | |
tree | 6b11c45f2eaa658bb8e6db56cd92b41435edcbae /Modules/_testcapi/parts.h | |
parent | 7276ca25f5f1440aa4d025350d3de15141854dde (diff) | |
download | cpython-0f2b469ce1a6f123ad9e151b1771651b3e1d2de6.zip cpython-0f2b469ce1a6f123ad9e151b1771651b3e1d2de6.tar.gz cpython-0f2b469ce1a6f123ad9e151b1771651b3e1d2de6.tar.bz2 |
gh-95991: Add some infrastructure for testing Limited API in _testcapi (GH-95992)
- Limited API needs to be enabled per source file
- Some builds don't support Limited API, so Limited API tests must be skipped on those builds
(currently this is `Py_TRACE_REFS`, but that may change.)
- `Py_LIMITED_API` must be defined before `<Python.h>` is included.
This puts the hoop-jumping in `testcapi/parts.h`, so individual
test files can be relatively simple. (Currently that's only
`vectorcall_limited.c`, imagine more.)
Diffstat (limited to 'Modules/_testcapi/parts.h')
-rw-r--r-- | Modules/_testcapi/parts.h | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h index a76ddd9..304e592 100644 --- a/Modules/_testcapi/parts.h +++ b/Modules/_testcapi/parts.h @@ -1,9 +1,36 @@ -#include "Python.h" +#ifndef Py_TESTCAPI_PARTS_H +#define Py_TESTCAPI_PARTS_H + +#include "pyconfig.h" // for Py_TRACE_REFS + +// Figure out if Limited API is available for this build. If it isn't we won't +// build tests for it. +// Currently, only Py_TRACE_REFS disables Limited API. +#ifdef Py_TRACE_REFS +#undef LIMITED_API_AVAILABLE +#else +#define LIMITED_API_AVAILABLE 1 +#endif -/* Always enable assertions */ +// Always enable assertions #undef NDEBUG +#if !defined(LIMITED_API_AVAILABLE) && defined(Py_LIMITED_API) +// Limited API being unavailable means that with Py_LIMITED_API defined +// we can't even include Python.h. +// Do nothing; the .c file that defined Py_LIMITED_API should also do nothing. + +#else + +#include "Python.h" + int _PyTestCapi_Init_Vectorcall(PyObject *module); -int _PyTestCapi_Init_VectorcallLimited(PyObject *module); int _PyTestCapi_Init_Heaptype(PyObject *module); int _PyTestCapi_Init_Unicode(PyObject *module); + +#ifdef LIMITED_API_AVAILABLE +int _PyTestCapi_Init_VectorcallLimited(PyObject *module); +#endif // LIMITED_API_AVAILABLE + +#endif +#endif // Py_TESTCAPI_PARTS_H |