Commit 2e16a6e4 authored by Xavier Thompson's avatar Xavier Thompson

Switch to using Py_TYPE and Py_REFCNT macros

parent 4f0f0a00
...@@ -991,6 +991,6 @@ def generate_cypclass_wrapper_allocation(code, wrapper_type): ...@@ -991,6 +991,6 @@ def generate_cypclass_wrapper_allocation(code, wrapper_type):
objstruct_cname = wrapper_type.objstruct_cname objstruct_cname = wrapper_type.objstruct_cname
code.putln("if (self) {") code.putln("if (self) {")
code.putln("%s * wrapper = (%s *) self;" % (objstruct_cname, objstruct_cname)) code.putln("%s * wrapper = (%s *) self;" % (objstruct_cname, objstruct_cname))
code.putln("((PyObject *)wrapper)->ob_refcnt = 0;") code.putln("Py_REFCNT(wrapper) = 0;")
code.putln("((PyObject *)wrapper)->ob_type = %s;" % wrapper_type.typeptr_cname) code.putln("Py_TYPE(wrapper) = %s;" % wrapper_type.typeptr_cname)
code.putln("}") code.putln("}")
...@@ -186,7 +186,7 @@ ...@@ -186,7 +186,7 @@
} }
PyObject * ob = reinterpret_cast<PyObject *>(static_cast<CyPyObject *>(cy)); PyObject * ob = reinterpret_cast<PyObject *>(static_cast<CyPyObject *>(cy));
// artificial atomic increment the first time Python gets a reference // artificial atomic increment the first time Python gets a reference
if (ob->ob_refcnt == 0) if (Py_REFCNT(ob) == 0)
cy->CyObject_INCREF(); cy->CyObject_INCREF();
// return a new Python reference // return a new Python reference
Py_INCREF(ob); Py_INCREF(ob);
...@@ -208,8 +208,8 @@ ...@@ -208,8 +208,8 @@
template <typename U> template <typename U>
static inline U* __Pyx_PyObject_AsCyObject(PyObject * ob, PyTypeObject * type) { static inline U* __Pyx_PyObject_AsCyObject(PyObject * ob, PyTypeObject * type) {
// the PyObject is not of the expected type // the PyObject is not of the expected type
if ( !PyType_IsSubtype(ob->ob_type, type) ) { if ( !PyType_IsSubtype(Py_TYPE(ob), type) ) {
PyErr_Format(PyExc_TypeError, "Cannot convert PyObject %s to CyObject %s", ob->ob_type->tp_name, type->tp_name); PyErr_Format(PyExc_TypeError, "Cannot convert PyObject %s to CyObject %s", Py_TYPE(ob)->tp_name, type->tp_name);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment