[Python-checkins] CVS: python/dist/src/Modules posixmodule.c,2.205,2.206

Guido van Rossum gvanrossum@users.sourceforge.net
Thu, 18 Oct 2001 18:32:02 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv3916/Modules

Modified Files:
	posixmodule.c 
Log Message:
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?)



Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.205
retrieving revision 2.206
diff -C2 -d -r2.205 -r2.206
*** posixmodule.c	2001/10/18 22:05:36	2.205
--- posixmodule.c	2001/10/19 01:31:59	2.206
***************
*** 4084,4087 ****
--- 4084,4118 ----
  #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__[] =
***************
*** 5667,5670 ****
--- 5698,5704 ----
  #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