Skip to content

Commit 95292d6

Browse files
committed
Constify filenames and scripts. Fixes #651362.
1 parent 0e88c9f commit 95292d6

12 files changed

Lines changed: 126 additions & 121 deletions

File tree

‎Include/compile.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ PyAPI_DATA(PyTypeObject) PyCode_Type;
5252

5353
/* Public interface */
5454
struct _node; /* Declare the existence of this type */
55-
PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, char *);
55+
PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
5656
PyAPI_FUNC(PyCodeObject *) PyCode_New(
5757
int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *,
5858
PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *);
@@ -67,8 +67,8 @@ typedef struct {
6767
int ff_features;
6868
} PyFutureFeatures;
6969

70-
PyAPI_FUNC(PyFutureFeatures *) PyNode_Future(struct _node *, char *);
71-
PyAPI_FUNC(PyCodeObject *) PyNode_CompileFlags(struct _node *, char *,
70+
PyAPI_FUNC(PyFutureFeatures *) PyNode_Future(struct _node *, const char *);
71+
PyAPI_FUNC(PyCodeObject *) PyNode_CompileFlags(struct _node *, const char *,
7272
PyCompilerFlags *);
7373

7474
#define FUTURE_NESTED_SCOPES "nested_scopes"

‎Include/parsetok.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extern "C" {
99

1010
typedef struct {
1111
int error;
12-
char *filename;
12+
const char *filename;
1313
int lineno;
1414
int offset;
1515
char *text;
@@ -21,19 +21,19 @@ typedef struct {
2121
#define PyPARSE_YIELD_IS_KEYWORD 0x0001
2222
#endif
2323

24-
PyAPI_FUNC(node *) PyParser_ParseString(char *, grammar *, int,
24+
PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int,
2525
perrdetail *);
26-
PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, char *, grammar *, int,
26+
PyAPI_FUNC(node *) PyParser_ParseFile (FILE *, const char *, grammar *, int,
2727
char *, char *, perrdetail *);
2828

29-
PyAPI_FUNC(node *) PyParser_ParseStringFlags(char *, grammar *, int,
29+
PyAPI_FUNC(node *) PyParser_ParseStringFlags(const char *, grammar *, int,
3030
perrdetail *, int);
31-
PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, char *, grammar *,
31+
PyAPI_FUNC(node *) PyParser_ParseFileFlags(FILE *, const char *, grammar *,
3232
int, char *, char *,
3333
perrdetail *, int);
3434

35-
PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(char *,
36-
char *,
35+
PyAPI_FUNC(node *) PyParser_ParseStringFlagsFilename(const char *,
36+
const char *,
3737
grammar *, int,
3838
perrdetail *, int);
3939
#ifdef __cplusplus

‎Include/pyerrors.h‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,17 @@ PyAPI_FUNC(void) PyErr_WriteUnraisable(PyObject *);
130130

131131
/* Issue a warning or exception */
132132
PyAPI_FUNC(int) PyErr_Warn(PyObject *, char *);
133-
PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, char *,
134-
char *, int, char *, PyObject *);
133+
PyAPI_FUNC(int) PyErr_WarnExplicit(PyObject *, const char *,
134+
const char *, int,
135+
const char *, PyObject *);
135136

136137
/* In sigcheck.c or signalmodule.c */
137138
PyAPI_FUNC(int) PyErr_CheckSignals(void);
138139
PyAPI_FUNC(void) PyErr_SetInterrupt(void);
139140

140141
/* Support for adding program text to SyntaxErrors */
141-
PyAPI_FUNC(void) PyErr_SyntaxLocation(char *, int);
142-
PyAPI_FUNC(PyObject *) PyErr_ProgramText(char *, int);
142+
PyAPI_FUNC(void) PyErr_SyntaxLocation(const char *, int);
143+
PyAPI_FUNC(PyObject *) PyErr_ProgramText(const char *, int);
143144

144145
#ifdef Py_USING_UNICODE
145146
/* The following functions are used to create and modify unicode

‎Include/pythonrun.h‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,47 @@ PyAPI_FUNC(int) Py_IsInitialized(void);
2626
PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);
2727
PyAPI_FUNC(void) Py_EndInterpreter(PyThreadState *);
2828

29-
PyAPI_FUNC(int) PyRun_AnyFile(FILE *, char *);
30-
PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *, char *, int);
31-
32-
PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, char *, PyCompilerFlags *);
33-
PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, char *, int, PyCompilerFlags *);
34-
35-
PyAPI_FUNC(int) PyRun_SimpleString(char *);
36-
PyAPI_FUNC(int) PyRun_SimpleStringFlags(char *, PyCompilerFlags *);
37-
PyAPI_FUNC(int) PyRun_SimpleFile(FILE *, char *);
38-
PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *, char *, int);
39-
PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, char *, int, PyCompilerFlags *);
40-
PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *, char *);
41-
PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, char *, PyCompilerFlags *);
42-
PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *, char *);
43-
PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, char *, PyCompilerFlags *);
44-
45-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseString(char *, int);
46-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFile(FILE *, char *, int);
47-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(char *, int, int);
48-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(char *,
49-
char *,
29+
PyAPI_FUNC(int) PyRun_AnyFile(FILE *, const char *);
30+
PyAPI_FUNC(int) PyRun_AnyFileEx(FILE *, const char *, int);
31+
32+
PyAPI_FUNC(int) PyRun_AnyFileFlags(FILE *, const char *, PyCompilerFlags *);
33+
PyAPI_FUNC(int) PyRun_AnyFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
34+
35+
PyAPI_FUNC(int) PyRun_SimpleString(const char *);
36+
PyAPI_FUNC(int) PyRun_SimpleStringFlags(const char *, PyCompilerFlags *);
37+
PyAPI_FUNC(int) PyRun_SimpleFile(FILE *, const char *);
38+
PyAPI_FUNC(int) PyRun_SimpleFileEx(FILE *, const char *, int);
39+
PyAPI_FUNC(int) PyRun_SimpleFileExFlags(FILE *, const char *, int, PyCompilerFlags *);
40+
PyAPI_FUNC(int) PyRun_InteractiveOne(FILE *, const char *);
41+
PyAPI_FUNC(int) PyRun_InteractiveOneFlags(FILE *, const char *, PyCompilerFlags *);
42+
PyAPI_FUNC(int) PyRun_InteractiveLoop(FILE *, const char *);
43+
PyAPI_FUNC(int) PyRun_InteractiveLoopFlags(FILE *, const char *, PyCompilerFlags *);
44+
45+
PyAPI_FUNC(struct _node *) PyParser_SimpleParseString(const char *, int);
46+
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFile(FILE *, const char *, int);
47+
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlags(const char *, int, int);
48+
PyAPI_FUNC(struct _node *) PyParser_SimpleParseStringFlagsFilename(const char *,
49+
const char *,
5050
int,
5151
int);
52-
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, char *,
52+
PyAPI_FUNC(struct _node *) PyParser_SimpleParseFileFlags(FILE *, const char *,
5353
int, int);
5454

55-
PyAPI_FUNC(PyObject *) PyRun_String(char *, int, PyObject *, PyObject *);
56-
PyAPI_FUNC(PyObject *) PyRun_File(FILE *, char *, int, PyObject *, PyObject *);
57-
PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *, char *, int,
55+
PyAPI_FUNC(PyObject *) PyRun_String(const char *, int, PyObject *, PyObject *);
56+
PyAPI_FUNC(PyObject *) PyRun_File(FILE *, const char *, int, PyObject *, PyObject *);
57+
PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *, const char *, int,
5858
PyObject *, PyObject *, int);
59-
PyAPI_FUNC(PyObject *) PyRun_StringFlags(char *, int, PyObject *, PyObject *,
59+
PyAPI_FUNC(PyObject *) PyRun_StringFlags(const char *, int, PyObject *, PyObject *,
6060
PyCompilerFlags *);
61-
PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *, char *, int, PyObject *,
61+
PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *, const char *, int, PyObject *,
6262
PyObject *, PyCompilerFlags *);
63-
PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, char *, int, PyObject *,
63+
PyAPI_FUNC(PyObject *) PyRun_FileExFlags(FILE *, const char *, int, PyObject *,
6464
PyObject *, int, PyCompilerFlags *);
6565

66-
PyAPI_FUNC(PyObject *) Py_CompileString(char *, char *, int);
67-
PyAPI_FUNC(PyObject *) Py_CompileStringFlags(char *, char *, int,
66+
PyAPI_FUNC(PyObject *) Py_CompileString(const char *, const char *, int);
67+
PyAPI_FUNC(PyObject *) Py_CompileStringFlags(const char *, const char *, int,
6868
PyCompilerFlags *);
69-
PyAPI_FUNC(struct symtable *) Py_SymtableString(char *, char *, int);
69+
PyAPI_FUNC(struct symtable *) Py_SymtableString(const char *, const char *, int);
7070

7171
PyAPI_FUNC(void) PyErr_Print(void);
7272
PyAPI_FUNC(void) PyErr_PrintEx(int);
@@ -76,7 +76,7 @@ PyAPI_FUNC(int) Py_AtExit(void (*func)(void));
7676

7777
PyAPI_FUNC(void) Py_Exit(int);
7878

79-
PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, char *);
79+
PyAPI_FUNC(int) Py_FdIsInteractive(FILE *, const char *);
8080

8181
/* Bootstrap */
8282
PyAPI_FUNC(int) Py_Main(int argc, char **argv);

‎Include/symtable.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct _symtable_entry;
2020

2121
struct symtable {
2222
int st_pass; /* pass == 1 or 2 */
23-
char *st_filename; /* name of file being compiled */
23+
const char *st_filename; /* name of file being compiled */
2424
struct _symtable_entry *st_cur; /* current symbol table entry */
2525
PyObject *st_symbols; /* dictionary of symbol table entries */
2626
PyObject *st_stack; /* stack of namespace info */
@@ -57,7 +57,7 @@ PyAPI_DATA(PyTypeObject) PySymtableEntry_Type;
5757
PyAPI_FUNC(PyObject *) PySymtableEntry_New(struct symtable *,
5858
char *, int, int);
5959

60-
PyAPI_FUNC(struct symtable *) PyNode_CompileSymtable(struct _node *, char *);
60+
PyAPI_FUNC(struct symtable *) PyNode_CompileSymtable(struct _node *, const char *);
6161
PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
6262

6363

‎Parser/parsetok.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ int Py_TabcheckFlag;
1515

1616
/* Forward */
1717
static node *parsetok(struct tok_state *, grammar *, int, perrdetail *, int);
18-
static void initerr(perrdetail *err_ret, char* filename);
18+
static void initerr(perrdetail *err_ret, const char* filename);
1919

2020
/* Parse input coming from a string. Return error code, print some errors. */
2121
node *
22-
PyParser_ParseString(char *s, grammar *g, int start, perrdetail *err_ret)
22+
PyParser_ParseString(const char *s, grammar *g, int start, perrdetail *err_ret)
2323
{
2424
return PyParser_ParseStringFlags(s, g, start, err_ret, 0);
2525
}
2626

2727
node *
28-
PyParser_ParseStringFlags(char *s, grammar *g, int start,
28+
PyParser_ParseStringFlags(const char *s, grammar *g, int start,
2929
perrdetail *err_ret, int flags)
3030
{
3131
return PyParser_ParseStringFlagsFilename(s, NULL,
3232
g, start, err_ret, 0);
3333
}
3434

3535
node *
36-
PyParser_ParseStringFlagsFilename(char *s, char *filename,
36+
PyParser_ParseStringFlagsFilename(const char *s, const char *filename,
3737
grammar *g, int start,
3838
perrdetail *err_ret, int flags)
3939
{
@@ -60,15 +60,15 @@ PyParser_ParseStringFlagsFilename(char *s, char *filename,
6060
/* Parse input coming from a file. Return error code, print some errors. */
6161

6262
node *
63-
PyParser_ParseFile(FILE *fp, char *filename, grammar *g, int start,
63+
PyParser_ParseFile(FILE *fp, const char *filename, grammar *g, int start,
6464
char *ps1, char *ps2, perrdetail *err_ret)
6565
{
6666
return PyParser_ParseFileFlags(fp, filename, g, start, ps1, ps2,
6767
err_ret, 0);
6868
}
6969

7070
node *
71-
PyParser_ParseFileFlags(FILE *fp, char *filename, grammar *g, int start,
71+
PyParser_ParseFileFlags(FILE *fp, const char *filename, grammar *g, int start,
7272
char *ps1, char *ps2, perrdetail *err_ret, int flags)
7373
{
7474
struct tok_state *tok;
@@ -201,7 +201,7 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
201201
}
202202

203203
static void
204-
initerr(perrdetail *err_ret, char* filename)
204+
initerr(perrdetail *err_ret, const char* filename)
205205
{
206206
err_ret->error = E_OK;
207207
err_ret->filename = filename;

‎Parser/tokenizer.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ fp_setreadl(struct tok_state *tok, const char* enc)
386386
{
387387
PyObject *reader, *stream, *readline;
388388

389-
stream = PyFile_FromFile(tok->fp, tok->filename, "rb", NULL);
389+
/* XXX: constify filename argument. */
390+
stream = PyFile_FromFile(tok->fp, (char*)tok->filename, "rb", NULL);
390391
if (stream == NULL)
391392
return 0;
392393

@@ -591,15 +592,16 @@ decode_str(const char *str, struct tok_state *tok)
591592
/* Set up tokenizer for string */
592593

593594
struct tok_state *
594-
PyTokenizer_FromString(char *str)
595+
PyTokenizer_FromString(const char *str)
595596
{
596597
struct tok_state *tok = tok_new();
597598
if (tok == NULL)
598599
return NULL;
599600
str = (char *)decode_str(str, tok);
600601
if (str == NULL)
601602
return NULL;
602-
tok->buf = tok->cur = tok->end = tok->inp = str;
603+
/* XXX: constify members. */
604+
tok->buf = tok->cur = tok->end = tok->inp = (char*)str;
603605
return tok;
604606
}
605607

‎Parser/tokenizer.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct tok_state {
3434
int level; /* () [] {} Parentheses nesting level */
3535
/* Used to allow free continuations inside them */
3636
/* Stuff for checking on different tab sizes */
37-
char *filename; /* For error messages */
37+
const char *filename; /* For error messages */
3838
int altwarning; /* Issue warning if alternate tabs don't match */
3939
int alterror; /* Issue error if alternate tabs don't match */
4040
int alttabsize; /* Alternate tab spacing */
@@ -54,7 +54,7 @@ struct tok_state {
5454
const char* str;
5555
};
5656

57-
extern struct tok_state *PyTokenizer_FromString(char *);
57+
extern struct tok_state *PyTokenizer_FromString(const char *);
5858
extern struct tok_state *PyTokenizer_FromFile(FILE *, char *, char *);
5959
extern void PyTokenizer_Free(struct tok_state *);
6060
extern int PyTokenizer_Get(struct tok_state *, char **, char **);

‎Python/compile.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ struct compiling {
472472
int c_begin; /* begin of current loop, for 'continue' */
473473
int c_block[CO_MAXBLOCKS]; /* stack of block types */
474474
int c_nblocks; /* current block stack level */
475-
char *c_filename; /* filename of current node */
475+
const char *c_filename; /* filename of current node */
476476
char *c_name; /* name of object (e.g. function) */
477477
int c_lineno; /* Current line number */
478478
int c_stacklevel; /* Current stack level */
@@ -574,8 +574,8 @@ block_pop(struct compiling *c, int type)
574574

575575
/* Prototype forward declarations */
576576

577-
static int issue_warning(char *, char *, int);
578-
static int com_init(struct compiling *, char *);
577+
static int issue_warning(const char *, const char *, int);
578+
static int com_init(struct compiling *, const char *);
579579
static void com_free(struct compiling *);
580580
static void com_push(struct compiling *, int);
581581
static void com_pop(struct compiling *, int);
@@ -597,7 +597,7 @@ static int com_argdefs(struct compiling *, node *);
597597
static void com_assign(struct compiling *, node *, int, node *);
598598
static void com_assign_name(struct compiling *, node *, int);
599599
static PyCodeObject *icompile(node *, struct compiling *);
600-
static PyCodeObject *jcompile(node *, char *, struct compiling *,
600+
static PyCodeObject *jcompile(node *, const char *, struct compiling *,
601601
PyCompilerFlags *);
602602
static PyObject *parsestrplus(struct compiling*, node *);
603603
static PyObject *parsestr(struct compiling *, char *);
@@ -654,7 +654,7 @@ dump(node *n, int pad, int depth)
654654
#define DUMP(N) dump(N, 0, -1)
655655

656656
static int
657-
com_init(struct compiling *c, char *filename)
657+
com_init(struct compiling *c, const char *filename)
658658
{
659659
memset((void *)c, '\0', sizeof(struct compiling));
660660
if ((c->c_code = PyString_FromStringAndSize((char *)NULL,
@@ -1182,7 +1182,9 @@ parsenumber(struct compiling *c, char *s)
11821182
"hex/oct constants > sys.maxint "
11831183
"will return positive values "
11841184
"in Python 2.4 and up",
1185-
c->c_filename,
1185+
/* XXX: Give WarnExplicit
1186+
a const char* argument. */
1187+
(char*)c->c_filename,
11861188
c->c_lineno,
11871189
NULL,
11881190
NULL) < 0)
@@ -4142,19 +4144,19 @@ dict_keys_inorder(PyObject *dict, int offset)
41424144
}
41434145

41444146
PyCodeObject *
4145-
PyNode_Compile(node *n, char *filename)
4147+
PyNode_Compile(node *n, const char *filename)
41464148
{
41474149
return PyNode_CompileFlags(n, filename, NULL);
41484150
}
41494151

41504152
PyCodeObject *
4151-
PyNode_CompileFlags(node *n, char *filename, PyCompilerFlags *flags)
4153+
PyNode_CompileFlags(node *n, const char *filename, PyCompilerFlags *flags)
41524154
{
41534155
return jcompile(n, filename, NULL, flags);
41544156
}
41554157

41564158
struct symtable *
4157-
PyNode_CompileSymtable(node *n, char *filename)
4159+
PyNode_CompileSymtable(node *n, const char *filename)
41584160
{
41594161
struct symtable *st;
41604162
PyFutureFeatures *ff;
@@ -4191,7 +4193,7 @@ icompile(node *n, struct compiling *base)
41914193
}
41924194

41934195
static PyCodeObject *
4194-
jcompile(node *n, char *filename, struct compiling *base,
4196+
jcompile(node *n, const char *filename, struct compiling *base,
41954197
PyCompilerFlags *flags)
41964198
{
41974199
struct compiling sc;
@@ -4351,7 +4353,7 @@ get_ref_type(struct compiling *c, char *name)
43514353
/* Helper functions to issue warnings */
43524354

43534355
static int
4354-
issue_warning(char *msg, char *filename, int lineno)
4356+
issue_warning(const char *msg, const char *filename, int lineno)
43554357
{
43564358
if (PyErr_WarnExplicit(PyExc_SyntaxWarning, msg, filename,
43574359
lineno, NULL, NULL) < 0) {

0 commit comments

Comments
 (0)