[Python-Dev] Sharing functions between C extension modules in stdlib

"Martin v. Löwis" martin at v.loewis.de
Tue Jun 15 01:09:44 CEST 2010


> $ 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;

'T' means "defined in text segment", so it looks like the code is 
included twice. And indeed, it is:

exts.append( Extension('time', ['timemodule.c'],
                                libraries=math_libs) )
exts.append( Extension('datetime', ['datetimemodule.c', 'timemodule.c'],
                                libraries=math_libs) )

 > and 2) is this intentional?


This was added with

------------------------------------------------------------------------
r36221 | bcannon | 2004-06-24 03:38:47 +0200 (Do, 24. Jun 2004) | 3 Zeilen

Add compilation of timemodule.c with datetimemodule.c to get
__PyTime_DoubleToTimet().

------------------------------------------------------------------------

So it's clearly intentional. I doubt its desirable, though. If only
__PyTime_DoubleToTimet needs to be duplicated, I'd rather put that
function into a separate C file that gets included twice, instead of 
including the full timemodule.c into datetimemodule.c.

Regards,
Martin


More information about the Python-Dev mailing list