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,21 +9136,20 @@ class ClassCellInjectorNode(ExprNode): ...@@ -9136,21 +9136,20 @@ class ClassCellInjectorNode(ExprNode):
def analyse_expressions(self, env): def analyse_expressions(self, env):
return self return self
def generate_evaluation_code(self, code): def generate_result_code(self, code):
if self.is_active: assert self.is_active
self.allocate_temp_result(code) code.putln(
code.putln( '%s = PyList_New(0); %s' % (
'%s = PyList_New(0); %s' % ( self.result(),
self.result(), code.error_goto_if_null(self.result(), self.pos)))
code.error_goto_if_null(self.result(), self.pos))) code.put_gotref(self.result())
code.put_gotref(self.result())
def generate_injection_code(self, code, classobj_cname): def generate_injection_code(self, code, classobj_cname):
if self.is_active: assert self.is_active
code.globalstate.use_utility_code( code.globalstate.use_utility_code(
UtilityCode.load_cached("CyFunctionClassCell", "CythonFunction.c")) UtilityCode.load_cached("CyFunctionClassCell", "CythonFunction.c"))
code.put_error_if_neg(self.pos, '__Pyx_CyFunction_InitClassCell(%s, %s)' % ( code.put_error_if_neg(self.pos, '__Pyx_CyFunction_InitClassCell(%s, %s)' % (
self.result(), classobj_cname)) self.result(), classobj_cname))
class ClassCellNode(ExprNode): class ClassCellNode(ExprNode):
......
...@@ -4596,12 +4596,22 @@ class PyClassDefNode(ClassDefNode): ...@@ -4596,12 +4596,22 @@ class PyClassDefNode(ClassDefNode):
self.metaclass.generate_evaluation_code(code) self.metaclass.generate_evaluation_code(code)
self.dict.generate_evaluation_code(code) self.dict.generate_evaluation_code(code)
cenv.namespace_cname = cenv.class_obj_cname = self.dict.result() 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.body.generate_execution_code(code)
self.class_result.generate_evaluation_code(code) self.class_result.generate_evaluation_code(code)
self.class_cell.generate_injection_code( if class_cell is not None:
code, self.class_result.result()) class_cell.generate_injection_code(
self.class_cell.generate_disposal_code(code) code, self.class_result.result())
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() cenv.namespace_cname = cenv.class_obj_cname = self.classobj.result()
self.target.generate_assignment_code(self.class_result, code) self.target.generate_assignment_code(self.class_result, code)
self.dict.generate_disposal_code(code) self.dict.generate_disposal_code(code)
......
# mode: run # mode: run
# tag: py3k_super # tag: py3k_super, gh3246
class A(object): class A(object):
def method(self): def method(self):
...@@ -89,3 +89,21 @@ cdef class CClassSub(CClassBase): ...@@ -89,3 +89,21 @@ cdef class CClassSub(CClassBase):
# return super().method_cp() # return super().method_cp()
# cdef method_c(self): # cdef method_c(self):
# return super().method_c() # 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