Commit 569bdff8 authored by Xavier Thompson's avatar Xavier Thompson

Give CyObject reference to PyObject wrapper instead of inheriting from PyObject

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