From a0a851b2f68ee37818e89d09b6de7ddf05c2d606 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 18 Nov 2010 21:40:33 +0100 Subject: [PATCH] minor code cleanups for metaclass patch --- Cython/Compiler/ExprNodes.py | 27 ++++----------------------- Cython/Compiler/Nodes.py | 2 +- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 2f45f1fa..9e4e4118 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -4593,14 +4593,14 @@ class Py3ClassNode(ExprNode): def analyse_types(self, env): self.type = py_object_type self.is_temp = 1 - env.use_utility_code(create_py3class_utility_code); def may_be_none(self): return True - gil_message = "Constructing Python3+ class" + gil_message = "Constructing Python class" def generate_result_code(self, code): + code.globalstate.use_utility_code(create_py3class_utility_code) cname = code.intern_identifier(self.name) code.putln( '%s = __Pyx_Py3ClassCreate(%s, %s, %s, %s, %s); %s' % ( @@ -4643,38 +4643,19 @@ class KeywordArgsNode(ExprNode): if self.keyword_args: code.putln("%s = %s;" % (self.result(), self.keyword_args.result())) code.put_incref(self.keyword_args.result(), self.keyword_args.ctype()) - code.put_giveref(self.keyword_args.result()) elif self.starstar_arg: code.putln( "%s = PyDict_Copy(%s); %s" % ( self.result(), self.starstar_arg.py_result(), code.error_goto_if_null(self.result(), self.pos))) + code.put_gotref(self.py_result()) else: code.putln( "%s = PyDict_New(); %s" % ( self.result(), code.error_goto_if_null(self.result(), self.pos))) - code.put_gotref(self.py_result()) - -class PyClassBasesNode(ExprNode): - # Helper class that holds bases for python3 class - # Actually hack to make `bases` visible across other nondes - # - # bases ExprNode Base class tuple - - subexprs = ['bases'] - type = py_object_type - is_temp = True - - def analyse_types(self, env): - self.bases.analyse_types(env) - - def generate_result_code(self, code): - code.putln("%s = %s;" % (self.result(), self.bases.result())) - code.put_incref(self.bases.result(), self.bases.ctype()) - code.put_giveref(self.bases.result()) - code.put_gotref(self.py_result()) + code.put_gotref(self.py_result()) class PyClassMetaclassNode(ExprNode): # Helper class holds Python3 metaclass object diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 64aac10f..17a28f7f 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2958,7 +2958,7 @@ class PyClassDefNode(ClassDefNode): doc_node = None if keyword_args or starstar_arg: self.py3_style_class = True - self.bases = ExprNodes.PyClassBasesNode(pos, bases = bases) + self.bases = bases self.mkw = ExprNodes.KeywordArgsNode(pos, keyword_args = keyword_args, starstar_arg = starstar_arg) self.metaclass = ExprNodes.PyClassMetaclassNode(pos, mkw = self.mkw, bases = self.bases) -- 2.26.2