summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1997-01-29 15:08:24 (GMT)
committerBarry Warsaw <barry@python.org>1997-01-29 15:08:24 (GMT)
commit5ed19dcc0e9ccd534a783e5f8e9c4a647d7081bf (patch)
tree4fdc8efa418f4e33f514471bd25013bfcc19e587 /Modules
parent4acdc2327f206ecaacad7671d9acb87a3b7e57dd (diff)
downloadcpython-5ed19dcc0e9ccd534a783e5f8e9c4a647d7081bf.zip
cpython-5ed19dcc0e9ccd534a783e5f8e9c4a647d7081bf.tar.gz
cpython-5ed19dcc0e9ccd534a783e5f8e9c4a647d7081bf.tar.bz2
posix_execve(): Accept any mapping protocol object for the env
argument, not hardwired to a dictionary.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index d73397d..fab6b40 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -842,7 +842,7 @@ posix_execve(self, args)
PyObject *argv, *env;
char **argvlist;
char **envlist;
- PyObject *key, *val;
+ PyObject *key, *val, *keys=NULL, *vals=NULL;
int i, pos, argc, envc;
PyObject *(*getitem) Py_PROTO((PyObject *, int));
@@ -864,8 +864,8 @@ posix_execve(self, args)
PyErr_SetString(PyExc_TypeError, "argv must be tuple or list");
return NULL;
}
- if (!PyDict_Check(env)) {
- PyErr_SetString(PyExc_TypeError, "env must be dictionary");
+ if (!PyMapping_Check(env)) {
+ PyErr_SetString(PyExc_TypeError, "env must be mapping object");
return NULL;
}
@@ -884,16 +884,26 @@ posix_execve(self, args)
}
argvlist[argc] = NULL;
- i = PyDict_Size(env);
+ i = PyMapping_Length(env);
envlist = PyMem_NEW(char *, i + 1);
if (envlist == NULL) {
PyErr_NoMemory();
goto fail_1;
}
- pos = 0;
envc = 0;
- while (PyDict_Next(env, &pos, &key, &val)) {
+ keys = PyMapping_Keys(env);
+ vals = PyMapping_Values(env);
+ if (!keys || !vals)
+ goto fail_2;
+
+ for (pos = 0; pos < i; pos++) {
char *p, *k, *v;
+
+ key = PyList_GetItem(keys, pos);
+ val = PyList_GetItem(vals, pos);
+ if (!key || !val)
+ goto fail_2;
+
if (!PyArg_Parse(key, "s;non-string key in env", &k) ||
!PyArg_Parse(val, "s;non-string value in env", &v))
{
@@ -926,7 +936,8 @@ posix_execve(self, args)
PyMem_DEL(envlist);
fail_1:
PyMem_DEL(argvlist);
-
+ Py_XDECREF(vals);
+ Py_XDECREF(keys);
return NULL;
}
#endif /* HAVE_EXECV */