symbols is needed, define these in Python.h with a Py_ prefix.
#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 */
#include "Python.h"
#include "cStringIO.h"
-#include "graminit.h"
#include "mymath.h"
#include <errno.h>
return NULL;
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);
return NULL;
}
UNLESS(eval_dict = Py_BuildValue("{s{}}", "__builtins__"))
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;
if (PyList_Append(self->stack, str) < 0)
/****************************************************************************
$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
Give PyErr_Format a new name and make it static.
#include "Python.h"
#include "node.h"
-#include "graminit.h"
#include "compile.h"
#include "eval.h"
if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
return NULL;
if (strcmp(startstr, "exec") == 0)
- start = file_input;
+ start = Py_file_input;
else if (strcmp(startstr, "eval") == 0)
- start = eval_input;
+ start = Py_eval_input;
else if (strcmp(startstr, "single") == 0)
- start = single_input;
+ start = Py_single_input;
else {
PyErr_SetString(PyExc_ValueError,
"compile() mode must be 'exec' or 'eval' or 'single'");
}
while (*str == ' ' || *str == '\t')
str++;
- return PyRun_String(str, eval_input, globals, locals);
+ return PyRun_String(str, Py_eval_input, globals, locals);
}
static PyObject *
PyErr_SetFromErrno(PyExc_IOError);
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
fclose(fp);
Py_END_ALLOW_THREADS
PyEval_GetBuiltins()) != 0)
return NULL;
}
- res = PyRun_String(str, eval_input, globals, locals);
+ res = PyRun_String(str, Py_eval_input, globals, locals);
Py_DECREF(line);
return res;
}
#include "frameobject.h"
#include "eval.h"
#include "opcode.h"
-#include "graminit.h"
#include <ctype.h>
if (PyFile_Check(prog)) {
FILE *fp = PyFile_AsFile(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 0;
}
"embedded '\\0' in exec string");
return -1;
}
- v = PyRun_String(s, file_input, globals, locals);
+ v = PyRun_String(s, Py_file_input, globals, locals);
if (v == NULL)
return -1;
Py_DECREF(v);
#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;
#define OP_DELETE 0
#include "node.h"
#include "token.h"
-#include "graminit.h"
#include "errcode.h"
#include "marshal.h"
#include "compile.h"
#include "osdefs.h"
#include "importdl.h"
#ifdef macintosh
-/* 'argument' is a grammar symbol, but also used in some mac header files */
-#undef argument
#include "macglue.h"
#endif
PyCodeObject *co;
node *n;
- n = PyParser_SimpleParseFile(fp, pathname, file_input);
+ n = PyParser_SimpleParseFile(fp, pathname, Py_file_input);
if (n == NULL)
return NULL;
co = PyNode_Compile(n, pathname);
#include "grammar.h"
#include "node.h"
#include "parsetok.h"
-#include "graminit.h"
#undef argument /* Avoid conflict on Mac */
#include "errcode.h"
#include "compile.h"
}
Py_BEGIN_ALLOW_THREADS
n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
- single_input, ps1, ps2, &err);
+ Py_single_input, ps1, ps2, &err);
Py_END_ALLOW_THREADS
Py_XDECREF(v);
Py_XDECREF(w);
Py_OptimizeFlag = 1;
v = run_pyc_file(fp, filename, d, d);
} else {
- v = PyRun_File(fp, filename, file_input, d, d);
+ v = PyRun_File(fp, filename, Py_file_input, d, d);
}
if (v == NULL) {
PyErr_Print();
if (m == NULL)
return -1;
d = PyModule_GetDict(m);
- v = PyRun_String(command, file_input, d, d);
+ v = PyRun_String(command, Py_file_input, d, d);
if (v == NULL) {
PyErr_Print();
return -1;