Skip to content

Commit

Permalink
MNT: account for CPython 314 changes (#760)
Browse files Browse the repository at this point in the history
* MNT: account for CPython 314 changes

python/cpython#125251 renamed
_PY_IMMORTAL_REFCNT -> _PY_IMMORTAL_INITIAL_REFCNT

* Define new macro to reduce duplication

---------

Co-authored-by: Jim Crist-Harif <[email protected]>
  • Loading branch information
tacaswell and jcrist authored Oct 24, 2024
1 parent 29390b0 commit f66bbbd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions msgspec/_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define PY311_PLUS (PY_VERSION_HEX >= 0x030b0000)
#define PY312_PLUS (PY_VERSION_HEX >= 0x030c0000)
#define PY313_PLUS (PY_VERSION_HEX >= 0x030d0000)
#define PY314_PLUS (PY_VERSION_HEX >= 0x030e0000)

/* Hint to the compiler not to store `x` in a register since it is likely to
* change. Results in much higher performance on GCC, with smaller benefits on
Expand Down Expand Up @@ -71,6 +72,12 @@ ms_popcount(uint64_t i) { \
#define MS_UNICODE_EQ(a, b) _PyUnicode_EQ(a, b)
#endif

#if PY314_PLUS
#define MS_IMMORTAL_INITIAL_REFCNT _Py_IMMORTAL_INITIAL_REFCNT
#else
#define MS_IMMORTAL_INITIAL_REFCNT _Py_IMMORTAL_REFCNT
#endif

#define DIV_ROUND_CLOSEST(n, d) ((((n) < 0) == ((d) < 0)) ? (((n) + (d)/2)/(d)) : (((n) - (d)/2)/(d)))

/* These macros are used to manually unroll some loops */
Expand Down Expand Up @@ -2155,7 +2162,7 @@ PyTypeObject NoDefault_Type = {
#if PY312_PLUS
PyObject _NoDefault_Object = {
_PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
{ MS_IMMORTAL_INITIAL_REFCNT },
&NoDefault_Type
};
#else
Expand Down Expand Up @@ -2259,7 +2266,7 @@ PyTypeObject Unset_Type = {
#if PY312_PLUS
PyObject _Unset_Object = {
_PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
{ MS_IMMORTAL_INITIAL_REFCNT },
&Unset_Type
};
#else
Expand Down

0 comments on commit f66bbbd

Please sign in to comment.