Skip to content

Commit ce6b210

Browse files
committed
pythongh-106320: Make some PyDict C-API functions public that should have been public right away.
See python#108449
1 parent 9bb202a commit ce6b210

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Include/cpython/dictobject.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
4545
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
4646

4747
PyAPI_FUNC(int) PyDict_ContainsString(PyObject *mp, const char *key);
48-
48+
PyAPI_FUNC(PyObject *) PyDict_NewPresized(Py_ssize_t minused);
49+
PyAPI_FUNC(PyObject *) PyDict_Pop(PyObject *dict, PyObject *key, PyObject *default_value);
4950

5051
/* Dictionary watchers */
5152

Include/internal/pycore_dict.h

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ extern int _PyDict_HasOnlyStringKeys(PyObject *mp);
4444

4545
extern void _PyDict_MaybeUntrack(PyObject *mp);
4646

47-
extern PyObject* _PyDict_NewPresized(Py_ssize_t minused);
48-
4947
// Export for '_ctypes' shared extension
5048
PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
5149

Objects/dictobject.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ dict_new_presized(PyInterpreterState *interp, Py_ssize_t minused, bool unicode)
16081608
}
16091609

16101610
PyObject *
1611-
_PyDict_NewPresized(Py_ssize_t minused)
1611+
PyDict_NewPresized(Py_ssize_t minused)
16121612
{
16131613
PyInterpreterState *interp = _PyInterpreterState_GET();
16141614
return dict_new_presized(interp, minused, false);
@@ -2272,6 +2272,16 @@ _PyDict_Pop(PyObject *dict, PyObject *key, PyObject *deflt)
22722272
return _PyDict_Pop_KnownHash(dict, key, hash, deflt);
22732273
}
22742274

2275+
PyObject *
2276+
PyDict_Pop(PyObject *dict, PyObject *key, PyObject *deflt)
2277+
{
2278+
if (!PyDict_Check(dict)) {
2279+
PyErr_BadInternalCall();
2280+
return -1;
2281+
}
2282+
return _PyDict_Pop(dict, key, deflt);
2283+
}
2284+
22752285
/* Internal version of dict.from_keys(). It is subclass-friendly. */
22762286
PyObject *
22772287
_PyDict_FromKeys(PyObject *cls, PyObject *iterable, PyObject *value)

0 commit comments

Comments
 (0)