some uglyness in Python imho

Paul Duffin pduffin at
Mon Sep 11 10:23:11 CEST 2000

Jay Krell wrote:
> I hadn't considered the difficulty of maintenance. Darn.
> >Since most development is done on Unix...
> Something to consider when most development moves to Windows. :)
> Right about Tcl. They used to run a simple (but correct) tool over the .objs
> to generate the .def. I think they're fully/only
> __declspec(dllimport/dllexport) now. I don't know why.

I don't know too much about how Tcl is built on Windows, specifically when
it comes down to usage of .def files against inline __declspec() calls.
Having a macro which is only needed on one platform is really no better
than a file because it is always possible to forget it, just as it is
possible to forget to update the file although the chances of it
happening are lower.

However, I do know that Tcl no longer has to rely on the platform linking
mechanism, instead it uses a very simple cross platform linking mechanism.
One of the 'features' of this is that Tcl now has a file which describes 
its external API which is used to automatically generate the files this
mechanism needs. It would be very easy to also automatically generate a
.def file from this as well.

As this mechanism is used on all platforms this description file is up to
date because it has to be.

> > ...besides, if Microsoft didn't want us to use this, they
> > shouldn't have added the declspec directive to the compiler
> > in the first place ;-)
> __declspec(dllimport) is a slight optimization, which is probably a big
> reason it exists. It saves one instruction per imported function call on
> x86, and some scheduling freedom, which the compiler actually takes
> advantage of. Without __declspec(dllimport), calls to imported functions are
> calls to a one instruction function that jumps through the (patched at
> runtime)) function pointer. With __declspec(dllimport), calls to imported
> functions are call through the function pointer, and sometimes the optimizer
> preloads the contents of the function pointer into a register and later
> jumps through it.
> __declspec(dllimport) on data is "impossible" without __declspec(dllimport),
> you have to use functions instead.
> I still doubt it's worth it..
> And just fyi, sometimes both the __declspecs and a .def file are used, like
> to get the optimization and to export by ordinal.

I have a feeling that that may be what Tcl does (it still tries to 
support the normal platform specific linking mechanism).

More information about the Python-list mailing list