@@ -692,13 +692,20 @@ static CYTHON_INLINE PyObject* {{TO_PY_FUNCTION}}({{TYPE}} value) {
692
692
}
693
693
}
694
694
{
695
- int one = 1 ; int little = (int )* (unsigned char * )& one ;
696
695
unsigned char * bytes = (unsigned char * )& value ;
697
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
696
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
697
+ if (is_unsigned ) {
698
+ return PyLong_FromUnsignedNativeBytes (bytes , sizeof (value ), -1 );
699
+ } else {
700
+ return PyLong_FromNativeBytes (bytes , sizeof (value ), -1 );
701
+ }
702
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
703
+ int one = 1 ; int little = (int )* (unsigned char * )& one ;
698
704
return _PyLong_FromByteArray (bytes , sizeof ({{TYPE }}),
699
705
little , !is_unsigned );
700
706
#else
701
707
// call int.from_bytes()
708
+ int one = 1 ; int little = (int )* (unsigned char * )& one ;
702
709
PyObject * from_bytes , * result = NULL , * kwds = NULL ;
703
710
PyObject * py_bytes = NULL , * order_str = NULL ;
704
711
from_bytes = PyObject_GetAttrString ((PyObject * )& PyLong_Type , "from_bytes" );
@@ -1008,7 +1015,16 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) {
1008
1015
PyObject * v = __Pyx_PyNumber_IntOrLong (x );
1009
1016
if (likely (v )) {
1010
1017
int ret = -1 ;
1011
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API ) || defined(_PyLong_AsByteArray )
1018
+ #if PY_VERSION_HEX >= 0x030d00A4 && !CYTHON_COMPILING_IN_LIMITED_API
1019
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes (v , & val , sizeof (val ), -1 );
1020
+ if (unlikely (bytes_copied == -1 )) {
1021
+ // failed
1022
+ } else if (unlikely (bytes_copied > sizeof (val ))) {
1023
+ goto raise_overflow ;
1024
+ } else {
1025
+ ret = 0 ;
1026
+ }
1027
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API ) || defined(_PyLong_AsByteArray )
1012
1028
int one = 1 ; int is_little = (int )* (unsigned char * )& one ;
1013
1029
unsigned char * bytes = (unsigned char * )& val ;
1014
1030
ret = _PyLong_AsByteArray ((PyLongObject * )v ,
0 commit comments