]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. (GH-19472)
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 12 Apr 2020 11:58:27 +0000 (14:58 +0300)
committerGitHub <noreply@github.com>
Sun, 12 Apr 2020 11:58:27 +0000 (14:58 +0300)
20 files changed:
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callproc.c
Modules/_ctypes/cfield.c
Modules/_cursesmodule.c
Modules/_elementtree.c
Modules/_io/bytesio.c
Modules/_io/textio.c
Modules/_localemodule.c
Modules/_sqlite/connection.c
Modules/_ssl.c
Modules/_struct.c
Modules/_tkinter.c
Modules/cjkcodecs/multibytecodec.c
Modules/readline.c
Objects/bytesobject.c
Objects/fileobject.c
Objects/longobject.c
Objects/stringlib/join.h
Objects/unicodeobject.c
Python/fileutils.c

index ba5ef397cf05bf217d8068715bee4714bfe62084..5548c50cf53e43709336007b9fdb8a5acc392338 100644 (file)
@@ -1310,7 +1310,7 @@ CharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored))
 static int
 CharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored))
 {
-    char *ptr;
+    const char *ptr;
     Py_ssize_t size;
 
     if (value == NULL) {
index d1c552af99bd1864c339bff80781e4a9903cc9d9..815fc6664d0ba4fe65caa70ecf4e7713f69274d6 100644 (file)
@@ -1384,7 +1384,7 @@ copy_com_pointer(PyObject *self, PyObject *args)
 static PyObject *py_dl_open(PyObject *self, PyObject *args)
 {
     PyObject *name, *name2;
-    char *name_str;
+    const char *name_str;
     void * handle;
 #if HAVE_DECL_RTLD_LOCAL
     int mode = RTLD_NOW | RTLD_LOCAL;
index f860e6e51b24686f5cfb379e13ae92943e56ad8d..2060d15a64de50ef937f575cb216e954093acb6e 100644 (file)
@@ -1283,7 +1283,7 @@ s_get(void *ptr, Py_ssize_t size)
 static PyObject *
 s_set(void *ptr, PyObject *value, Py_ssize_t length)
 {
-    char *data;
+    const char *data;
     Py_ssize_t size;
 
     if(!PyBytes_Check(value)) {
@@ -1321,7 +1321,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
         return value;
     }
     if (PyBytes_Check(value)) {
-        *(char **)ptr = PyBytes_AsString(value);
+        *(const char **)ptr = PyBytes_AsString(value);
         Py_INCREF(value);
         return value;
     } else if (PyLong_Check(value)) {
index ca6a89f1dbeb317f2057064f54e20de7dd962b8d..08991fd54808fb4899e06d2682139d7b3689c298 100644 (file)
@@ -709,7 +709,7 @@ _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
     else
 #endif
     {
-        char *str = PyBytes_AS_STRING(bytesobj);
+        const char *str = PyBytes_AS_STRING(bytesobj);
         funcname = "addstr";
         if (use_xy)
             rtn = mvwaddstr(self->win,y,x,str);
@@ -792,7 +792,7 @@ _curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,
     else
 #endif
     {
-        char *str = PyBytes_AS_STRING(bytesobj);
+        const char *str = PyBytes_AS_STRING(bytesobj);
         funcname = "addnstr";
         if (use_xy)
             rtn = mvwaddnstr(self->win,y,x,str,n);
@@ -1710,7 +1710,7 @@ _curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,
     else
 #endif
     {
-        char *str = PyBytes_AS_STRING(bytesobj);
+        const char *str = PyBytes_AS_STRING(bytesobj);
         funcname = "insstr";
         if (use_xy)
             rtn = mvwinsstr(self->win,y,x,str);
@@ -1795,7 +1795,7 @@ _curses_window_insnstr_impl(PyCursesWindowObject *self, int group_left_1,
     else
 #endif
     {
-        char *str = PyBytes_AS_STRING(bytesobj);
+        const char *str = PyBytes_AS_STRING(bytesobj);
         funcname = "insnstr";
         if (use_xy)
             rtn = mvwinsnstr(self->win,y,x,str,n);
index c0c741e51c712c1c1ee3fd502f190b4aa1480135..10d78dd58f0114fedf37c0ed8704f9eb0db695ae 100644 (file)
@@ -1153,7 +1153,7 @@ checkpath(PyObject* tag)
         return 0;
     }
     if (PyBytes_Check(tag)) {
-        char *p = PyBytes_AS_STRING(tag);
+        const char *p = PyBytes_AS_STRING(tag);
         const Py_ssize_t len = PyBytes_GET_SIZE(tag);
         if (len >= 3 && p[0] == '{' && (
                 p[1] == '}' || (p[1] == '*' && p[2] == '}'))) {
index b5d308a8bca42cc48fc25fd90f9ce8c377af2dfd..f4261b3713ac1546c95d3d893671dbda564e2f49 100644 (file)
@@ -393,7 +393,7 @@ _io_BytesIO_tell_impl(bytesio *self)
 static PyObject *
 read_bytes(bytesio *self, Py_ssize_t size)
 {
-    char *output;
+    const char *output;
 
     assert(self->buf != NULL);
     assert(size <= self->string_size);
@@ -502,7 +502,7 @@ _io_BytesIO_readlines_impl(bytesio *self, PyObject *arg)
 {
     Py_ssize_t maxsize, size, n;
     PyObject *result, *line;
-    char *output;
+    const char *output;
 
     CHECK_CLOSED(self);
 
index 12dba38d73bf05c23ab37752605fdedf1f468092..92d6faafa2ea5e7cd69675a71a5c23546ce6e994 100644 (file)
@@ -2640,7 +2640,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
     Py_ssize_t chars_to_skip, chars_decoded;
     Py_ssize_t skip_bytes, skip_back;
     PyObject *saved_state = NULL;
-    char *input, *input_end;
+    const char *input, *input_end;
     Py_ssize_t dec_buffer_len;
     int dec_flags;
 
index 5bf6638ed2a64355cd89deb917cf558739240602..0819d0e1924087f1df39d835511cc0bed2c665ed 100644 (file)
@@ -637,7 +637,7 @@ PyDoc_STRVAR(bindtextdomain__doc__,
 static PyObject*
 PyIntl_bindtextdomain(PyObject* self, PyObject*args)
 {
-    char *domain, *dirname, *current_dirname;
+    const char *domain, *dirname, *current_dirname;
     PyObject *dirname_obj, *dirname_bytes = NULL, *result;
 
     if (!PyArg_ParseTuple(args, "sO", &domain, &dirname_obj))
index 92bdfe36e6a43c3c7e8533e2d4a92895bfa21a1c..91041b95cd82f67cb86a7f536bc062812f882fe6 100644 (file)
@@ -79,7 +79,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
         NULL
     };
 
-    char* database;
+    const char* database;
     PyObject* database_obj;
     int detect_types = 0;
     PyObject* isolation_level = NULL;
index ef047126361ed5399c6d7381b4ef799e023f3761..a471a26e93360436357aeb66c0fdfd07ac2c3a8c 100644 (file)
@@ -4037,7 +4037,7 @@ error:
 /* internal helper function, returns -1 on error
  */
 static int
-_add_ca_certs(PySSLContext *self, void *data, Py_ssize_t len,
+_add_ca_certs(PySSLContext *self, const void *data, Py_ssize_t len,
               int filetype)
 {
     BIO *biobuf = NULL;
index 242ca9c10df2de221dda0c96e8fff94e4f162ccc..82ac0a19208d9af7896fc6643b0c6114810dfba3 100644 (file)
@@ -1785,7 +1785,7 @@ s_pack_internal(PyStructObject *soself, PyObject *const *args, int offset, char*
             if (e->format == 's') {
                 Py_ssize_t n;
                 int isstring;
-                void *p;
+                const void *p;
                 isstring = PyBytes_Check(v);
                 if (!isstring && !PyByteArray_Check(v)) {
                     PyErr_SetString(_structmodulestate_global->StructError,
@@ -1807,7 +1807,7 @@ s_pack_internal(PyStructObject *soself, PyObject *const *args, int offset, char*
             } else if (e->format == 'p') {
                 Py_ssize_t n;
                 int isstring;
-                void *p;
+                const void *p;
                 isstring = PyBytes_Check(v);
                 if (!isstring && !PyByteArray_Check(v)) {
                     PyErr_SetString(_structmodulestate_global->StructError,
index 5f001c6e73c6d978c7418518a2de4c1897413ed7..199ae4f0db8f001d6bde8f3fb8c0b5f8bea582ab 100644 (file)
@@ -574,9 +574,9 @@ SplitObj(PyObject *arg)
     else if (PyBytes_Check(arg)) {
         int argc;
         const char **argv;
-        char *list = PyBytes_AS_STRING(arg);
+        const char *list = PyBytes_AS_STRING(arg);
 
-        if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) {
+        if (Tcl_SplitList((Tcl_Interp *)NULL, (char *)list, &argc, &argv) != TCL_OK) {
             Py_INCREF(arg);
             return arg;
         }
index 9f9fbeb02ab696843dd6d474f70d7536458f2596..319dc52749c656d820e41190595a707825787de3 100644 (file)
@@ -1246,7 +1246,7 @@ _multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDe
     PyObject *buffer;
     PyLongObject *statelong;
     Py_ssize_t buffersize;
-    char *bufferstr;
+    const char *bufferstr;
     unsigned char statebytes[8];
 
     if (!PyArg_ParseTuple(state, "SO!;setstate(): illegal state argument",
index 225d06b0360d3bc2c07d30e774e88bbc1eebb495..12d6cc78e38a77491a21615c41573fe0ca4ad6f6 100644 (file)
@@ -234,7 +234,7 @@ static PyObject *
 write_history_file(PyObject *self, PyObject *args)
 {
     PyObject *filename_obj = Py_None, *filename_bytes;
-    char *filename;
+    const char *filename;
     int err;
     if (!PyArg_ParseTuple(args, "|O:write_history_file", &filename_obj))
         return NULL;
@@ -270,7 +270,7 @@ append_history_file(PyObject *self, PyObject *args)
 {
     int nelements;
     PyObject *filename_obj = Py_None, *filename_bytes;
-    char *filename;
+    const char *filename;
     int err;
     if (!PyArg_ParseTuple(args, "i|O:append_history_file", &nelements, &filename_obj))
         return NULL;
index 987d98d4ed50f674d9ef9d79346bc1746b5cecdf..7be075b72e32a86c7fa32ba4f00e183196e7b8a6 100644 (file)
@@ -1598,7 +1598,7 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
     else if (PySlice_Check(item)) {
         Py_ssize_t start, stop, step, slicelength, i;
         size_t cur;
-        char* source_buf;
+        const char* source_buf;
         char* result_buf;
         PyObject* result;
 
@@ -1863,7 +1863,7 @@ Py_LOCAL_INLINE(PyObject *)
 do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
 {
     Py_buffer vsep;
-    char *s = PyBytes_AS_STRING(self);
+    const char *s = PyBytes_AS_STRING(self);
     Py_ssize_t len = PyBytes_GET_SIZE(self);
     char *sep;
     Py_ssize_t seplen;
@@ -1903,7 +1903,7 @@ do_xstrip(PyBytesObject *self, int striptype, PyObject *sepobj)
 Py_LOCAL_INLINE(PyObject *)
 do_strip(PyBytesObject *self, int striptype)
 {
-    char *s = PyBytes_AS_STRING(self);
+    const char *s = PyBytes_AS_STRING(self);
     Py_ssize_t len = PyBytes_GET_SIZE(self), i, j;
 
     i = 0;
@@ -2020,7 +2020,8 @@ bytes_translate_impl(PyBytesObject *self, PyObject *table,
                      PyObject *deletechars)
 /*[clinic end generated code: output=43be3437f1956211 input=0ecdf159f654233c]*/
 {
-    char *input, *output;
+    const char *input;
+    char *output;
     Py_buffer table_view = {NULL, NULL};
     Py_buffer del_table_view = {NULL, NULL};
     const char *table_chars;
@@ -2371,7 +2372,7 @@ static PyObject *
 bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep)
 /*[clinic end generated code: output=1f134da504064139 input=f1238d3455990218]*/
 {
-    char* argbuf = PyBytes_AS_STRING(self);
+    const char *argbuf = PyBytes_AS_STRING(self);
     Py_ssize_t arglen = PyBytes_GET_SIZE(self);
     return _Py_strhex_with_sep(argbuf, arglen, sep, bytes_per_sep);
 }
@@ -3188,7 +3189,7 @@ _PyBytesWriter_AsString(_PyBytesWriter *writer)
 Py_LOCAL_INLINE(Py_ssize_t)
 _PyBytesWriter_GetSize(_PyBytesWriter *writer, char *str)
 {
-    char *start = _PyBytesWriter_AsString(writer);
+    const char *start = _PyBytesWriter_AsString(writer);
     assert(str != NULL);
     assert(str >= start);
     assert(str - start <= writer->allocated);
@@ -3199,7 +3200,7 @@ _PyBytesWriter_GetSize(_PyBytesWriter *writer, char *str)
 Py_LOCAL_INLINE(int)
 _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
 {
-    char *start, *end;
+    const char *start, *end;
 
     if (writer->use_small_buffer) {
         assert(writer->buffer == NULL);
index 840d17bee66bae03500b0ed126736787d3f87375..b8ec56e994ca6608f87f57485d6edb9d10de5256 100644 (file)
@@ -76,7 +76,7 @@ PyFile_GetLine(PyObject *f, int n)
     }
 
     if (n < 0 && result != NULL && PyBytes_Check(result)) {
-        char *s = PyBytes_AS_STRING(result);
+        const char *s = PyBytes_AS_STRING(result);
         Py_ssize_t len = PyBytes_GET_SIZE(result);
         if (len == 0) {
             Py_DECREF(result);
index 5d225cbd2fbdea395f093fc85dd98f43400ded2d..a66e1c49241afa7aaeb3e6e25a18635d9f4d2aee 100644 (file)
@@ -5071,7 +5071,7 @@ long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase)
     if (PyUnicode_Check(x))
         return PyLong_FromUnicodeObject(x, (int)base);
     else if (PyByteArray_Check(x) || PyBytes_Check(x)) {
-        char *string;
+        const char *string;
         if (PyByteArray_Check(x))
             string = PyByteArray_AS_STRING(x);
         else
index 8ad598ad5c9fd70aec5483724f9e270435e88859..53bcbdea7ade9d3d60ba3f8fa57ea329d0a0f599 100644 (file)
@@ -7,8 +7,8 @@
 Py_LOCAL_INLINE(PyObject *)
 STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable)
 {
-    char *sepstr = STRINGLIB_STR(sep);
-    const Py_ssize_t seplen = STRINGLIB_LEN(sep);
+    const char *sepstr = STRINGLIB_STR(sep);
+    Py_ssize_t seplen = STRINGLIB_LEN(sep);
     PyObject *res = NULL;
     char *p;
     Py_ssize_t seqlen = 0;
index 3c79febea7788000abd53e9800c1c4652a0e3499..7f39022d1e0b723d8788bc5492abb7042f65e17f 100644 (file)
@@ -3887,7 +3887,7 @@ PyUnicode_FSConverter(PyObject* arg, void* addr)
     PyObject *path = NULL;
     PyObject *output = NULL;
     Py_ssize_t size;
-    void *data;
+    const char *data;
     if (arg == NULL) {
         Py_DECREF(*(PyObject**)addr);
         *(PyObject**)addr = NULL;
@@ -4718,7 +4718,7 @@ _PyUnicode_EncodeUTF7(PyObject *str,
     unsigned int base64bits = 0;
     unsigned long base64buffer = 0;
     char * out;
-    char * start;
+    const char * start;
 
     if (PyUnicode_READY(str) == -1)
         return NULL;
@@ -5446,7 +5446,7 @@ unicode_fill_utf8(PyObject *unicode)
         return -1;
     }
 
-    char *start = writer.use_small_buffer ? writer.small_buffer :
+    const char *start = writer.use_small_buffer ? writer.small_buffer :
                     PyBytes_AS_STRING(writer.buffer);
     Py_ssize_t len = end - start;
 
index 6345553f484c77a147bad1f61f9e03dfbb72dee9..19ead9d676c7fce3fd60e0ac55fed68f9b7c50a1 100644 (file)
@@ -1452,7 +1452,7 @@ _Py_fopen_obj(PyObject *path, const char *mode)
              && errno == EINTR && !(async_err = PyErr_CheckSignals()));
 #else
     PyObject *bytes;
-    char *path_bytes;
+    const char *path_bytes;
 
     assert(PyGILState_Check());