Title: Lack of pw_gecos field in Android's struct passwd causes cross-compilation for the pwd module to fail
Type: compile error Stage: resolved
Components: Build Versions: Python 3.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: skrah Nosy List: WanderingLogic, freakboy3742, pitrou, python-dev, shiz, skrah, xdegaye
Priority: normal Keywords: patch

Created on 2014-01-19 18:23 by shiz, last changed 2016-04-26 09:50 by skrah. This issue is now closed.

File name Uploaded Description Edit
Python-3.4.0tip-workaround-android-missing-pw_gecos-field.patch shiz, 2014-01-19 18:23 A patch that works around the lack of a pw_gecos field by setting the relevant value to None. review
pw_gecos-field-workaround-with-config_ac-mods.patch WanderingLogic, 2014-10-24 22:44 shiz's patch extended with the required addition to review
pw_gecos-field-workaround-with-config_ac-mods.patch WanderingLogic, 2015-01-30 22:42 patch without mods to generated files (just mods pwdmodule.c and review
Messages (9)
msg208487 - (view) Author: Shiz (shiz) * Date: 2014-01-19 18:23
As the title states, mkpwent() in pwdmodule.c accesses `pw_gecos`, which is not defined for struct passwd in Bionic, Android's C library.

Attached is a patch that works around the issue by setting the field to None on Android.
msg217356 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-04-28 10:21
Interesting. It seems pw_gecos isn't mandated by POSIX:

I wonder if there's a better way to do this (autoconf check?) than an Android-specific #ifdef, though.
msg217368 - (view) Author: Shiz (shiz) * Date: 2014-04-28 12:20
Ah, yes, if it's not actually mandated by POSIX, something like HAVE_PASSWD_PW_GECOS would be more appropriate. I'll rework the patch into something more generic.
msg229964 - (view) Author: Matt Frank (WanderingLogic) * Date: 2014-10-24 22:44
Here is shiz's patch extended with the addition to  I added the variable HAVE_PASSWD_GECOS_FIELD and the appropriate tests.  Luckily this very problem (missing pw_gecos field) is the example used in the autoconf manual (  (Otherwise I would have been as lost as I usually am with autoconf.)
msg235061 - (view) Author: Matt Frank (WanderingLogic) * Date: 2015-01-30 22:42
Apologies.  That last patch includes diffs to generated files (configure and  This version just patches Modules/pwdmodule.c and

After applying the patch please run "autoheader" and "autoconf" to correctly regenerate configure and
msg264201 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-25 23:10
New changeset 0d74d4937ab9 by Stefan Krah in branch 'default':
Issue #20306: The pw_gecos and pw_passwd fields are not required by POSIX.
msg264229 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2016-04-26 07:55
With changeset 0d74d4937ab9, test_pwd fails on android API level 21 at test_values with:
  Traceback (most recent call last):
    File "/sdcard/org.bitbucket.pyona/lib/python3.6/test/", line 27, in test_values
      self.assertIsInstance(e.pw_passwd, str)
  AssertionError: None is not an instance of <class 'str'>

On android API 21 HAVE_STRUCT_PASSWD_PW_PASSWD is defined but p->pw_passwd is set to NULL.
msg264243 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-26 09:43
New changeset f0f519aca558 by Stefan Krah in branch 'default':
Issue #20306:  Android is the only system that returns NULL for the pw_passwd
msg264244 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-04-26 09:50
Okay, for the record: I think that returning "None" would probably be
more correct than the empty string, but I don't think users actually
care to the point that they will introduce a case split in their

Realistically, probably no one cares about pw_passwd at all.
Date User Action Args
2016-04-26 09:50:06skrahsetmessages: + msg264244
2016-04-26 09:43:35python-devsetmessages: + msg264243
2016-04-26 07:55:47xdegayesetnosy: + xdegaye
messages: + msg264229
2016-04-26 00:04:14skrahsetstatus: open -> closed
assignee: skrah
components: + Build, - Cross-Build
versions: + Python 3.6, - Python 3.4, Python 3.5
nosy: + skrah

resolution: fixed
stage: resolved
2016-04-25 23:10:39python-devsetnosy: + python-dev
messages: + msg264201
2015-01-30 22:42:38WanderingLogicsetfiles: + pw_gecos-field-workaround-with-config_ac-mods.patch

messages: + msg235061
2014-10-27 15:58:33WanderingLogicsetnosy: + freakboy3742
2014-10-24 22:44:46WanderingLogicsetfiles: + pw_gecos-field-workaround-with-config_ac-mods.patch

messages: + msg229964
2014-10-24 22:06:19WanderingLogicsetnosy: + WanderingLogic
2014-04-28 12:20:48shizsetmessages: + msg217368
2014-04-28 10:21:21pitrousetnosy: + pitrou

messages: + msg217356
versions: + Python 3.5
2014-01-19 18:23:41shizcreate