summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2003-02-04 20:24:45 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2003-02-04 20:24:45 (GMT)
commitc3da83fcd7e25ffb1ed15f5adad4efa1c03ebc03 (patch)
treeabf6639ce3bd8515011ff2bbeadc45f8a07caa73 /Python/bltinmodule.c
parent29273c87da0ef361f84fee41385f7c991536f9cd (diff)
downloadcpython-c3da83fcd7e25ffb1ed15f5adad4efa1c03ebc03.zip
cpython-c3da83fcd7e25ffb1ed15f5adad4efa1c03ebc03.tar.gz
cpython-c3da83fcd7e25ffb1ed15f5adad4efa1c03ebc03.tar.bz2
Make sure filter() never returns tuple, str or unicode
subclasses. (Discussed in SF patch #665835)
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 2383b4f..b74e09c 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1838,7 +1838,10 @@ filtertuple(PyObject *func, PyObject *tuple)
int len = PyTuple_Size(tuple);
if (len == 0) {
- Py_INCREF(tuple);
+ if (PyTuple_CheckExact(tuple))
+ Py_INCREF(tuple);
+ else
+ tuple = PyTuple_New(0);
return tuple;
}
@@ -1895,8 +1898,15 @@ filterstring(PyObject *func, PyObject *strobj)
int outlen = len;
if (func == Py_None) {
- /* No character is ever false -- share input string */
- Py_INCREF(strobj);
+ /* No character is ever false -- share input string
+ * (if it's not a subclass) */
+ if (PyString_CheckExact(strobj))
+ Py_INCREF(strobj);
+ else
+ strobj = PyString_FromStringAndSize(
+ PyString_AS_STRING(strobj),
+ len
+ );
return strobj;
}
if ((result = PyString_FromStringAndSize(NULL, len)) == NULL)
@@ -1980,8 +1990,15 @@ filterunicode(PyObject *func, PyObject *strobj)
int outlen = len;
if (func == Py_None) {
- /* No character is ever false -- share input string */
- Py_INCREF(strobj);
+ /* No character is ever false -- share input string
+ * (it if's not a subclass) */
+ if (PyUnicode_CheckExact(strobj))
+ Py_INCREF(strobj);
+ else
+ strobj = PyUnicode_FromUnicode(
+ PyUnicode_AS_UNICODE(strobj),
+ len
+ );
return strobj;
}
if ((result = PyUnicode_FromUnicode(NULL, len)) == NULL)