@@ -7267,13 +7267,13 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
72677267 BOOL * pusedDefaultChar = & usedDefaultChar ;
72687268 int outsize ;
72697269 PyObject * exc = NULL ;
7270- Py_UNICODE * p ;
7271- Py_ssize_t size ;
7270+ Py_UNICODE * p ;
7271+ Py_ssize_t size ;
72727272 const DWORD flags = encode_code_page_flags (code_page , NULL );
72737273 char * out ;
7274- /* Create a substring so that we can get the UTF-16 representation
7275- of just the slice under consideration. */
7276- PyObject * substring ;
7274+ /* Create a substring so that we can get the UTF-16 representation
7275+ of just the slice under consideration. */
7276+ PyObject * substring ;
72777277
72787278 assert (len > 0 );
72797279
@@ -7282,14 +7282,14 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
72827282 else
72837283 pusedDefaultChar = NULL ;
72847284
7285- substring = PyUnicode_Substring (unicode , offset , offset + len );
7286- if (substring == NULL )
7287- return -1 ;
7288- p = PyUnicode_AsUnicodeAndSize (substring , & size );
7289- if (p == NULL ) {
7290- Py_DECREF (substring );
7291- return -1 ;
7292- }
7285+ substring = PyUnicode_Substring (unicode , offset , offset + len );
7286+ if (substring == NULL )
7287+ return -1 ;
7288+ p = PyUnicode_AsUnicodeAndSize (substring , & size );
7289+ if (p == NULL ) {
7290+ Py_DECREF (substring );
7291+ return -1 ;
7292+ }
72937293
72947294 /* First get the size of the result */
72957295 outsize = WideCharToMultiByte (code_page , flags ,
@@ -7299,32 +7299,32 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
72997299 if (outsize <= 0 )
73007300 goto error ;
73017301 /* If we used a default char, then we failed! */
7302- if (pusedDefaultChar && * pusedDefaultChar ) {
7303- Py_DECREF (substring );
7302+ if (pusedDefaultChar && * pusedDefaultChar ) {
7303+ Py_DECREF (substring );
73047304 return -2 ;
7305- }
7305+ }
73067306
73077307 if (* outbytes == NULL ) {
73087308 /* Create string object */
73097309 * outbytes = PyBytes_FromStringAndSize (NULL , outsize );
7310- if (* outbytes == NULL ) {
7311- Py_DECREF (substring );
7310+ if (* outbytes == NULL ) {
7311+ Py_DECREF (substring );
73127312 return -1 ;
7313- }
7313+ }
73147314 out = PyBytes_AS_STRING (* outbytes );
73157315 }
73167316 else {
73177317 /* Extend string object */
73187318 const Py_ssize_t n = PyBytes_Size (* outbytes );
73197319 if (outsize > PY_SSIZE_T_MAX - n ) {
73207320 PyErr_NoMemory ();
7321- Py_DECREF (substring );
7321+ Py_DECREF (substring );
73227322 return -1 ;
73237323 }
7324- if (_PyBytes_Resize (outbytes , n + outsize ) < 0 ) {
7325- Py_DECREF (substring );
7324+ if (_PyBytes_Resize (outbytes , n + outsize ) < 0 ) {
7325+ Py_DECREF (substring );
73267326 return -1 ;
7327- }
7327+ }
73287328 out = PyBytes_AS_STRING (* outbytes ) + n ;
73297329 }
73307330
@@ -7333,15 +7333,15 @@ encode_code_page_strict(UINT code_page, PyObject **outbytes,
73337333 p , size ,
73347334 out , outsize ,
73357335 NULL , pusedDefaultChar );
7336- Py_CLEAR (substring );
7336+ Py_CLEAR (substring );
73377337 if (outsize <= 0 )
73387338 goto error ;
73397339 if (pusedDefaultChar && * pusedDefaultChar )
73407340 return -2 ;
73417341 return 0 ;
73427342
73437343error :
7344- Py_XDECREF (substring );
7344+ Py_XDECREF (substring );
73457345 if (GetLastError () == ERROR_NO_UNICODE_TRANSLATION )
73467346 return -2 ;
73477347 PyErr_SetFromWindowsErr (0 );
@@ -7361,8 +7361,8 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
73617361 Py_ssize_t insize , const char * errors )
73627362{
73637363 const DWORD flags = encode_code_page_flags (code_page , errors );
7364- Py_ssize_t pos = unicode_offset ;
7365- Py_ssize_t endin = unicode_offset + insize ;
7364+ Py_ssize_t pos = unicode_offset ;
7365+ Py_ssize_t endin = unicode_offset + insize ;
73667366 /* Ideally, we should get reason from FormatMessage. This is the Windows
73677367 2000 English version of the message. */
73687368 const char * reason = "invalid character" ;
@@ -7430,20 +7430,20 @@ encode_code_page_errors(UINT code_page, PyObject **outbytes,
74307430 /* Encode the string character per character */
74317431 while (pos < endin )
74327432 {
7433- Py_UCS4 ch = PyUnicode_READ_CHAR (unicode , pos );
7434- wchar_t chars [2 ];
7435- int charsize ;
7436- if (ch < 0x10000 ) {
7437- chars [0 ] = (wchar_t )ch ;
7438- charsize = 1 ;
7439- }
7440- else {
7441- ch -= 0x10000 ;
7442- chars [0 ] = 0xd800 + (ch >> 10 );
7443- chars [1 ] = 0xdc00 + (ch & 0x3ff );
7444- charsize = 2 ;
7445- }
7446-
7433+ Py_UCS4 ch = PyUnicode_READ_CHAR (unicode , pos );
7434+ wchar_t chars [2 ];
7435+ int charsize ;
7436+ if (ch < 0x10000 ) {
7437+ chars [0 ] = (wchar_t )ch ;
7438+ charsize = 1 ;
7439+ }
7440+ else {
7441+ ch -= 0x10000 ;
7442+ chars [0 ] = 0xd800 + (ch >> 10 );
7443+ chars [1 ] = 0xdc00 + (ch & 0x3ff );
7444+ charsize = 2 ;
7445+ }
7446+
74477447 outsize = WideCharToMultiByte (code_page , flags ,
74487448 chars , charsize ,
74497449 buffer , Py_ARRAY_LENGTH (buffer ),
@@ -7547,9 +7547,9 @@ encode_code_page(int code_page,
75477547 Py_ssize_t offset ;
75487548 int chunk_len , ret , done ;
75497549
7550- if (PyUnicode_READY (unicode ) < 0 )
7551- return NULL ;
7552- len = PyUnicode_GET_LENGTH (unicode );
7550+ if (PyUnicode_READY (unicode ) < 0 )
7551+ return NULL ;
7552+ len = PyUnicode_GET_LENGTH (unicode );
75537553
75547554 if (code_page < 0 ) {
75557555 PyErr_SetString (PyExc_ValueError , "invalid code page number" );
@@ -7563,7 +7563,7 @@ encode_code_page(int code_page,
75637563 do
75647564 {
75657565#ifdef NEED_RETRY
7566- /* UTF-16 encoding may double the size, so use only INT_MAX/2
7566+ /* UTF-16 encoding may double the size, so use only INT_MAX/2
75677567 chunks. */
75687568 if (len > INT_MAX /2 ) {
75697569 chunk_len = INT_MAX /2 ;
@@ -7575,7 +7575,7 @@ encode_code_page(int code_page,
75757575 chunk_len = (int )len ;
75767576 done = 1 ;
75777577 }
7578-
7578+
75797579 ret = encode_code_page_strict (code_page , & outbytes ,
75807580 unicode , offset , chunk_len ,
75817581 errors );
0 commit comments