Author chaselton
Recipients chaselton
Date 2015-02-21.20:46:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424551617.0.0.291471450783.issue23496@psf.upfronthosting.co.za>
In-reply-to
Content
This is a (hopefully) complete list of patches and modifications required to natively build Python 3.4.2 on an Android device where
patches == listed issues in this bug tracker
modifications (mods) == unsubmitted patches and/or edits made to source

CAVEATS
Build was completed on a tablet running Android 4.4.2 and within the KBOX environment; an app that simulates a Linux filesystem by using a ported version of fakechroot.  Details of the environment can be found here: http://kevinboone.net/kbox2_how_it_works.html. NOTE: During the Python build it was necessary to patch this environment with a modified version of fakechroot; the KBOX version currently available as of 2.21.2015 may not contain the modified fakechroot.

CONFIGURE && POST-CONFIGURE && MAKE
The configure command was run with the following parameters
--enable-shared
--without-ensurepip
--prefix=/usr/python

After running configure. changes were made to pyconfig.h to account for various platform limitations and to Setup to ensure that a) all modules specified were built as shared and b) modules that used symbols from libpython were explicitly linked to said library. See attached pyconfig.h and Setup.

Make fails when the newly built python binary tries to execute and run setup.py. This is resolved by copying the shared library from the build directory to /lib in the KBOX environment.  Otherwise make && make install runs without errors provided patches/mods are applied. I did not run make test or the equivalent for this build.

PATCHES/MODS
The attached patches from the following issues must be applied:
http://bugs.python.org/issue20305
http://bugs.python.org/issue16353 (NOTE: use patch with 'defpath' not 'confstr', which is not supported in Android)
http://bugs.python.org/issue21668

The following modifications to source must be made:
The instructions under 'Code Changes' at this link: https://code.google.com/p/python-for-android/wiki/CrossCompilingPython
The attached patch, contributed by Ryan Gonzales (patch.diff)
The changes listed below by file (apologies for formatting)
        
/* patch for strdup segfault issue in readline.c */
 #define RESTORE_LOCALE(sl) { if (sl) { setlocale(LC_CTYPE, sl); free(sl); } }
 
 char *_locale = setlocale(LC_CTYPE, NULL); 
 char *saved_locale; 
 if(!_locale) 
 _locale = ""; 
 saved_locale = strdup(_locale);
 
 
 char *saved_locale = setlocale(LC_CTYPE, NULL);
    if (saved_locale != NULL) {
        saved_locale = strdup(saved_locale);
        if (!saved_locale)
            Py_FatalError("not enough memory to save locale");
    }
    

/* fix for Lib/ctypes/__init.py__ */
 30 DEFAULT_MODE ==  RTLD_GLOBAL
 
 /* patch for python.c */
/* here line for oldloc is commented out */
     24     int i, res;
     25     /* char *oldloc; */
     26 #ifdef __FreeBSD__

/* here oldloc lines commented out */
     46
     47   /*  oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL));
     48    * if (!oldloc) {
     49    *     fprintf(stderr, "out of memory\n");
     50    *     return 1;
     51    *
     52    * }
     53    */

 /* patch for pythonrun.c 307, --309-310, ++311-313 --1009-1012 ++1013-1014 */
 
    305     return get_codec_name(codeset);
    306 #else
    307    char* m;
    308    PyErr_SetNone(PyExc_NotImplementedError);
    309    /*  return NULL; */
    310    /* char* m; */
    311    m = malloc(6);
    312    strcpy(m, "ascii");
    313    return m;
    314 #endif
    315 }
    
   1002 static int
   1003 initfsencoding(PyInterpreterState *interp)
   1004 {
   1005     PyObject *codec;
   1006
   1007     if (Py_FileSystemDefaultEncoding == NULL)
   1008     {
   1009         /* Py_FileSystemDefaultEncoding = get_locale_encoding();
   1010          * if (Py_FileSystemDefaultEncoding == NULL)
   1011          *   Py_FatalError("Py_Initialize: Unable to get the locale encoding
   1011 ");
   1012          */
   1013            Py_FileSystemDefaultEncoding = malloc(6);
   1014            strcpy(Py_FileSystemDefaultEncoding, "ascii");
   1015         Py_HasFileSystemDefaultEncoding = 0;
   1016         interp->fscodec_initialized = 1;
   1017         return 0;
   1018     }
   1019
   
/* changes to Lib/plat-linux/DLFCN.py */
     76 # Included from bits/dlfcn.h
     77 # Changed for Android
     78 RTLD_LAZY = 1
     79 RTLD_NOW = 0
     80 #RTLD_BINDING_MASK = 0x3
     81 #RTLD_NOLOAD = 0x00004
     82 RTLD_GLOBAL = 2
     83 RTLD_LOCAL = 0
     84 #RTLD_NODELETE = 0x01000
     85
     86 # Also from Android's dlfcn.h
     87 RTLD_DEFAULT ((void*) 0xffffffff)
     88 RTLD_NEXT     ((void*) 0xfffffffe)
     89
History
Date User Action Args
2015-02-21 20:46:57chaseltonsetrecipients: + chaselton
2015-02-21 20:46:57chaseltonsetmessageid: <1424551617.0.0.291471450783.issue23496@psf.upfronthosting.co.za>
2015-02-21 20:46:56chaseltonlinkissue23496 messages
2015-02-21 20:46:55chaseltoncreate