[Python-checkins] CVS: python/dist/src/Python bltinmodule.c,2.216,2.217 ceval.c,2.261,2.262 compile.c,2.206,2.207 future.c,2.6,2.7 pythonrun.c,2.134,2.135
Tim Peters
tim_one@users.sourceforge.net
Sun, 15 Jul 2001 19:29:47 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv30317/python/dist/src/Python
Modified Files:
bltinmodule.c ceval.c compile.c future.c pythonrun.c
Log Message:
Part way to allowing "from __future__ import generators" to communicate
that info to code dynamically compiled *by* code compiled with generators
enabled. Doesn't yet work because there's still no way to tell the parser
that "yield" is OK (unlike nested_scopes, the parser has its fingers in
this too).
Replaced PyEval_GetNestedScopes by a more-general
PyEval_MergeCompilerFlags. Perhaps I should not have? I doubted it was
*intended* to be part of the public API, so just did.
Index: bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.216
retrieving revision 2.217
diff -C2 -r2.216 -r2.217
*** bltinmodule.c 2001/07/09 12:30:54 2.216
--- bltinmodule.c 2001/07/16 02:29:45 2.217
***************
*** 394,397 ****
--- 394,398 ----
char *startstr;
int start;
+ PyCompilerFlags cf;
if (!PyArg_ParseTuple(args, "sss:compile", &str, &filename, &startstr))
***************
*** 408,416 ****
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);
}
--- 409,416 ----
return NULL;
}
! cf.cf_flags = 0;
! if (PyEval_MergeCompilerFlags(&cf))
return Py_CompileStringFlags(str, filename, start, &cf);
! else
return Py_CompileString(str, filename, start);
}
***************
*** 823,826 ****
--- 823,827 ----
PyObject *res;
FILE* fp;
+ PyCompilerFlags cf;
if (!PyArg_ParseTuple(args, "s|O!O!:execfile",
***************
*** 848,857 ****
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);
--- 849,857 ----
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.261
retrieving revision 2.262
diff -C2 -r2.261 -r2.262
*** ceval.c 2001/07/12 13:27:49 2.261
--- ceval.c 2001/07/16 02:29:45 2.262
***************
*** 2525,2529 ****
/* 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;
--- 2525,2529 ----
/* 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;
***************
*** 2907,2915 ****
int
! PyEval_GetNestedScopes(void)
{
PyFrameObject *current_frame = PyThreadState_Get()->frame;
! return current_frame == NULL ? 0 :
! current_frame->f_code->co_flags & CO_NESTED;
}
--- 2907,2927 ----
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;
}
***************
*** 3731,3754 ****
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);
}
--- 3743,3765 ----
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.206
retrieving revision 2.207
diff -C2 -r2.206 -r2.207
*** compile.c 2001/06/28 01:52:22 2.206
--- compile.c 2001/07/16 02:29:45 2.207
***************
*** 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) {
--- 3954,3966 ----
}
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;
--- 4432,4441 ----
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.6
retrieving revision 2.7
diff -C2 -r2.6 -r2.7
*** future.c 2001/07/15 21:08:29 2.6
--- future.c 2001/07/16 02:29:45 2.7
***************
*** 33,37 ****
ff->ff_nested_scopes = 1;
} else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
! /* OK; this is processed by the parser */
} else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
--- 33,37 ----
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,
***************
*** 234,237 ****
--- 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.134
retrieving revision 2.135
diff -C2 -r2.134 -r2.135
*** pythonrun.c 2001/06/13 17:18:06 2.134
--- pythonrun.c 2001/07/16 02:29:45 2.135
***************
*** 495,499 ****
if (flags == NULL) {
flags = &local_flags;
! local_flags.cf_nested_scopes = 0;
}
v = PySys_GetObject("ps1");
--- 495,499 ----
if (flags == NULL) {
flags = &local_flags;
! local_flags.cf_flags = 0;
}
v = PySys_GetObject("ps1");
***************
*** 1076,1083 ****
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
}
--- 1076,1087 ----
if (v && flags) {
if (co->co_flags & CO_NESTED)
! flags->cf_flags |= PyCF_NESTED_SCOPES;
! if (co->co_flags & CO_GENERATOR)
! 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
}