summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Include/pythonrun.h4
-rw-r--r--Modules/main.c7
-rw-r--r--Python/bltinmodule.c5
-rw-r--r--Python/pythonrun.c40
4 files changed, 41 insertions, 15 deletions
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index 0528702..bbf2903a 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -29,9 +29,11 @@ DL_IMPORT(PyThreadState *) Py_NewInterpreter(void);
DL_IMPORT(void) Py_EndInterpreter(PyThreadState *);
DL_IMPORT(int) PyRun_AnyFile(FILE *, char *);
+DL_IMPORT(int) PyRun_AnyFileEx(FILE *, char *, int);
DL_IMPORT(int) PyRun_SimpleString(char *);
DL_IMPORT(int) PyRun_SimpleFile(FILE *, char *);
+DL_IMPORT(int) PyRun_SimpleFileEx(FILE *, char *, int);
DL_IMPORT(int) PyRun_InteractiveOne(FILE *, char *);
DL_IMPORT(int) PyRun_InteractiveLoop(FILE *, char *);
@@ -40,6 +42,8 @@ DL_IMPORT(struct _node *) PyParser_SimpleParseFile(FILE *, char *, int);
DL_IMPORT(PyObject *) PyRun_String(char *, int, PyObject *, PyObject *);
DL_IMPORT(PyObject *) PyRun_File(FILE *, char *, int, PyObject *, PyObject *);
+DL_IMPORT(PyObject *) PyRun_FileEx(FILE *, char *, int,
+ PyObject *, PyObject *, int);
DL_IMPORT(PyObject *) Py_CompileString(char *, char *, int);
diff --git a/Modules/main.c b/Modules/main.c
index 34e99b9..9afe80b 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -268,11 +268,10 @@ Py_Main(int argc, char **argv)
}
}
}
- sts = PyRun_AnyFile(
+ sts = PyRun_AnyFileEx(
fp,
- filename == NULL ? "<stdin>" : filename) != 0;
- if (filename != NULL)
- fclose(fp);
+ filename == NULL ? "<stdin>" : filename,
+ filename != NULL) != 0;
}
if (inspect && stdin_is_interactive &&
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index ea1269e..c2a7499 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -815,10 +815,7 @@ builtin_execfile(PyObject *self, PyObject *args)
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
- res = PyRun_File(fp, filename, Py_file_input, globals, locals);
- Py_BEGIN_ALLOW_THREADS
- fclose(fp);
- Py_END_ALLOW_THREADS
+ res = PyRun_FileEx(fp, filename, Py_file_input, globals, locals, 1);
return res;
}
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index e951ccd..56b3ba8 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -450,12 +450,22 @@ initsite(void)
int
PyRun_AnyFile(FILE *fp, char *filename)
{
+ return PyRun_AnyFileEx(fp, filename, 0);
+}
+
+int
+PyRun_AnyFileEx(FILE *fp, char *filename, int closeit)
+{
if (filename == NULL)
filename = "???";
- if (Py_FdIsInteractive(fp, filename))
- return PyRun_InteractiveLoop(fp, filename);
+ if (Py_FdIsInteractive(fp, filename)) {
+ int err = PyRun_InteractiveLoop(fp, filename);
+ if (closeit)
+ fclose(fp);
+ return err;
+ }
else
- return PyRun_SimpleFile(fp, filename);
+ return PyRun_SimpleFileEx(fp, filename, closeit);
}
int
@@ -542,6 +552,12 @@ PyRun_InteractiveOne(FILE *fp, char *filename)
int
PyRun_SimpleFile(FILE *fp, char *filename)
{
+ return PyRun_SimpleFileEx(fp, filename, 0);
+}
+
+int
+PyRun_SimpleFileEx(FILE *fp, char *filename, int closeit)
+{
PyObject *m, *d, *v;
char *ext;
@@ -558,7 +574,8 @@ PyRun_SimpleFile(FILE *fp, char *filename)
#endif /* macintosh */
) {
/* Try to run a pyc file. First, re-open in binary */
- /* Don't close, done in main: fclose(fp); */
+ if (closeit)
+ fclose(fp);
if( (fp = fopen(filename, "rb")) == NULL ) {
fprintf(stderr, "python: Can't reopen .pyc file\n");
return -1;
@@ -568,7 +585,7 @@ PyRun_SimpleFile(FILE *fp, char *filename)
Py_OptimizeFlag = 1;
v = run_pyc_file(fp, filename, d, d);
} else {
- v = PyRun_File(fp, filename, Py_file_input, d, d);
+ v = PyRun_FileEx(fp, filename, Py_file_input, d, d, closeit);
}
if (v == NULL) {
PyErr_Print();
@@ -845,8 +862,17 @@ PyObject *
PyRun_File(FILE *fp, char *filename, int start, PyObject *globals,
PyObject *locals)
{
- return run_err_node(PyParser_SimpleParseFile(fp, filename, start),
- filename, globals, locals);
+ PyRun_FileEx(fp, filename, start, globals, locals, 0);
+}
+
+PyObject *
+PyRun_FileEx(FILE *fp, char *filename, int start, PyObject *globals,
+ PyObject *locals, int closeit)
+{
+ node *n = PyParser_SimpleParseFile(fp, filename, start);
+ if (closeit)
+ fclose(fp);
+ return run_err_node(n, filename, globals, locals);
}
static PyObject *
re_8_3_1_synthetic Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* see loghobbs1999-12-121-0/+17
* *** empty log message ***hobbs1999-12-121-1/+2
* * unix/configure.in:hobbs1999-12-123-76/+4
* * tests/info.test:hobbs1999-12-123-21/+35
* * tests/var.test:hobbs1999-12-129-72/+140
* see loghobbs1999-12-121-0/+34
* * win/tclWin32Dll.c:hobbs1999-12-0911-2038/+158
* * doc/exec.n:hobbs1999-12-092-64/+2
* see loghobbs1999-12-091-0/+19
* * unix/Makefile.in: fixed make gendate to swap const with CONSThobbs1999-12-081-3/+3
* * tests/io.test: removed 'knownBug' tests that were forhobbs1999-12-081-68/+1
* * mac/tclMacPort.h: added utime.h includehobbs1999-12-081-1/+2
* * generic/tclDate.c:hobbs1999-12-083-24/+26
* see loghobbs1999-12-081-1/+19
* Winhelp should build more cleanly now.wart1999-12-071-4/+4
* Don't build winhelp as part of the doc: target. Now we use a separate "winhe...wart1999-12-071-2/+4
* Added "doc" target to the Makefile that will build the winhelp fileswart1999-12-063-5/+44
* Added #define around include of <errno.h> so that systems with thewart1999-12-061-1/+4
* Changed version number from "82" to "83"wart1999-12-061-2/+2
* check for whitespace after bad octalshobbs1999-12-041-1/+4
* * tests/env.test: removed knownBug limitation from working testhobbs1999-12-046-13/+36
* * library/http2.1/http.tcl: fixed error handling in http::Eventhobbs1999-12-043-12/+9
* * tests/expr-old.test:hobbs1999-12-047-363/+257
* * doc/load.n: added note about NT's buggy handling of './' withhobbs1999-12-041-1/+8
* see loghobbs1999-12-041-1/+41
* * generic/tcl.decls :redman1999-12-02