Move generate_preamble() stuff back into generate_function_definitions()
authorVitja Makarov <vitja.makarov@gmail.com>
Fri, 7 Jan 2011 08:17:03 +0000 (11:17 +0300)
committerVitja Makarov <vitja.makarov@gmail.com>
Fri, 7 Jan 2011 08:17:03 +0000 (11:17 +0300)
Cython/Compiler/Nodes.py

index 3862673908df57b4871c31e5a5dd7f74730c1e94..d8b26d7ea17c58e3a2a78be3d8283cb8bbd30143 100644 (file)
@@ -1354,7 +1354,29 @@ class FuncDefNode(StatNode, BlockNode):
             # fatal error before hand, it's not really worth tracing
             code.put_trace_call(self.entry.name, self.pos)
         # ----- Fetch arguments
-        self.generate_preamble(env, code)
+        self.generate_argument_parsing_code(env, code)
+        # If an argument is assigned to in the body, we must
+        # incref it to properly keep track of refcounts.
+        for entry in lenv.arg_entries:
+            if entry.type.is_pyobject:
+                if (acquire_gil or entry.assignments) and not entry.in_closure:
+                    code.put_var_incref(entry)
+        # ----- Initialise local variables
+        for entry in lenv.var_entries:
+            if entry.type.is_pyobject and entry.init_to_none and entry.used:
+                code.put_init_var_to_py_none(entry)
+        # ----- Initialise local buffer auxiliary variables
+        for entry in lenv.var_entries + lenv.arg_entries:
+            if entry.type.is_buffer and entry.buffer_aux.buffer_info_var.used:
+                code.putln("%s.buf = NULL;" %
+                           entry.buffer_aux.buffer_info_var.cname)
+        # ----- Check and convert arguments
+        self.generate_argument_type_tests(code)
+        # ----- Acquire buffer arguments
+        for entry in lenv.arg_entries:
+            if entry.type.is_buffer:
+                Buffer.put_acquire_arg_buffer(entry, code, self.pos)
+
         # -------------------------
         # ----- Function body -----
         # -------------------------
@@ -1493,36 +1515,6 @@ class FuncDefNode(StatNode, BlockNode):
             self.py_func.generate_function_definitions(env, code)
         self.generate_wrapper_functions(code)
 
-    def generate_preamble(self, env, code):
-        """Parse arguments and prepare scope"""
-        import Buffer
-
-        lenv = self.local_scope
-        acquire_gil = self.acquire_gil
-
-        self.generate_argument_parsing_code(env, code)
-        # If an argument is assigned to in the body, we must
-        # incref it to properly keep track of refcounts.
-        for entry in lenv.arg_entries:
-            if entry.type.is_pyobject:
-                if (acquire_gil or entry.assignments) and not entry.in_closure:
-                    code.put_var_incref(entry)
-        # ----- Initialise local variables
-        for entry in lenv.var_entries:
-            if entry.type.is_pyobject and entry.init_to_none and entry.used:
-                code.put_init_var_to_py_none(entry)
-        # ----- Initialise local buffer auxiliary variables
-        for entry in lenv.var_entries + lenv.arg_entries:
-            if entry.type.is_buffer and entry.buffer_aux.buffer_info_var.used:
-                code.putln("%s.buf = NULL;" %
-                           entry.buffer_aux.buffer_info_var.cname)
-        # ----- Check and convert arguments
-        self.generate_argument_type_tests(code)
-        # ----- Acquire buffer arguments
-        for entry in lenv.arg_entries:
-            if entry.type.is_buffer:
-                Buffer.put_acquire_arg_buffer(entry, code, self.pos)
-
     def declare_argument(self, env, arg):
         if arg.type.is_void:
             error(arg.pos, "Invalid use of 'void'")