Skip to content

Commit

Permalink
Issue python#19512: Add a new _PyDict_DelItemId() function, similar to
Browse files Browse the repository at this point in the history
PyDict_DelItemString() but using an identifier for the key
  • Loading branch information
vstinner committed Nov 6, 2013
1 parent 7a07e45 commit 5fd2e5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Include/dictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *ke
PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);
PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);

#ifndef Py_LIMITED_API
int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
Expand Down
9 changes: 9 additions & 0 deletions Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2735,6 +2735,15 @@ PyDict_SetItemString(PyObject *v, const char *key, PyObject *item)
return err;
}

int
_PyDict_DelItemId(PyObject *v, _Py_Identifier *key)
{
PyObject *kv = _PyUnicode_FromId(key); /* borrowed */
if (kv == NULL)
return -1;
return PyDict_DelItem(v, kv);
}

int
PyDict_DelItemString(PyObject *v, const char *key)
{
Expand Down

0 comments on commit 5fd2e5a

Please sign in to comment.