File tree 6 files changed +69
-1
lines changed
Filter options
6 files changed +69
-1
lines changed
Original file line number Diff line number Diff line change
1
+ import unittest
2
+ from test .support import import_helper
3
+
4
+ _testcapi = import_helper .import_module ('_testcapi' )
5
+
6
+
7
+ class TestCAPI (unittest .TestCase ):
8
+ def test_immortal_builtins (self ):
9
+ _testcapi .test_immortal_builtins ()
10
+
11
+ def test_immortal_small_ints (self ):
12
+ _testcapi .test_immortal_small_ints ()
13
+
14
+
15
+ if __name__ == "__main__" :
16
+ unittest .main ()
Original file line number Diff line number Diff line change 169
169
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
170
170
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
171
171
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c
172
- @MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/unicode.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/pyos.c
172
+ @MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/unicode.c _testcapi/getargs.c _testcapi/pytime.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/pyos.c _testcapi/immortal.c
173
173
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
174
174
175
175
# Some testing modules MUST be built as shared libraries.
Original file line number Diff line number Diff line change
1
+ #include "parts.h"
2
+
3
+ int verify_immortality (PyObject * object )
4
+ {
5
+ assert (_Py_IsImmortal (object ));
6
+ Py_ssize_t old_count = Py_REFCNT (object );
7
+ for (int j = 0 ; j < 10000 ; j ++ ) {
8
+ Py_DECREF (object );
9
+ }
10
+ Py_ssize_t current_count = Py_REFCNT (object );
11
+ return old_count == current_count ;
12
+ }
13
+
14
+ static PyObject *
15
+ test_immortal_builtins (PyObject * self , PyObject * Py_UNUSED (ignored ))
16
+ {
17
+ PyObject * objects [] = {Py_True , Py_False , Py_None , Py_Ellipsis };
18
+ Py_ssize_t n = Py_ARRAY_LENGTH (objects );
19
+ for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
20
+ assert (verify_immortality (objects [i ]));
21
+ }
22
+ Py_RETURN_NONE ;
23
+ }
24
+
25
+ static PyObject *
26
+ test_immortal_small_ints (PyObject * self , PyObject * Py_UNUSED (ignored ))
27
+ {
28
+ for (int i = -5 ; i <= 256 ; i ++ ) {
29
+ assert (verify_immortality (PyLong_FromLong (i )));
30
+ }
31
+ Py_RETURN_NONE ;
32
+ }
33
+
34
+ static PyMethodDef test_methods [] = {
35
+ {"test_immortal_builtins" , test_immortal_builtins , METH_NOARGS },
36
+ {"test_immortal_small_ints" , test_immortal_small_ints , METH_NOARGS },
37
+ {NULL },
38
+ };
39
+
40
+ int
41
+ _PyTestCapi_Init_Immortal (PyObject * mod )
42
+ {
43
+ if (PyModule_AddFunctions (mod , test_methods ) < 0 ) {
44
+ return -1 ;
45
+ }
46
+ return 0 ;
47
+ }
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ int _PyTestCapi_Init_Structmember(PyObject *module);
39
39
int _PyTestCapi_Init_Exceptions (PyObject * module );
40
40
int _PyTestCapi_Init_Code (PyObject * module );
41
41
int _PyTestCapi_Init_PyOS (PyObject * module );
42
+ int _PyTestCapi_Init_Immortal (PyObject * module );
42
43
43
44
#ifdef LIMITED_API_AVAILABLE
44
45
int _PyTestCapi_Init_VectorcallLimited (PyObject * module );
Original file line number Diff line number Diff line change @@ -4313,6 +4313,9 @@ PyInit__testcapi(void)
4313
4313
if (_PyTestCapi_Init_PyOS (m ) < 0 ) {
4314
4314
return NULL ;
4315
4315
}
4316
+ if (_PyTestCapi_Init_Immortal (m ) < 0 ) {
4317
+ return NULL ;
4318
+ }
4316
4319
4317
4320
#ifndef LIMITED_API_AVAILABLE
4318
4321
PyModule_AddObjectRef (m , "LIMITED_API_AVAILABLE" , Py_False );
Original file line number Diff line number Diff line change 110
110
<ClCompile Include =" ..\Modules\_testcapi\exceptions.c" />
111
111
<ClCompile Include =" ..\Modules\_testcapi\code.c" />
112
112
<ClCompile Include =" ..\Modules\_testcapi\pyos.c" />
113
+ <ClCompile Include =" ..\Modules\_testcapi\immortal.c" />
113
114
</ItemGroup >
114
115
<ItemGroup >
115
116
<ResourceCompile Include =" ..\PC\python_nt.rc" />
You can’t perform that action at this time.
0 commit comments