Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 18 Include/internal/pycore_longobject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef Py_INTERNAL_LONGOBJECT_H
#define Py_INTERNAL_LONGOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif

#include "longobject.h"

PyAPI_FUNC(PyObject *) _PyLong_FromUnsignedChar(unsigned char);

#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_LONGOBJECT_H */
9 changes: 5 additions & 4 deletions 9 Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "pycore_longobject.h"
#include "pycore_object.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
Expand Down Expand Up @@ -387,7 +388,7 @@ bytearray_getitem(PyByteArrayObject *self, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
return NULL;
}
return PyLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i]));
return _PyLong_FromUnsignedChar((unsigned char)(PyByteArray_AS_STRING(self)[i]));
}

static PyObject *
Expand All @@ -406,7 +407,7 @@ bytearray_subscript(PyByteArrayObject *self, PyObject *index)
PyErr_SetString(PyExc_IndexError, "bytearray index out of range");
return NULL;
}
return PyLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i]));
return _PyLong_FromUnsignedChar((unsigned char)(PyByteArray_AS_STRING(self)[i]));
}
else if (PySlice_Check(index)) {
Py_ssize_t start, stop, step, slicelength, i;
Expand Down Expand Up @@ -1745,7 +1746,7 @@ bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index)
if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
return NULL;

return PyLong_FromLong((unsigned char)value);
return _PyLong_FromUnsignedChar((unsigned char)value);
}

/*[clinic input]
Expand Down Expand Up @@ -2339,7 +2340,7 @@ bytearrayiter_next(bytesiterobject *it)
assert(PyByteArray_Check(seq));

if (it->it_index < PyByteArray_GET_SIZE(seq)) {
item = PyLong_FromLong(
item = _PyLong_FromUnsignedChar(
(unsigned char)PyByteArray_AS_STRING(seq)[it->it_index]);
if (item != NULL)
++it->it_index;
Expand Down
7 changes: 4 additions & 3 deletions 7 Objects/bytesobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define PY_SSIZE_T_CLEAN

#include "Python.h"
#include "pycore_longobject.h"
#include "pycore_object.h"
#include "pycore_pymem.h"
#include "pycore_pystate.h"
Expand Down Expand Up @@ -1541,7 +1542,7 @@ bytes_item(PyBytesObject *a, Py_ssize_t i)
PyErr_SetString(PyExc_IndexError, "index out of range");
return NULL;
}
return PyLong_FromLong((unsigned char)a->ob_sval[i]);
return _PyLong_FromUnsignedChar((unsigned char)a->ob_sval[i]);
}

static int
Expand Down Expand Up @@ -1664,7 +1665,7 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
"index out of range");
return NULL;
}
return PyLong_FromLong((unsigned char)self->ob_sval[i]);
return _PyLong_FromUnsignedChar((unsigned char)self->ob_sval[i]);
}
else if (PySlice_Check(item)) {
Py_ssize_t start, stop, step, slicelength, i;
Expand Down Expand Up @@ -3091,7 +3092,7 @@ striter_next(striterobject *it)
assert(PyBytes_Check(seq));

if (it->it_index < PyBytes_GET_SIZE(seq)) {
item = PyLong_FromLong(
item = _PyLong_FromUnsignedChar(
(unsigned char)seq->ob_sval[it->it_index]);
if (item != NULL)
++it->it_index;
Expand Down
6 changes: 6 additions & 0 deletions 6 Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,12 @@ PyLong_FromUnsignedLong(unsigned long ival)
return (PyObject *)v;
}

PyObject *
_PyLong_FromUnsignedChar(unsigned char ival)
{
return PyLong_FromSize_t(ival);
}

/* Create a new int object from a C double */

PyObject *
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.