Mercurial > vim
changeset 4995:b4a2eaf28b51 v7.3.1242
updated for version 7.3.1242
Problem: No failure when trying to use a number as a string.
Solution: Give an error when StringToLine() is called with an instance of
the wrong type. (Jun Takimoto)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 24 Jun 2013 22:33:30 +0200 |
parents | 879ebefc462c |
children | 5759342cde79 |
files | src/if_py_both.h src/version.c |
diffstat | 2 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -3549,13 +3549,26 @@ StringToLine(PyObject *obj) if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) return NULL; - if(PyBytes_AsStringAndSize(bytes, &str, &len) == -1 + if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1 || str == NULL) { Py_DECREF(bytes); return NULL; } } + else + { +#if PY_MAJOR_VERSION < 3 + PyErr_FORMAT(PyExc_TypeError, + N_("expected str() or unicode() instance, but got %s"), + Py_TYPE_NAME(obj)); +#else + PyErr_FORMAT(PyExc_TypeError, + N_("expected bytes() or str() instance, but got %s"), + Py_TYPE_NAME(obj)); +#endif + return NULL; + } /* * Error checking: String must not contain newlines, as we