@@ -253,12 +253,6 @@ unicode_encode_call_errorhandler(const char *errors,
253253
254254static void
255255raise_encode_exception (PyObject * * exceptionObject ,
256- const char * encoding ,
257- const Py_UNICODE * unicode , Py_ssize_t size ,
258- Py_ssize_t startpos , Py_ssize_t endpos ,
259- const char * reason );
260- static void
261- raise_encode_exception_obj (PyObject * * exceptionObject ,
262256 const char * encoding ,
263257 PyObject * unicode ,
264258 Py_ssize_t startpos , Py_ssize_t endpos ,
@@ -3058,8 +3052,7 @@ PyUnicode_EncodeFSDefault(PyObject *unicode)
30583052 if (errmsg == NULL )
30593053 errmsg = "Py_wchar2char() failed" ;
30603054 raise_encode_exception (& exc ,
3061- "filesystemencoding" ,
3062- PyUnicode_AS_UNICODE (unicode ), PyUnicode_GET_SIZE (unicode ),
3055+ "filesystemencoding" , unicode ,
30633056 error_pos , error_pos + 1 ,
30643057 errmsg );
30653058 Py_XDECREF (exc );
@@ -4783,7 +4776,7 @@ _PyUnicode_AsUTF8String(PyObject *unicode, const char *errors)
47834776 for (k = 0 ; k < repsize ; k ++ ) {
47844777 c = prep [k ];
47854778 if (0x80 <= c ) {
4786- raise_encode_exception_obj (& exc , "utf-8" ,
4779+ raise_encode_exception (& exc , "utf-8" ,
47874780 unicode ,
47884781 i - 1 , i ,
47894782 "surrogates not allowed" );
@@ -6405,32 +6398,6 @@ PyUnicode_DecodeLatin1(const char *s,
64056398/* create or adjust a UnicodeEncodeError */
64066399static void
64076400make_encode_exception (PyObject * * exceptionObject ,
6408- const char * encoding ,
6409- const Py_UNICODE * unicode , Py_ssize_t size ,
6410- Py_ssize_t startpos , Py_ssize_t endpos ,
6411- const char * reason )
6412- {
6413- if (* exceptionObject == NULL ) {
6414- * exceptionObject = PyUnicodeEncodeError_Create (
6415- encoding , unicode , size , startpos , endpos , reason );
6416- }
6417- else {
6418- if (PyUnicodeEncodeError_SetStart (* exceptionObject , startpos ))
6419- goto onError ;
6420- if (PyUnicodeEncodeError_SetEnd (* exceptionObject , endpos ))
6421- goto onError ;
6422- if (PyUnicodeEncodeError_SetReason (* exceptionObject , reason ))
6423- goto onError ;
6424- return ;
6425- onError :
6426- Py_DECREF (* exceptionObject );
6427- * exceptionObject = NULL ;
6428- }
6429- }
6430-
6431- /* This is ultimately going t replace above function. */
6432- static void
6433- make_encode_exception_obj (PyObject * * exceptionObject ,
64346401 const char * encoding ,
64356402 PyObject * unicode ,
64366403 Py_ssize_t startpos , Py_ssize_t endpos ,
@@ -6458,25 +6425,12 @@ make_encode_exception_obj(PyObject **exceptionObject,
64586425/* raises a UnicodeEncodeError */
64596426static void
64606427raise_encode_exception (PyObject * * exceptionObject ,
6461- const char * encoding ,
6462- const Py_UNICODE * unicode , Py_ssize_t size ,
6463- Py_ssize_t startpos , Py_ssize_t endpos ,
6464- const char * reason )
6465- {
6466- make_encode_exception (exceptionObject ,
6467- encoding , unicode , size , startpos , endpos , reason );
6468- if (* exceptionObject != NULL )
6469- PyCodec_StrictErrors (* exceptionObject );
6470- }
6471- /* This is ultimately going to replace above function. */
6472- static void
6473- raise_encode_exception_obj (PyObject * * exceptionObject ,
64746428 const char * encoding ,
64756429 PyObject * unicode ,
64766430 Py_ssize_t startpos , Py_ssize_t endpos ,
64776431 const char * reason )
64786432{
6479- make_encode_exception_obj (exceptionObject ,
6433+ make_encode_exception (exceptionObject ,
64806434 encoding , unicode , startpos , endpos , reason );
64816435 if (* exceptionObject != NULL )
64826436 PyCodec_StrictErrors (* exceptionObject );
@@ -6509,7 +6463,7 @@ unicode_encode_call_errorhandler(const char *errors,
65096463 return NULL ;
65106464 len = PyUnicode_GET_LENGTH (unicode );
65116465
6512- make_encode_exception_obj (exceptionObject ,
6466+ make_encode_exception (exceptionObject ,
65136467 encoding , unicode , startpos , endpos , reason );
65146468 if (* exceptionObject == NULL )
65156469 return NULL ;
@@ -6617,7 +6571,7 @@ unicode_encode_ucs1(PyObject *unicode,
66176571 }
66186572 switch (known_errorHandler ) {
66196573 case 1 : /* strict */
6620- raise_encode_exception_obj (& exc , encoding , unicode , collstart , collend , reason );
6574+ raise_encode_exception (& exc , encoding , unicode , collstart , collend , reason );
66216575 goto onError ;
66226576 case 2 : /* replace */
66236577 while (collstart ++ < collend )
@@ -6712,7 +6666,7 @@ unicode_encode_ucs1(PyObject *unicode,
67126666 for (i = 0 ; repsize -- > 0 ; ++ i , ++ str ) {
67136667 c = PyUnicode_READ_CHAR (repunicode , i );
67146668 if (c >= limit ) {
6715- raise_encode_exception_obj (& exc , encoding , unicode ,
6669+ raise_encode_exception (& exc , encoding , unicode ,
67166670 pos , pos + 1 , reason );
67176671 Py_DECREF (repunicode );
67186672 goto onError ;
@@ -7434,7 +7388,7 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
74347388 if (errors == NULL || strcmp (errors , "strict" ) == 0 ) {
74357389 /* The last error was ERROR_NO_UNICODE_TRANSLATION,
74367390 then we raise a UnicodeEncodeError. */
7437- make_encode_exception_obj (& exc , encoding , unicode , 0 , 0 , reason );
7391+ make_encode_exception (& exc , encoding , unicode , 0 , 0 , reason );
74387392 if (exc != NULL ) {
74397393 PyCodec_StrictErrors (exc );
74407394 Py_DECREF (exc );
@@ -7555,7 +7509,7 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
75557509 for (i = 0 ; i < outsize ; i ++ ) {
75567510 Py_UCS4 ch = PyUnicode_READ (kind , data , i );
75577511 if (ch > 127 ) {
7558- raise_encode_exception_obj (& exc ,
7512+ raise_encode_exception (& exc ,
75597513 encoding , unicode ,
75607514 pos , pos + 1 ,
75617515 "unable to encode error handler result to ASCII" );
@@ -8250,7 +8204,7 @@ charmap_encoding_error(
82508204 }
82518205 switch (* known_errorHandler ) {
82528206 case 1 : /* strict */
8253- raise_encode_exception_obj (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
8207+ raise_encode_exception (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
82548208 return -1 ;
82558209 case 2 : /* replace */
82568210 for (collpos = collstartpos ; collpos < collendpos ; ++ collpos ) {
@@ -8259,7 +8213,7 @@ charmap_encoding_error(
82598213 return -1 ;
82608214 }
82618215 else if (x == enc_FAILED ) {
8262- raise_encode_exception_obj (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
8216+ raise_encode_exception (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
82638217 return -1 ;
82648218 }
82658219 }
@@ -8278,7 +8232,7 @@ charmap_encoding_error(
82788232 if (x == enc_EXCEPTION )
82798233 return -1 ;
82808234 else if (x == enc_FAILED ) {
8281- raise_encode_exception_obj (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
8235+ raise_encode_exception (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
82828236 return -1 ;
82838237 }
82848238 }
@@ -8319,7 +8273,7 @@ charmap_encoding_error(
83198273 }
83208274 else if (x == enc_FAILED ) {
83218275 Py_DECREF (repunicode );
8322- raise_encode_exception_obj (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
8276+ raise_encode_exception (exceptionObject , encoding , unicode , collstartpos , collendpos , reason );
83238277 return -1 ;
83248278 }
83258279 }
@@ -8990,7 +8944,11 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
89908944 }
89918945 switch (known_errorHandler ) {
89928946 case 1 : /* strict */
8993- raise_encode_exception (& exc , encoding , s , length , collstart - s , collend - s , reason );
8947+ unicode = PyUnicode_FromUnicode (s , length );
8948+ if (unicode == NULL )
8949+ goto onError ;
8950+ raise_encode_exception (& exc , encoding , unicode , collstart - s , collend - s , reason );
8951+ Py_DECREF (unicode );
89948952 goto onError ;
89958953 case 2 : /* replace */
89968954 for (p = collstart ; p < collend ; ++ p )
@@ -9035,8 +8993,12 @@ PyUnicode_EncodeDecimal(Py_UNICODE *s,
90358993 * output ++ = (char )ch ;
90368994 else {
90378995 Py_DECREF (repunicode );
8996+ unicode = PyUnicode_FromUnicode (s , length );
8997+ if (unicode == NULL )
8998+ goto onError ;
90388999 raise_encode_exception (& exc , encoding ,
9039- s , length , collstart - s , collend - s , reason );
9000+ unicode , collstart - s , collend - s , reason );
9001+ Py_DECREF (unicode );
90409002 goto onError ;
90419003 }
90429004 }
0 commit comments