Commit 12c3cd84 authored by Xavier Thompson's avatar Xavier Thompson

Expose simple cypclass methods to Python

parent 32eacafa
......@@ -742,10 +742,14 @@ def generate_cyp_class_wrapper_definition(type, wrapper_entry, constructor_entry
# initialise PyObject fields
if is_new_return_type and type.wrapper_type:
objstruct_cname = type.wrapper_type.objstruct_cname
code.putln("if(self) {")
code.putln("self->ob_cypyobject = new CyPyObject(); // fow now") # % type.wrapper_type.objstruct_cname
code.putln("self->ob_cypyobject->ob_refcnt = 0;")
code.putln("self->ob_cypyobject->ob_type = %s;" % type.wrapper_type.typeptr_cname)
code.putln("%s * wrapper = new %s();" % (objstruct_cname, objstruct_cname))
code.putln("wrapper->nogil_cyobject = self;")
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("}")
if init_entry:
......
......@@ -589,9 +589,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("")
code.putln("/* PyTypeObject pointer declarations for all c classes */")
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:
self.generate_objstruct_definition(entry.type, code)
......@@ -601,6 +598,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_exttype_vtable_struct(entry, code)
self.generate_exttype_vtabptr_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):
typecode = globalstate['type_declarations']
......
......@@ -56,19 +56,13 @@
int trywlock();
};
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;
PyObject * cy_pyobject;
CyObject(): nogil_ob_refcnt(1) {}
virtual ~CyObject() {}
void CyObject_INCREF();
......@@ -177,7 +171,12 @@
* reference would mean that Cy_DECREF should not be called after this.
*/
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
if (ob->ob_refcnt == 0)
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