[Python-3000-checkins] r59125 - python/branches/py3k/Objects/stringobject.c
amaury.forgeotdarc
python-3000-checkins at python.org
Thu Nov 22 22:42:04 CET 2007
Author: amaury.forgeotdarc
Date: Thu Nov 22 22:42:04 2007
New Revision: 59125
Modified:
python/branches/py3k/Objects/stringobject.c
Log:
Just inline a function, and discover that it can only raise an exception.
Next step: should PyString_AsStringAndSize accept buffer objects?
Modified: python/branches/py3k/Objects/stringobject.c
==============================================================================
--- python/branches/py3k/Objects/stringobject.c (original)
+++ python/branches/py3k/Objects/stringobject.c Thu Nov 22 22:42:04 2007
@@ -504,16 +504,6 @@
return len;
}
-static /*const*/ char *
-string_getbuffer(register PyObject *op)
-{
- char *s;
- Py_ssize_t len;
- if (PyString_AsStringAndSize(op, &s, &len))
- return NULL;
- return s;
-}
-
Py_ssize_t
PyString_Size(register PyObject *op)
{
@@ -525,8 +515,11 @@
/*const*/ char *
PyString_AsString(register PyObject *op)
{
- if (!PyString_Check(op))
- return string_getbuffer(op);
+ if (!PyString_Check(op)) {
+ PyErr_Format(PyExc_TypeError,
+ "expected bytes, %.200s found", Py_Type(op)->tp_name);
+ return NULL;
+ }
return ((PyStringObject *)op) -> ob_sval;
}
@@ -542,7 +535,7 @@
if (!PyString_Check(obj)) {
PyErr_Format(PyExc_TypeError,
- "expected string, %.200s found", Py_Type(obj)->tp_name);
+ "expected bytes, %.200s found", Py_Type(obj)->tp_name);
return -1;
}
@@ -551,7 +544,7 @@
*len = PyString_GET_SIZE(obj);
else if (strlen(*s) != (size_t)PyString_GET_SIZE(obj)) {
PyErr_SetString(PyExc_TypeError,
- "expected string without null bytes");
+ "expected bytes with no null");
return -1;
}
return 0;
More information about the Python-3000-checkins
mailing list