Mercurial > cpython-lru_cache-weakref
diff Objects/stringlib/string_format.h @ 42922:b110bac9df40
Cleanup in anticipation of moving formatteriterator and fieldnameiterator into stringlib/string_format.h.
| author | Eric Smith <eric@trueblade.com> |
|---|---|
| date | Mon, 27 Aug 2007 23:30:47 +0000 |
| parents | 6b4781dc81ff |
| children | fd1fcba5e16b |
line wrap: on
line diff
--- a/Objects/stringlib/string_format.h Mon Aug 27 23:26:56 2007 +0000 +++ b/Objects/stringlib/string_format.h Mon Aug 27 23:30:47 2007 +0000 @@ -55,24 +55,6 @@ } /************************************************************************/ -/*********** Error handling and exception generation **************/ -/************************************************************************/ - -/* - Most of our errors are value errors, because to Python, the - format string is a "value". Also, it's convenient to return - a NULL when we are erroring out. - - XXX: need better error handling, per PEP 3101. -*/ -static void * -SetError(const char *s) -{ - /* PyErr_Format always returns NULL */ - return PyErr_Format(PyExc_ValueError, "%s in format string", s); -} - -/************************************************************************/ /*********** Output string management functions ****************/ /************************************************************************/ @@ -187,7 +169,7 @@ getattr(PyObject *obj, SubString *name) { PyObject *newobj; - PyObject *str = STRINGLIB_NEW(name->ptr, name->end - name->ptr); + PyObject *str = SubString_new_object(name); if (str == NULL) return NULL; newobj = PyObject_GetAttr(obj, str); @@ -220,7 +202,7 @@ getitem_str(PyObject *obj, SubString *name) { PyObject *newobj; - PyObject *str = STRINGLIB_NEW(name->ptr, name->end - name->ptr); + PyObject *str = SubString_new_object(name); if (str == NULL) return NULL; newobj = PyObject_GetItem(obj, str); @@ -407,7 +389,7 @@ if (index == -1) { /* look up in kwargs */ - PyObject *key = STRINGLIB_NEW(first.ptr, first.end - first.ptr); + PyObject *key = SubString_new_object(&first); if (key == NULL) goto error; if ((kwargs == NULL) || (obj = PyDict_GetItem(kwargs, key)) == NULL) { @@ -719,11 +701,13 @@ len = self->str.ptr - start; if ((c == '}') && (at_end || (c != *self->str.ptr))) { - SetError("Single } encountered"); + PyErr_SetString(PyExc_ValueError, "Single '}' encountered " + "in format string"); return 0; } if (at_end && c == '{') { - SetError("Single { encountered"); + PyErr_SetString(PyExc_ValueError, "Single '{' encountered " + "in format string"); return 0; } if (!at_end) {
