diff options
author | Victor Stinner <vstinner@python.org> | 2024-03-11 10:28:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-11 10:28:16 (GMT) |
commit | 1cc02ca063f50b8c527fbdde9957b03c145c1575 (patch) | |
tree | 84cd4d2d13c8ca869749827d8f91d592e8a01ca2 /Modules | |
parent | d8712fa0c75ad5ea56543903fa45674ab47cc647 (diff) | |
download | cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.zip cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.tar.gz cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.tar.bz2 |
gh-116417: Move 4 limited C API test files to _testlimitedcapi (#116571)
Move the following files from Modules/_testcapi/ to
Modules/_testlimitedcapi/:
* bytearray.c
* bytes.c
* pyos.c
* sys.c
Changes:
* Replace PyBytes_AS_STRING() with PyBytes_AsString().
* Replace PyBytes_GET_SIZE() with PyBytes_Size().
* Update related test_capi tests.
* Copy Modules/_testcapi/util.h to Modules/_testlimitedcapi/util.h.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/Setup.stdlib.in | 4 | ||||
-rw-r--r-- | Modules/_testcapi/parts.h | 4 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 12 | ||||
-rw-r--r-- | Modules/_testlimitedcapi.c | 14 | ||||
-rw-r--r-- | Modules/_testlimitedcapi/bytearray.c (renamed from Modules/_testcapi/bytearray.c) | 0 | ||||
-rw-r--r-- | Modules/_testlimitedcapi/bytes.c (renamed from Modules/_testcapi/bytes.c) | 8 | ||||
-rw-r--r-- | Modules/_testlimitedcapi/parts.h | 6 | ||||
-rw-r--r-- | Modules/_testlimitedcapi/pyos.c (renamed from Modules/_testcapi/pyos.c) | 0 | ||||
-rw-r--r-- | Modules/_testlimitedcapi/sys.c (renamed from Modules/_testcapi/sys.c) | 0 | ||||
-rw-r--r-- | Modules/_testlimitedcapi/util.h | 33 |
10 files changed, 57 insertions, 24 deletions
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index e8eaafd..deada66 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -162,8 +162,8 @@ @MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c @MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c @MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c -@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/bytearray.c _testcapi/bytes.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/pyos.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/sys.c _testcapi/hash.c _testcapi/time.c -@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/heaptype_relative.c +@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c +@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/pyos.c _testlimitedcapi/sys.c _testlimitedcapi/vectorcall_limited.c @MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c @MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h index 2a043cf..f9bdd83 100644 --- a/Modules/_testcapi/parts.h +++ b/Modules/_testcapi/parts.h @@ -31,8 +31,6 @@ int _PyTestCapi_Init_Vectorcall(PyObject *module); int _PyTestCapi_Init_Heaptype(PyObject *module); int _PyTestCapi_Init_Abstract(PyObject *module); -int _PyTestCapi_Init_ByteArray(PyObject *module); -int _PyTestCapi_Init_Bytes(PyObject *module); int _PyTestCapi_Init_Unicode(PyObject *module); int _PyTestCapi_Init_GetArgs(PyObject *module); int _PyTestCapi_Init_DateTime(PyObject *module); @@ -52,12 +50,10 @@ int _PyTestCapi_Init_Exceptions(PyObject *module); int _PyTestCapi_Init_Code(PyObject *module); int _PyTestCapi_Init_Buffer(PyObject *module); int _PyTestCapi_Init_PyAtomic(PyObject *module); -int _PyTestCapi_Init_PyOS(PyObject *module); int _PyTestCapi_Init_File(PyObject *module); int _PyTestCapi_Init_Codec(PyObject *module); int _PyTestCapi_Init_Immortal(PyObject *module); int _PyTestCapi_Init_GC(PyObject *module); -int _PyTestCapi_Init_Sys(PyObject *module); int _PyTestCapi_Init_Hash(PyObject *module); int _PyTestCapi_Init_Time(PyObject *module); diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index b653604..b5e646f 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4017,12 +4017,6 @@ PyInit__testcapi(void) if (_PyTestCapi_Init_Abstract(m) < 0) { return NULL; } - if (_PyTestCapi_Init_ByteArray(m) < 0) { - return NULL; - } - if (_PyTestCapi_Init_Bytes(m) < 0) { - return NULL; - } if (_PyTestCapi_Init_Unicode(m) < 0) { return NULL; } @@ -4077,18 +4071,12 @@ PyInit__testcapi(void) if (_PyTestCapi_Init_Buffer(m) < 0) { return NULL; } - if (_PyTestCapi_Init_PyOS(m) < 0) { - return NULL; - } if (_PyTestCapi_Init_File(m) < 0) { return NULL; } if (_PyTestCapi_Init_Codec(m) < 0) { return NULL; } - if (_PyTestCapi_Init_Sys(m) < 0) { - return NULL; - } if (_PyTestCapi_Init_Immortal(m) < 0) { return NULL; } diff --git a/Modules/_testlimitedcapi.c b/Modules/_testlimitedcapi.c index da09e3f..49bf6a3 100644 --- a/Modules/_testlimitedcapi.c +++ b/Modules/_testlimitedcapi.c @@ -26,11 +26,23 @@ PyInit__testlimitedcapi(void) return NULL; } - if (_PyTestCapi_Init_VectorcallLimited(mod) < 0) { + if (_PyTestCapi_Init_ByteArray(mod) < 0) { + return NULL; + } + if (_PyTestCapi_Init_Bytes(mod) < 0) { return NULL; } if (_PyTestCapi_Init_HeaptypeRelative(mod) < 0) { return NULL; } + if (_PyTestCapi_Init_PyOS(mod) < 0) { + return NULL; + } + if (_PyTestCapi_Init_Sys(mod) < 0) { + return NULL; + } + if (_PyTestCapi_Init_VectorcallLimited(mod) < 0) { + return NULL; + } return mod; } diff --git a/Modules/_testcapi/bytearray.c b/Modules/_testlimitedcapi/bytearray.c index dc47ed2..dc47ed2 100644 --- a/Modules/_testcapi/bytearray.c +++ b/Modules/_testlimitedcapi/bytearray.c diff --git a/Modules/_testcapi/bytes.c b/Modules/_testlimitedcapi/bytes.c index da10503..a14c4f9 100644 --- a/Modules/_testcapi/bytes.c +++ b/Modules/_testlimitedcapi/bytes.c @@ -160,8 +160,8 @@ bytes_concat(PyObject *Py_UNUSED(module), PyObject *args) if (new) { assert(left != NULL); assert(PyBytes_CheckExact(left)); - left = PyBytes_FromStringAndSize(PyBytes_AS_STRING(left), - PyBytes_GET_SIZE(left)); + left = PyBytes_FromStringAndSize(PyBytes_AsString(left), + PyBytes_Size(left)); if (left == NULL) { return NULL; } @@ -191,8 +191,8 @@ bytes_concatanddel(PyObject *Py_UNUSED(module), PyObject *args) if (new) { assert(left != NULL); assert(PyBytes_CheckExact(left)); - left = PyBytes_FromStringAndSize(PyBytes_AS_STRING(left), - PyBytes_GET_SIZE(left)); + left = PyBytes_FromStringAndSize(PyBytes_AsString(left), + PyBytes_Size(left)); if (left == NULL) { return NULL; } diff --git a/Modules/_testlimitedcapi/parts.h b/Modules/_testlimitedcapi/parts.h index 83590a7..039576d 100644 --- a/Modules/_testlimitedcapi/parts.h +++ b/Modules/_testlimitedcapi/parts.h @@ -21,7 +21,11 @@ # error "Py_BUILD_CORE macro must not be defined" #endif -int _PyTestCapi_Init_VectorcallLimited(PyObject *module); +int _PyTestCapi_Init_ByteArray(PyObject *module); +int _PyTestCapi_Init_Bytes(PyObject *module); int _PyTestCapi_Init_HeaptypeRelative(PyObject *module); +int _PyTestCapi_Init_PyOS(PyObject *module); +int _PyTestCapi_Init_Sys(PyObject *module); +int _PyTestCapi_Init_VectorcallLimited(PyObject *module); #endif // Py_TESTLIMITEDCAPI_PARTS_H diff --git a/Modules/_testcapi/pyos.c b/Modules/_testlimitedcapi/pyos.c index 63140e9..63140e9 100644 --- a/Modules/_testcapi/pyos.c +++ b/Modules/_testlimitedcapi/pyos.c diff --git a/Modules/_testcapi/sys.c b/Modules/_testlimitedcapi/sys.c index aa40e3c..aa40e3c 100644 --- a/Modules/_testcapi/sys.c +++ b/Modules/_testlimitedcapi/sys.c diff --git a/Modules/_testlimitedcapi/util.h b/Modules/_testlimitedcapi/util.h new file mode 100644 index 0000000..f26d765 --- /dev/null +++ b/Modules/_testlimitedcapi/util.h @@ -0,0 +1,33 @@ +#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) + +/* Marker to check that pointer value was set. */ +static const char uninitialized[] = "uninitialized"; +#define UNINITIALIZED_PTR ((void *)uninitialized) +/* Marker to check that Py_ssize_t value was set. */ +#define UNINITIALIZED_SIZE ((Py_ssize_t)236892191) +/* Marker to check that integer value was set. */ +#define UNINITIALIZED_INT (63256717) |