Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bc9e48c

Browse files
committed
A test and a const
1 parent 79d4942 commit bc9e48c

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

Include/cpython/longobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ PyAPI_FUNC(int) PyLong_CopyBits(PyObject* v, void* buffer, size_t n_bytes,
2929
endianness is -1 for native endian, 0 for big endian or 1 for little.
3030
3131
Returns the int object, or NULL with an exception set. */
32-
PyAPI_FUNC(PyObject*) PyLong_FromBits(void* buffer, size_t n_bytes,
32+
PyAPI_FUNC(PyObject*) PyLong_FromBits(const void* buffer, size_t n_bytes,
3333
int endianness);
34-
PyAPI_FUNC(PyObject*) PyLong_FromUnsignedBits(void* buffer, size_t n_bytes,
34+
PyAPI_FUNC(PyObject*) PyLong_FromUnsignedBits(const void* buffer, size_t n_bytes,
3535
int endianness);
3636

3737
PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);

Lib/test/test_capi/test_long.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def test_long_copybits(self):
461461
for v, expect_be, expect_n in [
462462
(0, b'\x00', 1),
463463
(0, b'\x00' * 2, 2),
464-
(0, b'\x00' * 8, 8),
464+
(0, b'\x00' * 8, min(8, SZ)),
465465
(1, b'\x01', 1),
466466
(1, b'\x00' * 10 + b'\x01', min(11, SZ)),
467467
(42, b'\x2a', 1),

Objects/longobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ PyLong_CopyBits(PyObject* vv, void* buffer, size_t n, int endianness)
10961096
return -1;
10971097
}
10981098

1099-
if ((int)n != n || (int)n < 0) {
1099+
if ((size_t)(int)n != n || (int)n < 0) {
11001100
PyErr_SetString(PyExc_SystemError, "n_bytes too big to copy");
11011101
return -1;
11021102
}
@@ -1202,7 +1202,7 @@ PyLong_CopyBits(PyObject* vv, void* buffer, size_t n, int endianness)
12021202
* the sign and it cancels out. */
12031203
size_t n_needed = (nb / 8) + 1;
12041204
res = (int)n_needed;
1205-
if (res != n_needed) {
1205+
if ((size_t)res != n_needed) {
12061206
PyErr_SetString(PyExc_OverflowError,
12071207
"value too large to convert");
12081208
res = -1;
@@ -1240,7 +1240,7 @@ PyLong_FromBits(const void* buffer, size_t n, int endianness)
12401240

12411241

12421242
PyObject *
1243-
PyLong_FromUnsignedBits(void* buffer, size_t n, int endianness)
1243+
PyLong_FromUnsignedBits(const void* buffer, size_t n, int endianness)
12441244
{
12451245
if (!buffer) {
12461246
PyErr_BadInternalCall();

0 commit comments

Comments
 (0)