Commit 489fcbd3 authored by Xavier Thompson's avatar Xavier Thompson Committed by Xavier Thompson

Fix cypclass initialization after __new__ returns NULL

parent bcbfa073
......@@ -1302,6 +1302,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
)
if init_entry and is_new_return_type:
code.putln("if (self) {")
# Calling __init__
......@@ -1384,6 +1385,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
init_arg_string = ','.join(arg_names)
code.putln("self->%s(%s);" % (init_entry.cname, init_arg_string))
code.putln("}")
code.putln("return self;")
code.putln("}")
......
......@@ -109,3 +109,29 @@ def test_new_args_unpacking():
print obj1.b
print obj2.a
print obj2.b
cdef cypclass NullNew:
int a
NullNew __new__(alloc, int a):
if a < 0:
with gil:
print("nil")
return NULL
return alloc()
__init__(self, int a):
with gil:
print(a)
self.a = a
def test_null_new():
"""
>>> test_null_new()
nil
1
"""
cdef NullNew nil = NullNew(-1)
cdef NullNew one = NullNew(1)
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