Commit 5c88de32 authored by Xavier Thompson's avatar Xavier Thompson

Give CyObject reference to PyObject wrapper instead of inheriting from PyObject

parent bfa737ac
......@@ -593,9 +593,9 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
# initialise PyObject fields
if (is_new_return_type):
code.putln("if(self) {")
code.putln("self->ob_refcnt = 0;")
# code.putln("self->ob_type = NULL;")
code.putln("self->ob_type = &%s;" % type.typeobj_cname)
code.putln("self->ob_cypyobject = new CyPyObject(); // for now")
code.putln("self->ob_cypyobject->ob_refcnt = 0;")
code.putln("self->ob_cypyobject->ob_type = &%s;" % type.typeobj_cname)
code.putln("}")
if init_entry:
......
......@@ -56,12 +56,19 @@
int trywlock();
};
class CyObject : public PyObject {
class CyObject;
struct CyPyObject : public PyObject {
CyObject * nogil_cyobject;
};
class CyObject {
private:
CyObject_ATOMIC_REFCOUNT_TYPE nogil_ob_refcnt;
//pthread_rwlock_t ob_lock;
RecursiveUpgradeableRWLock ob_lock;
public:
CyPyObject * ob_cypyobject;
CyObject(): nogil_ob_refcnt(1) {}
virtual ~CyObject() {}
void CyObject_INCREF();
......@@ -169,13 +176,14 @@
* are likely (certain even?) to be followed by a Cy_DECREF; stealing the
* reference would mean that Cy_DECREF should not be called after this.
*/
static inline PyObject* __Pyx_PyObject_FromCyObject(CyObject * ob) {
static inline PyObject* __Pyx_PyObject_FromCyObject(CyObject * cy) {
CyPyObject * ob = cy->ob_cypyobject;
// artificial atomic increment the first time Python gets a reference
if (ob->ob_refcnt == 0)
ob->CyObject_INCREF();
cy->CyObject_INCREF();
// return a new Python reference
Py_INCREF((PyObject *)ob);
return (PyObject *)ob;
Py_INCREF(ob);
return ob;
}
/* Cast argument to CyObject* type. */
......
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