Dag Sverre Seljebotn | 20 Dec 19:39 2011
Picon
Picon

Differences between C++ Cython wrapper and C++ program

Hi list,

I'm trying to wrap a proprietary, closed-source C++ library using 
Cython. The library essentially fails to work when used through a Cython 
wrapper, but works when compiling as a standalone executable with the 
same compiler flags.

I.e., I have a function "foomain" with some C++ code which attempts to 
make a certain network connection. If I call foomain() from main() in a 
C++ program, things work. If I call foomain() from Cython, compiled in 
C++ mode, then things don't work (no connection is made).

So what are the possible differences in the runtime environment you can 
think of?

The first thing I had to do was this:

import sys, ctypes
sys.setdlopenflags(sys.getdlopenflags()|ctypes.RTLD_GLOBAL)

This fixed something else (a function mysteriously returning a NULL 
pointer when it shouldn't -- as I don't have the sources I don't know 
why, really). But apparently it didn't fix everything.

I've tried both with and without creating a thread using the threading 
module (so that a GIL is set up), and both with and without "with nogil" 
around the call to foomain().

Dag Sverre

(Continue reading)

Dag Sverre Seljebotn | 20 Dec 19:45 2011
Picon
Picon

Re: Differences between C++ Cython wrapper and C++ program

On 12/20/2011 07:39 PM, Dag Sverre Seljebotn wrote:
> Hi list,
>
> I'm trying to wrap a proprietary, closed-source C++ library using
> Cython. The library essentially fails to work when used through a Cython
> wrapper, but works when compiling as a standalone executable with the
> same compiler flags.
>
> I.e., I have a function "foomain" with some C++ code which attempts to
> make a certain network connection. If I call foomain() from main() in a
> C++ program, things work. If I call foomain() from Cython, compiled in
> C++ mode, then things don't work (no connection is made).
>
> So what are the possible differences in the runtime environment you can
> think of?
>
> The first thing I had to do was this:
>
> import sys, ctypes
> sys.setdlopenflags(sys.getdlopenflags()|ctypes.RTLD_GLOBAL)
>
> This fixed something else (a function mysteriously returning a NULL
> pointer when it shouldn't -- as I don't have the sources I don't know
> why, really). But apparently it didn't fix everything.
>
> I've tried both with and without creating a thread using the threading
> module (so that a GIL is set up), and both with and without "with nogil"
> around the call to foomain().

Got an idea just after writing this email (an instance of [1]). 
(Continue reading)

Vitja Makarov | 20 Dec 19:46 2011
Picon

Re: Differences between C++ Cython wrapper and C++ program

2011/12/20 Dag Sverre Seljebotn <d.s.seljebotn <at> astro.uio.no>:
> Hi list,
>
> I'm trying to wrap a proprietary, closed-source C++ library using Cython.
> The library essentially fails to work when used through a Cython wrapper,
> but works when compiling as a standalone executable with the same compiler
> flags.
>
> I.e., I have a function "foomain" with some C++ code which attempts to make
> a certain network connection. If I call foomain() from main() in a C++
> program, things work. If I call foomain() from Cython, compiled in C++ mode,
> then things don't work (no connection is made).
>

It might be useful to trace it with strace.

> So what are the possible differences in the runtime environment you can
> think of?
>
> The first thing I had to do was this:
>
> import sys, ctypes
> sys.setdlopenflags(sys.getdlopenflags()|ctypes.RTLD_GLOBAL)
>
> This fixed something else (a function mysteriously returning a NULL pointer
> when it shouldn't -- as I don't have the sources I don't know why, really).
> But apparently it didn't fix everything.
>
> I've tried both with and without creating a thread using the threading
> module (so that a GIL is set up), and both with and without "with nogil"
(Continue reading)

Lisandro Dalcin | 20 Dec 19:47 2011
Picon

Re: Differences between C++ Cython wrapper and C++ program

On 20 December 2011 15:39, Dag Sverre Seljebotn
<d.s.seljebotn <at> astro.uio.no> wrote:
> Hi list,
>
> I'm trying to wrap a proprietary, closed-source C++ library using Cython.
> The library essentially fails to work when used through a Cython wrapper,
> but works when compiling as a standalone executable with the same compiler
> flags.
>
> I.e., I have a function "foomain" with some C++ code which attempts to make
> a certain network connection. If I call foomain() from main() in a C++
> program, things work. If I call foomain() from Cython, compiled in C++ mode,
> then things don't work (no connection is made).
>
> So what are the possible differences in the runtime environment you can
> think of?
>
> The first thing I had to do was this:
>
> import sys, ctypes
> sys.setdlopenflags(sys.getdlopenflags()|ctypes.RTLD_GLOBAL)
>
> This fixed something else (a function mysteriously returning a NULL pointer
> when it shouldn't -- as I don't have the sources I don't know why, really).
> But apparently it didn't fix everything.
>
> I've tried both with and without creating a thread using the threading
> module (so that a GIL is set up), and both with and without "with nogil"
> around the call to foomain().
>
(Continue reading)

Dag Sverre Seljebotn | 20 Dec 19:55 2011
Picon
Picon

Re: Differences between C++ Cython wrapper and C++ program

On 12/20/2011 07:47 PM, Lisandro Dalcin wrote:
> On 20 December 2011 15:39, Dag Sverre Seljebotn
> <d.s.seljebotn <at> astro.uio.no>  wrote:
>> Hi list,
>>
>> I'm trying to wrap a proprietary, closed-source C++ library using Cython.
>> The library essentially fails to work when used through a Cython wrapper,
>> but works when compiling as a standalone executable with the same compiler
>> flags.
>>
>> I.e., I have a function "foomain" with some C++ code which attempts to make
>> a certain network connection. If I call foomain() from main() in a C++
>> program, things work. If I call foomain() from Cython, compiled in C++ mode,
>> then things don't work (no connection is made).
>>
>> So what are the possible differences in the runtime environment you can
>> think of?
>>
>> The first thing I had to do was this:
>>
>> import sys, ctypes
>> sys.setdlopenflags(sys.getdlopenflags()|ctypes.RTLD_GLOBAL)
>>
>> This fixed something else (a function mysteriously returning a NULL pointer
>> when it shouldn't -- as I don't have the sources I don't know why, really).
>> But apparently it didn't fix everything.
>>
>> I've tried both with and without creating a thread using the threading
>> module (so that a GIL is set up), and both with and without "with nogil"
>> around the call to foomain().
(Continue reading)

Lisandro Dalcin | 20 Dec 20:16 2011
Picon

Re: Differences between C++ Cython wrapper and C++ program

On 20 December 2011 15:55, Dag Sverre Seljebotn
<d.s.seljebotn <at> astro.uio.no> wrote:
> On 12/20/2011 07:47 PM, Lisandro Dalcin wrote:
>>
>> On 20 December 2011 15:39, Dag Sverre Seljebotn
>> <d.s.seljebotn <at> astro.uio.no>  wrote:
>>>
>>> Hi list,
>>>
>>> I'm trying to wrap a proprietary, closed-source C++ library using Cython.
>>> The library essentially fails to work when used through a Cython wrapper,
>>> but works when compiling as a standalone executable with the same
>>> compiler
>>> flags.
>>>
>>> I.e., I have a function "foomain" with some C++ code which attempts to
>>> make
>>> a certain network connection. If I call foomain() from main() in a C++
>>> program, things work. If I call foomain() from Cython, compiled in C++
>>> mode,
>>> then things don't work (no connection is made).
>>>
>>> So what are the possible differences in the runtime environment you can
>>> think of?
>>>
>>> The first thing I had to do was this:
>>>
>>> import sys, ctypes
>>> sys.setdlopenflags(sys.getdlopenflags()|ctypes.RTLD_GLOBAL)
>>>
(Continue reading)


Gmane