Skip to content

Commit

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

See #108449
  • Loading branch information
scoder committed Oct 24, 2023
1 parent 9bb202a commit 16a95d4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ Dictionary Objects
.. versionadded:: 3.4
.. c:function:: PyObject* PyDict_Pop(PyObject *p, PyObject *key, PyObject *defaultobj)
This is the same as the Python-level :meth:`dict.pop`. It removes the *key*
from the dictionary *p* and returns its value. If the key is not in the dict,
the value *defaultobj* is returned instead if it is not ``NULL``, or otherwise a
:exc:`KeyError` is raised and ``NULL`` is returned.
.. versionadded:: 3.13
.. c:function:: PyObject* PyDict_Items(PyObject *p)
Return a :c:type:`PyListObject` containing all the items from the dictionary.
Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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_Pop(PyObject *dict, PyObject *key, PyObject *default_value);

/* Dictionary watchers */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a new C-API function PyDict_Pop to replace a previously removed underscore function.
10 changes: 10 additions & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
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;

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (x64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu

returning ‘int’ from a function with return type ‘PyObject *’ {aka ‘struct _object *’} makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (1.1.1w)

returning ‘int’ from a function with return type ‘PyObject *’ {aka ‘struct _object *’} makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (arm64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (arm64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (arm64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Windows (arm64)

'return': 'PyObject *' differs in levels of indirection from 'int' [D:\a\cpython\cpython\PCbuild\pythoncore.vcxproj]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.0.11)

returning ‘int’ from a function with return type ‘PyObject *’ {aka ‘struct _object *’} makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Ubuntu SSL tests with OpenSSL (3.1.3)

returning ‘int’ from a function with return type ‘PyObject *’ {aka ‘struct _object *’} makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer

returning ‘int’ from a function with return type ‘PyObject *’ {aka ‘struct _object *’} makes pointer from integer without a cast [-Wint-conversion]

Check warning on line 2280 in Objects/dictobject.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

returning ‘int’ from a function with return type ‘PyObject *’ {aka ‘struct _object *’} makes pointer from integer without a cast [-Wint-conversion]
}
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 16a95d4

Please sign in to comment.