Fix remaining uses of ._PyType member in extension code
This should be replaced with Dtool_GetPyTypeObject, hiding the implementation details a bit so that we can more easily change the underlying structure if we need later Also adds Py_NewRef to py_compat.h, backporting from master
This commit is contained in:
parent
df5f8d77da
commit
f47b34d2a1
|
|
@ -247,6 +247,28 @@ INLINE PyObject *PyObject_CallMethodOneArg(PyObject *obj, PyObject *name, PyObje
|
|||
}
|
||||
#endif
|
||||
|
||||
/* Python 3.10 */
|
||||
|
||||
#if PY_VERSION_HEX < 0x030A0000
|
||||
INLINE int PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value) {
|
||||
int ret = PyModule_AddObject(module, name, value);
|
||||
if (ret == 0) {
|
||||
Py_INCREF(value);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE PyObject *Py_NewRef(PyObject *obj) {
|
||||
Py_INCREF(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE PyObject *Py_XNewRef(PyObject *obj) {
|
||||
Py_XINCREF(obj);
|
||||
return obj;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Python 3.12 */
|
||||
|
||||
#if PY_VERSION_HEX < 0x030C0000
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ __reduce__() const {
|
|||
}
|
||||
|
||||
extern struct Dtool_PyTypedObject Dtool_Datagram;
|
||||
Py_INCREF((PyObject *)&Dtool_Datagram._PyType);
|
||||
PyObject *tp = (PyObject *)Dtool_GetPyTypeObject(&Dtool_Datagram);
|
||||
|
||||
PyObject *result = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(result, 0, (PyObject *)&Dtool_Datagram._PyType);
|
||||
PyTuple_SET_ITEM(result, 0, Py_NewRef(tp));
|
||||
PyTuple_SET_ITEM(result, 1, args);
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ __init__(PyObject *self, PyObject *source) {
|
|||
|
||||
// Now construct the internal list by copying the elements one-at-a-time
|
||||
// from Python.
|
||||
PyObject *dict = DtoolInstance_TYPE(self)->_PyType.tp_dict;
|
||||
PyObject *dict = Dtool_GetPyTypeObject(DtoolInstance_TYPE(self))->tp_dict;
|
||||
PyObject *push_back = PyDict_GetItemString(dict, "push_back");
|
||||
if (push_back == nullptr) {
|
||||
PyErr_BadArgument();
|
||||
|
|
|
|||
Loading…
Reference in New Issue