8000 Inline PyLong_AsInt64() to avoid the exception · python/cpython@d70a121 · GitHub
[go: up one dir, main page]

Skip to content

Commit d70a121

Browse files
committed
Inline PyLong_AsInt64() to avoid the exception
1 parent 37b1d49 commit d70a121

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Objects/longobject.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6797,17 +6797,22 @@ PyLong_Export(PyObject *obj, PyLongExport *export_long)
67976797
PyErr_Format(PyExc_TypeError, "expect int, got %T", obj);
67986798
return -1;
67996799
}
6800+
68006801
int64_t value;
6801-
if (PyLong_AsInt64(obj, &value) >= 0) {
6802+
int flags = Py_ASNATIVEBYTES_NATIVE_ENDIAN;
6803+
Py_ssize_t bytes = PyLong_AsNativeBytes(obj, &value, sizeof(value), flags);
6804+
if (bytes < 0) {
6805+
return -1;
6806+
}
6807+
6808+
if ((size_t)bytes <= sizeof(value)) {
68026809
export_long->value = value;
68036810
export_long->negative = 0;
68046811
export_long->ndigits = 0;
68056812
export_long->digits = 0;
68066813
export_long->_reserved = 0;
68076814
}
68086815
else {
6809-
PyErr_Clear();
6810-
68116816
PyLongObject *self = (PyLongObject*)obj;
68126817
export_long->value = 0;
68136818
export_long->negative = _PyLong_IsNegative(self);

0 commit comments

Comments
 (0)
0