Commit cbbd9277 authored by Xavier Thompson's avatar Xavier Thompson

Allow casts from CyObject to PyObject

parent 9562d461
......@@ -3960,6 +3960,7 @@ class CypClassType(CppClassType):
# _mro [CppClassType] or None The Method Resolution Order of this cypclass according to Python
is_cyp_class = 1
to_py_function = "__Pyx_PyObject_FromCyObject"
def __init__(self, name, scope, cname, base_classes, templates=None, template_type=None, nogil=0, lock_mode=None, activable=False):
CppClassType.__init__(self, name, scope, cname, base_classes, templates, template_type, nogil)
......
......@@ -159,6 +159,25 @@
return op->CyObject_TRYWLOCK();
}
/*
* Cast from PyObject to CyObject:
* - borrow an atomic reference
* - return a new Python reference
*
* Note: an optimisation could be to steal a reference but only decrement
* when Python already has a reference, because calls to this function
* 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) {
// artificial atomic increment the first time Python gets a reference
if (ob->ob_refcnt == 0)
ob->CyObject_INCREF();
// return a new Python reference
Py_INCREF((PyObject *)ob);
return (PyObject *)ob;
}
/* Cast argument to CyObject* type. */
#define _CyObject_CAST(op) op
......
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