On Mon, Apr 11, 2016 at 8:36 PM, Ian Henriksen
<insertinterestingnameh...@gmail.com> wrote:
> On Mon, Apr 11, 2016 at 11:50 AM Ian Henriksen
> <insertinterestingnameh...@gmail.com> wrote:
>>
>> To answer the original question about define macros, it appears that the
>> canonical
>> way to pass preprocessor defines through distutils is to use the
>> define_macros
>> keyword when constructing your Extension class. You should also be able to
>> do
>> this within a Cython source file by including a directive like:
>>
>> # distutils: define_macros = MY_DEFINE, MY_DEFINE_2=2
>>
>> Unfortunately, it looks like there's a bug in that that's making it so
>> that these
>> macros are undef'ed rather than being defined, so, for now, just pass the
>> appropriate flags to your Extension object.
>>
>
> Small update on this, it looks like the issue with undef/define only applies
> when a
> define is specified this way without a value, so I either haven't gotten the
> syntax quite
> right, or that's not supported yet. Specifying an actual value for the macro
> works fine.

There is an issue specifically about this that I wanted to bring up,
though it's a bit tangential to my original issue (but maybe not
entirely?)

I know about putting "# distutils: " comments in a Cython source. But
I felt that requiring this in order to get dllexport/dllimport working
correctly on Windows is too much of a burden for a developer (who
normally might not be thinking about this).

The content of these comments *do* get written out to the generated C
sources under a "distutils" property in the JSON metadata at the top
of the file.  So I thought one way I might be able to influence the
compiler flags would be to modify the code that generates the JSON
metadata to include a `"distutils: {"define_macros": [ ... ]}` entry
in that metadata.  However, this was wrong because Cython itself never
actually does anything with that metadata, and it instead reads the
distutils directives (a second time) directly out of the Cython
sources during cythonize() in order to update the Extension
attributes.  I'm thinking it would make more sense if the distutils
options were read from the C sources, since those are what will
*actually* be handled by distutils, even if in the majority of cases
the JSON metadata is being generated directly from the Cython sources.

Changing this would have also provided a solution to my original
problem, even if we've agreed that it's mostly moot.  That said, I
think it makes more sense for cythonize() to read the distutils
options from the C source instead of the Cython source, though in
practice I don't know if it's a worthwhile change or not.

Thanks,
Erik
_______________________________________________
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel

Reply via email to