[Python-checkins] r81358 - in python/branches/py3k: Doc/c-api/sys.rst Include/sysmodule.h Misc/NEWS Modules/main.c Python/sysmodule.c

victor.stinner python-checkins at python.org
Wed May 19 18:53:30 CEST 2010


Author: victor.stinner
Date: Wed May 19 18:53:30 2010
New Revision: 81358

Log:
Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
encoding and surrogateespace error handler instead of the locale encoding to be
consistent with os.environ. Add PySys_AddWarnOptionUnicode() function.


Modified:
   python/branches/py3k/Doc/c-api/sys.rst
   python/branches/py3k/Include/sysmodule.h
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/main.c
   python/branches/py3k/Python/sysmodule.c

Modified: python/branches/py3k/Doc/c-api/sys.rst
==============================================================================
--- python/branches/py3k/Doc/c-api/sys.rst	(original)
+++ python/branches/py3k/Doc/c-api/sys.rst	Wed May 19 18:53:30 2010
@@ -81,6 +81,10 @@
 
    Append *s* to :data:`sys.warnoptions`.
 
+.. cfunction:: void PySys_AddWarnOptionUnicode(PyObject *unicode)
+
+   Append *unicode* to :data:`sys.warnoptions`.
+
 .. cfunction:: void PySys_SetPath(wchar_t *path)
 
    Set :data:`sys.path` to a list object of paths found in *path* which should

Modified: python/branches/py3k/Include/sysmodule.h
==============================================================================
--- python/branches/py3k/Include/sysmodule.h	(original)
+++ python/branches/py3k/Include/sysmodule.h	Wed May 19 18:53:30 2010
@@ -21,6 +21,7 @@
 
 PyAPI_FUNC(void) PySys_ResetWarnOptions(void);
 PyAPI_FUNC(void) PySys_AddWarnOption(const wchar_t *);
+PyAPI_FUNC(void) PySys_AddWarnOptionUnicode(PyObject *);
 PyAPI_FUNC(int) PySys_HasWarnOptions(void);
 
 #ifdef __cplusplus

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Wed May 19 18:53:30 2010
@@ -12,6 +12,10 @@
 Core and Builtins
 -----------------
 
+- Issue #8589: Decode PYTHONWARNINGS environment variable with the file system
+  encoding and surrogateespace error handler instead of the locale encoding to
+  be consistent with os.environ. Add PySys_AddWarnOptionUnicode() function.
+
 - PyObject_Dump() encodes unicode objects to utf8 with backslashreplace
   (instead of strict) error handler to escape surrogates
 

Modified: python/branches/py3k/Modules/main.c
==============================================================================
--- python/branches/py3k/Modules/main.c	(original)
+++ python/branches/py3k/Modules/main.c	Wed May 19 18:53:30 2010
@@ -425,7 +425,7 @@
 #else
     if ((p = Py_GETENV("PYTHONWARNINGS")) && *p != '\0') {
         char *buf, *oldloc;
-        wchar_t *warning;
+        PyObject *warning;
 
         /* settle for strtok here as there's no one standard
            C89 wcstok */
@@ -437,9 +437,10 @@
         oldloc = strdup(setlocale(LC_ALL, NULL));
         setlocale(LC_ALL, "");
         for (p = strtok(buf, ","); p != NULL; p = strtok(NULL, ",")) {
-            if ((warning = _Py_char2wchar(p)) != NULL) {
-                PySys_AddWarnOption(warning);
-                PyMem_Free(warning);
+            warning = PyUnicode_DecodeFSDefault(p);
+            if (warning != NULL) {
+                PySys_AddWarnOptionUnicode(warning);
+                Py_DECREF(warning);
             }
         }
         setlocale(LC_ALL, oldloc);

Modified: python/branches/py3k/Python/sysmodule.c
==============================================================================
--- python/branches/py3k/Python/sysmodule.c	(original)
+++ python/branches/py3k/Python/sysmodule.c	Wed May 19 18:53:30 2010
@@ -1048,21 +1048,26 @@
 }
 
 void
-PySys_AddWarnOption(const wchar_t *s)
+PySys_AddWarnOptionUnicode(PyObject *unicode)
 {
-    PyObject *str;
-
     if (warnoptions == NULL || !PyList_Check(warnoptions)) {
         Py_XDECREF(warnoptions);
         warnoptions = PyList_New(0);
         if (warnoptions == NULL)
             return;
     }
-    str = PyUnicode_FromWideChar(s, -1);
-    if (str != NULL) {
-        PyList_Append(warnoptions, str);
-        Py_DECREF(str);
-    }
+    PyList_Append(warnoptions, unicode);
+}
+
+void
+PySys_AddWarnOption(const wchar_t *s)
+{
+    PyObject *unicode;
+    unicode = PyUnicode_FromWideChar(s, -1);
+    if (unicode == NULL)
+        return;
+    PySys_AddWarnOptionUnicode(unicode);
+    Py_DECREF(unicode);
 }
 
 int


More information about the Python-checkins mailing list