@@ -1766,7 +1766,9 @@ long_to_decimal_string_internal(PyObject *aa,
1766
1766
digit * pout , * pin , rem , tenpow ;
1767
1767
int negative ;
1768
1768
int d ;
1769
- int kind ;
1769
+
1770
+ // writer or bytes_writer can be used, but not both at the same time.
1771
+ assert (writer == NULL || bytes_writer == NULL );
1770
1772
1771
1773
a = (PyLongObject * )aa ;
1772
1774
if (a == NULL || !PyLong_Check (a )) {
@@ -1879,7 +1881,6 @@ long_to_decimal_string_internal(PyObject *aa,
1879
1881
Py_DECREF (scratch );
1880
1882
return -1 ;
1881
1883
}
1882
- kind = writer -> kind ;
1883
1884
}
1884
1885
else if (bytes_writer ) {
1885
1886
* bytes_str = _PyBytesWriter_Prepare (bytes_writer , * bytes_str , strlen );
@@ -1894,7 +1895,6 @@ long_to_decimal_string_internal(PyObject *aa,
1894
1895
Py_DECREF (scratch );
1895
1896
return -1 ;
1896
1897
}
1897
- kind = PyUnicode_KIND (str );
1898
1898
}
1899
1899
1900
1900
#define WRITE_DIGITS (p ) \
@@ -1942,19 +1942,23 @@ long_to_decimal_string_internal(PyObject *aa,
1942
1942
WRITE_DIGITS (p );
1943
1943
assert (p == * bytes_str );
1944
1944
}
1945
- else if (kind == PyUnicode_1BYTE_KIND ) {
1946
- Py_UCS1 * p ;
1947
- WRITE_UNICODE_DIGITS (Py_UCS1 );
1948
- }
1949
- else if (kind == PyUnicode_2BYTE_KIND ) {
1950
- Py_UCS2 * p ;
1951
- WRITE_UNICODE_DIGITS (Py_UCS2 );
1952
- }
1953
1945
else {
1954
- Py_UCS4 * p ;
1955
- assert (kind == PyUnicode_4BYTE_KIND );
1956
- WRITE_UNICODE_DIGITS (Py_UCS4 );
1946
+ int kind = writer ? writer -> kind : PyUnicode_KIND (str );
1947
+ if (kind == PyUnicode_1BYTE_KIND ) {
1948
+ Py_UCS1 * p ;
1949
+ WRITE_UNICODE_DIGITS (Py_UCS1 );
1950
+ }
1951
+ else if (kind == PyUnicode_2BYTE_KIND ) {
1952
+ Py_UCS2 * p ;
1953
+ WRITE_UNICODE_DIGITS (Py_UCS2 );
1954
+ }
1955
+ else {
1956
+ assert (kind == PyUnicode_4BYTE_KIND );
1957
+ Py_UCS4 * p ;
1958
+ WRITE_UNICODE_DIGITS (Py_UCS4 );
1959
+ }
1957
1960
}
1961
+
1958
1962
#undef WRITE_DIGITS
1959
1963
#undef WRITE_UNICODE_DIGITS
1960
1964
@@ -1995,11 +1999,12 @@ long_format_binary(PyObject *aa, int base, int alternate,
1995
1999
PyObject * v = NULL ;
1996
2000
Py_ssize_t sz ;
1997
2001
Py_ssize_t size_a ;
1998
- int kind ;
1999
2002
int negative ;
2000
2003
int bits ;
2001
2004
2002
2005
assert (base == 2 || base == 8 || base == 16 );
2006
+ // writer or bytes_writer can be used, but not both at the same time.
2007
+ assert (writer == NULL || bytes_writer == NULL );
2003
2008
if (a == NULL || !PyLong_Check (a )) {
2004
2009
PyErr_BadInternalCall ();
2005
2010
return -1 ;
@@ -2047,7 +2052,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
2047
2052
if (writer ) {
2048
2053
if (_PyUnicodeWriter_Prepare (writer , sz , 'x' ) == -1 )
2049
2054
return -1 ;
2050
- kind = writer -> kind ;
2051
2055
}
2052
2056
else if (bytes_writer ) {
2053
2057
* bytes_str = _PyBytesWriter_Prepare (bytes_writer , * bytes_str , sz );
@@ -2058,7 +2062,6 @@ long_format_binary(PyObject *aa, int base, int alternate,
2058
2062
v = PyUnicode_New (sz , 'x' );
2059
2063
if (v == NULL )
2060
2064
return -1 ;
2061
- kind = PyUnicode_KIND (v );
2062
2065
}
2063
2066
2064
2067
#define WRITE_DIGITS (p ) \
@@ -2119,19 +2122,23 @@ long_format_binary(PyObject *aa, int base, int alternate,
2119
2122
WRITE_DIGITS (p );
2120
2123
assert (p == * bytes_str );
2121
2124
}
2122
- else if (kind == PyUnicode_1BYTE_KIND ) {
2123
- Py_UCS1 * p ;
2124
- WRITE_UNICODE_DIGITS (Py_UCS1 );
2125
- }
2126
- else if (kind == PyUnicode_2BYTE_KIND ) {
2127
- Py_UCS2 * p ;
2128
- WRITE_UNICODE_DIGITS (Py_UCS2 );
2129
- }
2130
2125
else {
2131
- Py_UCS4 * p ;
2132
- assert (kind == PyUnicode_4BYTE_KIND );
2133
- WRITE_UNICODE_DIGITS (Py_UCS4 );
2126
+ int kind = writer ? writer -> kind : PyUnicode_KIND (v );
2127
+ if (kind == PyUnicode_1BYTE_KIND ) {
2128
+ Py_UCS1 * p ;
2129
+ WRITE_UNICODE_DIGITS (Py_UCS1 );
2130
+ }
2131
+ else if (kind == PyUnicode_2BYTE_KIND ) {
2132
+ Py_UCS2 * p ;
2133
+ WRITE_UNICODE_DIGITS (Py_UCS2 );
2134
+ }
2135
+ else {
2136
+ assert (kind == PyUnicode_4BYTE_KIND );
2137
+ Py_UCS4 * p ;
2138
+ WRITE_UNICODE_DIGITS (Py_UCS4 );
2139
+ }
2134
2140
}
2141
+
2135
2142
#undef WRITE_DIGITS
2136
2143
#undef WRITE_UNICODE_DIGITS
2137
2144
0 commit comments