This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Weak linking support for OSX
Type: Stage:
Components: Extension Modules Versions:
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: loewis, ronaldoussoren
Priority: normal Keywords: patch

Created on 2006-04-17 19:49 by ronaldoussoren, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
weaklinking.patch ronaldoussoren, 2006-04-17 19:49
weaklinking-2.patch ronaldoussoren, 2006-04-18 19:27
weaklinking-3.patch ronaldoussoren, 2006-04-18 19:29
Messages (8)
msg50048 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-04-17 19:49
The "itch" that is scratched by this patch is the wish to be able to use a 
python binary that was build on OSX 10.4 on OSX 10.3 systems. At the 
same time the binary should offer full access to OSX 10.4 API's when 
running on that system.

This patch weakly links a number of functions in the posix, time and 
socket modules.

I'm not quite happy with code duplication in the time and socket modules, 
but don't quite know how to fix that.
msg50049 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-04-17 19:50
Logged In: YES 

I should not that I haven't checked this patch on other platforms than osx 10.4/
msg50050 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-04-17 22:18
Logged In: YES 

The patch looks fine to me. I wonder why you are clearing
the errors from PyObject_DelAttrString, though: There
shouldn't be any errors (right?), so if that fails,
something is seriously wrong.

As for the time changes: are you saying OSX doesn't have
gettimeofday? I can find a manual page on

This has higher resolution than ftime, and also takes higher
precedence in timemodule.c: Why is it not used?
msg50051 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-04-18 19:27
Logged In: YES 

Good points. I was clearing errors because it seemed better to ignore errors. 
But you're right, if this does fail somethings is seriously wrong. I've replaced 
error-checking by return statements (but have not replaced the patch).

The change to time is interesting, I added those changes because the binary 
wouldn't run without the patch, without realizing that configure/timemodule 
is picking up the wrong function for finding the current time.  That seems to 
be caused by a bug in the preprocessor code that selects the right section of 
code. OSX 10.4 has both gettimeofday and ftime, and with the current set of 
#if statements this means both the gettimeofday and ftime blocks get 
compiled in. The ftime-bit is dead code, but present nonetheless.

I tried to rearange the #if-statements to make sure just one block gets 
included, but then get compiler warnings because floattime checks for an 
error-return of gettimeofday.  IMHO the error-return check is rather lame, 
the only reason this could fail is when the first argument of gettimeofday is 
invalid (and SUS says this function will always return 0, although manpage on 
darwin and linux claim otherwise), And time(2) can also return -1 to indicate 
failure ;-)

If uploaded a new patch (version 2) that removes error clearing for the DelAttr 
calls in posixmodule and chickens out on the ftime issue by #undef-ing 

msg50052 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-04-18 19:29
Logged In: YES 

Version 3 solves the ftime issue the other (IMO more correct) way: it ignores the 
returnvalue of gettimeofday and conditionalizes the floattime code in such way 
that either gettimeofday or ftime is used, but never both.

msg50053 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-04-20 20:44
Logged In: YES 

The patch is fine(*). Please do add a comment to the time
implementation to elaborate on the story of return values,
and why falling back should not be done (it ought not be
necessary, on systems where it is necessary, it might not
help, and it will hurt the OSX port).

One more bit on return values: gettimeofday can indeed fail
on Linux, and also when there is a TZ problem. OTOH, ftime
is implemented on top of gettimeofday (sic), and will then
fail for the same reason. I haven't looked at the time

If you want to be really cautious, you could return 0.0 in
case the functions fail. The only caller of floattime will
then raise an IOError.
msg50054 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-04-20 20:54
Logged In: YES 

Thanks for the review. I will apply this patch this weekend, including the 
additional documentation in the time module.
msg50055 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2006-04-23 11:59
Logged In: YES 

I've checked in weaklinking-2.patch with a better comment. This is the version 
that #undefs HAVE_FTIME on OSX. I've checked in this version instead of the 
newer one because a comment in floattime claims that gettimeofday does 
actually fail on some platforms.

Checked in as revision 45660
Date User Action Args
2022-04-11 14:56:16adminsetgithub: 43230
2006-04-17 19:49:03ronaldoussorencreate