prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Python2 Build fails with make: *** [Makefile:426: sharedmods] Error 139
  # Python version: 3.6
  # OS: Arch Linux 
  # python-for-android version: 0.6.0 
  
  The command I use to build is:
  
  `  
      p4a  apk --private ~/Projects/Python/Mobile_Apps/BeerApp/ --package=org.drink.recommendations --name "Drink Recommendations" --version 0.2 --bootstrap=sdl2 --requirements=python2,kivy --ndk_version r9c
  `
  
  The error is:
  
  `
      make: *** [Makefile:426: sharedmods] Error 139
  `
  
  The build logs are in the following file.
  [p4a_errors.txt](https://github.com/kivy/python-for-android/files/2091833/p4a_errors.txt)
  
  Initally I thought that this was a buildozer issue, as I attempted it that way first. So, I opened an issue on their github page and multiple users pointed out that they too were experiencing this issue. I've tried with both python3 and python2, the out come is the same. There is absolutely no unicode in any of my source files, I've also attempted the build with pygame instead of sdl2 (for python 2). There are also multiple simillar SO threads open about this. 
  
  Does anyone have any sugesstions or ideas as to why this is happening and how to go about fixing it?
  
  It's also worth noting that if I use the kivy buildozer vm, I can use buildozer to carry out a successful build. Just not on any other machine using either buildozer or p4a, using the same source and build commands.
  
  The buildozer issue is here: https://github.com/kivy/buildozer/issues/673
  
  The output from the dump file is:
  
  `
      Reading symbols from /home/suroh/.local/share/python-for-android/build/other_builds/hostpython2/desktop/hostpython2/python...done.
      [New LWP 28854]
      [Thread debugging using libthread_db enabled]
      Using host libthread_db library "/usr/lib/libthread_db.so.1".
      Core was generated by ./python -E ./setup.py -q build.
      Program terminated with signal SIGSEGV, Segmentation fault.
      #0  0x000055731803eb2a in PyInstance_NewRaw (klass=klass@entry=0x7f7cbf1d1c18, dict=0x557319325210, dict@entry=0x0) at Objects/classobject.c:534
      534         inst->in_dict = dict;
      File "/home/suroh/.local/share/python-for-android/build/other_builds/hostpython2/desktop/hostpython2/python-gdb.py", line 55
          Py_TPFLAGS_HEAPTYPE = (1L << 9)
                                  ^
      SyntaxError: invalid syntax
  `
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pythonforandroid/recipes/hostpython2/__init__.py`
  Content:
  ```
  1 
  2 from pythonforandroid.toolchain import Recipe, shprint, current_directory, info, warning
  3 from os.path import join, exists
  4 import os
  5 import sh
  6 
  7 
  8 class Hostpython2Recipe(Recipe):
  9     version = '2.7.2'
  10     url = 'https://python.org/ftp/python/{version}/Python-{version}.tar.bz2'
  11     name = 'hostpython2'
  12 
  13     conflicts = ['hostpython3']
  14 
  15     def get_build_container_dir(self, arch=None):
  16         choices = self.check_recipe_choices()
  17         dir_name = '-'.join([self.name] + choices)
  18         return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')
  19 
  20     def get_build_dir(self, arch=None):
  21         return join(self.get_build_container_dir(), self.name)
  22 
  23     def prebuild_arch(self, arch):
  24         # Override hostpython Setup?
  25         shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
  26                 join(self.get_build_dir(), 'Modules', 'Setup'))
  27 
  28     def build_arch(self, arch):
  29         with current_directory(self.get_build_dir()):
  30 
  31             if exists('hostpython'):
  32                 info('hostpython already exists, skipping build')
  33                 self.ctx.hostpython = join(self.get_build_dir(),
  34                                            'hostpython')
  35                 self.ctx.hostpgen = join(self.get_build_dir(),
  36                                            'hostpgen')
  37                 return
  38 
  39             if 'LIBS' in os.environ:
  40                 os.environ.pop('LIBS')
  41             configure = sh.Command('./configure')
  42 
  43             shprint(configure)
  44             shprint(sh.make, '-j5')
  45 
  46             shprint(sh.mv, join('Parser', 'pgen'), 'hostpgen')
  47 
  48             if exists('python.exe'):
  49                 shprint(sh.mv, 'python.exe', 'hostpython')
  50             elif exists('python'):
  51                 shprint(sh.mv, 'python', 'hostpython')
  52             else:
  53                 warning('Unable to find the python executable after '
  54                         'hostpython build! Exiting.')
  55                 exit(1)
  56 
  57         self.ctx.hostpython = join(self.get_build_dir(), 'hostpython')
  58         self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen')
  59 
  60 
  61 recipe = Hostpython2Recipe()
  62
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pythonforandroid/recipes/hostpython2/__init__.py b/pythonforandroid/recipes/hostpython2/__init__.py
  --- a/pythonforandroid/recipes/hostpython2/__init__.py
  +++ b/pythonforandroid/recipes/hostpython2/__init__.py
  @@ -10,6 +10,7 @@
       version = '2.7.2'
       url = 'https://python.org/ftp/python/{version}/Python-{version}.tar.bz2'
       name = 'hostpython2'
  +    patches = ['fix-segfault-pygchead.patch']
   
       conflicts = ['hostpython3']
  
verification_info: {"golden_diff": "diff --git a/pythonforandroid/recipes/hostpython2/__init__.py b/pythonforandroid/recipes/hostpython2/__init__.py\n--- a/pythonforandroid/recipes/hostpython2/__init__.py\n+++ b/pythonforandroid/recipes/hostpython2/__init__.py\n@@ -10,6 +10,7 @@\n     version = '2.7.2'\n     url = 'https://python.org/ftp/python/{version}/Python-{version}.tar.bz2'\n     name = 'hostpython2'\n+    patches = ['fix-segfault-pygchead.patch']\n \n     conflicts = ['hostpython3']\n", "issue": "Python2 Build fails with make: *** [Makefile:426: sharedmods] Error 139\n# Python version: 3.6\r\n# OS: Arch Linux \r\n# python-for-android version: 0.6.0 \r\n\r\nThe command I use to build is:\r\n\r\n`  \r\n    p4a  apk --private ~/Projects/Python/Mobile_Apps/BeerApp/ --package=org.drink.recommendations --name \"Drink Recommendations\" --version 0.2 --bootstrap=sdl2 --requirements=python2,kivy --ndk_version r9c\r\n`\r\n\r\nThe error is:\r\n\r\n`\r\n    make: *** [Makefile:426: sharedmods] Error 139\r\n`\r\n\r\nThe build logs are in the following file.\r\n[p4a_errors.txt](https://github.com/kivy/python-for-android/files/2091833/p4a_errors.txt)\r\n\r\nInitally I thought that this was a buildozer issue, as I attempted it that way first. So, I opened an issue on their github page and multiple users pointed out that they too were experiencing this issue. I've tried with both python3 and python2, the out come is the same. There is absolutely no unicode in any of my source files, I've also attempted the build with pygame instead of sdl2 (for python 2). There are also multiple simillar SO threads open about this. \r\n\r\nDoes anyone have any sugesstions or ideas as to why this is happening and how to go about fixing it?\r\n\r\nIt's also worth noting that if I use the kivy buildozer vm, I can use buildozer to carry out a successful build. Just not on any other machine using either buildozer or p4a, using the same source and build commands.\r\n\r\nThe buildozer issue is here: https://github.com/kivy/buildozer/issues/673\r\n\r\nThe output from the dump file is:\r\n\r\n`\r\n    Reading symbols from /home/suroh/.local/share/python-for-android/build/other_builds/hostpython2/desktop/hostpython2/python...done.\r\n    [New LWP 28854]\r\n    [Thread debugging using libthread_db enabled]\r\n    Using host libthread_db library \"/usr/lib/libthread_db.so.1\".\r\n    Core was generated by ./python -E ./setup.py -q build.\r\n    Program terminated with signal SIGSEGV, Segmentation fault.\r\n    #0  0x000055731803eb2a in PyInstance_NewRaw (klass=klass@entry=0x7f7cbf1d1c18, dict=0x557319325210, dict@entry=0x0) at Objects/classobject.c:534\r\n    534         inst->in_dict = dict;\r\n    File \"/home/suroh/.local/share/python-for-android/build/other_builds/hostpython2/desktop/hostpython2/python-gdb.py\", line 55\r\n        Py_TPFLAGS_HEAPTYPE = (1L << 9)\r\n                                ^\r\n    SyntaxError: invalid syntax\r\n`\n", "before_files": [{"content": "\nfrom pythonforandroid.toolchain import Recipe, shprint, current_directory, info, warning\nfrom os.path import join, exists\nimport os\nimport sh\n\n\nclass Hostpython2Recipe(Recipe):\n    version = '2.7.2'\n    url = 'https://python.org/ftp/python/{version}/Python-{version}.tar.bz2'\n    name = 'hostpython2'\n\n    conflicts = ['hostpython3']\n\n    def get_build_container_dir(self, arch=None):\n        choices = self.check_recipe_choices()\n        dir_name = '-'.join([self.name] + choices)\n        return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')\n\n    def get_build_dir(self, arch=None):\n        return join(self.get_build_container_dir(), self.name)\n\n    def prebuild_arch(self, arch):\n        # Override hostpython Setup?\n        shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),\n                join(self.get_build_dir(), 'Modules', 'Setup'))\n\n    def build_arch(self, arch):\n        with current_directory(self.get_build_dir()):\n\n            if exists('hostpython'):\n                info('hostpython already exists, skipping build')\n                self.ctx.hostpython = join(self.get_build_dir(),\n                                           'hostpython')\n                self.ctx.hostpgen = join(self.get_build_dir(),\n                                           'hostpgen')\n                return\n\n            if 'LIBS' in os.environ:\n                os.environ.pop('LIBS')\n            configure = sh.Command('./configure')\n\n            shprint(configure)\n            shprint(sh.make, '-j5')\n\n            shprint(sh.mv, join('Parser', 'pgen'), 'hostpgen')\n\n            if exists('python.exe'):\n                shprint(sh.mv, 'python.exe', 'hostpython')\n            elif exists('python'):\n                shprint(sh.mv, 'python', 'hostpython')\n            else:\n                warning('Unable to find the python executable after '\n                        'hostpython build! Exiting.')\n                exit(1)\n\n        self.ctx.hostpython = join(self.get_build_dir(), 'hostpython')\n        self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen')\n\n\nrecipe = Hostpython2Recipe()\n", "path": "pythonforandroid/recipes/hostpython2/__init__.py"}], "after_files": [{"content": "\nfrom pythonforandroid.toolchain import Recipe, shprint, current_directory, info, warning\nfrom os.path import join, exists\nfrom os import chdir\nimport os\nimport sh\n\n\nclass Hostpython2Recipe(Recipe):\n    version = '2.7.2'\n    url = 'https://python.org/ftp/python/{version}/Python-{version}.tar.bz2'\n    name = 'hostpython2'\n    patches = ['fix-segfault-pygchead.patch']\n\n    conflicts = ['hostpython3']\n\n    def get_build_container_dir(self, arch=None):\n        choices = self.check_recipe_choices()\n        dir_name = '-'.join([self.name] + choices)\n        return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')\n\n    def get_build_dir(self, arch=None):\n        return join(self.get_build_container_dir(), self.name)\n\n    def prebuild_arch(self, arch):\n        # Override hostpython Setup?\n        shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),\n                join(self.get_build_dir(), 'Modules', 'Setup'))\n\n    def build_arch(self, arch):\n        with current_directory(self.get_build_dir()):\n\n            if exists('hostpython'):\n                info('hostpython already exists, skipping build')\n                self.ctx.hostpython = join(self.get_build_dir(),\n                                           'hostpython')\n                self.ctx.hostpgen = join(self.get_build_dir(),\n                                           'hostpgen')\n                return\n            \n            if 'LIBS' in os.environ:\n                os.environ.pop('LIBS')\n            configure = sh.Command('./configure')\n\n            shprint(configure)\n            shprint(sh.make, '-j5')\n\n            shprint(sh.mv, join('Parser', 'pgen'), 'hostpgen')\n\n            if exists('python.exe'):\n                shprint(sh.mv, 'python.exe', 'hostpython')\n            elif exists('python'):\n                shprint(sh.mv, 'python', 'hostpython')\n            else:\n                warning('Unable to find the python executable after '\n                        'hostpython build! Exiting.')\n                exit(1)\n\n        self.ctx.hostpython = join(self.get_build_dir(), 'hostpython')\n        self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen')\n\n\nrecipe = Hostpython2Recipe()\n", "path": "pythonforandroid/recipes/hostpython2/__init__.py"}]}