On Tue, Oct 16, 2018 at 9:51 AM Jerry James <loganjerry@xxxxxxxxx> wrote: > Sadly, no. Here is the challenge, Python aficionados. The attached file, test.pyx, can be processed like this on Fedora 28 with Cython 0.28.4: "cythonize -3 test.pyx". That succeeds and generates code that Does The Right Thing. On Rawhide with Cython 0.29rc2, that fails as noted earlier in this thread. The name PyLongObject cannot be imported with cimport. How does the code need to change to compute the same result? Thanks, -- Jerry James http://www.jamezone.org/
from cpython.object cimport Py_SIZE from cpython.longintrepr cimport PyLongObject, PyLong_SHIFT, digit cdef enum: ERR_TYPE = 1 ERR_INDEX = 2 ERR_OVERFLOW = 3 cdef inline long dig(const digit* D, int n): return (<long>D[n]) << (n * PyLong_SHIFT) cdef bint do_stuff_to_a_long(x, long* value, int* err) except -1: cdef const digit* D = (<PyLongObject*>x).ob_digit cdef Py_ssize_t size = Py_SIZE(x) cdef int BITS_IN_LONG = 8 * sizeof(long) - 1 cdef long lead cdef long lead_3_overflow = (<long>1) << (BITS_IN_LONG - 2 * PyLong_SHIFT) if size == 0: value[0] = 0 err[0] = 0 elif size == 1: value[0] = dig(D, 0) err[0] = 0 elif size == -1: value[0] = -dig(D, 0) err[0] = 0 elif size == 2: value[0] = dig(D, 0) + dig(D, 1) err[0] = 0 elif size == -2: value[0] = -(dig(D, 0) + dig(D, 1)) err[0] = 0 elif size == 3: lead = D[2] if lead < lead_3_overflow: value[0] = dig(D, 0) + dig(D, 1) + dig(D, 2) err[0] = 0 else: err[0] = ERR_OVERFLOW elif size == -3: lead = D[2] if lead < lead_3_overflow: value[0] = -(dig(D, 0) + dig(D, 1) + dig(D, 2)) err[0] = 0 elif D[0] == 0 and D[1] == 0 and lead == lead_3_overflow: # Special case for LONG_MIN value[0] = (<long>-1) << BITS_IN_LONG err[0] = 0 else: err[0] = ERR_OVERFLOW else: # 4 digits or more: guaranteed overflow err[0] = ERR_OVERFLOW return 1
_______________________________________________ devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx