Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b05a5c7

Browse files
committed
Instead of importing graminit.h whenever one of the three grammar 'root'
symbols is needed, define these in Python.h with a Py_ prefix.
1 parent 8813b58 commit b05a5c7

7 files changed

Lines changed: 39 additions & 21 deletions

File tree

Include/Python.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ PERFORMANCE OF THIS SOFTWARE.
112112

113113
#include "pyfpe.h"
114114

115+
/* These definitions much match corresponding definitions in graminit.h.
116+
There's code in compile.c that checks that they are the same. */
117+
#define Py_single_input 256
118+
#define Py_file_input 257
119+
#define Py_eval_input 258
120+
115121
#endif /* !Py_PYTHON_H */

Modules/cPickle.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static char cPickle_module_documentation[] =
5858

5959
#include "Python.h"
6060
#include "cStringIO.h"
61-
#include "graminit.h"
6261
#include "mymath.h"
6362

6463
#include <errno.h>
@@ -1883,7 +1882,7 @@ PyImport_ImportModuleNi(char *module_name)
18831882
return NULL;
18841883

18851884
if (!(import =
1886-
PyRun_String(import_str, eval_input, eval_dict, eval_dict))) {
1885+
PyRun_String(import_str, Py_eval_input, eval_dict, eval_dict))) {
18871886
free(import_str);
18881887
return NULL;
18891888
}
@@ -2223,7 +2222,7 @@ load_string(Unpicklerobject *self) {
22232222
UNLESS(eval_dict = Py_BuildValue("{s{}}", "__builtins__"))
22242223
goto finally;
22252224

2226-
UNLESS(str = PyRun_String(s, eval_input, eval_dict, eval_dict))
2225+
UNLESS(str = PyRun_String(s, Py_eval_input, eval_dict, eval_dict))
22272226
goto finally;
22282227

22292228
if (PyList_Append(self->stack, str) < 0)
@@ -3870,6 +3869,10 @@ initcPickle() {
38703869

38713870
/****************************************************************************
38723871
$Log$
3872+
Revision 2.5 1997/05/07 17:46:13 guido
3873+
Instead of importing graminit.h whenever one of the three grammar 'root'
3874+
symbols is needed, define these in Python.h with a Py_ prefix.
3875+
38733876
Revision 2.4 1997/04/09 17:47:47 guido
38743877
Give PyErr_Format a new name and make it static.
38753878

Python/bltinmodule.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ PERFORMANCE OF THIS SOFTWARE.
3434
#include "Python.h"
3535

3636
#include "node.h"
37-
#include "graminit.h"
3837
#include "compile.h"
3938
#include "eval.h"
4039

@@ -283,11 +282,11 @@ builtin_compile(self, args)
283282
if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
284283
return NULL;
285284
if (strcmp(startstr, "exec") == 0)
286-
start = file_input;
285+
start = Py_file_input;
287286
else if (strcmp(startstr, "eval") == 0)
288-
start = eval_input;
287+
start = Py_eval_input;
289288
else if (strcmp(startstr, "single") == 0)
290-
start = single_input;
289+
start = Py_single_input;
291290
else {
292291
PyErr_SetString(PyExc_ValueError,
293292
"compile() mode must be 'exec' or 'eval' or 'single'");
@@ -521,7 +520,7 @@ builtin_eval(self, args)
521520
}
522521
while (*str == ' ' || *str == '\t')
523522
str++;
524-
return PyRun_String(str, eval_input, globals, locals);
523+
return PyRun_String(str, Py_eval_input, globals, locals);
525524
}
526525

527526
static PyObject *
@@ -558,7 +557,7 @@ builtin_execfile(self, args)
558557
PyErr_SetFromErrno(PyExc_IOError);
559558
return NULL;
560559
}
561-
res = PyRun_File(fp, filename, file_input, globals, locals);
560+
res = PyRun_File(fp, filename, Py_file_input, globals, locals);
562561
Py_BEGIN_ALLOW_THREADS
563562
fclose(fp);
564563
Py_END_ALLOW_THREADS
@@ -882,7 +881,7 @@ builtin_input(self, args)
882881
PyEval_GetBuiltins()) != 0)
883882
return NULL;
884883
}
885-
res = PyRun_String(str, eval_input, globals, locals);
884+
res = PyRun_String(str, Py_eval_input, globals, locals);
886885
Py_DECREF(line);
887886
return res;
888887
}

Python/ceval.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ PERFORMANCE OF THIS SOFTWARE.
4343
#include "frameobject.h"
4444
#include "eval.h"
4545
#include "opcode.h"
46-
#include "graminit.h"
4746

4847
#include <ctype.h>
4948

@@ -2637,7 +2636,8 @@ exec_statement(f, prog, globals, locals)
26372636
if (PyFile_Check(prog)) {
26382637
FILE *fp = PyFile_AsFile(prog);
26392638
char *name = PyString_AsString(PyFile_Name(prog));
2640-
if (PyRun_File(fp, name, file_input, globals, locals) == NULL)
2639+
if (PyRun_File(fp, name, Py_file_input,
2640+
globals, locals) == NULL)
26412641
return -1;
26422642
return 0;
26432643
}
@@ -2647,7 +2647,7 @@ exec_statement(f, prog, globals, locals)
26472647
"embedded '\\0' in exec string");
26482648
return -1;
26492649
}
2650-
v = PyRun_String(s, file_input, globals, locals);
2650+
v = PyRun_String(s, Py_file_input, globals, locals);
26512651
if (v == NULL)
26522652
return -1;
26532653
Py_DECREF(v);

Python/compile.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ PERFORMANCE OF THIS SOFTWARE.
5858

5959
#include <ctype.h>
6060

61+
/* Three symbols from graminit.h are also defined in Python.h, with
62+
Py_ prefixes to their names. Python.h can't include graminit.h
63+
(which defines too many confusing symbols), but we can check here
64+
that they haven't changed (which is very unlikely, but possible). */
65+
#if Py_single_input != single_input
66+
#error "single_input has changed -- update Py_single_input in Python.h"
67+
#endif
68+
#if Py_file_input != file_input
69+
#error "file_input has changed -- update Py_file_input in Python.h"
70+
#endif
71+
#if Py_eval_input != eval_input
72+
#error "eval_input has changed -- update Py_eval_input in Python.h"
73+
#endif
74+
6175
int Py_OptimizeFlag = 0;
6276

6377
#define OP_DELETE 0

Python/import.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@ PERFORMANCE OF THIS SOFTWARE.
3535

3636
#include "node.h"
3737
#include "token.h"
38-
#include "graminit.h"
3938
#include "errcode.h"
4039
#include "marshal.h"
4140
#include "compile.h"
4241
#include "eval.h"
4342
#include "osdefs.h"
4443
#include "importdl.h"
4544
#ifdef macintosh
46-
/* 'argument' is a grammar symbol, but also used in some mac header files */
47-
#undef argument
4845
#include "macglue.h"
4946
#endif
5047

@@ -317,7 +314,7 @@ parse_source_module(pathname, fp)
317314
PyCodeObject *co;
318315
node *n;
319316

320-
n = PyParser_SimpleParseFile(fp, pathname, file_input);
317+
n = PyParser_SimpleParseFile(fp, pathname, Py_file_input);
321318
if (n == NULL)
322319
return NULL;
323320
co = PyNode_Compile(n, pathname);

Python/pythonrun.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ PERFORMANCE OF THIS SOFTWARE.
3636
#include "grammar.h"
3737
#include "node.h"
3838
#include "parsetok.h"
39-
#include "graminit.h"
4039
#undef argument /* Avoid conflict on Mac */
4140
#include "errcode.h"
4241
#include "compile.h"
@@ -237,7 +236,7 @@ PyRun_InteractiveOne(fp, filename)
237236
}
238237
Py_BEGIN_ALLOW_THREADS
239238
n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
240-
single_input, ps1, ps2, &err);
239+
Py_single_input, ps1, ps2, &err);
241240
Py_END_ALLOW_THREADS
242241
Py_XDECREF(v);
243242
Py_XDECREF(w);
@@ -296,7 +295,7 @@ PyRun_SimpleFile(fp, filename)
296295
Py_OptimizeFlag = 1;
297296
v = run_pyc_file(fp, filename, d, d);
298297
} else {
299-
v = PyRun_File(fp, filename, file_input, d, d);
298+
v = PyRun_File(fp, filename, Py_file_input, d, d);
300299
}
301300
if (v == NULL) {
302301
PyErr_Print();
@@ -316,7 +315,7 @@ PyRun_SimpleString(command)
316315
if (m == NULL)
317316
return -1;
318317
d = PyModule_GetDict(m);
319-
v = PyRun_String(command, file_input, d, d);
318+
v = PyRun_String(command, Py_file_input, d, d);
320319
if (v == NULL) {
321320
PyErr_Print();
322321
return -1;

0 commit comments

Comments
 (0)