summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-02-20 01:02:57 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-02-20 01:02:57 (GMT)
commit23d7f12ffb8983fa670ef289a03c3d55153f37ce (patch)
tree23eafcf933a4f63c8092e5ad9171000168ffd169 /Objects
parent8eb1269c346fa860acce9459c0bed065ffccd3ce (diff)
downloadcpython-23d7f12ffb8983fa670ef289a03c3d55153f37ce.zip
cpython-23d7f12ffb8983fa670ef289a03c3d55153f37ce.tar.gz
cpython-23d7f12ffb8983fa670ef289a03c3d55153f37ce.tar.bz2
use new generic __dict__ descriptor implementations
Diffstat (limited to 'Objects')
-rw-r--r--Objects/exceptions.c32
-rw-r--r--Objects/funcobject.c62
2 files changed, 4 insertions, 90 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index e770529..e9522e8 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -177,36 +177,6 @@ static PyMethodDef BaseException_methods[] = {
{NULL, NULL, 0, NULL},
};
-
-static PyObject *
-BaseException_get_dict(PyBaseExceptionObject *self)
-{
- if (self->dict == NULL) {
- self->dict = PyDict_New();
- if (!self->dict)
- return NULL;
- }
- Py_INCREF(self->dict);
- return self->dict;
-}
-
-static int
-BaseException_set_dict(PyBaseExceptionObject *self, PyObject *val)
-{
- if (val == NULL) {
- PyErr_SetString(PyExc_TypeError, "__dict__ may not be deleted");
- return -1;
- }
- if (!PyDict_Check(val)) {
- PyErr_SetString(PyExc_TypeError, "__dict__ must be a dictionary");
- return -1;
- }
- Py_CLEAR(self->dict);
- Py_INCREF(val);
- self->dict = val;
- return 0;
-}
-
static PyObject *
BaseException_get_args(PyBaseExceptionObject *self)
{
@@ -320,7 +290,7 @@ BaseException_set_cause(PyObject *self, PyObject *arg) {
static PyGetSetDef BaseException_getset[] = {
- {"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict},
+ {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
{"args", (getter)BaseException_get_args, (setter)BaseException_set_args},
{"__traceback__", (getter)BaseException_get_tb, (setter)BaseException_set_tb},
{"__context__", (getter)BaseException_get_context,
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 6dd91b8..49415b9 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -245,42 +245,6 @@ static PyMemberDef func_memberlist[] = {
};
static PyObject *
-func_get_dict(PyFunctionObject *op)
-{
- if (op->func_dict == NULL) {
- op->func_dict = PyDict_New();
- if (op->func_dict == NULL)
- return NULL;
- }
- Py_INCREF(op->func_dict);
- return op->func_dict;
-}
-
-static int
-func_set_dict(PyFunctionObject *op, PyObject *value)
-{
- PyObject *tmp;
-
- /* It is illegal to del f.func_dict */
- if (value == NULL) {
- PyErr_SetString(PyExc_TypeError,
- "function's dictionary may not be deleted");
- return -1;
- }
- /* Can only set func_dict to a dictionary */
- if (!PyDict_Check(value)) {
- PyErr_SetString(PyExc_TypeError,
- "setting function's dictionary to a non-dict");
- return -1;
- }
- tmp = op->func_dict;
- Py_INCREF(value);
- op->func_dict = value;
- Py_XDECREF(tmp);
- return 0;
-}
-
-static PyObject *
func_get_code(PyFunctionObject *op)
{
Py_INCREF(op->func_code);
@@ -476,7 +440,7 @@ static PyGetSetDef func_getsetlist[] = {
(setter)func_set_kwdefaults},
{"__annotations__", (getter)func_get_annotations,
(setter)func_set_annotations},
- {"__dict__", (getter)func_get_dict, (setter)func_set_dict},
+ {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
{"__name__", (getter)func_get_name, (setter)func_set_name},
{"__qualname__", (getter)func_get_qualname, (setter)func_set_qualname},
{NULL} /* Sentinel */
@@ -831,22 +795,12 @@ cm_get___isabstractmethod__(classmethod *cm, void *closure)
Py_RETURN_FALSE;
}
-static PyObject *
-cm_get___dict__(PyObject *cm, void *closure)
-{
- PyObject **dictptr = _PyObject_GetDictPtr(cm);
- if (*dictptr == NULL)
- *dictptr = PyDict_New();
- Py_XINCREF(*dictptr);
- return *dictptr;
-}
-
static PyGetSetDef cm_getsetlist[] = {
{"__isabstractmethod__",
(getter)cm_get___isabstractmethod__, NULL,
NULL,
NULL},
- {"__dict__", (getter)cm_get___dict__, NULL, NULL, NULL},
+ {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict, NULL, NULL},
{NULL} /* Sentinel */
};
@@ -1020,22 +974,12 @@ sm_get___isabstractmethod__(staticmethod *sm, void *closure)
Py_RETURN_FALSE;
}
-static PyObject *
-sm_get___dict__(PyObject *sm, void *closure)
-{
- PyObject **dictptr = _PyObject_GetDictPtr(sm);
- if (*dictptr == NULL)
- *dictptr = PyDict_New();
- Py_XINCREF(*dictptr);
- return *dictptr;
-}
-
static PyGetSetDef sm_getsetlist[] = {
{"__isabstractmethod__",
(getter)sm_get___isabstractmethod__, NULL,
NULL,
NULL},
- {"__dict__", (getter)sm_get___dict__, NULL, NULL, NULL},
+ {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict, NULL, NULL},
{NULL} /* Sentinel */
};