I have a sneaking suspicion that py2app's handling of command line arguments
in python 3 is fundamentally broken.
My application is written to potentially accept a large number of command line
arguments, and I regularly experience Bus error or Segmentation fault
crashes when passing more than a handful of arguments to a py2app-built
instance. I traced the crashes to
py2app/src/apptemplate/main.c:1037-1053.
This block reads in command line arguments one-by-one, decodes them into UTF8
strings, and then casts them into an array which is then passed to
PySys_SetArgv. However, there are a number of fundamental bugs in this
block, related to invalid use of the Python c-api, and invalid type-casting.
The patch listed below fixes my problems for python 3, but breaks support for
python 2. Unfortunately I don't know the py2app code well enough to propose
a perfect solution to this problem. For example, I'm not sure how you would be
able to typedef both the python-2 and -3 versions of the PySys_SetArgv
function, nor how you will be able to use a single definition of the
argv_new pointer for both py2 and 3.
This was fixed as a side effect of #370 . The patch above was correct, the call to surrogateescape was missing an argument (and is no longer needed now that there is a pu7blic API for this).
Original report by Paul McCarthy (Bitbucket: pauldmccarthy, GitHub: pauldmccarthy).
Howdy,
I have a sneaking suspicion that py2app's handling of command line arguments in python 3 is fundamentally broken.
My application is written to potentially accept a large number of command line arguments, and I regularly experience
Bus error
orSegmentation fault
crashes when passing more than a handful of arguments to a py2app-built instance. I traced the crashes to py2app/src/apptemplate/main.c:1037-1053.This block reads in command line arguments one-by-one, decodes them into UTF8 strings, and then casts them into an array which is then passed to
PySys_SetArgv
. However, there are a number of fundamental bugs in this block, related to invalid use of the Python c-api, and invalid type-casting.The patch listed below fixes my problems for python 3, but breaks support for python 2. Unfortunately I don't know the
py2app
code well enough to propose a perfect solution to this problem. For example, I'm not sure how you would be able to typedef both the python-2 and -3 versions of thePySys_SetArgv
function, nor how you will be able to use a single definition of theargv_new
pointer for both py2 and 3.