@@ -1849,3 +1849,59 @@ PyInterpreterState *pybind11::non_limited_api::pybind11NLA_PyInterpreterState_Ge
18491849 return ::PyInterpreterState_Get ();
18501850 #endif
18511851}
1852+
1853+ int pybind11::non_limited_api::pybind11NLA_pybind11_traverse (PyObject *self, visitproc visit, void *arg)
1854+ {
1855+ #if PY_VERSION_HEX >= 0x030D0000
1856+ PyObject_VisitManagedDict (self, visit, arg);
1857+ #else
1858+ PyObject *&dict = *non_limited_api::_PyObject_GetDictPtr (self);
1859+ Py_VISIT (dict);
1860+ #endif
1861+ // https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_traverse
1862+ #if PY_VERSION_HEX >= 0x03090000
1863+ Py_VISIT (Py_TYPE (self));
1864+ #endif
1865+ return 0 ;
1866+ }
1867+
1868+ int pybind11::non_limited_api::pybind11NLA_pybind11_clear (PyObject *self)
1869+ {
1870+ #if PY_VERSION_HEX >= 0x030D0000
1871+ PyObject_ClearManagedDict (self);
1872+ #else
1873+ PyObject *&dict = *non_limited_api::_PyObject_GetDictPtr (self);
1874+ Py_CLEAR (dict);
1875+ #endif
1876+ return 0 ;
1877+ }
1878+
1879+ void pybind11::non_limited_api::pybind11NLA_globals (dict &out)
1880+ {
1881+ #if PY_VERSION_HEX >= 0x030d0000
1882+ PyObject *p = PyEval_GetFrameGlobals ();
1883+ out = p ? reinterpret_steal<dict>(p)
1884+ : reinterpret_borrow<dict>(module_::import (" __main__" ).attr (" __dict__" ).ptr ());
1885+ #else
1886+ PyObject *p = PyEval_GetGlobals ();
1887+ out = reinterpret_borrow<dict>(p ? p : module_::import (" __main__" ).attr (" __dict__" ).ptr ());
1888+ #endif
1889+ }
1890+
1891+ PyObject *pybind11::non_limited_api::pybind11NLA_dict_getitemstringref (PyObject *v, const char *key)
1892+ {
1893+ #if PY_VERSION_HEX >= 0x030D0000
1894+ PyObject *rv;
1895+ if (PyDict_GetItemStringRef (v, key, &rv) < 0 ) {
1896+ throw error_already_set ();
1897+ }
1898+ return rv;
1899+ #else
1900+ PyObject *rv = dict_getitemstring (v, key);
1901+ if (rv == nullptr && PyErr_Occurred ()) {
1902+ throw error_already_set ();
1903+ }
1904+ Py_XINCREF (rv);
1905+ return rv;
1906+ #endif
1907+ }
0 commit comments