James Henstridge wrote:
>
> I think the point where the path gets altered by importing gtk.py is where
> _gtk sets the modified argv array (the call to gtk_init processes any gtk
> specific command line arguments and removes them from argv). Does anyone
> have an idea for a fix?
It looks like PySys_SetArgv is the problem -- it tries extract a path
from argv[0] and prepend it to sys.path. The following patch should
take care of it (it's basically a cut-n-paste from the Python source).
I wonder if the behavior of PySys_SetArgv should be changed so that it
only mucks with sys.path the first time it is called...
--
Richard Fish Enhanced Software Technologies, Inc.
Software Developer 4014 E Broadway Rd Suite 405
[EMAIL PROTECTED] Phoenix, AZ 85040
(602) 470-1115 http://www.estinc.com
--- gtkmodule.c.old Mon Dec 21 03:20:07 1998
+++ gtkmodule.c Thu Feb 11 21:42:47 1999
@@ -2904,6 +2904,31 @@
return obj;
}
+/* private function to rebuild argv */
+static PyObject * PyGtk_MakeArgvObject(int argc, char **argv) {
+ PyObject *av;
+ if (argc <= 0 || argv == NULL) {
+ /* Ensure at least one (empty) argument is seen */
+ static char *empty_argv[1] = {""};
+ argv = empty_argv;
+ argc = 1;
+ }
+ av = PyList_New(argc);
+ if (av != NULL) {
+ int i;
+ for (i = 0; i < argc; i++) {
+ PyObject *v = PyString_FromString(argv[i]);
+ if (v == NULL) {
+ Py_DECREF(av);
+ av = NULL;
+ break;
+ }
+ PyList_SetItem(av, i, v);
+ }
+ }
+ return av;
+}
+
static PyObject * _wrap_gtk_init(PyObject *self, PyObject *args) {
PyObject *av;
int argc, i;
@@ -2927,7 +2952,11 @@
argv[i] = strdup(PyString_AsString(PyList_GetItem(av, i)));
gtk_init(&argc, &argv);
- PySys_SetArgv(argc, argv);
+ av = PyGtk_MakeArgvObject(argc, argv);
+ if (av == NULL)
+ Py_FatalError("no mem to rebuild sys.argv");
+ if (PySys_SetObject("argv", av) != 0)
+ Py_FatalError("can't assign sys.argv");
if (argv != NULL) {
for (i = 0; i < argc; i++)