[Python-Dev] Sharing functions between C extension modules in stdlib (original) (raw)

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Jun 15 00:45:49 CEST 2010


I have learned a long time ago that it is not enough to simply declare a function in some header file if you want to define it in one module and use in another. You have to use what now is known as PyCapsule - an array of pointers to C functions wrapped in a Python object. However, while navigating through the time/datetime maze recently I have come across timefuncs.h which seems to share _PyTime_DoubleToTimet between time and datetime modules.

I did not expect this to work, but apparently the build machinery somehow knows how to place _PyTime_DoubleToTimet code in both time.so and datetime.so:

$ nm build/lib.macosx-10.4-x86_64-3.2-pydebug/datetime.so | grep _PyTime_DoubleToTimet 000000000000f4e2 T __PyTime_DoubleToTimet $ nm build/lib.macosx-10.4-x86_64-3.2-pydebug/time.so | grep _PyTime_DoubleToTimet 0000000000000996 T __PyTime_DoubleToTimet

I have two questions: 1) how does this happen; and 2) is this intentional?

Thanks.



More information about the Python-Dev mailing list