@@ -4489,15 +4489,17 @@ test_pymem_getallocatorsname(PyObject *self, PyObject *args)
44894489
44904490
44914491static PyObject *
4492- pyobject_is_freed ( PyObject * self , PyObject * op )
4492+ test_pyobject_is_freed ( const char * test_name , PyObject * op )
44934493{
4494- int res = _PyObject_IsFreed (op );
4495- return PyBool_FromLong (res );
4494+ if (!_PyObject_IsFreed (op )) {
4495+ return raiseTestError (test_name , "object is not seen as freed" );
4496+ }
4497+ Py_RETURN_NONE ;
44964498}
44974499
44984500
44994501static PyObject *
4500- pyobject_uninitialized (PyObject * self , PyObject * args )
4502+ check_pyobject_uninitialized_is_freed (PyObject * self , PyObject * Py_UNUSED ( args ) )
45014503{
45024504 PyObject * op = (PyObject * )PyObject_Malloc (sizeof (PyObject ));
45034505 if (op == NULL ) {
@@ -4506,12 +4508,12 @@ pyobject_uninitialized(PyObject *self, PyObject *args)
45064508 /* Initialize reference count to avoid early crash in ceval or GC */
45074509 Py_REFCNT (op ) = 1 ;
45084510 /* object fields like ob_type are uninitialized! */
4509- return op ;
4511+ return test_pyobject_is_freed ( "check_pyobject_uninitialized_is_freed" , op ) ;
45104512}
45114513
45124514
45134515static PyObject *
4514- pyobject_forbidden_bytes (PyObject * self , PyObject * args )
4516+ check_pyobject_forbidden_bytes_is_freed (PyObject * self , PyObject * Py_UNUSED ( args ) )
45154517{
45164518 /* Allocate an incomplete PyObject structure: truncate 'ob_type' field */
45174519 PyObject * op = (PyObject * )PyObject_Malloc (offsetof(PyObject , ob_type ));
@@ -4522,12 +4524,12 @@ pyobject_forbidden_bytes(PyObject *self, PyObject *args)
45224524 Py_REFCNT (op ) = 1 ;
45234525 /* ob_type field is after the memory block: part of "forbidden bytes"
45244526 when using debug hooks on memory allocatrs! */
4525- return op ;
4527+ return test_pyobject_is_freed ( "check_pyobject_forbidden_bytes_is_freed" , op ) ;
45264528}
45274529
45284530
45294531static PyObject *
4530- pyobject_freed (PyObject * self , PyObject * args )
4532+ check_pyobject_freed_is_freed (PyObject * self , PyObject * Py_UNUSED ( args ) )
45314533{
45324534 PyObject * op = _PyObject_CallNoArg ((PyObject * )& PyBaseObject_Type );
45334535 if (op == NULL ) {
@@ -4537,7 +4539,7 @@ pyobject_freed(PyObject *self, PyObject *args)
45374539 /* Reset reference count to avoid early crash in ceval or GC */
45384540 Py_REFCNT (op ) = 1 ;
45394541 /* object memory is freed! */
4540- return op ;
4542+ return test_pyobject_is_freed ( "check_pyobject_freed_is_freed" , op ) ;
45414543}
45424544
45434545
@@ -5264,10 +5266,9 @@ static PyMethodDef TestMethods[] = {
52645266 {"pymem_api_misuse" , pymem_api_misuse , METH_NOARGS },
52655267 {"pymem_malloc_without_gil" , pymem_malloc_without_gil , METH_NOARGS },
52665268 {"pymem_getallocatorsname" , test_pymem_getallocatorsname , METH_NOARGS },
5267- {"pyobject_is_freed" , (PyCFunction )(void (* )(void ))pyobject_is_freed , METH_O },
5268- {"pyobject_uninitialized" , pyobject_uninitialized , METH_NOARGS },
5269- {"pyobject_forbidden_bytes" , pyobject_forbidden_bytes , METH_NOARGS },
5270- {"pyobject_freed" , pyobject_freed , METH_NOARGS },
5269+ {"check_pyobject_uninitialized_is_freed" , check_pyobject_uninitialized_is_freed , METH_NOARGS },
5270+ {"check_pyobject_forbidden_bytes_is_freed" , check_pyobject_forbidden_bytes_is_freed , METH_NOARGS },
5271+ {"check_pyobject_freed_is_freed" , check_pyobject_freed_is_freed , METH_NOARGS },
52715272 {"pyobject_malloc_without_gil" , pyobject_malloc_without_gil , METH_NOARGS },
52725273 {"tracemalloc_track" , tracemalloc_track , METH_VARARGS },
52735274 {"tracemalloc_untrack" , tracemalloc_untrack , METH_VARARGS },
0 commit comments