#define _PyLong_SMALL_INTS _Py_SINGLETON(small_ints)
// _PyLong_GetZero() and _PyLong_GetOne() must always be available
-#if _PY_NSMALLPOSINTS < 2
-# error "_PY_NSMALLPOSINTS must be greater than 1"
+// _PyLong_FromUnsignedChar must always be available
+#if _PY_NSMALLPOSINTS < 257
+# error "_PY_NSMALLPOSINTS must be greater than or equal to 257"
#endif
// Return a borrowed reference to the zero singleton.
static inline PyObject* _PyLong_GetOne(void)
{ return (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+1]; }
+static inline PyObject* _PyLong_FromUnsignedChar(unsigned char i)
+{
+ return Py_NewRef((PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+i]);
+}
+
PyObject *_PyLong_Add(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Multiply(PyLongObject *left, PyLongObject *right);
PyObject *_PyLong_Subtract(PyLongObject *left, PyLongObject *right);
#include "pycore_bytes_methods.h"
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_strhex.h" // _Py_strhex_with_sep()
+#include "pycore_long.h" // _PyLong_FromUnsignedChar()
#include "bytesobject.h"
/*[clinic input]
bytearrayiter_next(bytesiterobject *it)
{
PyByteArrayObject *seq;
- PyObject *item;
assert(it != NULL);
seq = it->it_seq;
assert(PyByteArray_Check(seq));
if (it->it_index < PyByteArray_GET_SIZE(seq)) {
- item = PyLong_FromLong(
- (unsigned char)PyByteArray_AS_STRING(seq)[it->it_index]);
- if (item != NULL)
- ++it->it_index;
- return item;
+ return _PyLong_FromUnsignedChar(
+ (unsigned char)PyByteArray_AS_STRING(seq)[it->it_index++]);
}
it->it_seq = NULL;
assert(PyBytes_Check(seq));
if (it->it_index < PyBytes_GET_SIZE(seq)) {
- return PyLong_FromLong(
+ return _PyLong_FromUnsignedChar(
(unsigned char)seq->ob_sval[it->it_index++]);
}