summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-04-23 15:24:50 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-04-23 15:24:50 (GMT)
commit7d95e4072169911b228c9e42367afb5f17fd3db0 (patch)
treed07731f1b71b1eb5f653778141ca586069d216b1 /Objects/object.c
parent80d07f825108761af9fe2ac79c1ef50289c07c08 (diff)
downloadcpython-7d95e4072169911b228c9e42367afb5f17fd3db0.zip
cpython-7d95e4072169911b228c9e42367afb5f17fd3db0.tar.gz
cpython-7d95e4072169911b228c9e42367afb5f17fd3db0.tar.bz2
Implement PEP 412: Key-sharing dictionaries (closes #13903)
Patch from Mark Shannon.
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c27
1 files changed, 4 insertions, 23 deletions
diff --git a/Objects/object.c b/Objects/object.c
index c8c1861..20eaf31 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1188,13 +1188,10 @@ _PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name,
if (dict == NULL) {
dictptr = _PyObject_GetDictPtr(obj);
if (dictptr != NULL) {
- dict = *dictptr;
- if (dict == NULL && value != NULL) {
- dict = PyDict_New();
- if (dict == NULL)
- goto done;
- *dictptr = dict;
- }
+ res = _PyObjectDict_SetItem(Py_TYPE(obj), dictptr, name, value);
+ if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError))
+ PyErr_SetObject(PyExc_AttributeError, name);
+ goto done;
}
}
if (dict != NULL) {
@@ -1236,22 +1233,6 @@ PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value)
return _PyObject_GenericSetAttrWithDict(obj, name, value, NULL);
}
-PyObject *
-PyObject_GenericGetDict(PyObject *obj, void *context)
-{
- PyObject *dict, **dictptr = _PyObject_GetDictPtr(obj);
- if (dictptr == NULL) {
- PyErr_SetString(PyExc_AttributeError,
- "This object has no __dict__");
- return NULL;
- }
- dict = *dictptr;
- if (dict == NULL)
- *dictptr = dict = PyDict_New();
- Py_XINCREF(dict);
- return dict;
-}
-
int
PyObject_GenericSetDict(PyObject *obj, PyObject *value, void *context)
{