[Python-checkins] r67933 - in python/branches/py3k: Objects/unicodeobject.c

alexandre.vassalotti python-checkins at python.org
Sat Dec 27 07:43:59 CET 2008


Author: alexandre.vassalotti
Date: Sat Dec 27 07:43:58 2008
New Revision: 67933

Log:
Merged revisions 67932 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67932 | alexandre.vassalotti | 2008-12-27 01:36:10 -0500 (Sat, 27 Dec 2008) | 5 lines
  
  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/branches/py3k/   (props changed)
   python/branches/py3k/Objects/unicodeobject.c

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c	(original)
+++ python/branches/py3k/Objects/unicodeobject.c	Sat Dec 27 07:43:58 2008
@@ -418,7 +418,8 @@
     }
 }
 
-int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length)
+static
+int _PyUnicode_Resize(PyUnicodeObject **unicode, Py_ssize_t length)
 {
     register PyUnicodeObject *v;
 
@@ -427,7 +428,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;
@@ -444,7 +445,7 @@
 	Py_UNICODE_COPY(w->str, v->str,
 			length < v->length ? length : v->length);
 	Py_DECREF(*unicode);
-	*unicode = (PyObject *)w;
+	*unicode = w;
 	return 0;
     }
 
@@ -453,9 +454,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)
@@ -989,7 +991,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) {
@@ -1549,7 +1551,7 @@
                  const char *encoding, const char *reason,
                  const char **input, const char **inend, 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 (str, int) tuple";
 
@@ -1627,7 +1629,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;
     }
@@ -1827,7 +1829,7 @@
              errors, &errorHandler,
              "utf7", errmsg,
              &starts, &e, &startinpos, &endinpos, &exc, &s,
-             (PyObject **)&unicode, &outpos, &p))
+             &unicode, &outpos, &p))
         goto onError;
     }
 
@@ -1838,7 +1840,7 @@
              errors, &errorHandler,
              "utf7", "unterminated shift sequence",
              &starts, &e, &startinpos, &endinpos, &exc, &s,
-             (PyObject **)&unicode, &outpos, &p))
+             &unicode, &outpos, &p))
             goto onError;
         if (s < e)
            goto restart;
@@ -2166,7 +2168,7 @@
 	     errors, &errorHandler,
 	     "utf8", errmsg,
 	     &starts, &e, &startinpos, &endinpos, &exc, &s,
-	     (PyObject **)&unicode, &outpos, &p))
+	     &unicode, &outpos, &p))
 	goto onError;
     }
     if (consumed)
@@ -2446,7 +2448,7 @@
 	         errors, &errorHandler,
 	         "utf32", errmsg,
 	         &starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q,
-	         (PyObject **)&unicode, &outpos, &p))
+	         &unicode, &outpos, &p))
 	    goto onError;
     }
 
@@ -2724,7 +2726,7 @@
 	         errors, &errorHandler,
 	         "utf16", errmsg,
 	         &starts, (const char **)&e, &startinpos, &endinpos, &exc, (const char **)&q,
-	         (PyObject **)&unicode, &outpos, &p))
+	         &unicode, &outpos, &p))
 	    goto onError;
     }
 
@@ -2949,7 +2951,7 @@
                     errors, &errorHandler,
                     "unicodeescape", "end of string in escape sequence",
                     &starts, &end, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p))
+                    &v, &outpos, &p))
                     goto onError;
                 goto nextByte;
             }
@@ -2961,7 +2963,7 @@
                         errors, &errorHandler,
                         "unicodeescape", message,
                         &starts, &end, &startinpos, &endinpos, &exc, &s,
-                        (PyObject **)&v, &outpos, &p))
+                        &v, &outpos, &p))
                         goto onError;
                     goto nextByte;
                 }
@@ -3000,7 +3002,7 @@
                     errors, &errorHandler,
                     "unicodeescape", "illegal Unicode character",
                     &starts, &end, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p))
+                    &v, &outpos, &p))
                     goto onError;
             }
             break;
@@ -3042,7 +3044,7 @@
                 errors, &errorHandler,
                 "unicodeescape", message,
                 &starts, &end, &startinpos, &endinpos, &exc, &s,
-                (PyObject **)&v, &outpos, &p))
+                &v, &outpos, &p))
                 goto onError;
             break;
 
@@ -3056,7 +3058,7 @@
                     errors, &errorHandler,
                     "unicodeescape", message,
                     &starts, &end, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p))
+                    &v, &outpos, &p))
                     goto onError;
             }
             else {
@@ -3339,7 +3341,7 @@
 		    errors, &errorHandler,
 		    "rawunicodeescape", "truncated \\uXXXX",
 		    &starts, &end, &startinpos, &endinpos, &exc, &s,
-		    (PyObject **)&v, &outpos, &p))
+		    &v, &outpos, &p))
 		    goto onError;
 		goto nextByte;
 	    }
@@ -3371,7 +3373,7 @@
                     errors, &errorHandler,
                     "rawunicodeescape", "\\Uxxxxxxxx out of range",
 		    &starts, &end, &startinpos, &endinpos, &exc, &s,
-		    (PyObject **)&v, &outpos, &p))
+		    &v, &outpos, &p))
 		    goto onError;
         }
 	nextByte:
@@ -3551,7 +3553,7 @@
                     errors, &errorHandler,
                     "unicode_internal", reason,
                     &starts, &end, &startinpos, &endinpos, &exc, &s,
-                    (PyObject **)&v, &outpos, &p)) {
+                    &v, &outpos, &p)) {
                 goto onError;
             }
         }
@@ -3924,7 +3926,7 @@
 		 errors, &errorHandler,
 		 "ascii", "ordinal not in range(128)",
 		 &starts, &e, &startinpos, &endinpos, &exc, &s,
-		 (PyObject **)&v, &outpos, &p))
+		 &v, &outpos, &p))
 		goto onError;
 	}
     }
@@ -4225,7 +4227,7 @@
 		     errors, &errorHandler,
 		     "charmap", "character maps to <undefined>",
 		     &starts, &e, &startinpos, &endinpos, &exc, &s,
-		     (PyObject **)&v, &outpos, &p)) {
+		     &v, &outpos, &p)) {
 		    goto onError;
 		}
 		continue;
@@ -4275,7 +4277,7 @@
 		     errors, &errorHandler,
 		     "charmap", "character maps to <undefined>",
 		     &starts, &e, &startinpos, &endinpos, &exc, &s,
-		     (PyObject **)&v, &outpos, &p)) {
+		     &v, &outpos, &p)) {
 		    Py_DECREF(x);
 		    goto onError;
 		}
@@ -5025,7 +5027,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;
     }
@@ -5204,7 +5206,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);
@@ -7743,7 +7745,7 @@
     *p++ = PyUnicode_AS_UNICODE(repr)[0];
 
     *p = '\0';
-    _PyUnicode_Resize(&repr, p - PyUnicode_AS_UNICODE(repr));
+    PyUnicode_Resize(&repr, p - PyUnicode_AS_UNICODE(repr));
     return repr;
 }
 


More information about the Python-checkins mailing list