diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-04-11 07:48:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-11 07:48:40 (GMT) |
commit | cd8295ff758891f21084a6a5ad3403d35dda38f7 (patch) | |
tree | a77f829dea34198a7f36658c6e22baf4bc0bf5f5 /Python | |
parent | 7ec43a73092d43c6c95e7dd2669f49d54b57966f (diff) | |
download | cpython-cd8295ff758891f21084a6a5ad3403d35dda38f7.zip cpython-cd8295ff758891f21084a6a5ad3403d35dda38f7.tar.gz cpython-cd8295ff758891f21084a6a5ad3403d35dda38f7.tar.bz2 |
bpo-39943: Add the const qualifier to pointers on non-mutable PyUnicode data. (GH-19345)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/_warnings.c | 4 | ||||
-rw-r--r-- | Python/ast.c | 2 | ||||
-rw-r--r-- | Python/codecs.c | 26 | ||||
-rw-r--r-- | Python/formatter_unicode.c | 6 | ||||
-rw-r--r-- | Python/getargs.c | 2 | ||||
-rw-r--r-- | Python/traceback.c | 4 |
6 files changed, 21 insertions, 23 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index fd3ca60..e4dfb73 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -435,7 +435,7 @@ normalize_module(PyObject *filename) { PyObject *module; int kind; - void *data; + const void *data; Py_ssize_t len; len = PyUnicode_GetLength(filename); @@ -519,7 +519,7 @@ show_warning(PyObject *filename, int lineno, PyObject *text, /* Print " source_line\n" */ if (sourceline) { int kind; - void *data; + const void *data; Py_ssize_t i, len; Py_UCS4 ch; PyObject *truncated; diff --git a/Python/ast.c b/Python/ast.c index 0f23f67..1a4a311 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4588,7 +4588,7 @@ decode_unicode_with_escapes(struct compiling *c, const node *n, const char *s, if (*s & 0x80) { /* XXX inefficient */ PyObject *w; int kind; - void *data; + const void *data; Py_ssize_t len, i; w = decode_utf8(c, &s, end); if (w == NULL) { diff --git a/Python/codecs.c b/Python/codecs.c index bbbf774..7b35ded 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -701,8 +701,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc) if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeEncodeError)) { PyObject *res; - int kind; - void *data; + Py_UCS1 *outp; if (PyUnicodeEncodeError_GetStart(exc, &start)) return NULL; if (PyUnicodeEncodeError_GetEnd(exc, &end)) @@ -711,10 +710,10 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc) res = PyUnicode_New(len, '?'); if (res == NULL) return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); + assert(PyUnicode_KIND(res) == PyUnicode_1BYTE_KIND); + outp = PyUnicode_1BYTE_DATA(res); for (i = 0; i < len; ++i) - PyUnicode_WRITE(kind, data, i, '?'); + outp[i] = '?'; assert(_PyUnicode_CheckConsistency(res, 1)); return Py_BuildValue("(Nn)", res, end); } @@ -727,8 +726,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc) } else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeTranslateError)) { PyObject *res; - int kind; - void *data; + Py_UCS2 *outp; if (PyUnicodeTranslateError_GetStart(exc, &start)) return NULL; if (PyUnicodeTranslateError_GetEnd(exc, &end)) @@ -737,10 +735,10 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc) res = PyUnicode_New(len, Py_UNICODE_REPLACEMENT_CHARACTER); if (res == NULL) return NULL; - kind = PyUnicode_KIND(res); - data = PyUnicode_DATA(res); - for (i=0; i < len; i++) - PyUnicode_WRITE(kind, data, i, Py_UNICODE_REPLACEMENT_CHARACTER); + assert(PyUnicode_KIND(res) == PyUnicode_2BYTE_KIND); + outp = PyUnicode_2BYTE_DATA(res); + for (i = 0; i < len; i++) + outp[i] = Py_UNICODE_REPLACEMENT_CHARACTER; assert(_PyUnicode_CheckConsistency(res, 1)); return Py_BuildValue("(Nn)", res, end); } @@ -759,7 +757,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc) Py_ssize_t start; Py_ssize_t end; PyObject *res; - unsigned char *outp; + Py_UCS1 *outp; Py_ssize_t ressize; Py_UCS4 ch; if (PyUnicodeEncodeError_GetStart(exc, &start)) @@ -855,7 +853,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc) Py_ssize_t start; Py_ssize_t end; PyObject *res; - unsigned char *outp; + Py_UCS1 *outp; int ressize; Py_UCS4 c; @@ -966,7 +964,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc) Py_ssize_t start; Py_ssize_t end; PyObject *res; - unsigned char *outp; + Py_UCS1 *outp; Py_ssize_t ressize; int replsize; Py_UCS4 c; diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c index 841b25a..74638ca 100644 --- a/Python/formatter_unicode.c +++ b/Python/formatter_unicode.c @@ -62,7 +62,7 @@ get_integer(PyObject *str, Py_ssize_t *ppos, Py_ssize_t end, Py_ssize_t accumulator, digitval, pos = *ppos; int numdigits; int kind = PyUnicode_KIND(str); - void *data = PyUnicode_DATA(str); + const void *data = PyUnicode_DATA(str); accumulator = numdigits = 0; for (; pos < end; pos++, numdigits++) { @@ -170,7 +170,7 @@ parse_internal_render_format_spec(PyObject *format_spec, { Py_ssize_t pos = start; int kind = PyUnicode_KIND(format_spec); - void *data = PyUnicode_DATA(format_spec); + const void *data = PyUnicode_DATA(format_spec); /* end-pos is used throughout this code to specify the length of the input string */ #define READ_spec(index) PyUnicode_READ(kind, data, index) @@ -443,7 +443,7 @@ parse_number(PyObject *s, Py_ssize_t pos, Py_ssize_t end, { Py_ssize_t remainder; int kind = PyUnicode_KIND(s); - void *data = PyUnicode_DATA(s); + const void *data = PyUnicode_DATA(s); while (pos<end && Py_ISDIGIT(PyUnicode_READ(kind, data, pos))) ++pos; diff --git a/Python/getargs.c b/Python/getargs.c index 062f814..7742428 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -923,7 +923,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, case 'C': {/* unicode char */ int *p = va_arg(*p_va, int *); int kind; - void *data; + const void *data; if (!PyUnicode_Check(arg)) return converterr("a unicode character", arg, msgbuf, bufsize); diff --git a/Python/traceback.c b/Python/traceback.c index f88ba1d..2167e07 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -376,7 +376,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) int fd; int i; char *found_encoding; - char *encoding; + const char *encoding; PyObject *io; PyObject *binary; PyObject *fob = NULL; @@ -384,7 +384,7 @@ _Py_DisplaySourceLine(PyObject *f, PyObject *filename, int lineno, int indent) PyObject *res; char buf[MAXPATHLEN+1]; int kind; - void *data; + const void *data; /* open the file */ if (filename == NULL) |