Commit cd7afe2a authored by Xavier Thompson's avatar Xavier Thompson

Expose simple cypclass methods to Python

parent f401af05
...@@ -742,10 +742,14 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry ...@@ -742,10 +742,14 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
# initialise PyObject fields # initialise PyObject fields
if is_new_return_type and type.wrapper_type: if is_new_return_type and type.wrapper_type:
objstruct_cname = type.wrapper_type.objstruct_cname
code.putln("if(self) {") code.putln("if(self) {")
code.putln("self->ob_cypyobject = new CyPyObject(); // fow now") # % type.wrapper_type.objstruct_cname code.putln("%s * wrapper = new %s();" % (objstruct_cname, objstruct_cname))
code.putln("self->ob_cypyobject->ob_refcnt = 0;") code.putln("wrapper->nogil_cyobject = self;")
code.putln("self->ob_cypyobject->ob_type = %s;" % type.wrapper_type.typeptr_cname) code.putln("PyObject * wrapper_as_py = (PyObject *) wrapper;")
code.putln("wrapper_as_py->ob_refcnt = 0;")
code.putln("wrapper_as_py->ob_type = %s;" % type.wrapper_type.typeptr_cname)
code.putln("self->cy_pyobject = wrapper_as_py;")
code.putln("}") code.putln("}")
if init_entry: if init_entry:
......
...@@ -589,9 +589,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -589,9 +589,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("") code.putln("")
code.putln("/* PyTypeObject pointer declarations for all c classes */") code.putln("/* PyTypeObject pointer declarations for all c classes */")
self.generate_c_class_declarations(module, code, definition) self.generate_c_class_declarations(module, code, definition)
code.putln("")
code.putln("/* Deferred definitions for cypclasses */")
CypclassWrapper.generate_cyp_class_deferred_definitions(env, code, definition)
for entry in vtabslot_list: for entry in vtabslot_list:
self.generate_objstruct_definition(entry.type, code) self.generate_objstruct_definition(entry.type, code)
...@@ -602,6 +599,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -602,6 +599,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_exttype_vtabptr_declaration(entry, code) self.generate_exttype_vtabptr_declaration(entry, code)
self.generate_exttype_final_methods_declaration(entry, code) self.generate_exttype_final_methods_declaration(entry, code)
for module in modules:
definition = module is env
code.putln("")
code.putln("/* Deferred definitions for cypclasses */")
CypclassWrapper.generate_cyp_class_deferred_definitions(env, code, definition)
def generate_declarations_for_modules(self, env, modules, globalstate): def generate_declarations_for_modules(self, env, modules, globalstate):
typecode = globalstate['type_declarations'] typecode = globalstate['type_declarations']
typecode.putln("") typecode.putln("")
......
...@@ -56,19 +56,13 @@ ...@@ -56,19 +56,13 @@
int trywlock(); int trywlock();
}; };
class CyObject;
struct CyPyObject : public PyObject {
CyObject * nogil_cyobject;
};
class 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; PyObject * cy_pyobject;
CyObject(): nogil_ob_refcnt(1) {} CyObject(): nogil_ob_refcnt(1) {}
virtual ~CyObject() {} virtual ~CyObject() {}
void CyObject_INCREF(); void CyObject_INCREF();
...@@ -177,7 +171,12 @@ ...@@ -177,7 +171,12 @@
* 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 * cy) { static inline PyObject* __Pyx_PyObject_FromCyObject(CyObject * cy) {
CyPyObject * ob = cy->ob_cypyobject; // convert NULL to None
if (cy == NULL) {
Py_INCREF(Py_None);
return Py_None;
}
PyObject * ob = cy->cy_pyobject;
// 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)
cy->CyObject_INCREF(); cy->CyObject_INCREF();
......
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