[Cython] Fwd: Question about how best require compiler options for C sources

2016-04-08 Thread Erik Bray
Hi all,

I'd like to call attention to an issue I've been looking into for the
past couple days:

https://github.com/cython/cython/pull/360

To summarize the discussion, when building DLLs for Windows, functions
that should be exported by that DLL must be marked
__declspec(dllexport) in their declaration.  However, when using the
same header file in a project that links to that DLL the same function
must be declared __declspec(dllimport).

It's common practice to have a macro for this, whose value is
controlled by whether or not a macro (often called something like
"DLL_EXPORT").  When compiling the DLL we would define -DDLL_EXPORT to
output __declspec(dllexport).  Otherwise it outputs
__declspec(dllimport).

Cython currently handles this with such a macro called DL_IMPORT which
comes from Python. However, this macro was deprecated some time ago,
and is removed in current Python 3 versions.  So Cython must replace
it with its own.

I'm working on a patch for this--to reduce confusion the macro is
named specifically for the Cython module it's associated with.  For
example, for a Cython module named "foo.bar" there are two macros
DLL_EXPORT__foo__bar and EXPORT__foo__bar.  If the latter is defined
then the former outputs dllexport, otherwise it outputs dllimport.
I've attached the patch in progress.

I'm open to comment on this, but where I'm stuck now is that in order
for the "foo.bar" module to be compiled correctly it needs
EXPORT__foo__bar to be defined at compile time.  And it's not clear to
me what the best way is for the Cython compiler to pass down options
that are passed to the C/C++ compiler.  In general the best way would
be to attach this to the define_macros attribute of the associated
distutils/setuptools Extension object and let the distutils compiler
class generate the right compiler options.  But it's not clear to me
from Cython's internals where the best place to do that would be.

Thanks,
Erik


dll_export.patch
Description: Binary data
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Fwd: Question about how best require compiler options for C sources

2016-04-08 Thread Nathaniel Smith
Can you give a tiny concrete example? My questions are basic enough that I
feel like I'm missing something fundamental :-)

My first question is why you even need this, since AFAIK there are no cases
where it is correct to have a cython module dllexporting symbols that
appear in header files. This is what cimport is for, right?

My second question is why you would want to do this via the command line,
when compiling the dll means that you are compiling some cython-generated
.c, which means that you can put the #define directly in the source code,
no?

-n
On Apr 8, 2016 5:35 AM, "Erik Bray"  wrote:

> Hi all,
>
> I'd like to call attention to an issue I've been looking into for the
> past couple days:
>
> https://github.com/cython/cython/pull/360
>
> To summarize the discussion, when building DLLs for Windows, functions
> that should be exported by that DLL must be marked
> __declspec(dllexport) in their declaration.  However, when using the
> same header file in a project that links to that DLL the same function
> must be declared __declspec(dllimport).
>
> It's common practice to have a macro for this, whose value is
> controlled by whether or not a macro (often called something like
> "DLL_EXPORT").  When compiling the DLL we would define -DDLL_EXPORT to
> output __declspec(dllexport).  Otherwise it outputs
> __declspec(dllimport).
>
> Cython currently handles this with such a macro called DL_IMPORT which
> comes from Python. However, this macro was deprecated some time ago,
> and is removed in current Python 3 versions.  So Cython must replace
> it with its own.
>
> I'm working on a patch for this--to reduce confusion the macro is
> named specifically for the Cython module it's associated with.  For
> example, for a Cython module named "foo.bar" there are two macros
> DLL_EXPORT__foo__bar and EXPORT__foo__bar.  If the latter is defined
> then the former outputs dllexport, otherwise it outputs dllimport.
> I've attached the patch in progress.
>
> I'm open to comment on this, but where I'm stuck now is that in order
> for the "foo.bar" module to be compiled correctly it needs
> EXPORT__foo__bar to be defined at compile time.  And it's not clear to
> me what the best way is for the Cython compiler to pass down options
> that are passed to the C/C++ compiler.  In general the best way would
> be to attach this to the define_macros attribute of the associated
> distutils/setuptools Extension object and let the distutils compiler
> class generate the right compiler options.  But it's not clear to me
> from Cython's internals where the best place to do that would be.
>
> Thanks,
> Erik
>
> ___
> cython-devel mailing list
> cython-devel@python.org
> https://mail.python.org/mailman/listinfo/cython-devel
>
>
___
cython-devel mailing list
cython-devel@python.org
https://mail.python.org/mailman/listinfo/cython-devel