summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
Diffstat (limited to 'Objects')
-rw-r--r--Objects/exceptions.c42
-rw-r--r--Objects/floatobject.c13
-rw-r--r--Objects/intobject.c5
-rw-r--r--Objects/typeobject.c89
4 files changed, 122 insertions, 27 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 1096bace5a..c15c4aded1 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -176,13 +176,6 @@ static PyMethodDef BaseException_methods[] = {
};
-static PyMemberDef BaseException_members[] = {
- {"message", T_OBJECT, offsetof(PyBaseExceptionObject, message), 0,
- PyDoc_STR("exception message")},
- {NULL} /* Sentinel */
-};
-
-
static PyObject *
BaseException_get_dict(PyBaseExceptionObject *self)
{
@@ -238,9 +231,42 @@ BaseException_set_args(PyBaseExceptionObject *self, PyObject *val)
return 0;
}
+static PyObject *
+BaseException_get_message(PyBaseExceptionObject *self)
+{
+ int ret;
+ ret = PyErr_WarnEx(PyExc_DeprecationWarning,
+ "BaseException.message has been deprecated as "
+ "of Python 2.6",
+ 1);
+ if (ret == -1)
+ return NULL;
+
+ Py_INCREF(self->message);
+ return self->message;
+}
+
+static int
+BaseException_set_message(PyBaseExceptionObject *self, PyObject *val)
+{
+ int ret;
+ ret = PyErr_WarnEx(PyExc_DeprecationWarning,
+ "BaseException.message has been deprecated as "
+ "of Python 2.6",
+ 1);
+ if (ret == -1)
+ return -1;
+ Py_INCREF(val);
+ Py_DECREF(self->message);
+ self->message = val;
+ return 0;
+}
+
static PyGetSetDef BaseException_getset[] = {
{"__dict__", (getter)BaseException_get_dict, (setter)BaseException_set_dict},
{"args", (getter)BaseException_get_args, (setter)BaseException_set_args},
+ {"message", (getter)BaseException_get_message,
+ (setter)BaseException_set_message},
{NULL},
};
@@ -276,7 +302,7 @@ static PyTypeObject _PyExc_BaseException = {
0, /* tp_iter */
0, /* tp_iternext */
BaseException_methods, /* tp_methods */
- BaseException_members, /* tp_members */
+ 0, /* tp_members */
BaseException_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index fde2380fc9..b5fb9cfc55 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -675,18 +675,7 @@ float_pow(PyObject *v, PyObject *w, PyObject *z)
/* Sort out special cases here instead of relying on pow() */
if (iw == 0) { /* v**0 is 1, even 0**0 */
- PyFPE_START_PROTECT("pow", return NULL)
- if ((PyObject *)z != Py_None) {
- double iz;
- CONVERT_TO_DOUBLE(z, iz);
- ix = fmod(1.0, iz);
- if (ix != 0 && iz < 0)
- ix += iz;
- }
- else
- ix = 1.0;
- PyFPE_END_PROTECT(ix)
- return PyFloat_FromDouble(ix);
+ return PyFloat_FromDouble(1.0);
}
if (iv == 0.0) { /* 0**w is error if w<0, else 1 */
if (iw < 0.0) {
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 0aae6ac848..7f56acff5d 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -214,11 +214,10 @@ PyInt_AsSsize_t(register PyObject *op)
return -1;
}
- if (nb->nb_long != 0) {
+ if (nb->nb_long != 0)
io = (PyIntObject*) (*nb->nb_long) (op);
- } else {
+ else
io = (PyIntObject*) (*nb->nb_int) (op);
- }
if (io == NULL)
return -1;
if (!PyInt_Check(io)) {
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index f7431961b1..f6ae69bda3 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1360,10 +1360,12 @@ extra_ivars(PyTypeObject *type, PyTypeObject *base)
type->tp_itemsize != base->tp_itemsize;
}
if (type->tp_weaklistoffset && base->tp_weaklistoffset == 0 &&
- type->tp_weaklistoffset + sizeof(PyObject *) == t_size)
+ type->tp_weaklistoffset + sizeof(PyObject *) == t_size &&
+ type->tp_flags & Py_TPFLAGS_HEAPTYPE)
t_size -= sizeof(PyObject *);
if (type->tp_dictoffset && base->tp_dictoffset == 0 &&
- type->tp_dictoffset + sizeof(PyObject *) == t_size)
+ type->tp_dictoffset + sizeof(PyObject *) == t_size &&
+ type->tp_flags & Py_TPFLAGS_HEAPTYPE)
t_size -= sizeof(PyObject *);
return t_size != b_size;
@@ -1389,12 +1391,73 @@ static int object_init(PyObject *, PyObject *, PyObject *);
static int update_slot(PyTypeObject *, PyObject *);
static void fixup_slot_dispatchers(PyTypeObject *);
+/*
+ * Helpers for __dict__ descriptor. We don't want to expose the dicts
+ * inherited from various builtin types. The builtin base usually provides
+ * its own __dict__ descriptor, so we use that when we can.
+ */
+static PyTypeObject *
+get_builtin_base_with_dict(PyTypeObject *type)
+{
+ while (type->tp_base != NULL) {
+ if (type->tp_dictoffset != 0 &&
+ !(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
+ return type;
+ type = type->tp_base;
+ }
+ return NULL;
+}
+
+static PyObject *
+get_dict_descriptor(PyTypeObject *type)
+{
+ static PyObject *dict_str;
+ PyObject *descr;
+
+ if (dict_str == NULL) {
+ dict_str = PyString_InternFromString("__dict__");
+ if (dict_str == NULL)
+ return NULL;
+ }
+ descr = _PyType_Lookup(type, dict_str);
+ if (descr == NULL || !PyDescr_IsData(descr))
+ return NULL;
+
+ return descr;
+}
+
+static void
+raise_dict_descr_error(PyObject *obj)
+{
+ PyErr_Format(PyExc_TypeError,
+ "this __dict__ descriptor does not support "
+ "'%.200s' objects", obj->ob_type->tp_name);
+}
+
static PyObject *
subtype_dict(PyObject *obj, void *context)
{
- PyObject **dictptr = _PyObject_GetDictPtr(obj);
+ PyObject **dictptr;
PyObject *dict;
+ PyTypeObject *base;
+ base = get_builtin_base_with_dict(obj->ob_type);
+ if (base != NULL) {
+ descrgetfunc func;
+ PyObject *descr = get_dict_descriptor(base);
+ if (descr == NULL) {
+ raise_dict_descr_error(obj);
+ return NULL;
+ }
+ func = descr->ob_type->tp_descr_get;
+ if (func == NULL) {
+ raise_dict_descr_error(obj);
+ return NULL;
+ }
+ return func(descr, obj, (PyObject *)(obj->ob_type));
+ }
+
+ dictptr = _PyObject_GetDictPtr(obj);
if (dictptr == NULL) {
PyErr_SetString(PyExc_AttributeError,
"This object has no __dict__");
@@ -1410,9 +1473,27 @@ subtype_dict(PyObject *obj, void *context)
static int
subtype_setdict(PyObject *obj, PyObject *value, void *context)
{
- PyObject **dictptr = _PyObject_GetDictPtr(obj);
+ PyObject **dictptr;
PyObject *dict;
+ PyTypeObject *base;
+
+ base = get_builtin_base_with_dict(obj->ob_type);
+ if (base != NULL) {
+ descrsetfunc func;
+ PyObject *descr = get_dict_descriptor(base);
+ if (descr == NULL) {
+ raise_dict_descr_error(obj);
+ return -1;
+ }
+ func = descr->ob_type->tp_descr_set;
+ if (func == NULL) {
+ raise_dict_descr_error(obj);
+ return -1;
+ }
+ return func(descr, obj, value);
+ }
+ dictptr = _PyObject_GetDictPtr(obj);
if (dictptr == NULL) {
PyErr_SetString(PyExc_AttributeError,
"This object has no __dict__");