[Python-checkins] r72271 - python/branches/pep-0383/Modules/posixmodule.c

martin.v.loewis python-checkins at python.org
Mon May 4 06:45:51 CEST 2009


Author: martin.v.loewis
Date: Mon May  4 06:45:51 2009
New Revision: 72271

Log:
Implement PEP 383 for putenv.


Modified:
   python/branches/pep-0383/Modules/posixmodule.c

Modified: python/branches/pep-0383/Modules/posixmodule.c
==============================================================================
--- python/branches/pep-0383/Modules/posixmodule.c	(original)
+++ python/branches/pep-0383/Modules/posixmodule.c	Mon May  4 06:45:51 2009
@@ -5382,20 +5382,27 @@
         wchar_t *s1, *s2;
         wchar_t *newenv;
 #else
+	PyObject *os1, *os2;
         char *s1, *s2;
         char *newenv;
 #endif
 	PyObject *newstr;
 	size_t len;
 
-	if (!PyArg_ParseTuple(args,
 #ifdef MS_WINDOWS
+	if (!PyArg_ParseTuple(args,
 			      "uu:putenv",
-#else
-			      "ss:putenv",
-#endif
 			      &s1, &s2))
 		return NULL;
+#else
+	if (!PyArg_ParseTuple(args,
+			      "O&O&:putenv",
+			      PyUnicode_FSConverter, &os1, 
+			      PyUnicode_FSConverter, &os2))
+		return NULL;
+	s1 = bytes2str(os1, 1);
+	s2 = bytes2str(os2, 1);
+#endif
 
 #if defined(PYOS_OS2)
     if (stricmp(s1, "BEGINLIBPATH") == 0) {
@@ -5438,6 +5445,8 @@
 	PyOS_snprintf(newenv, len, "%s=%s", s1, s2);
 	if (putenv(newenv)) {
                 Py_DECREF(newstr);
+		release_bytes(os1);
+		release_bytes(os2);
                 posix_error();
                 return NULL;
 	}
@@ -5458,6 +5467,10 @@
 #if defined(PYOS_OS2)
     }
 #endif
+#ifndef MS_WINDOWS
+	release_bytes(os1);
+	release_bytes(os2);
+#endif
 	Py_INCREF(Py_None);
         return Py_None;
 }


More information about the Python-checkins mailing list