@@ -4489,15 +4489,17 @@ test_pymem_getallocatorsname(PyObject *self, PyObject *args)
4489
4489
4490
4490
4491
4491
static PyObject *
4492
- pyobject_is_freed ( PyObject * self , PyObject * op )
4492
+ test_pyobject_is_freed ( const char * test_name , PyObject * op )
4493
4493
{
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 ;
4496
4498
}
4497
4499
4498
4500
4499
4501
static PyObject *
4500
- pyobject_uninitialized (PyObject * self , PyObject * args )
4502
+ check_pyobject_uninitialized_is_freed (PyObject * self , PyObject * Py_UNUSED ( args ) )
4501
4503
{
4502
4504
PyObject * op = (PyObject * )PyObject_Malloc (sizeof (PyObject ));
4503
4505
if (op == NULL ) {
@@ -4506,12 +4508,12 @@ pyobject_uninitialized(PyObject *self, PyObject *args)
4506
4508
/* Initialize reference count to avoid early crash in ceval or GC */
4507
4509
Py_REFCNT (op ) = 1 ;
4508
4510
/* object fields like ob_type are uninitialized! */
4509
- return op ;
4511
+ return test_pyobject_is_freed ( "check_pyobject_uninitialized_is_freed" , op ) ;
4510
4512
}
4511
4513
4512
4514
4513
4515
static PyObject *
4514
- pyobject_forbidden_bytes (PyObject * self , PyObject * args )
4516
+ check_pyobject_forbidden_bytes_is_freed (PyObject * self , PyObject * Py_UNUSED ( args ) )
4515
4517
{
4516
4518
/* Allocate an incomplete PyObject structure: truncate 'ob_type' field */
4517
4519
PyObject * op = (PyObject * )PyObject_Malloc (offsetof(PyObject , ob_type ));
@@ -4522,12 +4524,12 @@ pyobject_forbidden_bytes(PyObject *self, PyObject *args)
4522
4524
Py_REFCNT (op ) = 1 ;
4523
4525
/* ob_type field is after the memory block: part of "forbidden bytes"
4524
4526
when using debug hooks on memory allocatrs! */
4525
- return op ;
4527
+ return test_pyobject_is_freed ( "check_pyobject_forbidden_bytes_is_freed" , op ) ;
4526
4528
}
4527
4529
4528
4530
4529
4531
static PyObject *
4530
- pyobject_freed (PyObject * self , PyObject * args )
4532
+ check_pyobject_freed_is_freed (PyObject * self , PyObject * Py_UNUSED ( args ) )
4531
4533
{
4532
4534
PyObject * op = _PyObject_CallNoArg ((PyObject * )& PyBaseObject_Type );
4533
4535
if (op == NULL ) {
@@ -4537,7 +4539,7 @@ pyobject_freed(PyObject *self, PyObject *args)
4537
4539
/* Reset reference count to avoid early crash in ceval or GC */
4538
4540
Py_REFCNT (op ) = 1 ;
4539
4541
/* object memory is freed! */
4540
- return op ;
4542
+ return test_pyobject_is_freed ( "check_pyobject_freed_is_freed" , op ) ;
4541
4543
}
4542
4544
4543
4545
@@ -5264,10 +5266,9 @@ static PyMethodDef TestMethods[] = {
5264
5266
{"pymem_api_misuse" , pymem_api_misuse , METH_NOARGS },
5265
5267
{"pymem_malloc_without_gil" , pymem_malloc_without_gil , METH_NOARGS },
5266
5268
{"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 },
5271
5272
{"pyobject_malloc_without_gil" , pyobject_malloc_without_gil , METH_NOARGS },
5272
5273
{"tracemalloc_track" , tracemalloc_track , METH_VARARGS },
5273
5274
{"tracemalloc_untrack" , tracemalloc_untrack , METH_VARARGS },
0 commit comments