<br><br><div><span class="gmail_quote">On 12/2/06, <b class="gmail_sendername">Fredrik Lundh</b> &lt;<a href="mailto:fredrik@pythonware.com">fredrik@pythonware.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Brett Cannon wrote:<br><br>&gt; So you are basically saying you want the preprocessor step to be<br>&gt; lightweight enough that you always develop with the file before the<br>&gt; preprocessor is run instead of with some generated file, right?
<br><br>exactly.&nbsp;&nbsp;the developer should *never* edit generated data (whether<br>that's a separate file fed to the compiler, an include file included by<br>the original file, or auto-generated sections *inside* the original file).
<br><br>&gt; Regardless, one could take a Pyrex bent on this and having Python-like<br>&gt; method declarations but have C as the code body::<br><br>(some days, I wonder if we shouldn't just include Pyrex and tell every-<br>
one to use that for *all* their extension work.&nbsp;&nbsp;Greg?&nbsp;&nbsp;how much work<br>would it be to equip Pyrex with a &quot;retargetable&quot; backend?)<br><br>:::<br><br>but back to the preprocessor; I think it might be possible to limit its
<br>impact on the C source file to a single #include statement at the end of<br>the file, which includes the generated code.&nbsp;&nbsp;to provide hints for the<br>preprocessor, Python.h would provide a bunch of C macros that are parsed
<br>by the module preprocessor, but (mostly) ignored by the C compiler.</blockquote><div><br>&gt; the spam module from the extension manual could then look something like<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>#include &quot;Python.h&quot;<br><br>static PyObject *SpamError;<br><br>PYM_FUNCTION(spam)(char* command)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; int sts;<br>&nbsp;&nbsp;&nbsp;&nbsp; sts = system(command);<br>&nbsp;&nbsp;&nbsp;&nbsp; return Py_BuildValue(&quot;i&quot;, sts);<br>}<br>
<br>PYM_INIT(PyObject* module)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; SpamError = PyErr_NewException(&quot;spam.error&quot;, NULL, NULL);<br>&nbsp;&nbsp;&nbsp;&nbsp; Py_INCREF(SpamError);<br>&nbsp;&nbsp;&nbsp;&nbsp; PyModule_AddObject(module, &quot;error&quot;, SpamError);<br>}<br><br>#include &quot;
spam.pym&quot;<br><br>and the preprocessor would then generate the necessary trampolines and<br>tables, and of course the public initspam function.&nbsp;&nbsp;extending this to<br>deal with optional arguments, methods, and perhaps even return values is
<br>mostly trivial.</blockquote><div><br>Assuming spam.pym is the generated C file that should be a good level of separation and minimize the impact of the generated code in debugging (assuming that module is not entirely object-based).
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(hmm.&nbsp;&nbsp;am I reinventing SWIG here?)</blockquote><div><br>=)&nbsp; Maybe.&nbsp; Depends on the level of hinting and syntax change you want from C code compared to the pre-processed code.
<br></div><br>-Brett<br></div>