[Python-checkins] r62199 - in python/trunk/Objects: stringlib/formatter.h stringlib/string_format.h unicodeobject.c

martin.v.loewis python-checkins at python.org
Mon Apr 7 05:08:29 CEST 2008


Author: martin.v.loewis
Date: Mon Apr  7 05:08:28 2008
New Revision: 62199

Modified:
   python/trunk/Objects/stringlib/formatter.h
   python/trunk/Objects/stringlib/string_format.h
   python/trunk/Objects/unicodeobject.c
Log:
Bug #2388: Fix gcc warnings when compiling with --enable-unicode=ucs4.


Modified: python/trunk/Objects/stringlib/formatter.h
==============================================================================
--- python/trunk/Objects/stringlib/formatter.h	(original)
+++ python/trunk/Objects/stringlib/formatter.h	Mon Apr  7 05:08:28 2008
@@ -785,8 +785,19 @@
         break;
     default:
         /* unknown */
-        PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
-                     format.type);
+	#if STRINGLIB_IS_UNICODE
+	/* If STRINGLIB_CHAR is Py_UNICODE, %c might be out-of-range,
+	   hence the two cases. If it is char, gcc complains that the
+	   condition below is always true, hence the ifdef. */
+        if (format.type > 32 && format.type <128)
+	#endif
+            PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
+                         (char)format.type);
+	#if STRINGLIB_IS_UNICODE
+	else
+            PyErr_Format(PyExc_ValueError, "Unknown conversion type '\\x%x'",
+                         (unsigned int)format.type);
+	#endif
         goto done;
     }
 

Modified: python/trunk/Objects/stringlib/string_format.h
==============================================================================
--- python/trunk/Objects/stringlib/string_format.h	(original)
+++ python/trunk/Objects/stringlib/string_format.h	Mon Apr  7 05:08:28 2008
@@ -740,9 +740,17 @@
     case 's':
         return STRINGLIB_TOSTR(obj);
     default:
-        PyErr_Format(PyExc_ValueError,
-                     "Unknown converion specifier %c",
-                     conversion);
+	if (conversion > 32 && conversion < 127) {
+		/* It's the ASCII subrange; casting to char is safe
+		   (assuming the execution character set is an ASCII
+		   superset). */
+        	PyErr_Format(PyExc_ValueError,
+                     "Unknown conversion specifier %c",
+                     (char)conversion);
+	} else
+		PyErr_Format(PyExc_ValueError,
+		     "Unknown conversion specifier \\x%x",
+		     (unsigned int)conversion);
         return NULL;
     }
 }

Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Mon Apr  7 05:08:28 2008
@@ -8644,7 +8644,7 @@
 		if (!isnumok) {
 			PyErr_Format(PyExc_TypeError, 
 			    "%%%c format: a number is required, "
-			    "not %.200s", c, Py_TYPE(v)->tp_name);
+                                     "not %.200s", (char)c, Py_TYPE(v)->tp_name);
 			goto onError;
 		}
 		if (flags & F_ZERO)


More information about the Python-checkins mailing list