[Python-checkins] r67932 - python/trunk/Objects/unicodeobject.c

alexandre.vassalotti python-checkins at python.org
Sat Dec 27 07:36:11 CET 2008


Author: alexandre.vassalotti
Date: Sat Dec 27 07:36:10 2008
New Revision: 67932

Log:
Remove unnecessary casts related to unicode_decode_call_errorhandler.
Make the _PyUnicode_Resize macro a static function.

These changes are needed to avoid breaking strict aliasing rules. 


Modified:
   python/trunk/Objects/unicodeobject.c

Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c	(original)
+++ python/trunk/Objects/unicodeobject.c	Sat Dec 27 07:36:10 2008
@@ -386,7 +386,8 @@
     }
 }
 
-int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
+static
+int _PyUnicode_Resize(PyUnicodeObject **unicode, Py_ssize_t length)
 {
     register PyUnicodeObject *v;
 
@@ -395,7 +396,7 @@
 	PyErr_BadInternalCall();
 	return -1;
     }
-    v = (PyUnicodeObject *)*unicode;
+    v = *unicode;
     if (v == NULL || !PyUnicode_Check(v) || Py_REFCNT(v) != 1 || length < 0) {
 	PyErr_BadInternalCall();
 	return -1;
@@ -412,7 +413,7 @@
 	Py_UNICODE_COPY(w->str, v->str,
 			length < v->length ? length : v->length);
 	Py_DECREF(*unicode);
-	*unicode = (PyObject *)w;
+	*unicode = w;
 	return 0;
     }
 
@@ -421,9 +422,10 @@
     return unicode_resize(v, length);
 }
 
-/* Internal API for use in unicodeobject.c only ! */
-#define _PyUnicode_Resize(unicodevar, length) \
-        PyUnicode_Resize(((PyObject **)(unicodevar)), length)
+int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
+{
+    return _PyUnicode_Resize((PyUnicodeObject **)unicode, length);
+}
 
 PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
 				Py_ssize_t size)
@@ -937,7 +939,7 @@
 		PyObject_Free(callresults);
 	if (abuffer)
 		PyObject_Free(abuffer);
-	_PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string));
+	PyUnicode_Resize(&string, s - PyUnicode_AS_UNICODE(string));
 	return string;
  fail:
 	if (callresults) {
@@ -1345,7 +1347,7 @@
                  const char *encoding, const char *reason,
                  const char *input, Py_ssize_t insize, Py_ssize_t *startinpos,
                  Py_ssize_t *endinpos, PyObject **exceptionObject, const char **inptr,
-                 PyObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
+                 PyUnicodeObject **output, Py_ssize_t *outpos, Py_UNICODE **outptr)
 {
     static char *argparse = "O!n;decoding error handler must return (unicode, int) tuple";
 
@@ -1405,7 +1407,7 @@
     if (requiredsize > outsize) {
 	if (requiredsize<2*outsize)
 	    requiredsize = 2*outsize;
-	if (PyUnicode_Resize(output, requiredsize) < 0)
+	if (_PyUnicode_Resize(output, requiredsize) < 0)
 	    goto onError;
 	*outptr = PyUnicode_AS_UNICODE(*output) + *outpos;
     }
@@ -1604,7 +1606,7 @@
              errors, &errorHandler,
              "utf7", errmsg,
              starts, size, &startinpos, &endinpos, &exc, &s,
-             (PyObject **)&unicode, &outpos, &p))
+             &unicode, &outpos, &p))
         goto onError;
     }
 
@@ -1615,7 +1617,7 @@
              errors, &errorHandler,
              "utf7", "unterminated shift sequence",
              starts, size, &startinpos, &endinpos, &exc, &s,
-             (PyObject **)&unicode, &outpos, &p))
+             &unicode, &outpos, &p))
             goto onError;
         if (s < e)
            goto restart;
@@ -1942,7 +1944,7 @@
 	     errors, &errorHandler,
 	     "utf8", errmsg,
 	     starts, size, &startinpos, &endinpos, &exc, &s,
-	     (PyObject **)&unicode, &outpos, &p))
+	     &unicode, &outpos, &p))
 	goto onError;
     }
     if (consumed)
@@ -2222,7 +2224,7 @@
          errors, &errorHandler,
          "utf32", errmsg,
          starts, size, &startinpos, &endinpos, &exc, &s,
-         (PyObject **)&unicode, &outpos, &p))
+         &unicode, &outpos, &p))
 	    goto onError;
     }
 
@@ -2496,7 +2498,7 @@
 	         errors, &errorHandler,
 	         "utf16", errmsg,
 	         starts, size, &startinpos, &endinpos, &exc, (const char **)&q,
-	         (PyObject **)&unicode, &outpos, &p))
+	         &unicode, &outpos, &p))
 	    goto onError;
     }
 
@@ -2717,7 +2719,7 @@
                     errors, &errorHandler,
                     "unicodeescape", "end of string in escape sequence",
                     starts, size, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p))
+                    &v, &outpos, &p))
                     goto onError;
                 goto nextByte;
             }
@@ -2729,7 +2731,7 @@
                         errors, &errorHandler,
                         "unicodeescape", message,
                         starts, size, &startinpos, &endinpos, &exc, &s,
-                        (PyObject **)&v, &outpos, &p))
+                        &v, &outpos, &p))
                         goto onError;
                     goto nextByte;
                 }
@@ -2768,7 +2770,7 @@
                     errors, &errorHandler,
                     "unicodeescape", "illegal Unicode character",
                     starts, size, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p))
+                    &v, &outpos, &p))
                     goto onError;
             }
             break;
@@ -2810,7 +2812,7 @@
                 errors, &errorHandler,
                 "unicodeescape", message,
                 starts, size, &startinpos, &endinpos, &exc, &s,
-                (PyObject **)&v, &outpos, &p))
+                &v, &outpos, &p))
                 goto onError;
             break;
 
@@ -2824,7 +2826,7 @@
                     errors, &errorHandler,
                     "unicodeescape", message,
                     starts, size, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p))
+                    &v, &outpos, &p))
                     goto onError;
             }
             else {
@@ -3113,7 +3115,7 @@
 		    errors, &errorHandler,
 		    "rawunicodeescape", "truncated \\uXXXX",
 		    starts, size, &startinpos, &endinpos, &exc, &s,
-		    (PyObject **)&v, &outpos, &p))
+		    &v, &outpos, &p))
 		    goto onError;
 		goto nextByte;
 	    }
@@ -3145,7 +3147,7 @@
                     errors, &errorHandler,
                     "rawunicodeescape", "\\Uxxxxxxxx out of range",
 		    starts, size, &startinpos, &endinpos, &exc, &s,
-		    (PyObject **)&v, &outpos, &p))
+		    &v, &outpos, &p))
 		    goto onError;
         }
 	nextByte:
@@ -3315,7 +3317,7 @@
                     errors, &errorHandler,
                     "unicode_internal", reason,
                     starts, size, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p)) {
+                    &v, &outpos, &p)) {
                 goto onError;
             }
         }
@@ -3695,7 +3697,7 @@
 		 errors, &errorHandler,
 		 "ascii", "ordinal not in range(128)",
 		 starts, size, &startinpos, &endinpos, &exc, &s,
-		 (PyObject **)&v, &outpos, &p))
+		 &v, &outpos, &p))
 		goto onError;
 	}
     }
@@ -3996,7 +3998,7 @@
 		     errors, &errorHandler,
 		     "charmap", "character maps to <undefined>",
 		     starts, size, &startinpos, &endinpos, &exc, &s,
-		     (PyObject **)&v, &outpos, &p)) {
+		     &v, &outpos, &p)) {
 		    goto onError;
 		}
 		continue;
@@ -4046,7 +4048,7 @@
 		     errors, &errorHandler,
 		     "charmap", "character maps to <undefined>",
 		     starts, size, &startinpos, &endinpos, &exc, &s,
-		     (PyObject **)&v, &outpos, &p)) {
+		     &v, &outpos, &p)) {
 		    Py_DECREF(x);
 		    goto onError;
 		}
@@ -4797,7 +4799,7 @@
 	/* exponentially overallocate to minimize reallocations */
 	if (requiredsize < 2 * oldsize)
 	    requiredsize = 2 * oldsize;
-	if (_PyUnicode_Resize(outobj, requiredsize) < 0)
+	if (PyUnicode_Resize(outobj, requiredsize) < 0)
 	    return -1;
 	*outp = PyUnicode_AS_UNICODE(*outobj) + outpos;
     }
@@ -4976,7 +4978,7 @@
     /* Resize if we allocated to much */
     respos = str-PyUnicode_AS_UNICODE(res);
     if (respos<PyUnicode_GET_SIZE(res)) {
-	if (_PyUnicode_Resize(&res, respos) < 0)
+	if (PyUnicode_Resize(&res, respos) < 0)
 	    goto onError;
     }
     Py_XDECREF(exc);


More information about the Python-checkins mailing list