mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
PyString_AsString is permissive and accepts unicode strings.
Replace it with PyUnicode_AsString when the argument is known to be a str.
This commit is contained in:
parent
484fcd4521
commit
39599dca9d
5 changed files with 9 additions and 9 deletions
|
@ -2303,7 +2303,7 @@ test_c_api(PySetObject *so)
|
||||||
/* Exercise direct iteration */
|
/* Exercise direct iteration */
|
||||||
i = 0, count = 0;
|
i = 0, count = 0;
|
||||||
while (_PySet_Next((PyObject *)dup, &i, &x)) {
|
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'));
|
assert(s && (s[0] == 'a' || s[0] == 'b' || s[0] == 'c'));
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3273,7 +3273,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
|
||||||
if (!result)
|
if (!result)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
buf = PyString_AsString(result);
|
buf = PyUnicode_AsString(result);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -3284,7 +3284,7 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
llen = PyString_Size(result);
|
llen = PyUnicode_GetSize(result);
|
||||||
if (llen > INT_MAX) {
|
if (llen > INT_MAX) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"string too large in _PyString_FormatLong");
|
"string too large in _PyString_FormatLong");
|
||||||
|
|
|
@ -1299,7 +1299,7 @@ ast_for_atom(struct compiling *c, const node *n)
|
||||||
if (errstr) {
|
if (errstr) {
|
||||||
char *s = "";
|
char *s = "";
|
||||||
char buf[128];
|
char buf[128];
|
||||||
s = PyString_AsString(errstr);
|
s = PyUnicode_AsString(errstr);
|
||||||
PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
|
PyOS_snprintf(buf, sizeof(buf), "(unicode error) %s", s);
|
||||||
ast_error(n, buf);
|
ast_error(n, buf);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -768,7 +768,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
else if (PyUnicode_Check(arg) &&
|
else if (PyUnicode_Check(arg) &&
|
||||||
PyUnicode_GET_SIZE(arg) == 1 &&
|
PyUnicode_GET_SIZE(arg) == 1 &&
|
||||||
PyUnicode_AS_UNICODE(arg)[0] < 256)
|
PyUnicode_AS_UNICODE(arg)[0] < 256)
|
||||||
*p = PyUnicode_AS_UNICODE(arg)[0];
|
*p = (char)PyUnicode_AS_UNICODE(arg)[0];
|
||||||
else
|
else
|
||||||
return converterr("char < 256", arg, msgbuf, bufsize);
|
return converterr("char < 256", arg, msgbuf, bufsize);
|
||||||
break;
|
break;
|
||||||
|
@ -823,7 +823,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return converterr("string", arg, msgbuf, bufsize);
|
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",
|
return converterr("string without null bytes",
|
||||||
arg, msgbuf, bufsize);
|
arg, msgbuf, bufsize);
|
||||||
}
|
}
|
||||||
|
@ -899,7 +899,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
else if (*p != NULL &&
|
else if (*p != NULL &&
|
||||||
(Py_ssize_t)strlen(*p) != PyString_Size(arg))
|
(Py_ssize_t)strlen(*p) != PyUnicode_GetSize(arg))
|
||||||
return converterr(
|
return converterr(
|
||||||
"string without null bytes or None",
|
"string without null bytes or None",
|
||||||
arg, msgbuf, bufsize);
|
arg, msgbuf, bufsize);
|
||||||
|
@ -1596,7 +1596,7 @@ vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
|
||||||
"keywords must be strings");
|
"keywords must be strings");
|
||||||
return cleanreturn(0, freelist);
|
return cleanreturn(0, freelist);
|
||||||
}
|
}
|
||||||
ks = PyString_AsString(key);
|
ks = PyUnicode_AsString(key);
|
||||||
for (i = 0; i < max; i++) {
|
for (i = 0; i < max; i++) {
|
||||||
if (!strcmp(ks, kwlist[i])) {
|
if (!strcmp(ks, kwlist[i])) {
|
||||||
match = 1;
|
match = 1;
|
||||||
|
|
|
@ -407,7 +407,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
|
||||||
case LOAD_NAME:
|
case LOAD_NAME:
|
||||||
case LOAD_GLOBAL:
|
case LOAD_GLOBAL:
|
||||||
j = GETARG(codestr, i);
|
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);
|
h = load_global(codestr, i, name, consts);
|
||||||
if (h < 0)
|
if (h < 0)
|
||||||
goto exitUnchanged;
|
goto exitUnchanged;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue