@@ -2863,10 +2863,10 @@ PyUnicode_FromEncodedObject(register PyObject *obj,
2863
2863
/* Convert encoding to lower case and replace '_' with '-' in order to
2864
2864
catch e.g. UTF_8. Return 0 on error (encoding is longer than lower_len-1),
2865
2865
1 on success. */
2866
- static int
2867
- normalize_encoding (const char * encoding ,
2868
- char * lower ,
2869
- size_t lower_len )
2866
+ int
2867
+ _Py_normalize_encoding (const char * encoding ,
2868
+ char * lower ,
2869
+ size_t lower_len )
2870
2870
{
2871
2871
const char * e ;
2872
2872
char * l ;
@@ -2908,7 +2908,7 @@ PyUnicode_Decode(const char *s,
2908
2908
char lower [11 ]; /* Enough for any encoding shortcut */
2909
2909
2910
2910
/* Shortcuts for common default encodings */
2911
- if (normalize_encoding (encoding , lower , sizeof (lower ))) {
2911
+ if (_Py_normalize_encoding (encoding , lower , sizeof (lower ))) {
2912
2912
if ((strcmp (lower , "utf-8" ) == 0 ) ||
2913
2913
(strcmp (lower , "utf8" ) == 0 ))
2914
2914
return PyUnicode_DecodeUTF8Stateful (s , size , errors , NULL );
@@ -3110,7 +3110,8 @@ locale_error_handler(const char *errors, int *surrogateescape)
3110
3110
* surrogateescape = 0 ;
3111
3111
return 0 ;
3112
3112
}
3113
- if (strcmp (errors , "surrogateescape" ) == 0 ) {
3113
+ if (errors == "surrogateescape"
3114
+ || strcmp (errors , "surrogateescape" ) == 0 ) {
3114
3115
* surrogateescape = 1 ;
3115
3116
return 0 ;
3116
3117
}
@@ -3148,7 +3149,7 @@ PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
3148
3149
}
3149
3150
3150
3151
if (surrogateescape ) {
3151
- /* locale encoding with surrogateescape */
3152
+ /* "surrogateescape" error handler */
3152
3153
char * str ;
3153
3154
3154
3155
str = _Py_wchar2char (wstr , & error_pos );
@@ -3168,6 +3169,7 @@ PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
3168
3169
PyMem_Free (str );
3169
3170
}
3170
3171
else {
3172
+ /* strict mode */
3171
3173
size_t len , len2 ;
3172
3174
3173
3175
len = wcstombs (NULL , wstr , 0 );
@@ -3273,7 +3275,7 @@ PyUnicode_AsEncodedString(PyObject *unicode,
3273
3275
}
3274
3276
3275
3277
/* Shortcuts for common default encodings */
3276
- if (normalize_encoding (encoding , lower , sizeof (lower ))) {
3278
+ if (_Py_normalize_encoding (encoding , lower , sizeof (lower ))) {
3277
3279
if ((strcmp (lower , "utf-8" ) == 0 ) ||
3278
3280
(strcmp (lower , "utf8" ) == 0 ))
3279
3281
{
@@ -3413,8 +3415,8 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
3413
3415
return NULL ;
3414
3416
}
3415
3417
3416
- if (surrogateescape )
3417
- {
3418
+ if (surrogateescape ) {
3419
+ /* "surrogateescape" error handler */
3418
3420
wstr = _Py_char2wchar (str , & wlen );
3419
3421
if (wstr == NULL ) {
3420
3422
if (wlen == (size_t )-1 )
@@ -3428,6 +3430,7 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
3428
3430
PyMem_Free (wstr );
3429
3431
}
3430
3432
else {
3433
+ /* strict mode */
3431
3434
#ifndef HAVE_BROKEN_MBSTOWCS
3432
3435
wlen = mbstowcs (NULL , str , 0 );
3433
3436
#else
@@ -3447,7 +3450,6 @@ PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t len,
3447
3450
return PyErr_NoMemory ();
3448
3451
}
3449
3452
3450
- /* This shouldn't fail now */
3451
3453
wlen2 = mbstowcs (wstr , str , wlen + 1 );
3452
3454
if (wlen2 == (size_t )-1 ) {
3453
3455
if (wstr != smallbuf )
0 commit comments