From 8ae1a3620c7e935d5a2c9c4c7759a8bab8360585 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Thu, 3 Apr 2008 22:07:13 -0700 Subject: [PATCH] Misc little fixes. Sage now builds and passes all tests. --- Cython/Compiler/Code.py | 4 ++-- Cython/Compiler/ExprNodes.py | 4 +++- Cython/Compiler/ModuleNode.py | 14 +++++++++----- Cython/Compiler/Nodes.py | 10 ++++++---- Cython/Compiler/Options.py | 2 +- Cython/Compiler/Parsing.py | 2 ++ Cython/Compiler/Symtab.py | 2 ++ 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 557a6043..c1f51de1 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -330,10 +330,10 @@ class CCodeWriter: lbl = self.error_label self.use_label(lbl) if Options.c_line_in_traceback: - cinfo = "%s = %s;" % (Naming.clineno_cname, Naming.line_c_macro) + cinfo = " %s = %s;" % (Naming.clineno_cname, Naming.line_c_macro) else: cinfo = "" - return "{%s = %s[%s]; %s = %s; %s goto %s;}" % ( + return "{%s = %s[%s]; %s = %s;%s goto %s;}" % ( Naming.filename_cname, Naming.filetable_cname, self.lookup_filename(pos[0]), diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 57c8a300..bec4b826 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2361,7 +2361,9 @@ class ListComprehensionAppendNode(ExprNode): class DictNode(ExprNode): # Dictionary constructor. # - # key_value_pairs [(ExprNode, ExprNode)] + # key_value_pairs [DictItemNode] + + subexprs = ['key_value_pairs'] def compile_time_value(self, denv): pairs = [(item.key.compile_time_value(denv), item.value.compile_time_value(denv)) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 48740706..f0e59f9f 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -20,23 +20,27 @@ from PyrexTypes import py_object_type from Cython.Utils import open_new_file, replace_suffix -def recurse_vtab_check_inheritance(entry,b, dict): +def recurse_vtab_check_inheritance(entry, b, dict): base = entry while base is not None: if base.type.base_type is None or base.type.base_type.vtabstruct_cname is None: return False if base.type.base_type.vtabstruct_cname == b.type.vtabstruct_cname: return True + if base.type.base_type.typedef_flag: + return True base = dict[base.type.base_type.vtabstruct_cname] return False -def recurse_vtabslot_check_inheritance(entry,b, dict): +def recurse_vtabslot_check_inheritance(entry, b, dict): base = entry while base is not None: if base.type.base_type is None: return False if base.type.base_type.objstruct_cname == b.type.objstruct_cname: return True + if base.type.base_type.typedef_flag: + return True base = dict[base.type.base_type.objstruct_cname] return False @@ -319,7 +323,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if Options.pre_import is not None: code.putln('static PyObject *%s;' % Naming.preimport_cname) code.putln('static int %s;' % Naming.lineno_cname) - code.putln('static int %s;' % Naming.clineno_cname) + code.putln('static int %s = 0;' % Naming.clineno_cname) code.putln('static char * %s= %s;' % (Naming.cfilenm_cname, Naming.file_c_macro)) code.putln('static char *%s;' % Naming.filename_cname) code.putln('static char **%s;' % Naming.filetable_cname) @@ -404,6 +408,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): scope = type.scope vtab_dict[type.objstruct_cname]=entry return vtab_dict + def generate_vtabslot_list(self, vtab_dict): vtab_list = list() for entry in vtab_dict.itervalues(): @@ -1381,8 +1386,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): header = "PyMODINIT_FUNC init%s(void)" % env.module_name code.putln("%s; /*proto*/" % header) code.putln("%s {" % header) - code.putln("PyObject* __pyx_internal1;") - code.putln("PyObject* __pyx_internal2;") + # do we need any of these here, or just in init2? code.put_var_declarations(env.temp_entries) code.putln("/*--- Libary function declarations ---*/") diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index eaf74f5e..76a14ee6 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -182,7 +182,10 @@ class Node: flat += child else: flat.append(child) - self._end_pos = max([child.end_pos() for child in flat]) + if len(flat) == 0: + self._end_pos = self.pos + else: + self._end_pos = max([child.end_pos() for child in flat]) return self._end_pos @@ -3290,9 +3293,8 @@ class ExceptClauseNode(Node): "if (%s) {" % self.match_flag) else: - code.putln( - "/*except:*/ {") - code.putln('__Pyx_AddTraceback("%s");' % self.function_name) + code.putln("/*except:*/ {") + code.putln('__Pyx_AddTraceback("%s");' % self.function_name) # We always have to fetch the exception value even if # there is no target, because this also normalises the # exception and stores it in the thread state. diff --git a/Cython/Compiler/Options.py b/Cython/Compiler/Options.py index 3a999d5d..0f409cea 100644 --- a/Cython/Compiler/Options.py +++ b/Cython/Compiler/Options.py @@ -52,4 +52,4 @@ init_local_none = 1 optimize_simple_methods = 1 # Append the c file and line number to the traceback for exceptions. -c_line_in_traceback = 1 +c_line_in_traceback = 0 diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 9b5775f2..93491c9e 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -323,6 +323,8 @@ def p_call(s, function): else: arg_tuple = star_arg_tuple if keyword_args: + keyword_args = [ExprNodes.DictItemNode(pos=key.pos, key=key, value=value) + for key, value in keyword_args] keyword_dict = ExprNodes.DictNode(pos, key_value_pairs = keyword_args) return ExprNodes.GeneralCallNode(pos, diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index f414830f..0a6e4293 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1070,6 +1070,8 @@ class StructOrUnionScope(Scope): # Add an entry for an attribute. if not cname: cname = name + if type.is_cfunction: + type = CPtrType(type) entry = self.declare(name, cname, type, pos) entry.is_variable = 1 self.var_entries.append(entry) -- 2.26.2