mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Instead of importing graminit.h whenever one of the three grammar 'root'
symbols is needed, define these in Python.h with a Py_ prefix.
This commit is contained in:
parent
8813b58ffa
commit
b05a5c7698
7 changed files with 39 additions and 21 deletions
|
@ -112,4 +112,10 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "pyfpe.h"
|
#include "pyfpe.h"
|
||||||
|
|
||||||
|
/* These definitions much match corresponding definitions in graminit.h.
|
||||||
|
There's code in compile.c that checks that they are the same. */
|
||||||
|
#define Py_single_input 256
|
||||||
|
#define Py_file_input 257
|
||||||
|
#define Py_eval_input 258
|
||||||
|
|
||||||
#endif /* !Py_PYTHON_H */
|
#endif /* !Py_PYTHON_H */
|
||||||
|
|
|
@ -58,7 +58,6 @@ static char cPickle_module_documentation[] =
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "cStringIO.h"
|
#include "cStringIO.h"
|
||||||
#include "graminit.h"
|
|
||||||
#include "mymath.h"
|
#include "mymath.h"
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -1883,7 +1882,7 @@ PyImport_ImportModuleNi(char *module_name)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(import =
|
if (!(import =
|
||||||
PyRun_String(import_str, eval_input, eval_dict, eval_dict))) {
|
PyRun_String(import_str, Py_eval_input, eval_dict, eval_dict))) {
|
||||||
free(import_str);
|
free(import_str);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2223,7 +2222,7 @@ load_string(Unpicklerobject *self) {
|
||||||
UNLESS(eval_dict = Py_BuildValue("{s{}}", "__builtins__"))
|
UNLESS(eval_dict = Py_BuildValue("{s{}}", "__builtins__"))
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
||||||
UNLESS(str = PyRun_String(s, eval_input, eval_dict, eval_dict))
|
UNLESS(str = PyRun_String(s, Py_eval_input, eval_dict, eval_dict))
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
||||||
if (PyList_Append(self->stack, str) < 0)
|
if (PyList_Append(self->stack, str) < 0)
|
||||||
|
@ -3870,6 +3869,10 @@ initcPickle() {
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 2.5 1997/05/07 17:46:13 guido
|
||||||
|
Instead of importing graminit.h whenever one of the three grammar 'root'
|
||||||
|
symbols is needed, define these in Python.h with a Py_ prefix.
|
||||||
|
|
||||||
Revision 2.4 1997/04/09 17:47:47 guido
|
Revision 2.4 1997/04/09 17:47:47 guido
|
||||||
Give PyErr_Format a new name and make it static.
|
Give PyErr_Format a new name and make it static.
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "graminit.h"
|
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
|
|
||||||
|
@ -283,11 +282,11 @@ builtin_compile(self, args)
|
||||||
if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
|
if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (strcmp(startstr, "exec") == 0)
|
if (strcmp(startstr, "exec") == 0)
|
||||||
start = file_input;
|
start = Py_file_input;
|
||||||
else if (strcmp(startstr, "eval") == 0)
|
else if (strcmp(startstr, "eval") == 0)
|
||||||
start = eval_input;
|
start = Py_eval_input;
|
||||||
else if (strcmp(startstr, "single") == 0)
|
else if (strcmp(startstr, "single") == 0)
|
||||||
start = single_input;
|
start = Py_single_input;
|
||||||
else {
|
else {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
"compile() mode must be 'exec' or 'eval' or 'single'");
|
"compile() mode must be 'exec' or 'eval' or 'single'");
|
||||||
|
@ -521,7 +520,7 @@ builtin_eval(self, args)
|
||||||
}
|
}
|
||||||
while (*str == ' ' || *str == '\t')
|
while (*str == ' ' || *str == '\t')
|
||||||
str++;
|
str++;
|
||||||
return PyRun_String(str, eval_input, globals, locals);
|
return PyRun_String(str, Py_eval_input, globals, locals);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -558,7 +557,7 @@ builtin_execfile(self, args)
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
res = PyRun_File(fp, filename, file_input, globals, locals);
|
res = PyRun_File(fp, filename, Py_file_input, globals, locals);
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
@ -882,7 +881,7 @@ builtin_input(self, args)
|
||||||
PyEval_GetBuiltins()) != 0)
|
PyEval_GetBuiltins()) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
res = PyRun_String(str, eval_input, globals, locals);
|
res = PyRun_String(str, Py_eval_input, globals, locals);
|
||||||
Py_DECREF(line);
|
Py_DECREF(line);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "frameobject.h"
|
#include "frameobject.h"
|
||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
#include "opcode.h"
|
#include "opcode.h"
|
||||||
#include "graminit.h"
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
@ -2637,7 +2636,8 @@ exec_statement(f, prog, globals, locals)
|
||||||
if (PyFile_Check(prog)) {
|
if (PyFile_Check(prog)) {
|
||||||
FILE *fp = PyFile_AsFile(prog);
|
FILE *fp = PyFile_AsFile(prog);
|
||||||
char *name = PyString_AsString(PyFile_Name(prog));
|
char *name = PyString_AsString(PyFile_Name(prog));
|
||||||
if (PyRun_File(fp, name, file_input, globals, locals) == NULL)
|
if (PyRun_File(fp, name, Py_file_input,
|
||||||
|
globals, locals) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2647,7 +2647,7 @@ exec_statement(f, prog, globals, locals)
|
||||||
"embedded '\\0' in exec string");
|
"embedded '\\0' in exec string");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
v = PyRun_String(s, file_input, globals, locals);
|
v = PyRun_String(s, Py_file_input, globals, locals);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
|
|
|
@ -58,6 +58,20 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/* Three symbols from graminit.h are also defined in Python.h, with
|
||||||
|
Py_ prefixes to their names. Python.h can't include graminit.h
|
||||||
|
(which defines too many confusing symbols), but we can check here
|
||||||
|
that they haven't changed (which is very unlikely, but possible). */
|
||||||
|
#if Py_single_input != single_input
|
||||||
|
#error "single_input has changed -- update Py_single_input in Python.h"
|
||||||
|
#endif
|
||||||
|
#if Py_file_input != file_input
|
||||||
|
#error "file_input has changed -- update Py_file_input in Python.h"
|
||||||
|
#endif
|
||||||
|
#if Py_eval_input != eval_input
|
||||||
|
#error "eval_input has changed -- update Py_eval_input in Python.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
int Py_OptimizeFlag = 0;
|
int Py_OptimizeFlag = 0;
|
||||||
|
|
||||||
#define OP_DELETE 0
|
#define OP_DELETE 0
|
||||||
|
|
|
@ -35,7 +35,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "token.h"
|
#include "token.h"
|
||||||
#include "graminit.h"
|
|
||||||
#include "errcode.h"
|
#include "errcode.h"
|
||||||
#include "marshal.h"
|
#include "marshal.h"
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
|
@ -43,8 +42,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "osdefs.h"
|
#include "osdefs.h"
|
||||||
#include "importdl.h"
|
#include "importdl.h"
|
||||||
#ifdef macintosh
|
#ifdef macintosh
|
||||||
/* 'argument' is a grammar symbol, but also used in some mac header files */
|
|
||||||
#undef argument
|
|
||||||
#include "macglue.h"
|
#include "macglue.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -317,7 +314,7 @@ parse_source_module(pathname, fp)
|
||||||
PyCodeObject *co;
|
PyCodeObject *co;
|
||||||
node *n;
|
node *n;
|
||||||
|
|
||||||
n = PyParser_SimpleParseFile(fp, pathname, file_input);
|
n = PyParser_SimpleParseFile(fp, pathname, Py_file_input);
|
||||||
if (n == NULL)
|
if (n == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
co = PyNode_Compile(n, pathname);
|
co = PyNode_Compile(n, pathname);
|
||||||
|
|
|
@ -36,7 +36,6 @@ PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "grammar.h"
|
#include "grammar.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "parsetok.h"
|
#include "parsetok.h"
|
||||||
#include "graminit.h"
|
|
||||||
#undef argument /* Avoid conflict on Mac */
|
#undef argument /* Avoid conflict on Mac */
|
||||||
#include "errcode.h"
|
#include "errcode.h"
|
||||||
#include "compile.h"
|
#include "compile.h"
|
||||||
|
@ -237,7 +236,7 @@ PyRun_InteractiveOne(fp, filename)
|
||||||
}
|
}
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
|
n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
|
||||||
single_input, ps1, ps2, &err);
|
Py_single_input, ps1, ps2, &err);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
Py_XDECREF(w);
|
Py_XDECREF(w);
|
||||||
|
@ -296,7 +295,7 @@ PyRun_SimpleFile(fp, filename)
|
||||||
Py_OptimizeFlag = 1;
|
Py_OptimizeFlag = 1;
|
||||||
v = run_pyc_file(fp, filename, d, d);
|
v = run_pyc_file(fp, filename, d, d);
|
||||||
} else {
|
} else {
|
||||||
v = PyRun_File(fp, filename, file_input, d, d);
|
v = PyRun_File(fp, filename, Py_file_input, d, d);
|
||||||
}
|
}
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
|
@ -316,7 +315,7 @@ PyRun_SimpleString(command)
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
d = PyModule_GetDict(m);
|
d = PyModule_GetDict(m);
|
||||||
v = PyRun_String(command, file_input, d, d);
|
v = PyRun_String(command, Py_file_input, d, d);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue