]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
PyString_AsString is permissive and accepts unicode strings.
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 22 Nov 2007 02:48:12 +0000 (02:48 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 22 Nov 2007 02:48:12 +0000 (02:48 +0000)
Replace it with PyUnicode_AsString when the argument is known to be a str.

Objects/setobject.c
Objects/stringobject.c
Python/ast.c
Python/getargs.c
Python/peephole.c

index f6ea441785b4147e3108ff7d43756c8b48cb7e53..d85a28d386b5cccba1d735658241757895e6b74a 100644 (file)
@@ -2303,7 +2303,7 @@ test_c_api(PySetObject *so)
        /* Exercise direct iteration */
        i = 0, count = 0;
        while (_PySet_Next((PyObject *)dup, &i, &x)) {
-               s = PyString_AsString(x);
+               s = PyUnicode_AsString(x);
                assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
                count++;
        }
index ae2a977425b8cf01bdf3d29e4802fcc795c20b5c..d341436d12834586227883cb9571afaa2c9e70fd 100644 (file)
@@ -3273,7 +3273,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
        if (!result)
                return NULL;
 
-       buf = PyString_AsString(result);
+       buf = PyUnicode_AsString(result);
        if (!buf) {
                Py_DECREF(result);
                return NULL;
@@ -3284,7 +3284,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
                PyErr_BadInternalCall();
                return NULL;
        }
-       llen = PyString_Size(result);
+       llen = PyUnicode_GetSize(result);
        if (llen > INT_MAX) {
                PyErr_SetString(PyExc_ValueError,
                                "string too large in _PyString_FormatLong");
index 2a5d8b8571129f07c396f5737a67e1d8e5eceb70..f3a282861a2fb3a49bca95848f17c291bde01e8a 100644 (file)
@@ -1299,7 +1299,7 @@ ast_for_atom(struct compiling *c, const node *n)
                 if (errstr) {
                     char *s = "";
                     char buf[128];
-                    s = PyString_AsString(errstr);
+                    s = PyUnicode_AsString(errstr);
                     PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
                     ast_error(n, buf);
                 } else {
index 48860cca639705aa2e1b73b5e9dcf14a9bbc372d..584805e25e601b1d92acbde63c0bb51242f404c4 100644 (file)
@@ -768,7 +768,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
                else if (PyUnicode_Check(arg) &&
                         PyUnicode_GET_SIZE(arg) == 1 &&
                         PyUnicode_AS_UNICODE(arg)[0] < 256)
-                       *p = PyUnicode_AS_UNICODE(arg)[0];
+                       *p = (char)PyUnicode_AS_UNICODE(arg)[0];
                else
                        return converterr("char < 256", arg, msgbuf, bufsize);
                break;
@@ -823,7 +823,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
                        }
                        else
                                return converterr("string", arg, msgbuf, bufsize);
-                       if ((Py_ssize_t)strlen(*p) != PyString_Size(arg))
+                       if ((Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
                                return converterr("string without null bytes",
                                                  arg, msgbuf, bufsize);
                }
@@ -899,7 +899,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
                                format++;
                        }
                        else if (*p != NULL &&
-                                (Py_ssize_t)strlen(*p) != PyString_Size(arg))
+                                (Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
                                return converterr(
                                        "string without null bytes or None",
                                        arg, msgbuf, bufsize);
@@ -1596,7 +1596,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
                                                "keywords must be strings");
                                return cleanreturn(0, freelist);
                        }
-                       ks = PyString_AsString(key);
+                       ks = PyUnicode_AsString(key);
                        for (i = 0; i < max; i++) {
                                if (!strcmp(ks, kwlist[i])) {
                                        match = 1;
index d012d391e71a6fb60be71118e442e3b0a3197bb5..9f1e6420e63d8e407da1fd71bc6a540bc1cb05d6 100644 (file)
@@ -407,7 +407,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
                        case LOAD_NAME:
                        case LOAD_GLOBAL:
                                j = GETARG(codestr, i);
-                               name = PyString_AsString(PyTuple_GET_ITEM(names, j));
+                               name = PyUnicode_AsString(PyTuple_GET_ITEM(names, j));
                                h = load_global(codestr, i, name, consts);
                                if (h < 0)
                                        goto exitUnchanged;