[Distutils] More (Windows) comments on distutils-0.1.2

Greg Ward gward@cnri.reston.va.us
Mon, 17 Jan 2000 15:39:51 -0500


On 13 January 2000, Thomas Heller said:
> 1. Python extensions for Windows MUST be linked with
> the /MD switch to use the multithreaded runtime
> library. Optimizations are also enabled by the following
> line:
> 
> > class MSVCCompiler (CCompiler) :
> >     def __init__ (self,
> >         [...]
> >         self.compile_options = [ '/nologo', '/Ox', '/MD', '/GD' ]

I haven't seen any disagreement with this, so I'll take your word for
it.  I'd feel more comfortable if another Python/Windows extension
developer would speak up and say, "Yep, that's the Right Thing to do".
(Mark?  Guido?)

So what are the flags here?  I assume /Ox is for optimization; you said
/MD selects the multithreaded RT library.  What is /GD for?


> 2. In build_ext.py I find the following code:
> 
[...code to deal with .def files elided...]

> Doesn't this belong into msvccompiler.py?

If anywhere at all.  I really, really dislike this whole .def file
thing, and I don't like them cluttering up the build options dictionary
or the build_ext command class.  But I don't know how else to do it,
because I know about as much about Python on Windows as I do about
skateboarding on Pluto.

> We do not need any stinkin' DEF-files, if we use the link options
> /EXPORT and /BASE. The following code builds the required arguments:

Hallelujah!  I've been waiting for someone to say this.  Ever since I
found out what .def files are, I've been wondering why the heck they are
needed. 

> >        if def_file is not None:
> >            extra_args.append ('/DEF:' + def_file)
> >        else:
> >            # if no def file is found, export the init<name> function
> >            # and calculate a random base address
> >            extra_args.append ('/EXPORT:init' + extension_name)
> >            import whrandom
> >            base = whrandom.randint (0x1000, 0x8000) * 0x10000
> >            extra_args.append ('/BASE:0x%x' % base)

But this looks weird: a random base address?  What the heck is going on
here?  Again, could another Python-on-Windows expert speak up?  Nothing
personal, Thomas, but I don't want to take the word of just one person
on this code, and I'd like to know what the heck the random base address
is all about.

Thanks for the code -- now let's hear from some other voices as to
whether this is the Right Thing to add to Distutils to compile
extensions with MSVC.  Anyone?

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                           voice: +1-703-620-8990
Reston, Virginia, USA  20191-5434                    fax: +1-703-620-0913