Skip to content

Commit 8f87eef

Browse files
bpo-39943: Add the const qualifier to pointers on non-mutable PyBytes data. (GH-19472)
1 parent 3e0dd37 commit 8f87eef

File tree

20 files changed

+38
-37
lines changed

20 files changed

+38
-37
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ CharArray_get_value(CDataObject *self, void *Py_UNUSED(ignored))
13101310
static int
13111311
CharArray_set_value(CDataObject *self, PyObject *value, void *Py_UNUSED(ignored))
13121312
{
1313-
char *ptr;
1313+
const char *ptr;
13141314
Py_ssize_t size;
13151315

13161316
if (value == NULL) {

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ copy_com_pointer(PyObject *self, PyObject *args)
13841384
static PyObject *py_dl_open(PyObject *self, PyObject *args)
13851385
{
13861386
PyObject *name, *name2;
1387-
char *name_str;
1387+
const char *name_str;
13881388
void * handle;
13891389
#if HAVE_DECL_RTLD_LOCAL
13901390
int mode = RTLD_NOW | RTLD_LOCAL;

Modules/_ctypes/cfield.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ s_get(void *ptr, Py_ssize_t size)
12831283
static PyObject *
12841284
s_set(void *ptr, PyObject *value, Py_ssize_t length)
12851285
{
1286-
char *data;
1286+
const char *data;
12871287
Py_ssize_t size;
12881288

12891289
if(!PyBytes_Check(value)) {
@@ -1321,7 +1321,7 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
13211321
return value;
13221322
}
13231323
if (PyBytes_Check(value)) {
1324-
*(char **)ptr = PyBytes_AsString(value);
1324+
*(const char **)ptr = PyBytes_AsString(value);
13251325
Py_INCREF(value);
13261326
return value;
13271327
} else if (PyLong_Check(value)) {

Modules/_cursesmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ _curses_window_addstr_impl(PyCursesWindowObject *self, int group_left_1,
709709
else
710710
#endif
711711
{
712-
char *str = PyBytes_AS_STRING(bytesobj);
712+
const char *str = PyBytes_AS_STRING(bytesobj);
713713
funcname = "addstr";
714714
if (use_xy)
715715
rtn = mvwaddstr(self->win,y,x,str);
@@ -792,7 +792,7 @@ _curses_window_addnstr_impl(PyCursesWindowObject *self, int group_left_1,
792792
else
793793
#endif
794794
{
795-
char *str = PyBytes_AS_STRING(bytesobj);
795+
const char *str = PyBytes_AS_STRING(bytesobj);
796796
funcname = "addnstr";
797797
if (use_xy)
798798
rtn = mvwaddnstr(self->win,y,x,str,n);
@@ -1710,7 +1710,7 @@ _curses_window_insstr_impl(PyCursesWindowObject *self, int group_left_1,
17101710
else
17111711
#endif
17121712
{
1713-
char *str = PyBytes_AS_STRING(bytesobj);
1713+
const char *str = PyBytes_AS_STRING(bytesobj);
17141714
funcname = "insstr";
17151715
if (use_xy)
17161716
rtn = mvwinsstr(self->win,y,x,str);
@@ -1795,7 +1795,7 @@ _curses_window_insnstr_impl(PyCursesWindowObject *self, int group_left_1,
17951795
else
17961796
#endif
17971797
{
1798-
char *str = PyBytes_AS_STRING(bytesobj);
1798+
const char *str = PyBytes_AS_STRING(bytesobj);
17991799
funcname = "insnstr";
18001800
if (use_xy)
18011801
rtn = mvwinsnstr(self->win,y,x,str,n);

Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ checkpath(PyObject* tag)
11531153
return 0;
11541154
}
11551155
if (PyBytes_Check(tag)) {
1156-
char *p = PyBytes_AS_STRING(tag);
1156+
const char *p = PyBytes_AS_STRING(tag);
11571157
const Py_ssize_t len = PyBytes_GET_SIZE(tag);
11581158
if (len >= 3 && p[0] == '{' && (
11591159
p[1] == '}' || (p[1] == '*' && p[2] == '}'))) {

Modules/_io/bytesio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ _io_BytesIO_tell_impl(bytesio *self)
393393
static PyObject *
394394
read_bytes(bytesio *self, Py_ssize_t size)
395395
{
396-
char *output;
396+
const char *output;
397397

398398
assert(self->buf != NULL);
399399
assert(size <= self->string_size);
@@ -502,7 +502,7 @@ _io_BytesIO_readlines_impl(bytesio *self, PyObject *arg)
502502
{
503503
Py_ssize_t maxsize, size, n;
504504
PyObject *result, *line;
505-
char *output;
505+
const char *output;
506506

507507
CHECK_CLOSED(self);
508508

Modules/_io/textio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ _io_TextIOWrapper_tell_impl(textio *self)
26402640
Py_ssize_t chars_to_skip, chars_decoded;
26412641
Py_ssize_t skip_bytes, skip_back;
26422642
PyObject *saved_state = NULL;
2643-
char *input, *input_end;
2643+
const char *input, *input_end;
26442644
Py_ssize_t dec_buffer_len;
26452645
int dec_flags;
26462646

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ PyDoc_STRVAR(bindtextdomain__doc__,
637637
static PyObject*
638638
PyIntl_bindtextdomain(PyObject* self, PyObject*args)
639639
{
640-
char *domain, *dirname, *current_dirname;
640+
const char *domain, *dirname, *current_dirname;
641641
PyObject *dirname_obj, *dirname_bytes = NULL, *result;
642642

643643
if (!PyArg_ParseTuple(args, "sO", &domain, &dirname_obj))

Modules/_sqlite/connection.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject
7979
NULL
8080
};
8181

82-
char* database;
82+
const char* database;
8383
PyObject* database_obj;
8484
int detect_types = 0;
8585
PyObject* isolation_level = NULL;

Modules/_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4037,7 +4037,7 @@ _ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile,
40374037
/* internal helper function, returns -1 on error
40384038
*/
40394039
static int
4040-
_add_ca_certs(PySSLContext *self, void *data, Py_ssize_t len,
4040+
_add_ca_certs(PySSLContext *self, const void *data, Py_ssize_t len,
40414041
int filetype)
40424042
{
40434043
BIO *biobuf = NULL;

0 commit comments

Comments
 (0)