Skip to content

Commit

Permalink
[mypyc] Fix i16 on Python 3.12
Browse files Browse the repository at this point in the history
Two recent mypyc PRs didn't work together (#15470 and #15464). Fix
them.
  • Loading branch information
JukkaL committed Jun 24, 2023
1 parent 9bd8563 commit 3f1c98a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mypyc/lib-rt/int_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,18 @@ void CPyInt32_Overflow() {

int16_t CPyLong_AsInt16(PyObject *o) {
if (likely(PyLong_Check(o))) {
#if CPY_3_12_FEATURES
PyLongObject *lobj = (PyLongObject *)o;
size_t tag = CPY_LONG_TAG(lobj);
if (likely(tag == (1 << CPY_NON_SIZE_BITS))) {
// Fast path
digit x = CPY_LONG_DIGIT(lobj, 0);
if (x < 0x8000)
return x;
} else if (likely(tag == CPY_SIGN_ZERO)) {
return 0;
}
#else
PyLongObject *lobj = (PyLongObject *)o;
Py_ssize_t size = lobj->ob_base.ob_size;
if (likely(size == 1)) {
Expand All @@ -664,6 +676,7 @@ int16_t CPyLong_AsInt16(PyObject *o) {
} else if (likely(size == 0)) {
return 0;
}
#endif
}
// Slow path
int overflow;
Expand Down

0 comments on commit 3f1c98a

Please sign in to comment.