Skip to content

Commit

Permalink
refactor: use the _PyDictView_New function in Python < 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Sep 23, 2024
1 parent 7f02431 commit a2d9ce8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/pyshim.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ inline int _PyArg_CheckPositional(const char *name, Py_ssize_t nargs, Py_ssize_t
* @see Modified from https://github.com/python/cpython/blob/v3.13.0rc1/Objects/dictobject.c#L5806-L5827
*/
inline PyObject *PyDictViewObject_new(PyObject *dict, PyTypeObject *type) {
#if PY_VERSION_HEX < 0x030d0000 // Python version is lower than 3.13
return _PyDictView_New(dict, type);
#else
_PyDictViewObject *dv;
dv = PyObject_GC_New(_PyDictViewObject, type);
if (dv == NULL)
Expand All @@ -87,6 +90,7 @@ inline PyObject *PyDictViewObject_new(PyObject *dict, PyTypeObject *type) {
dv->dv_dict = (PyDictObject *)dict;
PyObject_GC_Track(dv);
return (PyObject *)dv;
#endif
}

#endif // #ifndef PythonMonkey_py_version_shim_

0 comments on commit a2d9ce8

Please sign in to comment.