some uglyness in Python imho

Jay Krell jay.krell at cornell.edu
Mon Sep 11 10:35:30 EDT 2000


>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.

I just think the macro is ugly and *sort of* compromises the portability of
the source.
Right, the chance of forgetting the macro is probably lower given all the
likely nearby uses.

>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.
>
>> 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).

That's true, I forgot about that. Tcl has gone away from the native
mechanisms in order to control versioning issues. They do use offets into a
struct with their new mechanism --  a struct of function pointers. They do
not use ordinals in the "native Win32 dynamic linking sense", that requires
a hand maintained .def file, though they are definitely in some sense using
ordinals.

But, right, you sort of said, they still do support native linking and
export everything by name as well. Theoretically, once you move to your own
custom export by struct of function pointers mechanism, you can reduce your
exports to just one, "GetExports". There's even a Microsoft KB that
describes this approach. Of course, it's very COM-like as well, where you
just create objects that have vtables, and the only exported function is the
function to create objects.

And Tcl seems to avoid dynamic linking to data..

I've got Tcl/Tk in my build system too, also using .def files..

 ..Jay

-----Original Message-----
From: Paul Duffin <pduffin at hursley.ibm.com>
Newsgroups: comp.lang.python
To: python-list at python.org <python-list at python.org>
Date: Monday, September 11, 2000 5:15 AM
Subject: Re: some uglyness in Python imho


>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).
>--
>http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list