Commit a505e7ef authored by Xavier Thompson's avatar Xavier Thompson

Check isolation only for non-sendable cypclass fields

parent f5984db3
...@@ -975,9 +975,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -975,9 +975,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
""" """
scope = entry.type.scope scope = entry.type.scope
all_cypclass_attrs = [e for e in scope.entries.values() check_cypclass_attrs = [
if e.type.is_cyp_class and not e.name == "this" e
and not e.is_type] for e in scope.entries.values()
if e.type.is_cyp_class and e.name != "this" and not e.is_type
and not e.type.is_qualified_cyp_class
]
# potential template # potential template
if entry.type.templates: if entry.type.templates:
templates_code = "template <typename %s>" % ", typename ".join(t.name for t in entry.type.templates) templates_code = "template <typename %s>" % ", typename ".join(t.name for t in entry.type.templates)
...@@ -987,9 +990,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -987,9 +990,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
namespace = entry.type.empty_declaration_code() namespace = entry.type.empty_declaration_code()
if templates_code: if templates_code:
code.putln(templates_code) code.putln(templates_code)
code.putln("int %s::CyObject_traverse(void *(*visit)(const CyObject *o, void *arg), void *arg) const" % namespace) code.putln("int %s::CyObject_traverse_iso(void *(*visit)(const CyObject *o, void *arg), void *arg) const" % namespace)
code.putln("{") code.putln("{")
for attr in all_cypclass_attrs: for attr in check_cypclass_attrs:
code.putln("if (void *ret = visit(this->%s, arg)) return (int) (intptr_t) ret;" % attr.cname) code.putln("if (void *ret = visit(this->%s, arg)) return (int) (intptr_t) ret;" % attr.cname)
code.putln("return 0;") code.putln("return 0;")
code.putln("}") code.putln("}")
...@@ -998,7 +1001,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -998,7 +1001,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(templates_code) code.putln(templates_code)
code.putln("int %s::CyObject_iso() const" % namespace) code.putln("int %s::CyObject_iso() const" % namespace)
code.putln("{") code.putln("{")
if all_cypclass_attrs: if check_cypclass_attrs:
code.putln("return __Pyx_CyObject_owning(this) == 1;") code.putln("return __Pyx_CyObject_owning(this) == 1;")
else: else:
code.putln("return this->CyObject_GETREF() == 1;") code.putln("return this->CyObject_GETREF() == 1;")
...@@ -1669,7 +1672,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1669,7 +1672,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Declare the method to check isolation # Declare the method to check isolation
code.putln("virtual int CyObject_iso() const;") code.putln("virtual int CyObject_iso() const;")
# Declare the traverse method # Declare the traverse method
code.putln("virtual int CyObject_traverse(void *(*visit)(const CyObject *o, void *arg), void *arg) const;") code.putln("virtual int CyObject_traverse_iso(void *(*visit)(const CyObject *o, void *arg), void *arg) const;")
if type.is_cyp_class and cypclass_attrs: if type.is_cyp_class and cypclass_attrs:
# Declaring a small destruction handler which will always try to Cy_XDECREF # Declaring a small destruction handler which will always try to Cy_XDECREF
......
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
virtual int CyObject_iso() const { virtual int CyObject_iso() const {
return this->nogil_ob_refcnt == 1; return this->nogil_ob_refcnt == 1;
} }
virtual int CyObject_traverse(void *(*visit)(const CyObject *o, void *arg), void *arg) const { virtual int CyObject_traverse_iso(void *(*visit)(const CyObject *o, void *arg), void *arg) const {
return 0; return 0;
} }
...@@ -524,11 +524,11 @@ ...@@ -524,11 +524,11 @@
root->__refcnt = root->CyObject_GETREF(); root->__refcnt = root->CyObject_GETREF();
/* Collect the reachable objects */ /* Collect the reachable objects */
for(current = root; current != NULL; current = current->__next) { for(current = root; current != NULL; current = current->__next) {
current->CyObject_traverse(__Pyx_CyObject_visit_collect, (void*)current); current->CyObject_traverse_iso(__Pyx_CyObject_visit_collect, (void*)current);
} }
/* Decref the reachable objects */ /* Decref the reachable objects */
for(current = root; current != NULL; current = current->__next) { for(current = root; current != NULL; current = current->__next) {
current->CyObject_traverse(__Pyx_CyObject_visit_decref, (void*)current); current->CyObject_traverse_iso(__Pyx_CyObject_visit_decref, (void*)current);
} }
/* Search for externally reachable object */ /* Search for externally reachable object */
for(current = root->__next; current != NULL; current = current->__next) { for(current = root->__next; current != NULL; current = current->__next) {
......
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