clone 484305 -1 reassign -1 vim-python thanks Shouldn't Python builds of vim avoid this bug by stopping '' from being prepended to sys.path in the first place?
After looking through Python initialization and vim's if_python.c it seems that the way forward is to set Python's argv, via PySys_SetArgv(), to have a non-empty and absolute first argument. vim sets Python's argv to { "", NULL }, which according to a comment is to avoid a crash when warn() is called. Changing that to { "/usr/bin/vim", NULL } would seem to solve this problem - but for that matter, any safe value is fine. A safe value for argv[0] is any value where there won't be files dir/*.py or dir/*/__init__.py, where dir == dirname(argv[0]). So setting argv[0] to "/", "/usr/lib/something" or "/usr/share/vim" would be safe too, for instance. I'm afraid I haven't tested this in vim itself (the multiple builds take a while...) but the attached program demonstrates it: [EMAIL PROTECTED] gcc -o484305 `python-config --cflags` `python-config --ldflags` 484305.c [EMAIL PROTECTED] ./484305 (I have no argv!) ['/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', ... more output ... '/var/lib/python-support/python2.5/pyinotify'] [EMAIL PROTECTED] ./484305 "" [''] ['', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', ... more output ... '/var/lib/python-support/python2.5/pyinotify'] [EMAIL PROTECTED] ./484305 "/usr/bin/vim" ['/usr/bin/vim'] ['/usr/bin', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', ... more output ... '/var/lib/python-support/python2.5/pyinotify'] Hope this helps, Simon
/* * Usage: * gcc -o484305 `python-config --cflags` `python-config --ldflags` 484305.c * ./484305 <- default behaviour of embedded Python * ./484305 "" <- what vim does now * ./484305 /usr/bin/vim * ./484305 / * ./484305 /usr/share/vim */ #include <Python.h> int main(int argc, char **argv) { char *replacement_argv[] = { argv[1], NULL }; Py_Initialize(); if (argc >= 2) { PySys_SetArgv(1, replacement_argv); } PyRun_SimpleString("import sys\n" "print getattr(sys, 'argv', '(I have no argv!)')\n" "print sys.path\n"); return 0; }