digit *pout, *pin, rem, tenpow;
int negative;
int d;
- int kind;
+
+ // writer or bytes_writer can be used, but not both at the same time.
+ assert(writer == NULL || bytes_writer == NULL);
a = (PyLongObject *)aa;
if (a == NULL || !PyLong_Check(a)) {
Py_DECREF(scratch);
return -1;
}
- kind = writer->kind;
}
else if (bytes_writer) {
*bytes_str = _PyBytesWriter_Prepare(bytes_writer, *bytes_str, strlen);
Py_DECREF(scratch);
return -1;
}
- kind = PyUnicode_KIND(str);
}
#define WRITE_DIGITS(p) \
WRITE_DIGITS(p);
assert(p == *bytes_str);
}
- else if (kind == PyUnicode_1BYTE_KIND) {
- Py_UCS1 *p;
- WRITE_UNICODE_DIGITS(Py_UCS1);
- }
- else if (kind == PyUnicode_2BYTE_KIND) {
- Py_UCS2 *p;
- WRITE_UNICODE_DIGITS(Py_UCS2);
- }
else {
- Py_UCS4 *p;
- assert (kind == PyUnicode_4BYTE_KIND);
- WRITE_UNICODE_DIGITS(Py_UCS4);
+ int kind = writer ? writer->kind : PyUnicode_KIND(str);
+ if (kind == PyUnicode_1BYTE_KIND) {
+ Py_UCS1 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS1);
+ }
+ else if (kind == PyUnicode_2BYTE_KIND) {
+ Py_UCS2 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS2);
+ }
+ else {
+ assert (kind == PyUnicode_4BYTE_KIND);
+ Py_UCS4 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS4);
+ }
}
+
#undef WRITE_DIGITS
#undef WRITE_UNICODE_DIGITS
PyObject *v = NULL;
Py_ssize_t sz;
Py_ssize_t size_a;
- int kind;
int negative;
int bits;
assert(base == 2 || base == 8 || base == 16);
+ // writer or bytes_writer can be used, but not both at the same time.
+ assert(writer == NULL || bytes_writer == NULL);
if (a == NULL || !PyLong_Check(a)) {
PyErr_BadInternalCall();
return -1;
if (writer) {
if (_PyUnicodeWriter_Prepare(writer, sz, 'x') == -1)
return -1;
- kind = writer->kind;
}
else if (bytes_writer) {
*bytes_str = _PyBytesWriter_Prepare(bytes_writer, *bytes_str, sz);
v = PyUnicode_New(sz, 'x');
if (v == NULL)
return -1;
- kind = PyUnicode_KIND(v);
}
#define WRITE_DIGITS(p) \
WRITE_DIGITS(p);
assert(p == *bytes_str);
}
- else if (kind == PyUnicode_1BYTE_KIND) {
- Py_UCS1 *p;
- WRITE_UNICODE_DIGITS(Py_UCS1);
- }
- else if (kind == PyUnicode_2BYTE_KIND) {
- Py_UCS2 *p;
- WRITE_UNICODE_DIGITS(Py_UCS2);
- }
else {
- Py_UCS4 *p;
- assert (kind == PyUnicode_4BYTE_KIND);
- WRITE_UNICODE_DIGITS(Py_UCS4);
+ int kind = writer ? writer->kind : PyUnicode_KIND(v);
+ if (kind == PyUnicode_1BYTE_KIND) {
+ Py_UCS1 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS1);
+ }
+ else if (kind == PyUnicode_2BYTE_KIND) {
+ Py_UCS2 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS2);
+ }
+ else {
+ assert (kind == PyUnicode_4BYTE_KIND);
+ Py_UCS4 *p;
+ WRITE_UNICODE_DIGITS(Py_UCS4);
+ }
}
+
#undef WRITE_DIGITS
#undef WRITE_UNICODE_DIGITS