mirror of
https://github.com/python/cpython.git
synced 2025-08-14 22:01:08 +00:00
[3.12] gh-127906: Backport test_cppext changes from the main branch (#127915)
This commit is contained in:
parent
c77bfd768f
commit
6544f99463
3 changed files with 99 additions and 42 deletions
|
@ -8,10 +8,8 @@
|
|||
|
||||
#include "Python.h"
|
||||
|
||||
#if __cplusplus >= 201103
|
||||
# define NAME _testcpp11ext
|
||||
#else
|
||||
# define NAME _testcpp03ext
|
||||
#ifndef MODULE_NAME
|
||||
# error "MODULE_NAME macro must be defined"
|
||||
#endif
|
||||
|
||||
#define _STR(NAME) #NAME
|
||||
|
@ -160,7 +158,7 @@ PyType_Slot VirtualPyObject_Slots[] = {
|
|||
};
|
||||
|
||||
PyType_Spec VirtualPyObject_Spec = {
|
||||
/* .name */ STR(NAME) ".VirtualPyObject",
|
||||
/* .name */ STR(MODULE_NAME) ".VirtualPyObject",
|
||||
/* .basicsize */ sizeof(VirtualPyObject),
|
||||
/* .itemsize */ 0,
|
||||
/* .flags */ Py_TPFLAGS_DEFAULT,
|
||||
|
@ -227,6 +225,10 @@ _testcppext_exec(PyObject *module)
|
|||
if (!result) return -1;
|
||||
Py_DECREF(result);
|
||||
|
||||
// test Py_BUILD_ASSERT() and Py_BUILD_ASSERT_EXPR()
|
||||
Py_BUILD_ASSERT(sizeof(int) == sizeof(unsigned int));
|
||||
assert(Py_BUILD_ASSERT_EXPR(sizeof(int) == sizeof(unsigned int)) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -240,7 +242,7 @@ PyDoc_STRVAR(_testcppext_doc, "C++ test extension.");
|
|||
|
||||
static struct PyModuleDef _testcppext_module = {
|
||||
PyModuleDef_HEAD_INIT, // m_base
|
||||
STR(NAME), // m_name
|
||||
STR(MODULE_NAME), // m_name
|
||||
_testcppext_doc, // m_doc
|
||||
0, // m_size
|
||||
_testcppext_methods, // m_methods
|
||||
|
@ -254,7 +256,7 @@ static struct PyModuleDef _testcppext_module = {
|
|||
#define FUNC_NAME(NAME) _FUNC_NAME(NAME)
|
||||
|
||||
PyMODINIT_FUNC
|
||||
FUNC_NAME(NAME)(void)
|
||||
FUNC_NAME(MODULE_NAME)(void)
|
||||
{
|
||||
return PyModuleDef_Init(&_testcppext_module);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue