classification
Title: gethostbyname_r() is broken on android
Type: behavior Stage: resolved
Components: Cross-Build Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: skrah Nosy List: Alex.Willmer, Chi Hsuan Yen, python-dev, skrah, xdegaye
Priority: normal Keywords: patch

Created on 2016-04-26 13:33 by xdegaye, last changed 2016-05-22 15:37 by skrah. This issue is now closed.

Files
File name Uploaded Description Edit
socketmodule.patch xdegaye, 2016-04-26 13:33 review
socketmodule_2.patch xdegaye, 2016-05-11 06:44 conditional on __ANDROID_API__ value review
issue26857.diff skrah, 2016-05-22 13:36 review
Messages (13)
msg264280 - (view) Author: Xavier de Gaye (xdegaye) * (Python committer) Date: 2016-04-26 13:33
HAVE_GETHOSTBYNAME_R is defined on android API 21, but importing the _socket module fails with:

    ImportError: dlopen failed: cannot locate symbol "gethostbyaddr_r" referenced by "_socket.cpython-36m-i386-linux-gnu.so"

Patch attached.
The patch does not take into account the fact that this may be fixed in future versions of android.
msg264290 - (view) Author: Roundup Robot (python-dev) Date: 2016-04-26 14:20
New changeset eb19ad1918cd by Stefan Krah in branch 'default':
Issue #26857: Workaround for missing symbol "gethostbyaddr_r" on Android.
https://hg.python.org/cpython/rev/eb19ad1918cd
msg264296 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-04-26 14:37
Thanks, fixed.
msg265292 - (view) Author: Xavier de Gaye (xdegaye) * (Python committer) Date: 2016-05-11 06:44
gethostbyaddr_r() is implemented now on Android 6.0 (API 23). The attached patch has been tested on the android-21-x86 emulator (API 21) and android-23-x86 emulator (API 23). No new NDK has been released at Android 5.1 (API 22) so there is no need to test the patch for this release.
msg265309 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-05-11 12:17
How about supporting API >= 23 only? Can people upgrade their devices or do they have to buy a new one?
msg265310 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2016-05-11 12:48
> Can people upgrade their devices or do they have to buy a new one?

AFAIK most models other than Nexus won't get updates with a bumped major version. (5.x => 6.x for example)
msg265315 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2016-05-11 13:28
By the way, socketmodule_2.patch is problematic. Developers may choose to build CPython against API level 21 and run it on all devices with API level >= 21. In general Android keeps ABI compatibility between consecutive versions. That is, most binaries built for API 21 can be run on API 21, 22, 23 and 24. With this patch, developers have to build two versions of CPython, one for API < 23 and one for API >= 23, or gethostbyname_r() may not be used.
msg265321 - (view) Author: Xavier de Gaye (xdegaye) * (Python committer) Date: 2016-05-11 15:42
So what is problematic with this new patch ?  Obviously you need to build with API 23 to get gethostbyname_r() since it was not supported by android before, with the previous patch you don't get gethostbyname_r(), even when building with API 23.
msg265323 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2016-05-11 15:54
I was thinking the (somewhat hacky) dlopen() approach so that gethostbyname_r() works in API 21 builds. If a universal build is not necessary this patch is OK.
msg266077 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-05-22 13:36
Okay thanks, let's assume api-level >= 21 for now. I've moved the include into pyport.h in order to save a little space everywhere. Could you check if that works?
msg266079 - (view) Author: Xavier de Gaye (xdegaye) * (Python committer) Date: 2016-05-22 14:50
> I've moved the include into pyport.h

and also fixed the error in my patch, thanks :)

With issue26857.diff, importing the socket module does not fail both with an API 21 emulator and an API 23 emulator.
msg266082 - (view) Author: Roundup Robot (python-dev) Date: 2016-05-22 15:36
New changeset 09af54099973 by Stefan Krah in branch 'default':
Issue #26857: The gethostbyaddr_r() workaround is no longer needed with
https://hg.python.org/cpython/rev/09af54099973
msg266083 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-05-22 15:37
Thanks! Closing again.
History
Date User Action Args
2016-05-22 15:37:26skrahsetstatus: open -> closed
resolution: fixed
messages: + msg266083
2016-05-22 15:36:16python-devsetmessages: + msg266082
2016-05-22 14:50:26xdegayesetmessages: + msg266079
2016-05-22 13:36:23skrahsetfiles: + issue26857.diff

messages: + msg266077
2016-05-11 15:54:52Chi Hsuan Yensetmessages: + msg265323
2016-05-11 15:42:37xdegayesetmessages: + msg265321
2016-05-11 13:28:06Chi Hsuan Yensetmessages: + msg265315
2016-05-11 12:48:14Chi Hsuan Yensetmessages: + msg265310
2016-05-11 12:17:38skrahsetnosy: + Chi Hsuan Yen
messages: + msg265309
2016-05-11 06:44:07xdegayesetstatus: closed -> open
files: + socketmodule_2.patch
resolution: fixed -> (no value)
messages: + msg265292
2016-04-26 16:04:41zach.warelinkissue26865 dependencies
2016-04-26 14:37:00skrahsetstatus: open -> closed

assignee: skrah

nosy: + skrah
messages: + msg264296
resolution: fixed
stage: resolved
2016-04-26 14:20:52python-devsetnosy: + python-dev
messages: + msg264290
2016-04-26 13:33:19xdegayecreate