[Python-checkins] CVS: python/dist/src/Python pythonmain.c,NONE,2.30.2.1 bltinmodule.c,2.198.2.8,2.198.2.9 ceval.c,2.241.2.8,2.241.2.9 compile.c,2.197.2.1,2.197.2.2 future.c,2.5,2.5.6.1 pythonrun.c,2.133.4.4,2.133.4.5
Tim Peters
tim_one@users.sourceforge.net
2001年7月16日 14:42:49 -0700
- Previous message: [Python-checkins] CVS: python/dist/src/Parser parser.c,2.18,2.18.8.1 parser.h,2.14,2.14.8.1 parsetok.c,2.25,2.25.8.1
- Next message: [Python-checkins] CVS: python/dist/src/Modules Setup.guido,NONE,2.7.2.1 Setup.irix4,NONE,1.1.4.1 Setup.irix5,NONE,2.6.2.1 Setup.minix,NONE,2.3.2.1 Setup.solaris2,NONE,1.1.4.1 Setup.sunos4,NONE,1.1.4.1 imgformat.c,NONE,2.1.2.1 version.c,NONE,2.2.2.1 main.c,1.52.4.1,1.52.4.2 mmapmodule.c,2.28.2.1,2.28.2.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv12359/descr/dist/src/Python
Modified Files:
Tag: descr-branch
bltinmodule.c ceval.c compile.c future.c pythonrun.c
Added Files:
Tag: descr-branch
pythonmain.c
Log Message:
Resuming interrupted merge checkin.
--- NEW FILE: pythonmain.c ---
/***********************************************************
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Python interpreter main program */
#include "allobjects.h"
extern int debugging; /* Needed in parser.c, declared in pythonrun.c */
extern int verbose; /* Needed in import.c, declared in pythonrun.c */
extern int suppress_print; /* Needed in ceval.c, declared in pythonrun.c */
/* Interface to getopt(): */
extern int optind;
extern char *optarg;
extern int getopt(); /* PROTO((int, char **, char *)); -- not standardized */
extern char *getenv();
extern char *getversion();
extern char *getcopyright();
int
realmain(argc, argv)
int argc;
char **argv;
{
int c;
int sts;
char *command = NULL;
char *filename = NULL;
FILE *fp = stdin;
char *p;
int inspect = 0;
int unbuffered = 0;
if ((p = getenv("PYTHONDEBUG")) && *p != '0円')
debugging = 1;
if ((p = getenv("PYTHONSUPPRESS")) && *p != '0円')
suppress_print = 1;
if ((p = getenv("PYTHONVERBOSE")) && *p != '0円')
verbose = 1;
if ((p = getenv("PYTHONINSPECT")) && *p != '0円')
inspect = 1;
if ((p = getenv("PYTHONUNBUFFERED")) && *p != '0円')
unbuffered = 1;
#ifdef macintosh
PyMac_InteractiveOptions(&inspect, &verbose, &suppress_print, &unbuffered, &debugging);
#endif
while ((c = getopt(argc, argv, "c:disuv")) != EOF) {
if (c == 'c') {
/* -c is the last option; following arguments
that look like options are left for the
the command to interpret. */
command = malloc(strlen(optarg) + 2);
if (command == NULL)
fatal("not enough memory to copy -c argument");
strcpy(command, optarg);
strcat(command, "\n");
break;
}
switch (c) {
case 'd':
debugging++;
break;
case 'i':
inspect++;
break;
case 's':
suppress_print++;
break;
case 'u':
unbuffered++;
break;
case 'v':
verbose++;
break;
/* This space reserved for other options */
default:
fprintf(stderr,
"usage: %s [-d] [-i] [-s] [-u ] [-v] [-c cmd | file | -] [arg] ...\n",
argv[0]);
#if !(defined(__CFM68K__) && defined(__MWERKS__))
/* Mwerks cfm68k linker doesn't like these... */
fprintf(stderr, "\
\n\
Options and arguments (and corresponding environment variables):\n\
-d : debug output from parser (also PYTHONDEBUG=x)\n\
-i : inspect interactively after running script (also PYTHONINSPECT=x)\n\
-s : suppress the printing of top level expressions (also PYTHONSUPPRESS=x)\n\
-u : unbuffered stdout and stderr (also PYTHONUNBUFFERED=x)\n\
-v : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
-c cmd : program passed in as string (terminates option list)\n\
");
/* ANSI does not allow strings > 512 chars
and MPW doesn't like it either -- so split it! */
fprintf(stderr, "\
file : program read from script file\n\
- : program read from stdin (default; interactive mode if a tty)\n\
arg ...: arguments passed to program in sys.argv[1:]\n\
\n\
Other environment variables:\n\
PYTHONSTARTUP: file executed on interactive startup (no default)\n\
PYTHONPATH : colon-separated list of directories prefixed to the\n\
default module search path. The result is sys.path.\n\
");
#endif /* !cfm68k || !mwerks */
exit(2);
/*NOTREACHED*/
}
}
if (unbuffered) {
#ifndef MPW
setbuf(stdout, (char *)NULL);
setbuf(stderr, (char *)NULL);
#else
/* On MPW (3.2) unbuffered seems to hang */
setvbuf(stdout, (char *)NULL, _IOLBF, BUFSIZ);
setvbuf(stderr, (char *)NULL, _IOLBF, BUFSIZ);
#endif
}
if (command == NULL && optind < argc && strcmp(argv[optind], "-") != 0)
filename = argv[optind];
if (verbose ||
command == NULL && filename == NULL && isatty((int)fileno(fp)))
fprintf(stderr, "Python %s\n%s\n",
getversion(), getcopyright());
if (filename != NULL) {
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "%s: can't open file '%s'\n",
argv[0], filename);
exit(2);
}
}
initall();
if (command != NULL) {
/* Backup optind and force sys.argv[0] = '-c' */
optind--;
argv[optind] = "-c";
}
setpythonargv(argc-optind, argv+optind);
if (command) {
sts = run_command(command) != 0;
}
else {
if (filename == NULL && isatty((int)fileno(fp))) {
char *startup = getenv("PYTHONSTARTUP");
#ifdef macintosh
if (startup == NULL)
startup = "PythonStartup";
#endif
if (startup != NULL && startup[0] != '0円') {
FILE *fp = fopen(startup, "r");
if (fp != NULL) {
(void) run_script(fp, startup);
err_clear();
fclose(fp);
}
}
}
sts = run(fp, filename == NULL ? "<stdin>" : filename) != 0;
if (filename != NULL)
fclose(fp);
}
if (inspect && isatty((int)fileno(stdin)) &&
(filename != NULL || command != NULL))
sts = run(stdin, "<stdin>") != 0;
goaway(sts);
/*NOTREACHED*/
}
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.198.2.8
retrieving revision 2.198.2.9
diff -C2 -r2.198.2.8 -r2.198.2.9
*** bltinmodule.c 2001年07月14日 07:47:35 2.198.2.8
--- bltinmodule.c 2001年07月16日 21:42:46 2.198.2.9
***************
*** 374,377 ****
--- 374,378 ----
char *startstr;
int start;
+ PyCompilerFlags cf;
if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
***************
*** 388,396 ****
return NULL;
}
! if (PyEval_GetNestedScopes()) {
! PyCompilerFlags cf;
! cf.cf_nested_scopes = 1;
return Py_CompileStringFlags(str, filename, start, &cf);
! } else
return Py_CompileString(str, filename, start);
}
--- 389,396 ----
return NULL;
}
! cf.cf_flags = 0;
! if (PyEval_MergeCompilerFlags(&cf))
return Py_CompileStringFlags(str, filename, start, &cf);
! else
return Py_CompileString(str, filename, start);
}
***************
*** 552,555 ****
--- 552,556 ----
PyObject *res;
FILE* fp;
+ PyCompilerFlags cf;
if (!PyArg_ParseTuple(args, "s|O!O!:execfile",
***************
*** 577,586 ****
return NULL;
}
! if (PyEval_GetNestedScopes()) {
! PyCompilerFlags cf;
! cf.cf_nested_scopes = 1;
res = PyRun_FileExFlags(fp, filename, Py_file_input, globals,
locals, 1, &cf);
! } else
res = PyRun_FileEx(fp, filename, Py_file_input, globals,
locals, 1);
--- 578,586 ----
return NULL;
}
! cf.cf_flags = 0;
! if (PyEval_MergeCompilerFlags(&cf))
res = PyRun_FileExFlags(fp, filename, Py_file_input, globals,
locals, 1, &cf);
! else
res = PyRun_FileEx(fp, filename, Py_file_input, globals,
locals, 1);
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.241.2.8
retrieving revision 2.241.2.9
diff -C2 -r2.241.2.8 -r2.241.2.9
*** ceval.c 2001年07月14日 07:47:35 2.241.2.8
--- ceval.c 2001年07月16日 21:42:46 2.241.2.9
***************
*** 2508,2512 ****
/* Don't need to keep the reference to f_back, it will be set
* when the generator is resumed. */
! Py_DECREF(f->f_back);
f->f_back = NULL;
--- 2508,2512 ----
/* Don't need to keep the reference to f_back, it will be set
* when the generator is resumed. */
! Py_XDECREF(f->f_back);
f->f_back = NULL;
***************
*** 2890,2898 ****
int
! PyEval_GetNestedScopes(void)
{
PyFrameObject *current_frame = PyThreadState_Get()->frame;
! return current_frame == NULL ? 0 :
! current_frame->f_code->co_flags & CO_NESTED;
}
--- 2890,2910 ----
int
! PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
{
PyFrameObject *current_frame = PyThreadState_Get()->frame;
! int result = 0;
!
! if (current_frame != NULL) {
! const int codeflags = current_frame->f_code->co_flags;
! if (codeflags & CO_NESTED) {
! result = 1;
! cf->cf_flags |= PyCF_NESTED_SCOPES;
! }
! if (codeflags & CO_GENERATOR_ALLOWED) {
! result = 1;
! cf->cf_flags |= PyCF_GENERATORS;
! }
! }
! return result;
}
***************
*** 3677,3700 ****
FILE *fp = PyFile_AsFile(prog);
char *name = PyString_AsString(PyFile_Name(prog));
! if (PyEval_GetNestedScopes()) {
! PyCompilerFlags cf;
! cf.cf_nested_scopes = 1;
v = PyRun_FileFlags(fp, name, Py_file_input, globals,
locals, &cf);
! } else {
v = PyRun_File(fp, name, Py_file_input, globals,
locals);
- }
}
else {
char *str;
if (PyString_AsStringAndSize(prog, &str, NULL))
return -1;
! if (PyEval_GetNestedScopes()) {
! PyCompilerFlags cf;
! cf.cf_nested_scopes = 1;
v = PyRun_StringFlags(str, Py_file_input, globals,
locals, &cf);
! } else
v = PyRun_String(str, Py_file_input, globals, locals);
}
--- 3689,3711 ----
FILE *fp = PyFile_AsFile(prog);
char *name = PyString_AsString(PyFile_Name(prog));
! PyCompilerFlags cf;
! cf.cf_flags = 0;
! if (PyEval_MergeCompilerFlags(&cf))
v = PyRun_FileFlags(fp, name, Py_file_input, globals,
locals, &cf);
! else
v = PyRun_File(fp, name, Py_file_input, globals,
locals);
}
else {
char *str;
+ PyCompilerFlags cf;
if (PyString_AsStringAndSize(prog, &str, NULL))
return -1;
! cf.cf_flags = 0;
! if (PyEval_MergeCompilerFlags(&cf))
v = PyRun_StringFlags(str, Py_file_input, globals,
locals, &cf);
! else
v = PyRun_String(str, Py_file_input, globals, locals);
}
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.197.2.1
retrieving revision 2.197.2.2
diff -C2 -r2.197.2.1 -r2.197.2.2
*** compile.c 2001年07月07日 22:55:30 2.197.2.1
--- compile.c 2001年07月16日 21:42:46 2.197.2.2
***************
*** 3946,3949 ****
--- 3946,3950 ----
|| (sc.c_symtable->st_cur->ste_type == TYPE_FUNCTION))
sc.c_nested = 1;
+ sc.c_flags |= base->c_flags & CO_GENERATOR_ALLOWED;
} else {
sc.c_private = NULL;
***************
*** 3954,3961 ****
}
if (flags) {
! if (flags->cf_nested_scopes)
sc.c_future->ff_nested_scopes = 1;
else if (sc.c_future->ff_nested_scopes)
! flags->cf_nested_scopes = 1;
}
if (symtable_build(&sc, n) < 0) {
--- 3955,3967 ----
}
if (flags) {
! if (flags->cf_flags & PyCF_NESTED_SCOPES)
sc.c_future->ff_nested_scopes = 1;
else if (sc.c_future->ff_nested_scopes)
! flags->cf_flags |= PyCF_NESTED_SCOPES;
!
! if (flags->cf_flags & PyCF_GENERATORS)
! sc.c_future->ff_generators = 1;
! else if (sc.c_future->ff_generators)
! flags->cf_flags |= PyCF_GENERATORS;
}
if (symtable_build(&sc, n) < 0) {
***************
*** 4427,4432 ****
struct symbol_info *si)
{
! if (c->c_future && c->c_future->ff_nested_scopes)
! c->c_flags |= CO_NESTED;
if (ste->ste_generator)
c->c_flags |= CO_GENERATOR;
--- 4433,4442 ----
struct symbol_info *si)
{
! if (c->c_future) {
! if (c->c_future->ff_nested_scopes)
! c->c_flags |= CO_NESTED;
! if (c->c_future->ff_generators)
! c->c_flags |= CO_GENERATOR_ALLOWED;
! }
if (ste->ste_generator)
c->c_flags |= CO_GENERATOR;
Index: future.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/future.c,v
retrieving revision 2.5
retrieving revision 2.5.6.1
diff -C2 -r2.5 -r2.5.6.1
*** future.c 2001年03月10日 02:15:37 2.5
--- future.c 2001年07月16日 21:42:46 2.5.6.1
***************
*** 32,35 ****
--- 32,37 ----
if (strcmp(feature, FUTURE_NESTED_SCOPES) == 0) {
ff->ff_nested_scopes = 1;
+ } else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
+ ff->ff_generators = 1;
} else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
***************
*** 232,235 ****
--- 234,238 ----
ff->ff_last_lineno = -1;
ff->ff_nested_scopes = 0;
+ ff->ff_generators = 0;
if (future_parse(ff, n, filename) < 0) {
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.133.4.4
retrieving revision 2.133.4.5
diff -C2 -r2.133.4.4 -r2.133.4.5
*** pythonrun.c 2001年07月07日 22:55:31 2.133.4.4
--- pythonrun.c 2001年07月16日 21:42:47 2.133.4.5
***************
*** 498,502 ****
if (flags == NULL) {
flags = &local_flags;
! local_flags.cf_nested_scopes = 0;
}
v = PySys_GetObject("ps1");
--- 498,502 ----
if (flags == NULL) {
flags = &local_flags;
! local_flags.cf_flags = 0;
}
v = PySys_GetObject("ps1");
***************
*** 537,540 ****
--- 537,541 ----
perrdetail err;
char *ps1 = "", *ps2 = "";
+
v = PySys_GetObject("ps1");
if (v != NULL) {
***************
*** 553,558 ****
ps2 = PyString_AsString(w);
}
! n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,
! Py_single_input, ps1, ps2, &err);
Py_XDECREF(v);
Py_XDECREF(w);
--- 554,562 ----
ps2 = PyString_AsString(w);
}
! n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar,
! Py_single_input, ps1, ps2, &err,
! (flags &&
! flags->cf_flags & PyCF_GENERATORS) ?
! PyPARSE_YIELD_IS_KEYWORD : 0);
Py_XDECREF(v);
Py_XDECREF(w);
***************
*** 1005,1009 ****
PyCompilerFlags *flags)
{
! return run_err_node(PyParser_SimpleParseString(str, start),
"<string>", globals, locals, flags);
}
--- 1009,1016 ----
PyCompilerFlags *flags)
{
! return run_err_node(PyParser_SimpleParseStringFlags(
! str, start,
! (flags && flags->cf_flags & PyCF_GENERATORS) ?
! PyPARSE_YIELD_IS_KEYWORD : 0),
"<string>", globals, locals, flags);
}
***************
*** 1021,1025 ****
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
! node *n = PyParser_SimpleParseFile(fp, filename, start);
if (closeit)
fclose(fp);
--- 1028,1034 ----
PyObject *locals, int closeit, PyCompilerFlags *flags)
{
! node *n = PyParser_SimpleParseFileFlags(fp, filename, start,
! (flags && flags->cf_flags & PyCF_GENERATORS) ?
! PyPARSE_YIELD_IS_KEYWORD : 0);
if (closeit)
fclose(fp);
***************
*** 1079,1086 ****
if (v && flags) {
if (co->co_flags & CO_NESTED)
! flags->cf_nested_scopes = 1;
#if 0
fprintf(stderr, "run_pyc_file: nested_scopes: %d\n",
! flags->cf_nested_scopes);
#endif
}
--- 1088,1099 ----
if (v && flags) {
if (co->co_flags & CO_NESTED)
! flags->cf_flags |= PyCF_NESTED_SCOPES;
! if (co->co_flags & CO_GENERATOR_ALLOWED)
! flags->cf_flags |= PyCF_GENERATORS;
#if 0
fprintf(stderr, "run_pyc_file: nested_scopes: %d\n",
! flags->cf_flags & PyCF_NESTED_SCOPES);
! fprintf(stderr, "run_pyc_file: generators: %d\n",
! flags->cf_flags & PyCF_GENERATORS);
#endif
}
***************
*** 1101,1105 ****
node *n;
PyCodeObject *co;
! n = PyParser_SimpleParseString(str, start);
if (n == NULL)
return NULL;
--- 1114,1120 ----
node *n;
PyCodeObject *co;
! n = PyParser_SimpleParseStringFlags(str, start,
! (flags && flags->cf_flags & PyCF_GENERATORS) ?
! PyPARSE_YIELD_IS_KEYWORD : 0);
if (n == NULL)
return NULL;
***************
*** 1125,1134 ****
node *
! PyParser_SimpleParseFile(FILE *fp, char *filename, int start)
{
node *n;
perrdetail err;
! n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar, start,
! (char *)0, (char *)0, &err);
if (n == NULL)
err_input(&err);
--- 1140,1149 ----
node *
! PyParser_SimpleParseFileFlags(FILE *fp, char *filename, int start, int flags)
{
node *n;
perrdetail err;
! n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, start,
! (char *)0, (char *)0, &err, flags);
if (n == NULL)
err_input(&err);
***************
*** 1136,1150 ****
}
/* Simplified interface to parsestring -- return node or set exception */
node *
! PyParser_SimpleParseString(char *str, int start)
{
node *n;
perrdetail err;
! n = PyParser_ParseString(str, &_PyParser_Grammar, start, &err);
if (n == NULL)
err_input(&err);
return n;
}
--- 1151,1178 ----
}
+ node *
+ PyParser_SimpleParseFile(FILE *fp, char *filename, int start)
+ {
+ return PyParser_SimpleParseFileFlags(fp, filename, start, 0);
+ }
+
/* Simplified interface to parsestring -- return node or set exception */
node *
! PyParser_SimpleParseStringFlags(char *str, int start, int flags)
{
node *n;
perrdetail err;
! n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, start, &err,
! flags);
if (n == NULL)
err_input(&err);
return n;
+ }
+
+ node *
+ PyParser_SimpleParseString(char *str, int start)
+ {
+ return PyParser_SimpleParseStringFlags(str, start, 0);
}
- Previous message: [Python-checkins] CVS: python/dist/src/Parser parser.c,2.18,2.18.8.1 parser.h,2.14,2.14.8.1 parsetok.c,2.25,2.25.8.1
- Next message: [Python-checkins] CVS: python/dist/src/Modules Setup.guido,NONE,2.7.2.1 Setup.irix4,NONE,1.1.4.1 Setup.irix5,NONE,2.6.2.1 Setup.minix,NONE,2.3.2.1 Setup.solaris2,NONE,1.1.4.1 Setup.sunos4,NONE,1.1.4.1 imgformat.c,NONE,2.1.2.1 version.c,NONE,2.2.2.1 main.c,1.52.4.1,1.52.4.2 mmapmodule.c,2.28.2.1,2.28.2.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]