cpython/Modules/_testlimitedcapi.c
Victor Stinner 8bea6c411d
gh-115754: Add Py_GetConstant() function (#116883)
Add Py_GetConstant() and Py_GetConstantBorrowed() functions.

In the limited C API version 3.13, getting Py_None, Py_False,
Py_True, Py_Ellipsis and Py_NotImplemented singletons is now
implemented as function calls at the stable ABI level to hide
implementation details. Getting these constants still return borrowed
references.

Add _testlimitedcapi/object.c and test_capi/test_object.py to test
Py_GetConstant() and Py_GetConstantBorrowed() functions.
2024-03-21 16:07:00 +00:00

76 lines
1.8 KiB
C

/*
* Test the limited C API.
*
* The 'test_*' functions exported by this module are run as part of the
* standard Python regression test, via Lib/test/test_capi.py.
*/
#include "_testlimitedcapi/parts.h"
static PyMethodDef TestMethods[] = {
{NULL, NULL} /* sentinel */
};
static struct PyModuleDef _testlimitedcapimodule = {
PyModuleDef_HEAD_INIT,
.m_name = "_testlimitedcapi",
.m_size = 0,
.m_methods = TestMethods,
};
PyMODINIT_FUNC
PyInit__testlimitedcapi(void)
{
PyObject *mod = PyModule_Create(&_testlimitedcapimodule);
if (mod == NULL) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Abstract(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_ByteArray(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Bytes(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Complex(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Dict(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Float(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_HeaptypeRelative(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_List(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Long(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Object(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_PyOS(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Set(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Sys(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_Unicode(mod) < 0) {
return NULL;
}
if (_PyTestLimitedCAPI_Init_VectorcallLimited(mod) < 0) {
return NULL;
}
return mod;
}