On Apr 22, 2009, at 7:18 PM, Mark Lodato wrote:

> The embedded mode is a really good idea, but I think it would make
> more sense as a separate script for several reasons:
> 1. If it is separate, Cython itself doesn't have to change.
> 2. The same Cython C output file be made into a module and also  
> embedded.
> 3. Multiple Cython modules can be embedded into a single executable.

I was going for something really simple--running Cython files should  
be as easy as running Python files (with a compile step in there of  
course). What you're describing is valuable too, but I don't think  
the two are mutually exclusive. Also, I'm not scared of changing  
Cython :)

> I have included a first draft of such a script.

Thanks.

> Other (minor) changes:
> * I call Py_SetProgramName(), which seems like a good idea.

Good.

> * I create a MODINIT() macro to create the module initialization name,
> but I don't know how portable the ## concatenation is.

Also, the two functions have different signatures.

> An additional idea (not implemented) - it would be awesome to have the
> first module listed (that is, the one directly imported) to have
> __name__ == "__main__", so the normal Python idiom works.  I
> researched this for the past few hours, but I could not find a way to
> do this without modifying the module's code.  My best solution is the
> following:
> 1. For each module, mymod.pyx:
> 1a. Add a new externally-visible global variable:
>     int __pyx_mymod_is___main__ = 0;
> 1b. When converting the code for __name__, if __pyx_mymod_is___main__,
> return "__main__", else the module name.
> 2. In the script below, set
>     __pyx_mainmod_is___main__ = 1;
> right before the call to PyImport_ImportModule(), where "mainmod" is
> the main module.

I actually thought about doing this, and this is the only way I could  
come up with as well. If there's no objection I could push this so  
it'd be available for all generated .c files by default.

> Quick question, is the following a typo?
>         if (Py_FlushLine()); PyErr_Clear();
> Should that middle semi-colon be there?  If so, why the if statement?

Yes, oops. Fixed.

- Robert


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

Reply via email to