@@ -485,6 +485,28 @@ is_uniquely_referenced(PyObject *self, PyObject *op)
485485}
486486
487487
488+ static PyObject *
489+ object_getdictptr (PyObject * self , PyObject * obj )
490+ {
491+ NULLABLE (obj );
492+
493+ PyObject * * dict_ptr = UNINITIALIZED_PTR ;
494+ switch (PyObject_GetDictPtr (obj , & dict_ptr )) {
495+ case -1 :
496+ assert (dict_ptr == NULL );
497+ return NULL ;
498+ case 0 :
499+ assert (dict_ptr == NULL );
500+ return Py_NewRef (PyExc_AttributeError );
501+ case 1 :
502+ return Py_NewRef (* dict_ptr );
503+ default :
504+ Py_FatalError ("PyObject_GetDictPtr() returned invalid code" );
505+ Py_UNREACHABLE ();
506+ }
507+ }
508+
509+
488510static PyMethodDef test_methods [] = {
489511 {"call_pyobject_print" , call_pyobject_print , METH_VARARGS },
490512 {"pyobject_print_null" , pyobject_print_null , METH_VARARGS },
@@ -511,6 +533,7 @@ static PyMethodDef test_methods[] = {
511533 {"test_py_is_funcs" , test_py_is_funcs , METH_NOARGS },
512534 {"clear_managed_dict" , clear_managed_dict , METH_O , NULL },
513535 {"is_uniquely_referenced" , is_uniquely_referenced , METH_O },
536+ {"object_getdictptr" , object_getdictptr , METH_O },
514537 {NULL },
515538};
516539
0 commit comments