Jeff Copeland | 3 Aug 2012 02:18
Picon

[Cython] Add includes to generated header files

I'm working on some C++ projects and I'm using cython to embed python
code.  In an effort to make things easy for C++ devs not as familiar
with cython/python I've made a small change to insert #includes in
generated header files the same as is done in generated c code.  This
allows one who is using code processed with cython to just include the
header and not worry about any other headers that may be required to
match data types.

Not having these headers is especially problematic because otherwise
the error message presented at compilation can sometimes be quite
cryptic.

Patch is attached.  Any reason this should not be done?

Thanks,

Jeff
I'm working on some C++ projects and I'm using cython to embed python
code.  In an effort to make things easy for C++ devs not as familiar
with cython/python I've made a small change to insert #includes in
generated header files the same as is done in generated c code.  This
allows one who is using code processed with cython to just include the
header and not worry about any other headers that may be required to
match data types.

Not having these headers is especially problematic because otherwise
the error message presented at compilation can sometimes be quite
(Continue reading)

Stefan Behnel | 3 Aug 2012 05:43
Picon
Favicon

Re: [Cython] Add includes to generated header files

Jeff Copeland, 03.08.2012 02:18:
> I'm working on some C++ projects and I'm using cython to embed python
> code.  In an effort to make things easy for C++ devs not as familiar
> with cython/python I've made a small change to insert #includes in
> generated header files the same as is done in generated c code.  This
> allows one who is using code processed with cython to just include the
> header and not worry about any other headers that may be required to
> match data types.
> 
> Not having these headers is especially problematic because otherwise
> the error message presented at compilation can sometimes be quite
> cryptic.
> 
> Patch is attached.  Any reason this should not be done?

Hmm, didn't try your patch, but I guess it inserts includes for *all*
header files that the module that exports the C-API uses internally, right?

If so, I'm not sure that's always wanted. I see the advantage, sure, but it
may expose a lot of implementation details that external code may not
normally have to care about.

On the other hand, if extension types are exported, for example, it's
somewhat unlikely that their struct would compile without at least some of
those header files, because they almost always wrap some kind of externally
defined struct, pointer or whatever kind of other data type.

That sounds to me like we should make it a configurable option, something
like "capi_reexport_cincludes".

(Continue reading)

Jeff Copeland | 3 Aug 2012 06:11
Picon

Re: [Cython] Add includes to generated header files

On Thu, Aug 2, 2012 at 8:43 PM, Stefan Behnel <stefan_ml@...> wrote:
> Jeff Copeland, 03.08.2012 02:18:
>> I'm working on some C++ projects and I'm using cython to embed python
>> code.  In an effort to make things easy for C++ devs not as familiar
>> with cython/python I've made a small change to insert #includes in
>> generated header files the same as is done in generated c code.  This
>> allows one who is using code processed with cython to just include the
>> header and not worry about any other headers that may be required to
>> match data types.
>>
>> Not having these headers is especially problematic because otherwise
>> the error message presented at compilation can sometimes be quite
>> cryptic.
>>
>> Patch is attached.  Any reason this should not be done?
>
> Hmm, didn't try your patch, but I guess it inserts includes for *all*
> header files that the module that exports the C-API uses internally, right?

Yes, you've got it.  Certainly quick and dirty to satisfy my immediate need.

> If so, I'm not sure that's always wanted. I see the advantage, sure, but it
> may expose a lot of implementation details that external code may not
> normally have to care about.
>
> On the other hand, if extension types are exported, for example, it's
> somewhat unlikely that their struct would compile without at least some of
> those header files, because they almost always wrap some kind of externally
> defined struct, pointer or whatever kind of other data type.

(Continue reading)

Jeff Copeland | 11 Aug 2012 19:27
Picon

Re: [Cython] Add includes to generated header files

On Thu, Aug 2, 2012 at 8:43 PM, Stefan Behnel <stefan_ml@...> wrote:
> That sounds to me like we should make it a configurable option, something
> like "capi_reexport_cincludes".

Do mean as a command line option, or something else like a compiler directive?
Jeff Copeland | 11 Aug 2012 20:54
Picon

Re: [Cython] Add includes to generated header files

On Sat, Aug 11, 2012 at 10:27 AM, Jeff Copeland <mongi3@...> wrote:
> On Thu, Aug 2, 2012 at 8:43 PM, Stefan Behnel <stefan_ml@...> wrote:
>> That sounds to me like we should make it a configurable option, something
>> like "capi_reexport_cincludes".
>
> Do mean as a command line option, or something else like a compiler directive?

I went ahead and added a command line option.

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

Gmane