From: Stefan Behnel Date: Thu, 22 Apr 2010 18:29:10 +0000 (+0200) Subject: merged in latest cython-devel X-Git-Tag: 0.13.beta0~2^2~91 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6c2a2b3b42e58a5a634f1091bf08e846d9c8775b;p=cython.git merged in latest cython-devel --- 6c2a2b3b42e58a5a634f1091bf08e846d9c8775b diff --cc Cython/Compiler/ExprNodes.py index d0817ddd,c8c5d96c..9fef2a3a --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@@ -4170,8 -4205,10 +4250,11 @@@ class PyCFunctionNode(ExprNode) is_temp = 1 def analyse_types(self, env): - pass + if self.binding: + env.use_utility_code(binding_cfunc_utility_code) + + def may_be_none(self): + return False gil_message = "Constructing Python function" diff --cc Cython/Compiler/ModuleNode.py index 6b859990,641c0805..1b38fc80 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@@ -1658,13 -1678,11 +1676,13 @@@ class ModuleNode(Nodes.Node, Nodes.Bloc code.putln("__pyx_refnanny = __Pyx_RefNanny->SetupContext(\"%s\", __LINE__, __FILE__);"% header3) code.putln("#endif") - self.generate_filename_init_call(code) - code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos))); - code.putln("%s = __Pyx_PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos))); - + code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos))); + + code.putln("#ifdef %s_USED" % Naming.binding_cfunc) + code.putln("if (%s_init() < 0) %s" % (Naming.binding_cfunc, code.error_goto(self.pos))) + code.putln("#endif") + code.putln("/*--- Library function declarations ---*/") env.generate_library_function_declarations(code) diff --cc Cython/Compiler/Nodes.py index c8cb9d82,68ab97f8..653efc13 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@@ -630,9 -630,10 +630,11 @@@ class CArgDeclNode(Node) # base_type CBaseTypeNode # declarator CDeclaratorNode # not_none boolean Tagged with 'not None' + # or_none boolean Tagged with 'or None' + # accept_none boolean Resolved boolean for not_none/or_none # default ExprNode or None # default_value PyObjectConst constant for default value + # annotation ExprNode or None Py3 function arg annotation # is_self_arg boolean Is the "self" arg of an extension type method # is_type_arg boolean Is the "class" arg of an extension type classmethod # is_kw_only boolean Is a keyword-only argument diff --cc Cython/Compiler/Parsing.pxd index aec498fc,31c10569..edbf6e38 --- a/Cython/Compiler/Parsing.pxd +++ b/Cython/Compiler/Parsing.pxd @@@ -45,11 -42,11 +45,11 @@@ cpdef p_atom(PyrexScanner s cpdef p_name(PyrexScanner s, name) cpdef p_cat_string_literal(PyrexScanner s) cpdef p_opt_string_literal(PyrexScanner s) - cpdef p_string_literal(PyrexScanner s) + cpdef p_string_literal(PyrexScanner s, kind_override=*) cpdef p_list_maker(PyrexScanner s) -cpdef p_list_iter(PyrexScanner s, body) -cpdef p_list_for(PyrexScanner s, body) -cpdef p_list_if(PyrexScanner s, body) +cpdef p_comp_iter(PyrexScanner s, body) +cpdef p_comp_for(PyrexScanner s, body) +cpdef p_comp_if(PyrexScanner s, body) cpdef p_dict_or_set_maker(PyrexScanner s) cpdef p_backquote_expr(PyrexScanner s) cpdef p_simple_expr_list(PyrexScanner s) diff --cc Cython/Compiler/Parsing.py index 63b85e5a,ebee3bf7..fcbc4184 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@@ -2136,12 -2081,10 +2132,12 @@@ def p_optional_ellipsis(s) else: return 0 -def p_c_arg_decl(s, ctx, in_pyfunc, cmethod_flag = 0, nonempty = 0, kw_only = 0): +def p_c_arg_decl(s, ctx, in_pyfunc, cmethod_flag = 0, nonempty = 0, + kw_only = 0, annotated = 1): pos = s.position() - not_none = 0 + not_none = or_none = 0 default = None + annotation = None if s.in_python_file: # empty type declaration base_type = Nodes.CSimpleBaseTypeNode(pos, @@@ -2159,11 -2103,9 +2156,12 @@@ else: s.error("Expected 'None'") if not in_pyfunc: - error(pos, "'not None' only allowed in Python functions") - not_none = 1 + error(pos, "'%s None' only allowed in Python functions" % kind) + or_none = kind == 'or' + not_none = kind == 'not' + if annotated and s.sy == ':': + s.next() + annotation = p_simple_expr(s) if s.sy == '=': s.next() if 'pxd' in s.level: @@@ -2177,8 -2119,8 +2175,9 @@@ base_type = base_type, declarator = declarator, not_none = not_none, + or_none = or_none, default = default, + annotation = annotation, kw_only = kw_only) def p_api(s): diff --cc Cython/Compiler/Symtab.py index 528c6406,5b74ebc1..2c0f6289 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@@ -209,7 -207,8 +209,9 @@@ class Scope(object) # return_type PyrexType or None Return type of function owning scope # is_py_class_scope boolean Is a Python class scope # is_c_class_scope boolean Is an extension type scope + # is_closure_scope boolean + # is_cpp_class_scope boolean Is a C++ class scope + # is_property_scope boolean Is a extension type property scope # scope_prefix string Disambiguator for C names # in_cinclude boolean Suppress C declaration code # qualified_name string "modname" or "modname.classname" @@@ -223,10 -221,9 +225,11 @@@ is_py_class_scope = 0 is_c_class_scope = 0 + is_closure_scope = 0 is_cpp_class_scope = 0 + is_property_scope = 0 is_module_scope = 0 + is_internal = 0 scope_prefix = "" in_cinclude = 0 nogil = 0