When trying out the native M$FT compiler with Cython
I found that the declarations are required to all be
ahead of any executable code.

Please consider the trivial patch below.

=== This code fails because declaration not top.
PyMODINIT_FUNC init2calendar(void); /*proto*/
PyMODINIT_FUNC init2calendar(void) {
   static int __Pyx_unique = 0;
   if (__Pyx_unique==1) return;
   __Pyx_unique = 1;
////         V  Can't be declared after execution code.
   PyObject *__pyx_1 = 0;
   /*--- Execution code ---*/

=== This code succeeds:
PyMODINIT_FUNC init2calendar(void); /*proto*/
PyMODINIT_FUNC init2calendar(void) {
   static int __Pyx_unique = 0;
////         V  Moving this up fixes it.
   PyObject *__pyx_1 = 0;
   if (__Pyx_unique==1) return;
   __Pyx_unique = 1;
   /*--- Execution code ---*/

=== Trivial patch:

--- ModuleNode.py.orig  2008-05-15 17:18:08.363704000 -0700
+++ ModuleNode.py       2008-05-15 17:18:32.506829000 -0700
@@ -1443,10 +1443,10 @@
          header = "PyMODINIT_FUNC init2%s(void)" % env.module_name
          code.putln("%s; /*proto*/" % header)
          code.putln("%s {" % header)
+        code.put_var_declarations(env.temp_entries)
          code.putln("static int __Pyx_unique = 0;")
          code.putln("if (__Pyx_unique==1) return;")
          code.putln("__Pyx_unique = 1;")
-        code.put_var_declarations(env.temp_entries)
          code.putln("/*--- Execution code ---*/")
          code.mark_pos(None)
          self.body.generate_execution_code(code)

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to