Skip to content

Commit

Permalink
Define new macro to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Oct 24, 2024
1 parent 93e131c commit f46c882
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions msgspec/_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,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 @@ -2153,16 +2159,10 @@ PyTypeObject NoDefault_Type = {
.tp_basicsize = 0
};

#if PY314_PLUS
PyObject _NoDefault_Object = {
_PyObject_EXTRA_INIT
{ _Py_IMMORTAL_INITIAL_REFCNT },
&NoDefault_Type
};
#elif PY312_PLUS
#if PY312_PLUS
PyObject _NoDefault_Object = {
_PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
{ MS_IMMORTAL_INITIAL_REFCNT },
&NoDefault_Type
};
#else
Expand Down Expand Up @@ -2263,16 +2263,10 @@ PyTypeObject Unset_Type = {
.tp_basicsize = 0
};

#if PY314_PLUS
PyObject _Unset_Object = {
_PyObject_EXTRA_INIT
{ _Py_IMMORTAL_INITIAL_REFCNT },
&NoDefault_Type
};
#elif PY312_PLUS
#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 f46c882

Please sign in to comment.