diff options
author | Guido van Rossum <guido@python.org> | 2001-10-19 01:31:59 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-19 01:31:59 (GMT) |
commit | c524d952da928f745203876f2e67f651c2bc7246 (patch) | |
tree | 59686a72378708c6884596341bdd353d5ac3e4bf /Modules | |
parent | b6c1d5239cfeadd761d2055cc44212f7a6b7e5af (diff) | |
download | cpython-c524d952da928f745203876f2e67f651c2bc7246.zip cpython-c524d952da928f745203876f2e67f651c2bc7246.tar.gz cpython-c524d952da928f745203876f2e67f651c2bc7246.tar.bz2 |
SF patch #460805 by Chris Gonnerman: Support for unsetenv()
This adds unsetenv to posix, and uses it in the __delitem__ method of
os.environ.
(XXX Should we change the preferred name for putenv to setenv, for
consistency?)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 22f70b1..65e09c0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4083,6 +4083,37 @@ posix_putenv(PyObject *self, PyObject *args) } #endif /* putenv */ +#ifdef HAVE_UNSETENV +static char posix_unsetenv__doc__[] = +"unsetenv(key) -> None\n\ +Delete an environment variable."; + +static PyObject * +posix_unsetenv(PyObject *self, PyObject *args) +{ + char *s1; + + if (!PyArg_ParseTuple(args, "s:unsetenv", &s1)) + return NULL; + + unsetenv(s1); + + /* Remove the key from posix_putenv_garbage; + * this will cause it to be collected. This has to + * happen after the real unsetenv() call because the + * old value was still accessible until then. + */ + if (PyDict_DelItem(posix_putenv_garbage, + PyTuple_GET_ITEM(args, 0))) { + /* really not much we can do; just leak */ + PyErr_Clear(); + } + + Py_INCREF(Py_None); + return Py_None; +} +#endif /* unsetenv */ + #ifdef HAVE_STRERROR static char posix_strerror__doc__[] = "strerror(code) -> string\n\ @@ -5667,6 +5698,9 @@ static PyMethodDef posix_methods[] = { #ifdef HAVE_PUTENV {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__}, #endif +#ifdef HAVE_UNSETENV + {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__}, +#endif #ifdef HAVE_STRERROR {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__}, #endif |