From: Stefan Behnel Date: Sun, 28 Dec 2008 15:33:44 +0000 (+0100) Subject: initialise argument value array with default values to avoid having to check for... X-Git-Tag: 0.11-beta~72 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e5681e07a3a8c5032060a9ea3f5b8403c00e9a83;p=cython.git initialise argument value array with default values to avoid having to check for NULL on assignments --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 85d57ab1..89e12f5c 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2101,8 +2101,17 @@ class DefNode(FuncDefNode): all_args = tuple(positional_args) + tuple(kw_only_args) max_args = len(all_args) + default_args = [] + for arg in all_args: + if arg.default and arg.type.is_pyobject: + default_value = arg.default_result_code + if arg.type is not PyrexTypes.py_object_type: + default_value = "(PyObject*)"+default_value + default_args.append(default_value) + else: + default_args.append('0') code.putln("PyObject* values[%d] = {%s};" % ( - max_args, ('0,'*max_args)[:-1])) + max_args, ', '.join(default_args))) code.putln("Py_ssize_t kw_args = PyDict_Size(%s);" % Naming.kwds_cname) @@ -2186,10 +2195,10 @@ class DefNode(FuncDefNode): # convert arg values to their final type and assign them for i, arg in enumerate(all_args): - if arg.default: + if arg.default and not arg.type.is_pyobject: code.putln("if (values[%d]) {" % i) self.generate_arg_assignment(arg, "values[%d]" % i, code) - if arg.default: + if arg.default and not arg.type.is_pyobject: code.putln('}') def generate_argument_conversion_code(self, code):