Python extensions in C... and stdout problems!

Andrew MacIntyre andymac at bullseye.apana.org.au
Tue Aug 15 22:01:13 EDT 2000


On 15 Aug 2000, Victor B.Putz wrote:

> OS supremacy comments aside, this is happening on Linux, kernel 2.2.10 to be
> precise, with glibc-2.1.3 and python1.5.2-7, both installed via rpm.  I suppose
> if the Python interpreter is compiled statically and my shared module is trying
> to use it locally, then they could be using different versions, but that would
> surprise me--I thought darn near EVERYTHING on Linux was dynamically linked.
> 
> But it could be the problem, or at least related--I can compile the module into
> a custom interpreter and it works fine--not ideal by any stretch, but at least
> acceptable.  I'm running a little experiment to script Eiffel components through
> Python (just say .NO to .NET!), and was rather frustrated with the stdin/out
> problem.  If I have time I'll try just recompiling the interpreter and trying it
> out as a shared module again.

How are you building your extension?.  A trap I have run into (on Solaris) 
is a variation of the Windows problem already noted.

The problem has do with linkage contexts (the only term I can come up with
to describe this), as Python extensions on most Unices actually get
created as "unfinished executables", in that undefined references are
allowed (and get resolved against the Python interpreter's symbol table
when dlopen'ed).  If you explicitly link an extension against a library
that the interpreter (or another extension as it was in my case), you run
the risk of the two instances of the library references not having the
same references to what is expected to be data common to both instances
(such as the libc file pointer table).

if you use ldd on your extension, does it have a reference to libc?  If
so, can you change your linking spec to exclude libc and see whether that
changes what you see.

I have to say that using Distutils makes managing this much easier (thanks
to the Distutils-SIG people!), and its not particularly difficult to make
a Distutils setup.py for an extension.

--
Andrew I MacIntyre                     "These thoughts are mine alone..."
E-mail: andrew.macintyre at aba.gov.au    (work) | Snail: PO Box 370
        andymac at bullseye.apana.org.au  (play) |        Belconnen  ACT  2616
        andymac at pcug.org.au           (play2) |        Australia





More information about the Python-list mailing list