@@ -83,7 +83,7 @@ Unicode Integration Proposal (see file Misc/unicode.txt).
8383 all objects on the free list having a size less than this
8484 limit. This reduces malloc() overhead for small Unicode objects.
8585
86- At worse this will result in MAX_UNICODE_FREELIST_SIZE *
86+ At worst this will result in MAX_UNICODE_FREELIST_SIZE *
8787 (sizeof(PyUnicodeObject) + STAYALIVE_SIZE_LIMIT +
8888 malloc()-overhead) bytes of unused garbage.
8989
@@ -180,7 +180,7 @@ PyUnicodeObject *_PyUnicode_New(int length)
180180 unicode_freelist = * (PyUnicodeObject * * )unicode_freelist ;
181181 unicode_freelist_size -- ;
182182 unicode -> ob_type = & PyUnicode_Type ;
183- _Py_NewReference (unicode );
183+ _Py_NewReference (( PyObject * ) unicode );
184184 if (unicode -> str ) {
185185 if (unicode -> length < length &&
186186 _PyUnicode_Resize (unicode , length )) {
@@ -199,16 +199,19 @@ PyUnicodeObject *_PyUnicode_New(int length)
199199 unicode -> str = PyMem_NEW (Py_UNICODE , length + 1 );
200200 }
201201
202- if (!unicode -> str ) {
203- PyMem_DEL (unicode );
204- PyErr_NoMemory ();
205- return NULL ;
206- }
202+ if (!unicode -> str )
203+ goto onError ;
207204 unicode -> str [length ] = 0 ;
208205 unicode -> length = length ;
209206 unicode -> hash = -1 ;
210207 unicode -> utf8str = NULL ;
211208 return unicode ;
209+
210+ onError :
211+ _Py_ForgetReference ((PyObject * )unicode );
212+ PyMem_DEL (unicode );
213+ PyErr_NoMemory ();
214+ return NULL ;
212215}
213216
214217static
@@ -224,7 +227,6 @@ void _PyUnicode_Free(register PyUnicodeObject *unicode)
224227 * (PyUnicodeObject * * )unicode = unicode_freelist ;
225228 unicode_freelist = unicode ;
226229 unicode_freelist_size ++ ;
227- _Py_ForgetReference (unicode );
228230 }
229231 else {
230232 free (unicode -> str );
@@ -489,7 +491,7 @@ int utf8_decoding_error(const char **source,
489491 }
490492 else {
491493 PyErr_Format (PyExc_ValueError ,
492- "UTF-8 decoding error; unkown error handling code: %s" ,
494+ "UTF-8 decoding error; unknown error handling code: %s" ,
493495 errors );
494496 return -1 ;
495497 }
@@ -611,7 +613,7 @@ int utf8_encoding_error(const Py_UNICODE **source,
611613 else {
612614 PyErr_Format (PyExc_ValueError ,
613615 "UTF-8 encoding error; "
614- "unkown error handling code: %s" ,
616+ "unknown error handling code: %s" ,
615617 errors );
616618 return -1 ;
617619 }
@@ -733,7 +735,7 @@ int utf16_decoding_error(const Py_UNICODE **source,
733735 }
734736 else {
735737 PyErr_Format (PyExc_ValueError ,
736- "UTF-16 decoding error; unkown error handling code: %s" ,
738+ "UTF-16 decoding error; unknown error handling code: %s" ,
737739 errors );
738740 return -1 ;
739741 }
@@ -921,7 +923,7 @@ int unicodeescape_decoding_error(const char **source,
921923 else {
922924 PyErr_Format (PyExc_ValueError ,
923925 "Unicode-Escape decoding error; "
924- "unkown error handling code: %s" ,
926+ "unknown error handling code: %s" ,
925927 errors );
926928 return -1 ;
927929 }
@@ -1051,6 +1053,10 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
10511053
10521054*/
10531055
1056+ static const Py_UNICODE * findchar (const Py_UNICODE * s ,
1057+ int size ,
1058+ Py_UNICODE ch );
1059+
10541060static
10551061PyObject * unicodeescape_string (const Py_UNICODE * s ,
10561062 int size ,
@@ -1069,9 +1075,6 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
10691075 p = q = PyString_AS_STRING (repr );
10701076
10711077 if (quotes ) {
1072- static const Py_UNICODE * findchar (const Py_UNICODE * s ,
1073- int size ,
1074- Py_UNICODE ch );
10751078 * p ++ = 'u' ;
10761079 * p ++ = (findchar (s , size , '\'' ) &&
10771080 !findchar (s , size , '"' )) ? '"' : '\'' ;
@@ -1298,7 +1301,7 @@ int latin1_encoding_error(const Py_UNICODE **source,
12981301 else {
12991302 PyErr_Format (PyExc_ValueError ,
13001303 "Latin-1 encoding error; "
1301- "unkown error handling code: %s" ,
1304+ "unknown error handling code: %s" ,
13021305 errors );
13031306 return -1 ;
13041307 }
@@ -1369,7 +1372,7 @@ int ascii_decoding_error(const char **source,
13691372 else {
13701373 PyErr_Format (PyExc_ValueError ,
13711374 "ASCII decoding error; "
1372- "unkown error handling code: %s" ,
1375+ "unknown error handling code: %s" ,
13731376 errors );
13741377 return -1 ;
13751378 }
@@ -1431,7 +1434,7 @@ int ascii_encoding_error(const Py_UNICODE **source,
14311434 else {
14321435 PyErr_Format (PyExc_ValueError ,
14331436 "ASCII encoding error; "
1434- "unkown error handling code: %s" ,
1437+ "unknown error handling code: %s" ,
14351438 errors );
14361439 return -1 ;
14371440 }
@@ -1502,7 +1505,7 @@ int charmap_decoding_error(const char **source,
15021505 else {
15031506 PyErr_Format (PyExc_ValueError ,
15041507 "charmap decoding error; "
1505- "unkown error handling code: %s" ,
1508+ "unknown error handling code: %s" ,
15061509 errors );
15071510 return -1 ;
15081511 }
@@ -1618,7 +1621,7 @@ int charmap_encoding_error(const Py_UNICODE **source,
16181621 else {
16191622 PyErr_Format (PyExc_ValueError ,
16201623 "charmap encoding error; "
1621- "unkown error handling code: %s" ,
1624+ "unknown error handling code: %s" ,
16221625 errors );
16231626 return -1 ;
16241627 }
@@ -1750,7 +1753,7 @@ int translate_error(const Py_UNICODE **source,
17501753 else {
17511754 PyErr_Format (PyExc_ValueError ,
17521755 "translate error; "
1753- "unkown error handling code: %s" ,
1756+ "unknown error handling code: %s" ,
17541757 errors );
17551758 return -1 ;
17561759 }
0 commit comments