Skip to content

Commit

Permalink
pythongh-106320: Make some PyDict C-API functions public that should …
Browse files Browse the repository at this point in the history
…have been public right away.

See python#108449
  • Loading branch information
scoder committed Oct 24, 2023
1 parent 9bb202a commit ce6b210
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Include/cpython/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))

PyAPI_FUNC(int) PyDict_ContainsString(PyObject *mp, const char *key);

PyAPI_FUNC(PyObject *) PyDict_NewPresized(Py_ssize_t minused);
PyAPI_FUNC(PyObject *) PyDict_Pop(PyObject *dict, PyObject *key, PyObject *default_value);

/* Dictionary watchers */

Expand Down
2 changes: 0 additions & 2 deletions Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ extern int _PyDict_HasOnlyStringKeys(PyObject *mp);

extern void _PyDict_MaybeUntrack(PyObject *mp);

extern PyObject* _PyDict_NewPresized(Py_ssize_t minused);

// Export for '_ctypes' shared extension
PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);

Expand Down
12 changes: 11 additions & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ dict_new_presized(PyInterpreterState *interp, Py_ssize_t minused, bool unicode)
}

PyObject *
_PyDict_NewPresized(Py_ssize_t minused)
PyDict_NewPresized(Py_ssize_t minused)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
return dict_new_presized(interp, minused, false);
Expand Down Expand Up @@ -2272,6 +2272,16 @@ _PyDict_Pop(PyObject *dict, PyObject *key, PyObject *deflt)
return _PyDict_Pop_KnownHash(dict, key, hash, deflt);
}

PyObject *
PyDict_Pop(PyObject *dict, PyObject *key, PyObject *deflt)
{
if (!PyDict_Check(dict)) {
PyErr_BadInternalCall();
return -1;
}
return _PyDict_Pop(dict, key, deflt);
}

/* Internal version of dict.from_keys(). It is subclass-friendly. */
PyObject *
_PyDict_FromKeys(PyObject *cls, PyObject *iterable, PyObject *value)
Expand Down

0 comments on commit ce6b210

Please sign in to comment.