@@ -1965,7 +1965,9 @@ long_to_decimal_string_internal(PyObject *aa,
1965
1965
digit * pout , * pin , rem , tenpow ;
1966
1966
int negative ;
1967
1967
int d ;
1968
- int kind ;
1968
+
1969
+ // writer or bytes_writer can be used, but not both at the same time.
1970
+ assert (writer == NULL || bytes_writer == NULL );
1969
1971
1970
1972
a = (PyLongObject * )aa ;
1971
1973
if (a == NULL || !PyLong_Check (a )) {
@@ -2078,7 +2080,6 @@ long_to_decimal_string_internal(PyObject *aa,
2078
2080
Py_DECREF (scratch );
2079
2081
return -1 ;
2080
2082
}
2081
- kind = writer -> kind ;
2082
2083
}
2083
2084
else if (bytes_writer ) {
2084
2085
* bytes_str = _PyBytesWriter_Prepare (bytes_writer , * bytes_str , strlen );
@@ -2093,7 +2094,6 @@ long_to_decimal_string_internal(PyObject *aa,
2093
2094
Py_DECREF (scratch );
2094
2095
return -1 ;
2095
2096
}
2096
- kind = PyUnicode_KIND (str );
2097
2097
}
2098
2098
2099
2099
#define WRITE_DIGITS (p ) \
@@ -2141,19 +2141,23 @@ long_to_decimal_string_internal(PyObject *aa,
2141
2141
WRITE_DIGITS (p );
2142
2142
assert (p == * bytes_str );
2143
2143
}
2144
- else if (kind == PyUnicode_1BYTE_KIND ) {
2145
- Py_UCS1 * p ;
2146
- WRITE_UNICODE_DIGITS (Py_UCS1 );
2147
- }
2148
- else if (kind == PyUnicode_2BYTE_KIND ) {
2149
- Py_UCS2 * p ;
2150
- WRITE_UNICODE_DIGITS (Py_UCS2 );
2151
- }
2152
2144
else {
2153
- Py_UCS4 * p ;
2154
- assert (kind == PyUnicode_4BYTE_KIND );
2155
- WRITE_UNICODE_DIGITS (Py_UCS4 );
2145
+ int kind = writer ? writer -> kind : PyUnicode_KIND (str );
2146
+ if (kind == PyUnicode_1BYTE_KIND ) {
2147
+ Py_UCS1 * p ;
2148
+ WRITE_UNICODE_DIGITS (Py_UCS1 );
2149
+ }
2150
+ else if (kind == PyUnicode_2BYTE_KIND ) {
2151
+ Py_UCS2 * p ;
2152
+ WRITE_UNICODE_DIGITS (Py_UCS2 );
2153
+ }
2154
+ else {
2155
+ assert (kind == PyUnicode_4BYTE_KIND );
2156
+ Py_UCS4 * p ;
2157
+ WRITE_UNICODE_DIGITS (Py_UCS4 );
2158
+ }
2156
2159
}
2160
+
2157
2161
#undef WRITE_DIGITS
2158
2162
#undef WRITE_UNICODE_DIGITS
2159
2163
@@ -2194,11 +2198,12 @@ long_format_binary(PyObject *aa, int base, int alternate,
2194
2198
PyObject * v = NULL ;
2195
2199
Py_ssize_t sz ;
2196
2200
Py_ssize_t size_a ;
2197
- int kind ;
2198
2201
int negative ;
2199
2202
int bits ;
2200
2203
2201
2204
assert (base == 2 || base == 8 || base == 16 );
2205
+ // writer or bytes_writer can be used, but not both at the same time.
2206
+ assert (writer == NULL || bytes_writer == NULL );
2202
2207
if (a == NULL || !PyLong_Check (a )) {
2203
2208
PyErr_BadInternalCall ();
2204
2209
return -1 ;
@@ -2246,7 +2251,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
2246
2251
if (writer ) {
2247
2252
if (_PyUnicodeWriter_Prepare (writer , sz , 'x' ) == -1 )
2248
2253
return -1 ;
2249
- kind = writer -> kind ;
2250
2254
}
2251
2255
else if (bytes_writer ) {
2252
2256
* bytes_str = _PyBytesWriter_Prepare (bytes_writer , * bytes_str , sz );
@@ -2257,7 +2261,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
2257
2261
v = PyUnicode_New (sz , 'x' );
2258
2262
if (v == NULL )
2259
2263
return -1 ;
2260
- kind = PyUnicode_KIND (v );
2261
2264
}
2262
2265
2263
2266
#define WRITE_DIGITS (p ) \
@@ -2318,19 +2321,23 @@ long_format_binary(PyObject *aa, int base, int alternate,
2318
2321
WRITE_DIGITS (p );
2319
2322
assert (p == * bytes_str );
2320
2323
}
2321
- else if (kind == PyUnicode_1BYTE_KIND ) {
2322
- Py_UCS1 * p ;
2323
- WRITE_UNICODE_DIGITS (Py_UCS1 );
2324
- }
2325
- else if (kind == PyUnicode_2BYTE_KIND ) {
2326
- Py_UCS2 * p ;
2327
- WRITE_UNICODE_DIGITS (Py_UCS2 );
2328
- }
2329
2324
else {
2330
- Py_UCS4 * p ;
2331
- assert (kind == PyUnicode_4BYTE_KIND );
2332
- WRITE_UNICODE_DIGITS (Py_UCS4 );
2325
+ int kind = writer ? writer -> kind : PyUnicode_KIND (v );
2326
+ if (kind == PyUnicode_1BYTE_KIND ) {
2327
+ Py_UCS1 * p ;
2328
+ WRITE_UNICODE_DIGITS (Py_UCS1 );
2329
+ }
2330
+ else if (kind == PyUnicode_2BYTE_KIND ) {
2331
+ Py_UCS2 * p ;
2332
+ WRITE_UNICODE_DIGITS (Py_UCS2 );
2333
+ }
2334
+ else {
2335
+ assert (kind == PyUnicode_4BYTE_KIND );
2336
+ Py_UCS4 * p ;
2337
+ WRITE_UNICODE_DIGITS (Py_UCS4 );
2338
+ }
2333
2339
}
2340
+
2334
2341
#undef WRITE_DIGITS
2335
2342
#undef WRITE_UNICODE_DIGITS
2336
2343
0 commit comments