Commit a560f42b authored by Xavier Thompson's avatar Xavier Thompson

Manage cypclass attributes properly in cdef class __new__ and __dealloc__

parent 76be6d8c
......@@ -1900,6 +1900,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
cpp_class_attrs = [entry for entry in scope.var_entries
if entry.type.is_cpp_class and not entry.type.is_cyp_class]
cyp_class_attrs = [entry for entry in scope.var_entries
if entry.type.is_cyp_class]
cinit_func_entry = scope.lookup_here("__cinit__")
if cinit_func_entry and not cinit_func_entry.is_special:
cinit_func_entry = None
......@@ -1932,7 +1935,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
need_self_cast = (type.vtabslot_cname or
(py_buffers or memoryview_slices or py_attrs) or
cpp_class_attrs)
cpp_class_attrs or cyp_class_attrs)
if need_self_cast:
code.putln("%s;" % scope.parent_type.declaration_code("p"))
if base_type:
......@@ -1994,6 +1997,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("new((void*)&(p->%s)) %s();" % (
entry.cname, entry.type.empty_declaration_code()))
for entry in cyp_class_attrs:
code.putln("p->%s = NULL;" % entry.cname)
for entry in py_attrs:
if entry.name == "__dict__":
needs_error_cleanup = True
......@@ -2060,7 +2066,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
cpp_class_attrs = [entry for entry in scope.var_entries
if entry.type.is_cpp_class and not entry.type.is_cyp_class]
if py_attrs or cpp_class_attrs or memoryview_slices or weakref_slot or dict_slot:
cyp_class_attrs = [entry for entry in scope.var_entries
if entry.type.is_cyp_class]
if py_attrs or cpp_class_attrs or cyp_class_attrs or memoryview_slices or weakref_slot or dict_slot:
self.generate_self_cast(scope, code)
if not is_final_type:
......@@ -2107,6 +2116,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
for entry in cpp_class_attrs:
code.putln("__Pyx_call_destructor(p->%s);" % entry.cname)
for entry in cyp_class_attrs:
code.putln("Cy_XDECREF(p->%s);" % entry.cname)
for entry in py_attrs:
code.put_xdecref_clear("p->%s" % entry.cname, entry.type, nanny=False,
clear_before_decref=True)
......
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