--- /home/user/.tmp/cpython-3de678cd184d/Modules/main.c 2014-12-18 23:47:55.000000000 +0100 +++ /home/user/.tmp/cpython-edited/Modules/main.c 2014-12-30 16:52:22.126885885 +0100 @@ -37,7 +37,7 @@ static int orig_argc; /* command line options */ -#define BASE_OPTS L"bBc:dEhiIJm:OqRsStuvVW:xX:?" +#define BASE_OPTS L"bBc:dEhiIJm:Op:qRsStuvVW:xX:?" #define PROGRAM_OPTS BASE_OPTS @@ -63,6 +63,8 @@ -m mod : run library module as a script (terminates option list)\n\ -O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x\n\ -OO : remove doc-strings in addition to the -O optimizations\n\ +-p pth : let pth become the highest priority module search path,\n\ + earlier ones have higher priority in case of multiple such arguments\n\ -q : don't print version and copyright messages on interactive startup\n\ -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE\n\ -S : don't imply 'import site' on initialization\n\ @@ -345,6 +347,17 @@ PyObject *warning_option = NULL; PyObject *warning_options = NULL; + int searchpath_args_num = 0; + wchar_t ** searchpath_args = NULL; + PyObject * sys_path = NULL; + + searchpath_args = + /* max number of `-p` arg strings <= argc */ + (wchar_t **)PyMem_RawCalloc(argc, sizeof(wchar_t*)); + if(searchpath_args == NULL){ + Py_FatalError("not enough memory to reference searchpath arguments"); + } + cf.cf_flags = 0; orig_argc = argc; /* For Py_GetArgcArgv() */ @@ -489,6 +502,10 @@ /* Ignored */ break; + case 'p': + searchpath_args[searchpath_args_num++] = _PyOS_optarg; + break; + /* This space reserved for other options */ default: @@ -669,6 +686,41 @@ Py_Initialize(); Py_XDECREF(warning_options); + sys_path = PySys_GetObject("path"); + if (sys_path == NULL) { + Py_FatalError("failure in handling of -p arguments, unable to get sys.path\n"); + } else { + /* This loop is O(n^2), since insert is O(n). Creating a new list, and + * appending everything would be O(n), given the amortized O(1) append. */ + /* The first `-p` argument must be the last one prepended, + * so it becomes the head of sys.path. The second ... */ + for(/* `case 'p'` */; 0