Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described
here (it's not a Py3K issue, just something Py3K discovers):
http://mail.python.org/pipermail/python-dev/2006-April/064051.html
Hye-Shik Chang promised to look for a fix, so no need to fix it here. The
tests that are expected to break are:
test_codecencodings_cn
test_codecencodings_hk
test_codecencodings_jp
test_codecencodings_kr
test_codecencodings_tw
test_codecs
test_multibytecodec
This merge fixes an actual test failure (test_weakref) in this branch,
though, so I believe merging is the right thing to do anyway.
diff --git a/Objects/abstract.c b/Objects/abstract.c
index c755654..13a9473 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -10,6 +10,7 @@
#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
+
/* Shorthands to return certain errors */
static PyObject *
@@ -940,8 +941,9 @@
value = nb->nb_index(item);
}
else {
- PyErr_SetString(PyExc_IndexError,
- "object cannot be interpreted as an index");
+ PyErr_Format(PyExc_TypeError,
+ "'%.200s' object cannot be interpreted "
+ "as an index", item->ob_type->tp_name);
}
return value;
}
@@ -1245,24 +1247,6 @@
return type_error("unindexable object");
}
-static PyObject *
-sliceobj_from_intint(Py_ssize_t i, Py_ssize_t j)
-{
- PyObject *start, *end, *slice;
- start = PyInt_FromLong((long)i);
- if (!start)
- return NULL;
- end = PyInt_FromLong((long)j);
- if (!end) {
- Py_DECREF(start);
- return NULL;
- }
- slice = PySlice_New(start, end, NULL);
- Py_DECREF(start);
- Py_DECREF(end);
- return slice;
-}
-
PyObject *
PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
{
@@ -1287,7 +1271,7 @@
return m->sq_slice(s, i1, i2);
} else if ((mp = s->ob_type->tp_as_mapping) && mp->mp_subscript) {
PyObject *res;
- PyObject *slice = sliceobj_from_intint(i1, i2);
+ PyObject *slice = _PySlice_FromIndices(i1, i2);
if (!slice)
return NULL;
res = mp->mp_subscript(s, slice);
@@ -1379,7 +1363,7 @@
return m->sq_ass_slice(s, i1, i2, o);
} else if ((mp = s->ob_type->tp_as_mapping) && mp->mp_ass_subscript) {
int res;
- PyObject *slice = sliceobj_from_intint(i1, i2);
+ PyObject *slice = _PySlice_FromIndices(i1, i2);
if (!slice)
return -1;
res = mp->mp_ass_subscript(s, slice, o);
@@ -1815,11 +1799,37 @@
return NULL;
}
+static PyObject*
+call_function_tail(PyObject *callable, PyObject *args)
+{
+ PyObject *retval;
+
+ if (args == NULL)
+ return NULL;
+
+ if (!PyTuple_Check(args)) {
+ PyObject *a;
+
+ a = PyTuple_New(1);
+ if (a == NULL) {
+ Py_DECREF(args);
+ return NULL;
+ }
+ PyTuple_SET_ITEM(a, 0, args);
+ args = a;
+ }
+ retval = PyObject_Call(callable, args, NULL);
+
+ Py_DECREF(args);
+
+ return retval;
+}
+
PyObject *
PyObject_CallFunction(PyObject *callable, char *format, ...)
{
va_list va;
- PyObject *args, *retval;
+ PyObject *args;
if (callable == NULL)
return null_error();
@@ -1832,31 +1842,34 @@
else
args = PyTuple_New(0);
- if (args == NULL)
- return NULL;
+ return call_function_tail(callable, args);
+}
- if (!PyTuple_Check(args)) {
- PyObject *a;
+PyObject *
+_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...)
+{
+ va_list va;
+ PyObject *args;
- a = PyTuple_New(1);
- if (a == NULL)
- return NULL;
- if (PyTuple_SetItem(a, 0, args) < 0)
- return NULL;
- args = a;
+ if (callable == NULL)
+ return null_error();
+
+ if (format && *format) {
+ va_start(va, format);
+ args = _Py_VaBuildValue_SizeT(format, va);
+ va_end(va);
}
- retval = PyObject_Call(callable, args, NULL);
+ else
+ args = PyTuple_New(0);
- Py_DECREF(args);
-
- return retval;
+ return call_function_tail(callable, args);
}
PyObject *
PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
{
va_list va;
- PyObject *args = NULL;
+ PyObject *args;
PyObject *func = NULL;
PyObject *retval = NULL;
@@ -1882,24 +1895,49 @@
else
args = PyTuple_New(0);
- if (!args)
- goto exit;
-
- if (!PyTuple_Check(args)) {
- PyObject *a;
-
- a = PyTuple_New(1);
- if (a == NULL)
- goto exit;
- if (PyTuple_SetItem(a, 0, args) < 0)
- goto exit;
- args = a;
- }
-
- retval = PyObject_Call(func, args, NULL);
+ retval = call_function_tail(func, args);
exit:
- Py_XDECREF(args);
+ /* args gets consumed in call_function_tail */
+ Py_XDECREF(func);
+
+ return retval;
+}
+
+PyObject *
+_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...)
+{
+ va_list va;
+ PyObject *args;
+ PyObject *func = NULL;
+ PyObject *retval = NULL;
+
+ if (o == NULL || name == NULL)
+ return null_error();
+
+ func = PyObject_GetAttrString(o, name);
+ if (func == NULL) {
+ PyErr_SetString(PyExc_AttributeError, name);
+ return 0;
+ }
+
+ if (!PyCallable_Check(func)) {
+ type_error("call of non-callable attribute");
+ goto exit;
+ }
+
+ if (format && *format) {
+ va_start(va, format);
+ args = _Py_VaBuildValue_SizeT(format, va);
+ va_end(va);
+ }
+ else
+ args = PyTuple_New(0);
+
+ retval = call_function_tail(func, args);
+
+ exit:
+ /* args gets consumed in call_function_tail */
Py_XDECREF(func);
return retval;