summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-06-10 19:20:26 (GMT)
committerGeorg Brandl <georg@python.org>2008-06-10 19:20:26 (GMT)
commitc28e1fa71f61278256887d257e4e7e24b0e7e7ce (patch)
tree5cea84b5d34c9a4ed7a84ca0ae990a24c102a465 /Objects
parente932c5c81322637a2cb8bfbcf42af7bd3a8f3418 (diff)
downloadcpython-c28e1fa71f61278256887d257e4e7e24b0e7e7ce.zip
cpython-c28e1fa71f61278256887d257e4e7e24b0e7e7ce.tar.gz
cpython-c28e1fa71f61278256887d257e4e7e24b0e7e7ce.tar.bz2
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line Add long double check support to configure test. ........ r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line Remove locking part of new buffer protocol. ........ r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines Finished bug #2451. Fixed the retrying part to make it more robust. ........ r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines #3028: tokenize passes the physical line. ........ r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines Argh, I read it wrong. Reverted 64036 and added a clarifying remark. ........ r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line Issue3065: Fixed pickling of named tuples. Added tests. ........ r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line Issue #2138: Add math.factorial(). ........ r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line Let set.union() and set.update() accept multiple inputs. ........ r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line Address double-rounding scenarios by setting all variables to long doubles. ........ r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds. ........ r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line Let set.intersection() and set.intersection_update() take multiple input arguments. ........ r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines Issue 3048: Fixed sys.getsizeof for unicode objects. ........ r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines NEWS entry for: Add an optional 'offset' parameter to byref, defaulting to zero. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/setobject.c92
-rw-r--r--Objects/unicodeobject.c23
2 files changed, 97 insertions, 18 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index f760b6a..4456ef4 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -959,15 +959,20 @@ set_update_internal(PySetObject *so, PyObject *other)
}
static PyObject *
-set_update(PySetObject *so, PyObject *other)
+set_update(PySetObject *so, PyObject *args)
{
- if (set_update_internal(so, other) == -1)
- return NULL;
+ Py_ssize_t i;
+
+ for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
+ PyObject *other = PyTuple_GET_ITEM(args, i);
+ if (set_update_internal(so, other) == -1)
+ return NULL;
+ }
Py_RETURN_NONE;
}
PyDoc_STRVAR(update_doc,
-"Update a set with the union of itself and another.");
+"Update a set with the union of itself and others.");
static PyObject *
make_new_set(PyTypeObject *type, PyObject *iterable)
@@ -1148,35 +1153,53 @@ set_clear(PySetObject *so)
PyDoc_STRVAR(clear_doc, "Remove all elements from this set.");
static PyObject *
-set_union(PySetObject *so, PyObject *other)
+set_union(PySetObject *so, PyObject *args)
{
PySetObject *result;
+ PyObject *other;
+ Py_ssize_t i;
result = (PySetObject *)set_copy(so);
if (result == NULL)
return NULL;
- if ((PyObject *)so == other)
- return (PyObject *)result;
- if (set_update_internal(result, other) == -1) {
- Py_DECREF(result);
- return NULL;
+
+ for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
+ other = PyTuple_GET_ITEM(args, i);
+ if ((PyObject *)so == other)
+ return (PyObject *)result;
+ if (set_update_internal(result, other) == -1) {
+ Py_DECREF(result);
+ return NULL;
+ }
}
return (PyObject *)result;
}
PyDoc_STRVAR(union_doc,
- "Return the union of two sets as a new set.\n\
+ "Return the union of sets as a new set.\n\
\n\
(i.e. all elements that are in either set.)");
static PyObject *
set_or(PySetObject *so, PyObject *other)
{
+ PySetObject *result;
+
if (!PyAnySet_Check(so) || !PyAnySet_Check(other)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
- return set_union(so, other);
+
+ result = (PySetObject *)set_copy(so);
+ if (result == NULL)
+ return NULL;
+ if ((PyObject *)so == other)
+ return (PyObject *)result;
+ if (set_update_internal(result, other) == -1) {
+ Py_DECREF(result);
+ return NULL;
+ }
+ return (PyObject *)result;
}
static PyObject *
@@ -1275,6 +1298,26 @@ set_intersection(PySetObject *so, PyObject *other)
return (PyObject *)result;
}
+static PyObject *
+set_intersection_multi(PySetObject *so, PyObject *args)
+{
+ Py_ssize_t i;
+ PyObject *result = (PyObject *)so;
+
+ Py_INCREF(so);
+ for (i=0 ; i<PyTuple_GET_SIZE(args) ; i++) {
+ PyObject *other = PyTuple_GET_ITEM(args, i);
+ PyObject *newresult = set_intersection((PySetObject *)result, other);
+ if (newresult == NULL) {
+ Py_DECREF(result);
+ return NULL;
+ }
+ Py_DECREF(result);
+ result = newresult;
+ }
+ return result;
+}
+
PyDoc_STRVAR(intersection_doc,
"Return the intersection of two sets as a new set.\n\
\n\
@@ -1293,6 +1336,19 @@ set_intersection_update(PySetObject *so, PyObject *other)
Py_RETURN_NONE;
}
+static PyObject *
+set_intersection_update_multi(PySetObject *so, PyObject *args)
+{
+ PyObject *tmp;
+
+ tmp = set_intersection_multi(so, args);
+ if (tmp == NULL)
+ return NULL;
+ set_swap_bodies(so, (PySetObject *)tmp);
+ Py_DECREF(tmp);
+ Py_RETURN_NONE;
+}
+
PyDoc_STRVAR(intersection_update_doc,
"Update a set with the intersection of itself and another.");
@@ -1911,9 +1967,9 @@ static PyMethodDef set_methods[] = {
difference_doc},
{"difference_update", (PyCFunction)set_difference_update, METH_O,
difference_update_doc},
- {"intersection",(PyCFunction)set_intersection, METH_O,
+ {"intersection",(PyCFunction)set_intersection_multi, METH_VARARGS,
intersection_doc},
- {"intersection_update",(PyCFunction)set_intersection_update, METH_O,
+ {"intersection_update",(PyCFunction)set_intersection_update_multi, METH_VARARGS,
intersection_update_doc},
{"isdisjoint", (PyCFunction)set_isdisjoint, METH_O,
isdisjoint_doc},
@@ -1935,9 +1991,9 @@ static PyMethodDef set_methods[] = {
{"test_c_api", (PyCFunction)test_c_api, METH_NOARGS,
test_c_api_doc},
#endif
- {"union", (PyCFunction)set_union, METH_O,
+ {"union", (PyCFunction)set_union, METH_VARARGS,
union_doc},
- {"update", (PyCFunction)set_update, METH_O,
+ {"update", (PyCFunction)set_update, METH_VARARGS,
update_doc},
{NULL, NULL} /* sentinel */
};
@@ -2036,7 +2092,7 @@ static PyMethodDef frozenset_methods[] = {
copy_doc},
{"difference", (PyCFunction)set_difference, METH_O,
difference_doc},
- {"intersection",(PyCFunction)set_intersection, METH_O,
+ {"intersection",(PyCFunction)set_intersection_multi, METH_VARARGS,
intersection_doc},
{"isdisjoint", (PyCFunction)set_isdisjoint, METH_O,
isdisjoint_doc},
@@ -2048,7 +2104,7 @@ static PyMethodDef frozenset_methods[] = {
reduce_doc},
{"symmetric_difference",(PyCFunction)set_symmetric_difference, METH_O,
symmetric_difference_doc},
- {"union", (PyCFunction)set_union, METH_O,
+ {"union", (PyCFunction)set_union, METH_VARARGS,
union_doc},
{NULL, NULL} /* sentinel */
};
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 5cd9eb9..db907d6 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8301,6 +8301,28 @@ PyDoc_STRVAR(p_format__doc__,
");
static PyObject *
+unicode__sizeof__(PyUnicodeObject *v)
+{
+ PyObject *res = NULL, *defsize = NULL;
+
+ res = PyLong_FromSsize_t(sizeof(PyUnicodeObject) +
+ sizeof(Py_UNICODE) * (v->length + 1));
+ if (v->defenc) {
+ defsize = PyObject_CallMethod(v->defenc, "__sizeof__", NULL);
+ if (defsize == NULL) {
+ Py_DECREF(res);
+ return NULL;
+ }
+ res = PyNumber_Add(res, defsize);
+ Py_DECREF(defsize);
+ }
+ return res;
+}
+
+PyDoc_STRVAR(sizeof__doc__,
+"S.__sizeof__() -> size of S in memory, in bytes");
+
+static PyObject *
unicode_getnewargs(PyUnicodeObject *v)
{
return Py_BuildValue("(u#)", v->str, v->length);
@@ -8357,6 +8379,7 @@ static PyMethodDef unicode_methods[] = {
{"_formatter_parser", (PyCFunction) formatter_parser, METH_NOARGS},
{"maketrans", (PyCFunction) unicode_maketrans,
METH_VARARGS | METH_STATIC, maketrans__doc__},
+ {"__sizeof__", (PyCFunction) unicode__sizeof__, METH_NOARGS, sizeof__doc__},
#if 0
{"capwords", (PyCFunction) unicode_capwords, METH_NOARGS, capwords__doc__},
#endif