[Distutils] Mingw Python 2.4
Michiel Jan Laurens de Hoon
mdehoon at ims.u-tokyo.ac.jp
Sun Apr 3 11:08:34 CEST 2005
I just tried to compile a bunch of C extensions (coming from the biopython
project) with mingw as compiler. Most of them link to msvcr71.dll and not to
msvcrt.dll, except for one, which links to both. By uncommenting various parts
of the code, I discovered that the culprit is a call to strdup. When such a call
is made, the extension module will link to both msvcr71.dll and msvcrt.dll. Now,
strdup is not part of ANSI-C, so for portability it is better to avoid this
function altogether. I don't know if your extension module links to msvcrt.dll
for the same reason, but you may be able to find out which part of the code is
causing the .pyd to be linked to msvcrt. It may turn out to be strdup or another
non-standard function.
--Michiel.
AGiss wrote:
> Hello,
>
> I tried to compile some extensions under Windows/Python
> 2.4 using distutils and mingw as compiler (not MS-VC++).
>
> -----
> (You can just jump to conclusion at the bottom if you like,
> but be aware that I don't really master the subject, so
> I may have missed something. If you thing my conclusions
> doesn't make sense, please read what happens to me.)
> -----
>
> (Official Python2.4, the one that use msvcr71.dll)
>
> I got some strange results like "the softwares I wrote using this
> extension crashed randomly". I first thought that extension
> (that I didn't wrote) was crappy.
>
> When the second extension crashed too, I tried to understand
> a bit more.
>
> The crash is more or less random, (but when it doesn't crash,
> everything works as expected even the code in the extension)
> and it crash with an OS error 0xc0000008 (it look like it's
> an internal windows error which mean there is something really
> nasty with the memory.
>
> So the .pyd was linked to msvcrt.dll and to msvcr71.dll.
> As it looks fishy, I tried to reinstall python 2.3 for
> windows that doesn't use msvcr71.dll but msvcrt.dll).
>
> I wasn't able to reproduce the crash.
>
> Then I realize the extension provided a way to build the same
> .pyd (but I wasn't able to generate an installer for the
> extension, that's why I didn't use it).
>
> So I look at the .pyd generated for python 2.4 with the
> makefile, and... it was only linked to msvcrt.dll.
> So I trie to use it instead and... it works !!!
>
> I tried to recompile everything from scratch using distutils
> because it may just be because a "bad neutrino who hit my
> motherboard at the worst moment", but the bug was still here.
>
> So I tried to figure out what was the difference between the
> command lines used by the makefile and distutils. And... the
> obvious difference was that distutils used a -lmsvcr71.
>
> Gooood
>
> I looked at distutils code source, and quickly found the line
> that makes mingw use msvcr71. IV just changed it.
>
> I rebuild all, and... It just worked well. (and of course, the
> .pyd was just linked to msvcrt and not msvcr71 anymore)
>
> --------------
>
> Sooooooooooooooooo here are my conclusions :
>
> Something isn't right when compiling with mingw using msvcr71.
> (command line option ? problem with mingw ? problem with
> msvcr71 ? mingw just need some more configuration to works
> with msvcr71 ? I don't really know)
>
> It *look* like compilling extension using msvcrt instad of
> msvcr71, even if python use msvcr71 is safer that letting
> mingw using msvcr71.
>
> So I propose to remove the lines from 330 to 332 on the file
> cygwinccompiler.py (revision 1.29, the actual one, and the
> one used with python 2.4)
>
> The code is specific for Windows/Mingw/(python compiled with msvc 7.1)
> so there shouldn't be any side effect.
>
> Perahps it's wise to do the same for the line that add "msvcr70"
> (but I don't know).
>
> Perhaps it's wise to do the same on lines 130-135 (The same code,
> but for cygwin's internal gcc, and not mingw's gcc), but I don't
> know if cygwin suffer for the same problems.
>
>
> _______________________________________________
> Distutils-SIG maillist - Distutils-SIG at python.org
> http://mail.python.org/mailman/listinfo/distutils-sig
>
>
--
Michiel de Hoon, Assistant Professor
University of Tokyo, Institute of Medical Science
Human Genome Center
4-6-1 Shirokane-dai, Minato-ku
Tokyo 108-8639
Japan
http://bonsai.ims.u-tokyo.ac.jp/~mdehoon
More information about the Distutils-SIG
mailing list