Commit 7a1213a3 authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Fix temp variable handling for the super() class cell. (GH-3289)

Closes GH-3246.
parent bfcaf163
......@@ -9136,9 +9136,8 @@ class ClassCellInjectorNode(ExprNode):
def analyse_expressions(self, env):
return self
def generate_evaluation_code(self, code):
if self.is_active:
self.allocate_temp_result(code)
def generate_result_code(self, code):
assert self.is_active
code.putln(
'%s = PyList_New(0); %s' % (
self.result(),
......@@ -9146,7 +9145,7 @@ class ClassCellInjectorNode(ExprNode):
code.put_gotref(self.result())
def generate_injection_code(self, code, classobj_cname):
if self.is_active:
assert self.is_active
code.globalstate.use_utility_code(
UtilityCode.load_cached("CyFunctionClassCell", "CythonFunction.c"))
code.put_error_if_neg(self.pos, '__Pyx_CyFunction_InitClassCell(%s, %s)' % (
......
......@@ -4596,12 +4596,22 @@ class PyClassDefNode(ClassDefNode):
self.metaclass.generate_evaluation_code(code)
self.dict.generate_evaluation_code(code)
cenv.namespace_cname = cenv.class_obj_cname = self.dict.result()
self.class_cell.generate_evaluation_code(code)
class_cell = self.class_cell
if class_cell is not None and not class_cell.is_active:
class_cell = None
if class_cell is not None:
class_cell.generate_evaluation_code(code)
self.body.generate_execution_code(code)
self.class_result.generate_evaluation_code(code)
self.class_cell.generate_injection_code(
if class_cell is not None:
class_cell.generate_injection_code(
code, self.class_result.result())
self.class_cell.generate_disposal_code(code)
if class_cell is not None:
class_cell.generate_disposal_code(code)
class_cell.free_temps(code)
cenv.namespace_cname = cenv.class_obj_cname = self.classobj.result()
self.target.generate_assignment_code(self.class_result, code)
self.dict.generate_disposal_code(code)
......
# mode: run
# tag: py3k_super
# tag: py3k_super, gh3246
class A(object):
def method(self):
......@@ -89,3 +89,21 @@ cdef class CClassSub(CClassBase):
# return super().method_cp()
# cdef method_c(self):
# return super().method_c()
def freeing_class_cell_temp_gh3246():
# https://github.com/cython/cython/issues/3246
"""
>>> abc = freeing_class_cell_temp_gh3246()
>>> abc().a
1
"""
class SimpleBase(object):
def __init__(self):
self.a = 1
class ABC(SimpleBase):
def __init__(self):
super().__init__()
return ABC
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