From e165727d57afb2059ec807acf5c1b32cb6f0ea9b Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Thu, 22 Nov 2007 21:42:04 +0000 Subject: Just inline a function, and discover that it can only raise an exception. Next step: should PyString_AsStringAndSize accept buffer objects? --- Objects/stringobject.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Objects/stringobject.c b/Objects/stringobject.c index c33332e..fd320f3 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -504,16 +504,6 @@ string_getsize(register PyObject *op) 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 @@ PyString_Size(register PyObject *op) /*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 @@ PyString_AsStringAndSize(register PyObject *obj, 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 @@ PyString_AsStringAndSize(register PyObject *obj, *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; -- cgit v0.12