File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -6797,17 +6797,22 @@ PyLong_Export(PyObject *obj, PyLongExport *export_long)
6797
6797
PyErr_Format (PyExc_TypeError , "expect int, got %T" , obj );
6798
6798
return -1 ;
6799
6799
}
6800
+
6800
6801
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 )) {
6802
6809
export_long -> value = value ;
6803
6810
export_long -> negative = 0 ;
6804
6811
export_long -> ndigits = 0 ;
6805
6812
export_long -> digits = 0 ;
6806
6813
export_long -> _reserved = 0 ;
6807
6814
}
6808
6815
else {
6809
- PyErr_Clear ();
6810
-
6811
6816
PyLongObject * self = (PyLongObject * )obj ;
6812
6817
export_long -> value = 0 ;
6813
6818
export_long -> negative = _PyLong_IsNegative (self );
You can’t perform that action at this time.
0 commit comments