@@ -4188,6 +4188,48 @@ test_pymem_alloc0(PyObject *self, PyObject *Py_UNUSED(ignored))
41884188 Py_RETURN_NONE ;
41894189}
41904190
4191+ static PyObject *
4192+ test_pymem_new (PyObject * self , PyObject * Py_UNUSED (ignored ))
4193+ {
4194+ char * ptr ;
4195+ PyTypeObject * type = & PyBaseObject_Type ;
4196+ PyTypeObject * var_type = & PyLong_Type ;
4197+
4198+ // PyObject_New()
4199+ ptr = PyObject_New (char , type );
4200+ if (ptr == NULL ) {
4201+ goto alloc_failed ;
4202+ }
4203+ PyObject_Free (ptr );
4204+
4205+ // PyObject_NEW()
4206+ ptr = PyObject_NEW (char , type );
4207+ if (ptr == NULL ) {
4208+ goto alloc_failed ;
4209+ }
4210+ PyObject_Free (ptr );
4211+
4212+ // PyObject_NewVar()
4213+ ptr = PyObject_NewVar (char , var_type , 3 );
4214+ if (ptr == NULL ) {
4215+ goto alloc_failed ;
4216+ }
4217+ PyObject_Free (ptr );
4218+
4219+ // PyObject_NEW_VAR()
4220+ ptr = PyObject_NEW_VAR (char , var_type , 3 );
4221+ if (ptr == NULL ) {
4222+ goto alloc_failed ;
4223+ }
4224+ PyObject_Free (ptr );
4225+
4226+ Py_RETURN_NONE ;
4227+
4228+ alloc_failed :
4229+ PyErr_NoMemory ();
4230+ return NULL ;
4231+ }
4232+
41914233typedef struct {
41924234 PyMemAllocatorEx alloc ;
41934235
@@ -6284,6 +6326,7 @@ static PyMethodDef TestMethods[] = {
62846326 {"with_tp_del" , with_tp_del , METH_VARARGS },
62856327 {"create_cfunction" , create_cfunction , METH_NOARGS },
62866328 {"test_pymem_alloc0" , test_pymem_alloc0 , METH_NOARGS },
6329+ {"test_pymem_new" , test_pymem_new , METH_NOARGS },
62876330 {"test_pymem_setrawallocators" ,test_pymem_setrawallocators , METH_NOARGS },
62886331 {"test_pymem_setallocators" ,test_pymem_setallocators , METH_NOARGS },
62896332 {"test_pyobject_setallocators" ,test_pyobject_setallocators , METH_NOARGS },
0 commit comments