Constify filenames and scripts. Fixes #651362. · pythoncapi/cpython@95292d6 · GitHub
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

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

0 commit comments

Comments
 (0)