Mercurial > cpython-lru_cache-weakref
annotate Python/pythonrun.c @ 62743:2145593d108d legacy-trunk v2.7
move sections
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 03 Jul 2010 13:57:30 +0000 |
| parents | bd5f5df7ed78 |
| children | 55397533da51 |
| rev | line source |
|---|---|
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Python interpreter top-level routines, including init/exit */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
4 #include "Python.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
6 #include "Python-ast.h" |
|
41526
708c8c5fc173
Make pythoncore compile cleanly with VisualStudio 2005. Used an explicit typecast to get a 64 bit integer, and undefined the Yield macro that conflicts with winbase.h
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
41128
diff
changeset
|
7 #undef Yield /* undefine macro conflicting with winbase.h */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 #include "grammar.h" |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #include "node.h" |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
10 #include "token.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #include "parsetok.h" |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #include "errcode.h" |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
13 #include "code.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 #include "compile.h" |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
15 #include "symtable.h" |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
35961
diff
changeset
|
16 #include "pyarena.h" |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
17 #include "ast.h" |
| 926 | 18 #include "eval.h" |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
19 #include "marshal.h" |
|
56645
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
20 #include "abstract.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38455
diff
changeset
|
22 #ifdef HAVE_SIGNAL_H |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
23 #include <signal.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
38455
diff
changeset
|
24 #endif |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
25 |
|
50462
68c9f8b6584d
fix compilation on non-Windows platforms
Benjamin Peterson <benjamin@python.org>
parents:
50460
diff
changeset
|
26 #ifdef MS_WINDOWS |
|
50460
636a0ac9607b
Issue #4075: Use OutputDebugStringW in Py_FatalError.
Martin v. Löwis <martin@v.loewis.de>
parents:
49818
diff
changeset
|
27 #include "malloc.h" /* for alloca */ |
|
50462
68c9f8b6584d
fix compilation on non-Windows platforms
Benjamin Peterson <benjamin@python.org>
parents:
50460
diff
changeset
|
28 #endif |
|
50460
636a0ac9607b
Issue #4075: Use OutputDebugStringW in Py_FatalError.
Martin v. Löwis <martin@v.loewis.de>
parents:
49818
diff
changeset
|
29 |
|
28174
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
30 #ifdef HAVE_LANGINFO_H |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
31 #include <locale.h> |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
32 #include <langinfo.h> |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
33 #endif |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
34 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
35 #ifdef MS_WINDOWS |
|
2529
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
36 #undef BYTE |
|
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
37 #include "windows.h" |
|
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
38 #endif |
|
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
39 |
|
36837
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
40 #ifndef Py_REF_DEBUG |
|
37290
89142cadcfb9
In format strings slinging Py_ssize_t, unconditionally
Tim Peters <tim.peters@gmail.com>
parents:
37229
diff
changeset
|
41 #define PRINT_TOTAL_REFS() |
|
36837
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
42 #else /* Py_REF_DEBUG */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
43 #define PRINT_TOTAL_REFS() fprintf(stderr, \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
44 "[%" PY_FORMAT_SIZE_T "d refs]\n", \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
45 _Py_GetRefTotal()) |
|
36837
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
46 #endif |
|
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
47 |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
48 #ifdef __cplusplus |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
49 extern "C" { |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
50 #endif |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
51 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
52 extern char *Py_GetPath(void); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
54 extern grammar _PyParser_Grammar; /* From graminit.c */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
1391
7c3245c18677
* ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
56 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
57 static void initmain(void); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
58 static void initsite(void); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
59 static PyObject *run_mod(mod_ty, const char *, PyObject *, PyObject *, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
60 PyCompilerFlags *, PyArena *); |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
61 static PyObject *run_pyc_file(FILE *, const char *, PyObject *, PyObject *, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
62 PyCompilerFlags *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
63 static void err_input(perrdetail *); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
64 static void initsigs(void); |
|
56645
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
65 static void wait_for_thread_shutdown(void); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
66 static void call_sys_exitfunc(void); |
|
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
67 static void call_ll_exitfuncs(void); |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
68 extern void _PyUnicode_Init(void); |
|
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
69 extern void _PyUnicode_Fini(void); |
|
11977
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
70 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
71 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
72 extern void _PyGILState_Init(PyInterpreterState *, PyThreadState *); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
73 extern void _PyGILState_Fini(void); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
74 #endif /* WITH_THREAD */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
75 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
76 int Py_DebugFlag; /* Needed by parser.c */ |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
77 int Py_VerboseFlag; /* Needed by import.c */ |
|
5108
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
78 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
|
41043
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
79 int Py_InspectFlag; /* Needed to determine whether to exit at SystemError */ |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
80 int Py_NoSiteFlag; /* Suppress 'import site' */ |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45891
diff
changeset
|
81 int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */ |
|
44566
599f22a349a2
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
Georg Brandl <georg@python.org>
parents:
44063
diff
changeset
|
82 int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */ |
|
12555
04cf788d862b
Py_UseClassExceptionsFlag is deprecated. We keep the C variable for C
Barry Warsaw <barry@python.org>
parents:
12539
diff
changeset
|
83 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
84 int Py_FrozenFlag; /* Needed by getpath.c */ |
| 12539 | 85 int Py_UnicodeFlag = 0; /* Needed by compile.c */ |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
86 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ |
|
21251
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21077
diff
changeset
|
87 /* _XXX Py_QnewFlag should go away in 2.3. It's true iff -Qnew is passed, |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21077
diff
changeset
|
88 on the command line, and is used in 2.2 by ceval.c to make all "/" divisions |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21077
diff
changeset
|
89 true divisions (which they will be in 2.3). */ |
|
45e1177424e1
SF bug #488514: -Qnew needs work
Tim Peters <tim.peters@gmail.com>
parents:
21077
diff
changeset
|
90 int _Py_QnewFlag = 0; |
|
46698
1a2dbc84bdfc
Implemented PEP 370
Christian Heimes <christian@cheimes.de>
parents:
46414
diff
changeset
|
91 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
46414
840064802952
Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents:
46123
diff
changeset
|
93 /* PyModule_GetWarningsModule is no longer necessary as of 2.6 |
|
840064802952
Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents:
46123
diff
changeset
|
94 since _warnings is builtin. This API should not be used. */ |
|
840064802952
Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents:
46123
diff
changeset
|
95 PyObject * |
|
840064802952
Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents:
46123
diff
changeset
|
96 PyModule_GetWarningsModule(void) |
|
29877
72cbc41ccc2f
Fix [ 771097 ] frozen programs fail due to implicit import of "warnings".
Mark Hammond <mhammond@skippinet.com.au>
parents:
28720
diff
changeset
|
97 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
98 return PyImport_ImportModule("warnings"); |
|
29877
72cbc41ccc2f
Fix [ 771097 ] frozen programs fail due to implicit import of "warnings".
Mark Hammond <mhammond@skippinet.com.au>
parents:
28720
diff
changeset
|
99 } |
|
27958
e07b21ea3c45
Fix bug 683658 - PyErr_Warn may cause import deadlock.
Mark Hammond <mhammond@skippinet.com.au>
parents:
27878
diff
changeset
|
100 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
101 static int initialized = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13552
diff
changeset
|
103 /* API to access the initialized flag -- useful for esoteric use */ |
|
6136
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
104 |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
105 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
106 Py_IsInitialized(void) |
|
6136
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
107 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
108 return initialized; |
|
6136
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
109 } |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
110 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
111 /* Global initializations. Can be undone by Py_Finalize(). Don't |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
112 call this twice without an intervening Py_Finalize() call. When |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
113 initializations fail, a fatal error is issued and the function does |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
114 not return. On return, the first thread and interpreter state have |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
115 been created. |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
117 Locking: you must hold the interpreter lock while calling this. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
118 (If the lock has not yet been initialized, that's equivalent to |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
119 having the lock, but you cannot use multiple threads.) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
120 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
121 */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
122 |
|
20401
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
123 static int |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
124 add_flag(int flag, const char *envs) |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
125 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
126 int env = atoi(envs); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
127 if (flag < env) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
128 flag = env; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
129 if (flag < 1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
130 flag = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
131 return flag; |
|
20401
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
132 } |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
133 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
134 void |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
135 Py_InitializeEx(int install_sigs) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
136 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
137 PyInterpreterState *interp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
138 PyThreadState *tstate; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
139 PyObject *bimod, *sysmod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
140 char *p; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
141 char *icodeset = NULL; /* On Windows, input codeset may theoretically |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
142 differ from output codeset. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
143 char *codeset = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
144 char *errors = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
145 int free_codeset = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
146 int overridden = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
147 PyObject *sys_stream, *sys_isatty; |
|
30108
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
148 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
149 char *saved_locale, *loc_codeset; |
|
30108
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
150 #endif |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
151 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
152 char ibuf[128]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
153 char buf[128]; |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
154 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
155 extern void _Py_ReadyTypes(void); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
156 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
157 if (initialized) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
158 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
159 initialized = 1; |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
160 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
161 if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
162 Py_DebugFlag = add_flag(Py_DebugFlag, p); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
163 if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
164 Py_VerboseFlag = add_flag(Py_VerboseFlag, p); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
165 if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
166 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
167 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
168 Py_DontWriteBytecodeFlag = add_flag(Py_DontWriteBytecodeFlag, p); |
|
5850
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
169 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
170 interp = PyInterpreterState_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
171 if (interp == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
172 Py_FatalError("Py_Initialize: can't make first interpreter"); |
|
5850
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
173 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
174 tstate = PyThreadState_New(interp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
175 if (tstate == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
176 Py_FatalError("Py_Initialize: can't make first thread"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
177 (void) PyThreadState_Swap(tstate); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
178 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
179 _Py_ReadyTypes(); |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
180 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
181 if (!_PyFrame_Init()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
182 Py_FatalError("Py_Initialize: can't init frames"); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
183 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
184 if (!_PyInt_Init()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
185 Py_FatalError("Py_Initialize: can't init ints"); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
186 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
187 if (!_PyLong_Init()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
188 Py_FatalError("Py_Initialize: can't init longs"); |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
50462
diff
changeset
|
189 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
190 if (!PyByteArray_Init()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
191 Py_FatalError("Py_Initialize: can't init bytearray"); |
|
46107
5341b30b1812
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45891
diff
changeset
|
192 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
193 _PyFloat_Init(); |
| 34972 | 194 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
195 interp->modules = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
196 if (interp->modules == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
197 Py_FatalError("Py_Initialize: can't make modules dictionary"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
198 interp->modules_reloading = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
199 if (interp->modules_reloading == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
200 Py_FatalError("Py_Initialize: can't make modules_reloading dictionary"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
201 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19296
diff
changeset
|
202 #ifdef Py_USING_UNICODE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
203 /* Init Unicode implementation; relies on the codec registry */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
204 _PyUnicode_Init(); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19296
diff
changeset
|
205 #endif |
|
11977
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
206 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
207 bimod = _PyBuiltin_Init(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
208 if (bimod == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
209 Py_FatalError("Py_Initialize: can't initialize __builtin__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
210 interp->builtins = PyModule_GetDict(bimod); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
211 if (interp->builtins == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
212 Py_FatalError("Py_Initialize: can't initialize builtins dict"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
213 Py_INCREF(interp->builtins); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
214 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
215 sysmod = _PySys_Init(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
216 if (sysmod == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
217 Py_FatalError("Py_Initialize: can't initialize sys"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
218 interp->sysdict = PyModule_GetDict(sysmod); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
219 if (interp->sysdict == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
220 Py_FatalError("Py_Initialize: can't initialize sys dict"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
221 Py_INCREF(interp->sysdict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
222 _PyImport_FixupExtension("sys", "sys"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
223 PySys_SetPath(Py_GetPath()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
224 PyDict_SetItemString(interp->sysdict, "modules", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
225 interp->modules); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
226 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
227 _PyImport_Init(); |
|
11113
be8ec828c072
Marc-Andre Lemburg discovered that the switch from .pyc to .pyo files,
Guido van Rossum <guido@python.org>
parents:
10534
diff
changeset
|
228 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
229 /* initialize builtin exceptions */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
230 _PyExc_Init(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
231 _PyImport_FixupExtension("exceptions", "exceptions"); |
|
12754
5213abfe5230
Py_Initialize(): Now that standard exceptions are builtin, we don't
Barry Warsaw <barry@python.org>
parents:
12576
diff
changeset
|
232 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
233 /* phase 2 of builtins */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
234 _PyImport_FixupExtension("__builtin__", "__builtin__"); |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
235 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
236 _PyImportHooks_Init(); |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26643
diff
changeset
|
237 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
238 if (install_sigs) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
239 initsigs(); /* Signal handling stuff, including initintr() */ |
|
61274
95c400b9d74c
Change to a Py_XDECREF and fix some whitespace.
Brett Cannon <bcannon@gmail.com>
parents:
59499
diff
changeset
|
240 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
241 /* Initialize warnings. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
242 _PyWarnings_Init(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
243 if (PySys_HasWarnOptions()) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
244 PyObject *warnings_module = PyImport_ImportModule("warnings"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
245 if (!warnings_module) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
246 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
247 Py_XDECREF(warnings_module); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
248 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
249 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
250 initmain(); /* Module __main__ */ |
|
28065
c61ef183ce2f
Addendum to #683658:
Just van Rossum <just@letterror.com>
parents:
27958
diff
changeset
|
251 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
252 /* auto-thread-state API, if available */ |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
253 #ifdef WITH_THREAD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
254 _PyGILState_Init(interp, tstate); |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
255 #endif /* WITH_THREAD */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
256 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
257 if (!Py_NoSiteFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
258 initsite(); /* Module site */ |
|
59499
4468666d01c4
Issue #3137: Don't ignore errors at startup, especially a keyboard interrupt
Victor Stinner <victor.stinner@haypocalc.com>
parents:
56645
diff
changeset
|
259 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
260 if ((p = Py_GETENV("PYTHONIOENCODING")) && *p != '\0') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
261 p = icodeset = codeset = strdup(p); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
262 free_codeset = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
263 errors = strchr(p, ':'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
264 if (errors) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
265 *errors = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
266 errors++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
267 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
268 overridden = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
269 } |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
270 |
|
28174
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
271 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
272 /* On Unix, set the file system encoding according to the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
273 user's preference, if the CODESET names a well-known |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
274 Python codec, and Py_FileSystemDefaultEncoding isn't |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
275 initialized by other means. Also set the encoding of |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
276 stdin and stdout if these are terminals, unless overridden. */ |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
277 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
278 if (!overridden || !Py_FileSystemDefaultEncoding) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
279 saved_locale = strdup(setlocale(LC_CTYPE, NULL)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
280 setlocale(LC_CTYPE, ""); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
281 loc_codeset = nl_langinfo(CODESET); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
282 if (loc_codeset && *loc_codeset) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
283 PyObject *enc = PyCodec_Encoder(loc_codeset); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
284 if (enc) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
285 loc_codeset = strdup(loc_codeset); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
286 Py_DECREF(enc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
287 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
288 if (PyErr_ExceptionMatches(PyExc_LookupError)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
289 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
290 loc_codeset = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
291 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
292 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
293 exit(1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
294 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
295 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
296 } else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
297 loc_codeset = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
298 setlocale(LC_CTYPE, saved_locale); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
299 free(saved_locale); |
|
30108
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
300 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
301 if (!overridden) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
302 codeset = icodeset = loc_codeset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
303 free_codeset = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
304 } |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
305 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
306 /* Initialize Py_FileSystemDefaultEncoding from |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
307 locale even if PYTHONIOENCODING is set. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
308 if (!Py_FileSystemDefaultEncoding) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
309 Py_FileSystemDefaultEncoding = loc_codeset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
310 if (!overridden) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
311 free_codeset = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
312 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
313 } |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
314 #endif |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
315 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
316 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
317 if (!overridden) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
318 icodeset = ibuf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
319 codeset = buf; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
320 sprintf(ibuf, "cp%d", GetConsoleCP()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
321 sprintf(buf, "cp%d", GetConsoleOutputCP()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
322 } |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
323 #endif |
|
30108
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
324 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
325 if (codeset) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
326 sys_stream = PySys_GetObject("stdin"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
327 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
328 if (!sys_isatty) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
329 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
330 if ((overridden || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
331 (sys_isatty && PyObject_IsTrue(sys_isatty))) && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
332 PyFile_Check(sys_stream)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
333 if (!PyFile_SetEncodingAndErrors(sys_stream, icodeset, errors)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
334 Py_FatalError("Cannot set codeset of stdin"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
335 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
336 Py_XDECREF(sys_isatty); |
|
30108
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
337 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
338 sys_stream = PySys_GetObject("stdout"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
339 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
340 if (!sys_isatty) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
341 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
342 if ((overridden || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
343 (sys_isatty && PyObject_IsTrue(sys_isatty))) && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
344 PyFile_Check(sys_stream)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
345 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
346 Py_FatalError("Cannot set codeset of stdout"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
347 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
348 Py_XDECREF(sys_isatty); |
|
30108
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
349 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
350 sys_stream = PySys_GetObject("stderr"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
351 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
352 if (!sys_isatty) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
353 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
354 if((overridden || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
355 (sys_isatty && PyObject_IsTrue(sys_isatty))) && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
356 PyFile_Check(sys_stream)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
357 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
358 Py_FatalError("Cannot set codeset of stderr"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
359 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
360 Py_XDECREF(sys_isatty); |
|
37423
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
361 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
362 if (free_codeset) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
363 free(codeset); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
364 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
365 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
366 |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
367 void |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
368 Py_Initialize(void) |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
369 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
370 Py_InitializeEx(1); |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
371 } |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
372 |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
373 |
|
9641
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
374 #ifdef COUNT_ALLOCS |
|
37831
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
375 extern void dump_counts(FILE*); |
|
9641
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
376 #endif |
|
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
377 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
378 /* Undo the effect of Py_Initialize(). |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
379 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
380 Beware: if multiple interpreter and/or thread states exist, these |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
381 are not wiped out; only the current thread and interpreter state |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
382 are deleted. But since everything else is deleted, those other |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
383 interpreter and thread states should no longer be used. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
384 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
385 (XXX We should do better, e.g. wipe out all interpreters and |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
386 threads.) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
387 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
388 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
389 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
390 */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
391 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
392 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
393 Py_Finalize(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
394 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
395 PyInterpreterState *interp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
396 PyThreadState *tstate; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
397 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
398 if (!initialized) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
399 return; |
|
16073
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
400 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
401 wait_for_thread_shutdown(); |
|
56645
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
402 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
403 /* The interpreter is still entirely intact at this point, and the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
404 * exit funcs may be relying on that. In particular, if some thread |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
405 * or exit func is still waiting to do an import, the import machinery |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
406 * expects Py_IsInitialized() to return true. So don't say the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
407 * interpreter is uninitialized until after the exit funcs have run. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
408 * Note that Threading.py uses an exit func to do a join on all the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
409 * threads created thru it, so this also protects pending imports in |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
410 * the threads created via Threading. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
411 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
412 call_sys_exitfunc(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
413 initialized = 0; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
414 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
415 /* Get current thread state and interpreter pointer */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
416 tstate = PyThreadState_GET(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
417 interp = tstate->interp; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
418 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
419 /* Disable signal handling */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
420 PyOS_FiniInterrupts(); |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
421 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
422 /* Clear type lookup cache */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
423 PyType_ClearCache(); |
|
45025
ea3fe302d392
Added clear cache methods to clear the internal type lookup cache for ref leak test runs.
Christian Heimes <christian@cheimes.de>
parents:
44566
diff
changeset
|
424 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
425 /* Collect garbage. This may call finalizers; it's nice to call these |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
426 * before all modules are destroyed. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
427 * XXX If a __del__ or weakref callback is triggered here, and tries to |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
428 * XXX import a module, bad things can happen, because Python no |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
429 * XXX longer believes it's initialized. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
430 * XXX Fatal Python error: Interpreter not initialized (version mismatch?) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
431 * XXX is easy to provoke that way. I've also seen, e.g., |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
432 * XXX Exception exceptions.ImportError: 'No module named sha' |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
433 * XXX in <function callback at 0x008F5718> ignored |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
434 * XXX but I'm unclear on exactly how that one happens. In any case, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
435 * XXX I haven't seen a real-life report of either of these. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
436 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
437 PyGC_Collect(); |
|
37831
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
438 #ifdef COUNT_ALLOCS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
439 /* With COUNT_ALLOCS, it helps to run GC multiple times: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
440 each collection might release some types from the type |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
441 list, so they become garbage. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
442 while (PyGC_Collect() > 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
443 /* nothing */; |
|
37831
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
444 #endif |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
445 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
446 /* Destroy all modules */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
447 PyImport_Cleanup(); |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
448 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
449 /* Collect final garbage. This disposes of cycles created by |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
450 * new-style class definitions, for example. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
451 * XXX This is disabled because it caused too many problems. If |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
452 * XXX a __del__ or weakref callback triggers here, Python code has |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
453 * XXX a hard time running, because even the sys module has been |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
454 * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc). |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
455 * XXX One symptom is a sequence of information-free messages |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
456 * XXX coming from threads (if a __del__ or callback is invoked, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
457 * XXX other threads can execute too, and any exception they encounter |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
458 * XXX triggers a comedy of errors as subsystem after subsystem |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
459 * XXX fails to find what it *expects* to find in sys to help report |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
460 * XXX the exception and consequent unexpected failures). I've also |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
461 * XXX seen segfaults then, after adding print statements to the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
462 * XXX Python code getting called. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
463 */ |
|
31057
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
464 #if 0 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
465 PyGC_Collect(); |
|
31057
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
466 #endif |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
467 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
468 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
469 _PyImport_Fini(); |
|
6786
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
470 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
471 /* Debugging stuff */ |
|
6786
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
472 #ifdef COUNT_ALLOCS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
473 dump_counts(stdout); |
|
6786
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
474 #endif |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
475 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
476 PRINT_TOTAL_REFS(); |
|
6786
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
477 |
|
28647
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
478 #ifdef Py_TRACE_REFS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
479 /* Display all objects still alive -- this can invoke arbitrary |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
480 * __repr__ overrides, so requires a mostly-intact interpreter. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
481 * Alas, a lot of stuff may still be alive now that will be cleaned |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
482 * up later. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
483 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
484 if (Py_GETENV("PYTHONDUMPREFS")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
485 _Py_PrintReferences(stderr); |
|
28647
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
486 #endif /* Py_TRACE_REFS */ |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
487 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
488 /* Clear interpreter state */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
489 PyInterpreterState_Clear(interp); |
|
28613
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
490 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
491 /* Now we decref the exception classes. After this point nothing |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
492 can raise an exception. That's okay, because each Fini() method |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
493 below has been checked to make sure no exceptions are ever |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
494 raised. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
495 */ |
|
34834
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
496 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
497 _PyExc_Fini(); |
|
34834
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
498 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
499 /* Cleanup auto-thread-state */ |
|
44063
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
500 #ifdef WITH_THREAD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
501 _PyGILState_Fini(); |
|
44063
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
502 #endif /* WITH_THREAD */ |
|
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
503 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
504 /* Delete current thread */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
505 PyThreadState_Swap(NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
506 PyInterpreterState_Delete(interp); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
507 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
508 /* Sundry finalizers */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
509 PyMethod_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
510 PyFrame_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
511 PyCFunction_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
512 PyTuple_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
513 PyList_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
514 PySet_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
515 PyString_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
516 PyByteArray_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
517 PyInt_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
518 PyFloat_Fini(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
519 PyDict_Fini(); |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
520 |
|
22883
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
521 #ifdef Py_USING_UNICODE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
522 /* Cleanup Unicode implementation */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
523 _PyUnicode_Fini(); |
|
22883
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
524 #endif |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
525 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
526 /* XXX Still allocated: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
527 - various static ad-hoc pointers to interned strings |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
528 - int and float free list blocks |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
529 - whatever various modules and libraries allocate |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
530 */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
531 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
532 PyGrammar_RemoveAccelerators(&_PyParser_Grammar); |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
533 |
|
28653
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
534 #ifdef Py_TRACE_REFS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
535 /* Display addresses (& refcnts) of all objects still alive. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
536 * An address can be used to find the repr of the object, printed |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
537 * above by _Py_PrintReferences. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
538 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
539 if (Py_GETENV("PYTHONDUMPREFS")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
540 _Py_PrintReferenceAddresses(stderr); |
|
28653
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
541 #endif /* Py_TRACE_REFS */ |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
542 #ifdef PYMALLOC_DEBUG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
543 if (Py_GETENV("PYTHONMALLOCSTATS")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
544 _PyObject_DebugMallocStats(); |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
545 #endif |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
546 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
547 call_ll_exitfuncs(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
548 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
549 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
550 /* Create and initialize a new interpreter and thread, and return the |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
551 new thread. This requires that Py_Initialize() has been called |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
552 first. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
553 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
554 Unsuccessful initialization yields a NULL pointer. Note that *no* |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
555 exception information is available even in this case -- the |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
556 exception information is held in the thread, and there is no |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
557 thread. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
558 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
559 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
560 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
561 */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
562 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
563 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
564 Py_NewInterpreter(void) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
565 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
566 PyInterpreterState *interp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
567 PyThreadState *tstate, *save_tstate; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
568 PyObject *bimod, *sysmod; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
569 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
570 if (!initialized) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
571 Py_FatalError("Py_NewInterpreter: call Py_Initialize first"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
572 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
573 interp = PyInterpreterState_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
574 if (interp == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
575 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
576 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
577 tstate = PyThreadState_New(interp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
578 if (tstate == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
579 PyInterpreterState_Delete(interp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
580 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
581 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
582 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
583 save_tstate = PyThreadState_Swap(tstate); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
584 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
585 /* XXX The following is lax in error checking */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
586 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
587 interp->modules = PyDict_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
588 interp->modules_reloading = PyDict_New(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
589 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
590 bimod = _PyImport_FindExtension("__builtin__", "__builtin__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
591 if (bimod != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
592 interp->builtins = PyModule_GetDict(bimod); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
593 if (interp->builtins == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
594 goto handle_error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
595 Py_INCREF(interp->builtins); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
596 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
597 sysmod = _PyImport_FindExtension("sys", "sys"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
598 if (bimod != NULL && sysmod != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
599 interp->sysdict = PyModule_GetDict(sysmod); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
600 if (interp->sysdict == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
601 goto handle_error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
602 Py_INCREF(interp->sysdict); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
603 PySys_SetPath(Py_GetPath()); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
604 PyDict_SetItemString(interp->sysdict, "modules", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
605 interp->modules); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
606 _PyImportHooks_Init(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
607 initmain(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
608 if (!Py_NoSiteFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
609 initsite(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
610 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
611 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
612 if (!PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
613 return tstate; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
614 |
|
39614
9dee81dcb9b4
Handle a few more error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39458
diff
changeset
|
615 handle_error: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
616 /* Oops, it didn't work. Undo it all. */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
617 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
618 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
619 PyThreadState_Clear(tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
620 PyThreadState_Swap(save_tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
621 PyThreadState_Delete(tstate); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
622 PyInterpreterState_Delete(interp); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
623 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
624 return NULL; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
625 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
626 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
627 /* Delete an interpreter and its last thread. This requires that the |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
628 given thread state is current, that the thread has no remaining |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
629 frames, and that it is its interpreter's only remaining thread. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
630 It is a fatal error to violate these constraints. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
631 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
632 (Py_Finalize() doesn't have these constraints -- it zaps |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
633 everything, regardless.) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
634 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
635 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
636 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
637 */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
638 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
639 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
640 Py_EndInterpreter(PyThreadState *tstate) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
641 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
642 PyInterpreterState *interp = tstate->interp; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
643 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
644 if (tstate != PyThreadState_GET()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
645 Py_FatalError("Py_EndInterpreter: thread is not current"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
646 if (tstate->frame != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
647 Py_FatalError("Py_EndInterpreter: thread still has a frame"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
648 if (tstate != interp->tstate_head || tstate->next != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
649 Py_FatalError("Py_EndInterpreter: not the last thread"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
650 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
651 PyImport_Cleanup(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
652 PyInterpreterState_Clear(interp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
653 PyThreadState_Swap(NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
654 PyInterpreterState_Delete(interp); |
|
5850
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
655 } |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
656 |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
657 static char *progname = "python"; |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
658 |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
659 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
660 Py_SetProgramName(char *pn) |
|
5850
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
661 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
662 if (pn && *pn) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
663 progname = pn; |
|
5850
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
664 } |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
665 |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
666 char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
667 Py_GetProgramName(void) |
|
5850
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
668 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
669 return progname; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
670 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
671 |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
672 static char *default_home = NULL; |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
673 |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
674 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
675 Py_SetPythonHome(char *home) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
676 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
677 default_home = home; |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
678 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
679 |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
680 char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
681 Py_GetPythonHome(void) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
682 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
683 char *home = default_home; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
684 if (home == NULL && !Py_IgnoreEnvironmentFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
685 home = Py_GETENV("PYTHONHOME"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
686 return home; |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
687 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
688 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
689 /* Create __main__ module */ |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
690 |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
691 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
692 initmain(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
693 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
694 PyObject *m, *d; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
695 m = PyImport_AddModule("__main__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
696 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
697 Py_FatalError("can't create __main__ module"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
698 d = PyModule_GetDict(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
699 if (PyDict_GetItemString(d, "__builtins__") == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
700 PyObject *bimod = PyImport_ImportModule("__builtin__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
701 if (bimod == NULL || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
702 PyDict_SetItemString(d, "__builtins__", bimod) != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
703 Py_FatalError("can't add __builtins__ to __main__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
704 Py_XDECREF(bimod); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
705 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
706 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
707 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
708 /* Import the site module (not into __main__ though) */ |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
709 |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
710 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
711 initsite(void) |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
712 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
713 PyObject *m; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
714 m = PyImport_ImportModule("site"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
715 if (m == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
716 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
717 Py_Finalize(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
718 exit(1); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
719 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
720 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
721 Py_DECREF(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
722 } |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
723 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
724 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 /* Parse input from a file and execute it */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
727 int |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
728 PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
729 PyCompilerFlags *flags) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
730 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
731 if (filename == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
732 filename = "???"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
733 if (Py_FdIsInteractive(fp, filename)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
734 int err = PyRun_InteractiveLoopFlags(fp, filename, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
735 if (closeit) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
736 fclose(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
737 return err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
738 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
739 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
740 return PyRun_SimpleFileExFlags(fp, filename, closeit, flags); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
741 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
742 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
743 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
744 PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
745 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
746 PyObject *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
747 int ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
748 PyCompilerFlags local_flags; |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
749 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
750 if (flags == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
751 flags = &local_flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
752 local_flags.cf_flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
753 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
754 v = PySys_GetObject("ps1"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
755 if (v == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
756 PySys_SetObject("ps1", v = PyString_FromString(">>> ")); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
757 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
758 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
759 v = PySys_GetObject("ps2"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
760 if (v == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
761 PySys_SetObject("ps2", v = PyString_FromString("... ")); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
762 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
763 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
764 for (;;) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
765 ret = PyRun_InteractiveOneFlags(fp, filename, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
766 PRINT_TOTAL_REFS(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
767 if (ret == E_EOF) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
768 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
769 /* |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
770 if (ret == E_NOMEM) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
771 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
772 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
773 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
775 |
|
45891
727f743cf630
Backport of the print function, using a __future__ import.
Eric Smith <eric@trueblade.com>
parents:
45389
diff
changeset
|
776 #if 0 |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22121
diff
changeset
|
777 /* compute parser flags based on compiler flags */ |
|
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22121
diff
changeset
|
778 #define PARSER_FLAGS(flags) \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
779 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
780 PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0) |
|
45891
727f743cf630
Backport of the print function, using a __future__ import.
Eric Smith <eric@trueblade.com>
parents:
45389
diff
changeset
|
781 #endif |
|
727f743cf630
Backport of the print function, using a __future__ import.
Eric Smith <eric@trueblade.com>
parents:
45389
diff
changeset
|
782 #if 1 |
|
39779
b8fbd322760a
with and as are now keywords. There are some generated files I can't recreate.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39614
diff
changeset
|
783 /* Keep an example of flags with future keyword support. */ |
|
b8fbd322760a
with and as are now keywords. There are some generated files I can't recreate.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39614
diff
changeset
|
784 #define PARSER_FLAGS(flags) \ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
785 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
786 PyPARSE_DONT_IMPLY_DEDENT : 0) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
787 | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
788 PyPARSE_PRINT_IS_FUNCTION : 0) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
789 | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
790 PyPARSE_UNICODE_LITERALS : 0) \ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
791 ) : 0) |
|
39779
b8fbd322760a
with and as are now keywords. There are some generated files I can't recreate.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39614
diff
changeset
|
792 #endif |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22121
diff
changeset
|
793 |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
794 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
795 PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags) |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
796 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
797 PyObject *m, *d, *v, *w; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
798 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
799 PyArena *arena; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
800 char *ps1 = "", *ps2 = ""; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
801 int errcode = 0; |
|
18615
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
802 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
803 v = PySys_GetObject("ps1"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
804 if (v != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
805 v = PyObject_Str(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
806 if (v == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
807 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
808 else if (PyString_Check(v)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
809 ps1 = PyString_AsString(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
810 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
811 w = PySys_GetObject("ps2"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
812 if (w != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
813 w = PyObject_Str(w); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
814 if (w == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
815 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
816 else if (PyString_Check(w)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
817 ps2 = PyString_AsString(w); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
818 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
819 arena = PyArena_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
820 if (arena == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
821 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
822 Py_XDECREF(w); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
823 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
824 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
825 mod = PyParser_ASTFromFile(fp, filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
826 Py_single_input, ps1, ps2, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
827 flags, &errcode, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
828 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
829 Py_XDECREF(w); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
830 if (mod == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
831 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
832 if (errcode == E_EOF) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
833 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
834 return E_EOF; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
835 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
836 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
837 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
838 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
839 m = PyImport_AddModule("__main__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
840 if (m == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
841 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
842 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
843 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
844 d = PyModule_GetDict(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
845 v = run_mod(mod, filename, d, d, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
846 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
847 if (v == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
848 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
849 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
850 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
851 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
852 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
853 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
854 return 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
855 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
856 |
|
15738
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
857 /* Check whether a file maybe a pyc file: Look at the extension, |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
858 the file type, and, if we may close it, at the first few bytes. */ |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
859 |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
860 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
861 maybe_pyc_file(FILE *fp, const char* filename, const char* ext, int closeit) |
|
15738
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
862 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
863 if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
864 return 1; |
|
15738
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
865 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
866 /* Only look into the file if we are allowed to close it, since |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
867 it then should also be seekable. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
868 if (closeit) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
869 /* Read only two bytes of the magic. If the file was opened in |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
870 text mode, the bytes 3 and 4 of the magic (\r\n) might not |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
871 be read as they are on disk. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
872 unsigned int halfmagic = PyImport_GetMagicNumber() & 0xFFFF; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
873 unsigned char buf[2]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
874 /* Mess: In case of -x, the stream is NOT at its start now, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
875 and ungetc() was used to push back the first newline, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
876 which makes the current stream position formally undefined, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
877 and a x-platform nightmare. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
878 Unfortunately, we have no direct way to know whether -x |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
879 was specified. So we use a terrible hack: if the current |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
880 stream position is not 0, we assume -x was specified, and |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
881 give up. Bug 132850 on SourceForge spells out the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
882 hopelessness of trying anything else (fseek and ftell |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
883 don't work predictably x-platform for text-mode files). |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
884 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
885 int ispyc = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
886 if (ftell(fp) == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
887 if (fread(buf, 1, 2, fp) == 2 && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
888 ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
889 ispyc = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
890 rewind(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
891 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
892 return ispyc; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
893 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
894 return 0; |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
895 } |
|
15738
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
896 |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
897 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
898 PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
899 PyCompilerFlags *flags) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
900 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
901 PyObject *m, *d, *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
902 const char *ext; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
903 int set_file_name = 0, ret, len; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
904 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
905 m = PyImport_AddModule("__main__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
906 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
907 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
908 d = PyModule_GetDict(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
909 if (PyDict_GetItemString(d, "__file__") == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
910 PyObject *f = PyString_FromString(filename); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
911 if (f == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
912 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
913 if (PyDict_SetItemString(d, "__file__", f) < 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
914 Py_DECREF(f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
915 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
916 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
917 set_file_name = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
918 Py_DECREF(f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
919 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
920 len = strlen(filename); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
921 ext = filename + len - (len > 4 ? 4 : 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
922 if (maybe_pyc_file(fp, filename, ext, closeit)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
923 /* Try to run a pyc file. First, re-open in binary */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
924 if (closeit) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
925 fclose(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
926 if ((fp = fopen(filename, "rb")) == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
927 fprintf(stderr, "python: Can't reopen .pyc file\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
928 ret = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
929 goto done; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
930 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
931 /* Turn on optimization if a .pyo file is given */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
932 if (strcmp(ext, ".pyo") == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
933 Py_OptimizeFlag = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
934 v = run_pyc_file(fp, filename, d, d, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
935 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
936 v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
937 closeit, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
938 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
939 if (v == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
940 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
941 ret = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
942 goto done; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
943 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
944 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
945 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
946 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
947 ret = 0; |
|
41044
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
948 done: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
949 if (set_file_name && PyDict_DelItemString(d, "__file__")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
950 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
951 return ret; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
952 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
953 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
954 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
955 PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags) |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
956 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
957 PyObject *m, *d, *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
958 m = PyImport_AddModule("__main__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
959 if (m == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
960 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
961 d = PyModule_GetDict(m); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
962 v = PyRun_StringFlags(command, Py_file_input, d, d, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
963 if (v == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
964 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
965 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
966 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
967 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
968 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
969 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
970 return 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
971 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
973 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
974 parse_syntax_error(PyObject *err, PyObject **message, const char **filename, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
975 int *lineno, int *offset, const char **text) |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
976 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
977 long hold; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
978 PyObject *v; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
979 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
980 /* old style errors */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
981 if (PyTuple_Check(err)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
982 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
983 lineno, offset, text); |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
984 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
985 /* new style errors. `err' is an instance */ |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
986 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
987 if (! (v = PyObject_GetAttrString(err, "msg"))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
988 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
989 *message = v; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
990 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
991 if (!(v = PyObject_GetAttrString(err, "filename"))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
992 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
993 if (v == Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
994 *filename = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
995 else if (! (*filename = PyString_AsString(v))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
996 goto finally; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
997 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
998 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
999 if (!(v = PyObject_GetAttrString(err, "lineno"))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1000 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1001 hold = PyInt_AsLong(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1002 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1003 v = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1004 if (hold < 0 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1005 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1006 *lineno = (int)hold; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1007 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1008 if (!(v = PyObject_GetAttrString(err, "offset"))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1009 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1010 if (v == Py_None) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1011 *offset = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1012 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1013 v = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1014 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1015 hold = PyInt_AsLong(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1016 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1017 v = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1018 if (hold < 0 && PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1019 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1020 *offset = (int)hold; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1021 } |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1022 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1023 if (!(v = PyObject_GetAttrString(err, "text"))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1024 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1025 if (v == Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1026 *text = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1027 else if (! (*text = PyString_AsString(v))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1028 goto finally; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1029 Py_DECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1030 return 1; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1031 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1032 finally: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1033 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1034 return 0; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1035 } |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1036 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1037 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1038 PyErr_Print(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1039 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1040 PyErr_PrintEx(1); |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1041 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1042 |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1043 static void |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1044 print_error_text(PyObject *f, int offset, const char *text) |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1045 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1046 char *nl; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1047 if (offset >= 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1048 if (offset > 0 && offset == (int)strlen(text)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1049 offset--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1050 for (;;) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1051 nl = strchr(text, '\n'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1052 if (nl == NULL || nl-text >= offset) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1053 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1054 offset -= (int)(nl+1-text); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1055 text = nl+1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1056 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1057 while (*text == ' ' || *text == '\t') { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1058 text++; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1059 offset--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1060 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1061 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1062 PyFile_WriteString(" ", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1063 PyFile_WriteString(text, f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1064 if (*text == '\0' || text[strlen(text)-1] != '\n') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1065 PyFile_WriteString("\n", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1066 if (offset == -1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1067 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1068 PyFile_WriteString(" ", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1069 offset--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1070 while (offset > 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1071 PyFile_WriteString(" ", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1072 offset--; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1073 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1074 PyFile_WriteString("^\n", f); |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1075 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1076 |
|
17212
215dc725db84
Finishing touch to Ping's changes. This is a patch that Ping sent me
Guido van Rossum <guido@python.org>
parents:
17207
diff
changeset
|
1077 static void |
|
215dc725db84
Finishing touch to Ping's changes. This is a patch that Ping sent me
Guido van Rossum <guido@python.org>
parents:
17207
diff
changeset
|
1078 handle_system_exit(void) |
|
17191
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1079 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1080 PyObject *exception, *value, *tb; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1081 int exitcode = 0; |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1082 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1083 if (Py_InspectFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1084 /* Don't exit if -i flag was given. This flag is set to 0 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1085 * when entering interactive mode for inspecting. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1086 return; |
|
41043
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
1087 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1088 PyErr_Fetch(&exception, &value, &tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1089 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1090 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1091 fflush(stdout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1092 if (value == NULL || value == Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1093 goto done; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1094 if (PyExceptionInstance_Check(value)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1095 /* The error code should be in the `code' attribute. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1096 PyObject *code = PyObject_GetAttrString(value, "code"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1097 if (code) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1098 Py_DECREF(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1099 value = code; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1100 if (value == Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1101 goto done; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1102 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1103 /* If we failed to dig out the 'code' attribute, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1104 just let the else clause below print the error. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1105 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1106 if (PyInt_Check(value)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1107 exitcode = (int)PyInt_AsLong(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1108 else { |
|
61920
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1109 PyObject *sys_stderr = PySys_GetObject("stderr"); |
|
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1110 if (sys_stderr != NULL && sys_stderr != Py_None) { |
|
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1111 PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); |
|
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1112 } else { |
|
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1113 PyObject_Print(value, stderr, Py_PRINT_RAW); |
|
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1114 fflush(stderr); |
|
bd5f5df7ed78
Issue #3798: Write sys.exit() message to sys.stderr to use stderr encoding and
Victor Stinner <victor.stinner@haypocalc.com>
parents:
61463
diff
changeset
|
1115 } |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1116 PySys_WriteStderr("\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1117 exitcode = 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1118 } |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1119 done: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1120 /* Restore and clear the exception info, in order to properly decref |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1121 * the exception, value, and traceback. If we just exit instead, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1122 * these leak, which confuses PYTHONDUMPREFS output, and may prevent |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1123 * some finalizers from running. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1124 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1125 PyErr_Restore(exception, value, tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1126 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1127 Py_Exit(exitcode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1128 /* NOTREACHED */ |
|
17191
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1129 } |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1130 |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1131 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1132 PyErr_PrintEx(int set_sys_last_vars) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1133 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1134 PyObject *exception, *v, *tb, *hook; |
|
17212
215dc725db84
Finishing touch to Ping's changes. This is a patch that Ping sent me
Guido van Rossum <guido@python.org>
parents:
17207
diff
changeset
|
1135 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1136 if (PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1137 handle_system_exit(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1138 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1139 PyErr_Fetch(&exception, &v, &tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1140 if (exception == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1141 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1142 PyErr_NormalizeException(&exception, &v, &tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1143 if (exception == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1144 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1145 /* Now we know v != NULL too */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1146 if (set_sys_last_vars) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1147 PySys_SetObject("last_type", exception); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1148 PySys_SetObject("last_value", v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1149 PySys_SetObject("last_traceback", tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1150 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1151 hook = PySys_GetObject("excepthook"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1152 if (hook) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1153 PyObject *args = PyTuple_Pack(3, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1154 exception, v, tb ? tb : Py_None); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1155 PyObject *result = PyEval_CallObject(hook, args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1156 if (result == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1157 PyObject *exception2, *v2, *tb2; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1158 if (PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1159 handle_system_exit(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1160 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1161 PyErr_Fetch(&exception2, &v2, &tb2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1162 PyErr_NormalizeException(&exception2, &v2, &tb2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1163 /* It should not be possible for exception2 or v2 |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1164 to be NULL. However PyErr_Display() can't |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1165 tolerate NULLs, so just be safe. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1166 if (exception2 == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1167 exception2 = Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1168 Py_INCREF(exception2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1169 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1170 if (v2 == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1171 v2 = Py_None; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1172 Py_INCREF(v2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1173 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1174 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1175 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1176 fflush(stdout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1177 PySys_WriteStderr("Error in sys.excepthook:\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1178 PyErr_Display(exception2, v2, tb2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1179 PySys_WriteStderr("\nOriginal exception was:\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1180 PyErr_Display(exception, v, tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1181 Py_DECREF(exception2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1182 Py_DECREF(v2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1183 Py_XDECREF(tb2); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1184 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1185 Py_XDECREF(result); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1186 Py_XDECREF(args); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1187 } else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1188 PySys_WriteStderr("sys.excepthook is missing\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1189 PyErr_Display(exception, v, tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1190 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1191 Py_XDECREF(exception); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1192 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1193 Py_XDECREF(tb); |
| 17164 | 1194 } |
| 1195 | |
|
38431
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
37845
diff
changeset
|
1196 void |
|
4c0823f0a0a1
Conversion of exceptions over from faked-up classes to new-style C types.
Richard Jones <richard@commonground.com.au>
parents:
37845
diff
changeset
|
1197 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) |
| 17164 | 1198 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1199 int err = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1200 PyObject *f = PySys_GetObject("stderr"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1201 Py_INCREF(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1202 if (f == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1203 fprintf(stderr, "lost sys.stderr\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1204 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1205 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1206 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1207 fflush(stdout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1208 if (tb && tb != Py_None) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1209 err = PyTraceBack_Print(tb, f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1210 if (err == 0 && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1211 PyObject_HasAttrString(value, "print_file_and_line")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1212 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1213 PyObject *message; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1214 const char *filename, *text; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1215 int lineno, offset; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1216 if (!parse_syntax_error(value, &message, &filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1217 &lineno, &offset, &text)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1218 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1219 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1220 char buf[10]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1221 PyFile_WriteString(" File \"", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1222 if (filename == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1223 PyFile_WriteString("<string>", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1224 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1225 PyFile_WriteString(filename, f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1226 PyFile_WriteString("\", line ", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1227 PyOS_snprintf(buf, sizeof(buf), "%d", lineno); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1228 PyFile_WriteString(buf, f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1229 PyFile_WriteString("\n", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1230 if (text != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1231 print_error_text(f, offset, text); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1232 Py_DECREF(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1233 value = message; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1234 /* Can't be bothered to check all those |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1235 PyFile_WriteString() calls */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1236 if (PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1237 err = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1238 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1239 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1240 if (err) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1241 /* Don't do anything else */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1242 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1243 else if (PyExceptionClass_Check(exception)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1244 PyObject* moduleName; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1245 char* className = PyExceptionClass_Name(exception); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1246 if (className != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1247 char *dot = strrchr(className, '.'); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1248 if (dot != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1249 className = dot+1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1250 } |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1251 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1252 moduleName = PyObject_GetAttrString(exception, "__module__"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1253 if (moduleName == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1254 err = PyFile_WriteString("<unknown>", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1255 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1256 char* modstr = PyString_AsString(moduleName); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1257 if (modstr && strcmp(modstr, "exceptions")) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1258 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1259 err = PyFile_WriteString(modstr, f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1260 err += PyFile_WriteString(".", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1261 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1262 Py_DECREF(moduleName); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1263 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1264 if (err == 0) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1265 if (className == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1266 err = PyFile_WriteString("<unknown>", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1267 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1268 err = PyFile_WriteString(className, f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1269 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1270 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1271 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1272 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1273 if (err == 0 && (value != Py_None)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1274 PyObject *s = PyObject_Str(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1275 /* only print colon if the str() of the |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1276 object is not the empty string |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1277 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1278 if (s == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1279 err = -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1280 else if (!PyString_Check(s) || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1281 PyString_GET_SIZE(s) != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1282 err = PyFile_WriteString(": ", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1283 if (err == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1284 err = PyFile_WriteObject(s, f, Py_PRINT_RAW); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1285 Py_XDECREF(s); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1286 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1287 /* try to write a newline in any case */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1288 err += PyFile_WriteString("\n", f); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1289 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1290 Py_DECREF(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1291 /* If an error happened here, don't show it. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1292 XXX This is wrong, but too many callers rely on this behavior. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1293 if (err != 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1294 PyErr_Clear(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1295 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1296 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1297 PyObject * |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1298 PyRun_StringFlags(const char *str, int start, PyObject *globals, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1299 PyObject *locals, PyCompilerFlags *flags) |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
1300 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1301 PyObject *ret = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1302 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1303 PyArena *arena = PyArena_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1304 if (arena == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1305 return NULL; |
|
61274
95c400b9d74c
Change to a Py_XDECREF and fix some whitespace.
Brett Cannon <bcannon@gmail.com>
parents:
59499
diff
changeset
|
1306 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1307 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1308 if (mod != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1309 ret = run_mod(mod, "<string>", globals, locals, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1310 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1311 return ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1312 } |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1313 |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1314 PyObject * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1315 PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1316 PyObject *locals, int closeit, PyCompilerFlags *flags) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1317 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1318 PyObject *ret; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1319 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1320 PyArena *arena = PyArena_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1321 if (arena == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1322 return NULL; |
|
61274
95c400b9d74c
Change to a Py_XDECREF and fix some whitespace.
Brett Cannon <bcannon@gmail.com>
parents:
59499
diff
changeset
|
1323 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1324 mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1325 flags, NULL, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1326 if (closeit) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1327 fclose(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1328 if (mod == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1329 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1330 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1331 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1332 ret = run_mod(mod, filename, globals, locals, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1333 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1334 return ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1335 } |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1336 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1337 static PyObject * |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1338 run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1339 PyCompilerFlags *flags, PyArena *arena) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1340 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1341 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1342 PyObject *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1343 co = PyAST_Compile(mod, filename, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1344 if (co == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1345 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1346 v = PyEval_EvalCode(co, globals, locals); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1347 Py_DECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1348 return v; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1349 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1350 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1351 static PyObject * |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1352 run_pyc_file(FILE *fp, const char *filename, PyObject *globals, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1353 PyObject *locals, PyCompilerFlags *flags) |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1354 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1355 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1356 PyObject *v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1357 long magic; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1358 long PyImport_GetMagicNumber(void); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1359 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1360 magic = PyMarshal_ReadLongFromFile(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1361 if (magic != PyImport_GetMagicNumber()) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1362 PyErr_SetString(PyExc_RuntimeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1363 "Bad magic number in .pyc file"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1364 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1365 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1366 (void) PyMarshal_ReadLongFromFile(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1367 v = PyMarshal_ReadLastObjectFromFile(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1368 fclose(fp); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1369 if (v == NULL || !PyCode_Check(v)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1370 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1371 PyErr_SetString(PyExc_RuntimeError, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1372 "Bad code object in .pyc file"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1373 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1374 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1375 co = (PyCodeObject *)v; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1376 v = PyEval_EvalCode(co, globals, locals); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1377 if (v && flags) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1378 flags->cf_flags |= (co->co_flags & PyCF_MASK); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1379 Py_DECREF(co); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1380 return v; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1381 } |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1382 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1383 PyObject * |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1384 Py_CompileStringFlags(const char *str, const char *filename, int start, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1385 PyCompilerFlags *flags) |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1386 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1387 PyCodeObject *co; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1388 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1389 PyArena *arena = PyArena_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1390 if (arena == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1391 return NULL; |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1392 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1393 mod = PyParser_ASTFromString(str, filename, start, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1394 if (mod == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1395 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1396 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1397 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1398 if (flags && (flags->cf_flags & PyCF_ONLY_AST)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1399 PyObject *result = PyAST_mod2obj(mod); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1400 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1401 return result; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1402 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1403 co = PyAST_Compile(mod, filename, flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1404 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1405 return (PyObject *)co; |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1406 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1407 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1408 struct symtable * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1409 Py_SymtableString(const char *str, const char *filename, int start) |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1410 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1411 struct symtable *st; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1412 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1413 PyCompilerFlags flags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1414 PyArena *arena = PyArena_New(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1415 if (arena == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1416 return NULL; |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1417 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1418 flags.cf_flags = 0; |
|
46121
d00ded8b2677
Initialize PyCompilerFlags cf_flags with 0
Christian Heimes <christian@cheimes.de>
parents:
46118
diff
changeset
|
1419 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1420 mod = PyParser_ASTFromString(str, filename, start, &flags, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1421 if (mod == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1422 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1423 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1424 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1425 st = PySymtable_Build(mod, filename, 0); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1426 PyArena_Free(arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1427 return st; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1428 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1429 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1430 /* Preferred access to parser is through AST. */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1431 mod_ty |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1432 PyParser_ASTFromString(const char *s, const char *filename, int start, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1433 PyCompilerFlags *flags, PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1434 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1435 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1436 PyCompilerFlags localflags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1437 perrdetail err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1438 int iflags = PARSER_FLAGS(flags); |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1439 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1440 node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1441 &_PyParser_Grammar, start, &err, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1442 &iflags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1443 if (flags == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1444 localflags.cf_flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1445 flags = &localflags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1446 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1447 if (n) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1448 flags->cf_flags |= iflags & PyCF_MASK; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1449 mod = PyAST_FromNode(n, flags, filename, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1450 PyNode_Free(n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1451 return mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1452 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1453 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1454 err_input(&err); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1455 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1456 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1457 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1458 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1459 mod_ty |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1460 PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1461 char *ps2, PyCompilerFlags *flags, int *errcode, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1462 PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1463 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1464 mod_ty mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1465 PyCompilerFlags localflags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1466 perrdetail err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1467 int iflags = PARSER_FLAGS(flags); |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1468 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1469 node *n = PyParser_ParseFileFlagsEx(fp, filename, &_PyParser_Grammar, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1470 start, ps1, ps2, &err, &iflags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1471 if (flags == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1472 localflags.cf_flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1473 flags = &localflags; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1474 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1475 if (n) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1476 flags->cf_flags |= iflags & PyCF_MASK; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1477 mod = PyAST_FromNode(n, flags, filename, arena); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1478 PyNode_Free(n); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1479 return mod; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1480 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1481 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1482 err_input(&err); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1483 if (errcode) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1484 *errcode = err.error; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1485 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1486 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1487 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1488 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1489 /* Simplified interface to parsefile -- return node or set exception */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1490 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1491 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1492 PyParser_SimpleParseFileFlags(FILE *fp, const char *filename, int start, int flags) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1493 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1494 perrdetail err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1495 node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1496 start, NULL, NULL, &err, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1497 if (n == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1498 err_input(&err); |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1499 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1500 return n; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1501 } |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1502 |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1503 /* Simplified interface to parsestring -- return node or set exception */ |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1504 |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1505 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1506 PyParser_SimpleParseStringFlags(const char *str, int start, int flags) |
|
18615
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1507 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1508 perrdetail err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1509 node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1510 start, &err, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1511 if (n == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1512 err_input(&err); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1513 return n; |
|
18615
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1514 } |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1515 |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1516 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1517 PyParser_SimpleParseStringFlagsFilename(const char *str, const char *filename, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1518 int start, int flags) |
|
24159
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1519 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1520 perrdetail err; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1521 node *n = PyParser_ParseStringFlagsFilename(str, filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1522 &_PyParser_Grammar, start, &err, flags); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1523 if (n == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1524 err_input(&err); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1525 return n; |
|
24159
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1526 } |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1527 |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1528 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1529 PyParser_SimpleParseStringFilename(const char *str, const char *filename, int start) |
|
24159
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1530 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1531 return PyParser_SimpleParseStringFlagsFilename(str, filename, start, 0); |
|
24159
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1532 } |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1533 |
|
28649
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1534 /* May want to move a more generalized form of this to parsetok.c or |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1535 even parser modules. */ |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1536 |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1537 void |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1538 PyParser_SetError(perrdetail *err) |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1539 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1540 err_input(err); |
|
28649
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1541 } |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1542 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1543 /* Set the error appropriate to the given input error code (see errcode.h) */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1544 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1545 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1546 err_input(perrdetail *err) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1547 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1548 PyObject *v, *w, *errtype; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1549 PyObject* u = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1550 char *msg = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1551 errtype = PyExc_SyntaxError; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1552 switch (err->error) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1553 case E_ERROR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1554 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1555 case E_SYNTAX: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1556 errtype = PyExc_IndentationError; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1557 if (err->expected == INDENT) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1558 msg = "expected an indented block"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1559 else if (err->token == INDENT) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1560 msg = "unexpected indent"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1561 else if (err->token == DEDENT) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1562 msg = "unexpected unindent"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1563 else { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1564 errtype = PyExc_SyntaxError; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1565 msg = "invalid syntax"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1566 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1567 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1568 case E_TOKEN: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1569 msg = "invalid token"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1570 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1571 case E_EOFS: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1572 msg = "EOF while scanning triple-quoted string literal"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1573 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1574 case E_EOLS: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1575 msg = "EOL while scanning string literal"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1576 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1577 case E_INTR: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1578 if (!PyErr_Occurred()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1579 PyErr_SetNone(PyExc_KeyboardInterrupt); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1580 goto cleanup; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1581 case E_NOMEM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1582 PyErr_NoMemory(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1583 goto cleanup; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1584 case E_EOF: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1585 msg = "unexpected EOF while parsing"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1586 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1587 case E_TABSPACE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1588 errtype = PyExc_TabError; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1589 msg = "inconsistent use of tabs and spaces in indentation"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1590 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1591 case E_OVERFLOW: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1592 msg = "expression too long"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1593 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1594 case E_DEDENT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1595 errtype = PyExc_IndentationError; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1596 msg = "unindent does not match any outer indentation level"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1597 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1598 case E_TOODEEP: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1599 errtype = PyExc_IndentationError; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1600 msg = "too many levels of indentation"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1601 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1602 case E_DECODE: { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1603 PyObject *type, *value, *tb; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1604 PyErr_Fetch(&type, &value, &tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1605 if (value != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1606 u = PyObject_Str(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1607 if (u != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1608 msg = PyString_AsString(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1609 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1610 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1611 if (msg == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1612 msg = "unknown decode error"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1613 Py_XDECREF(type); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1614 Py_XDECREF(value); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1615 Py_XDECREF(tb); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1616 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1617 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1618 case E_LINECONT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1619 msg = "unexpected character after line continuation character"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1620 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1621 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1622 fprintf(stderr, "error=%d\n", err->error); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1623 msg = "unknown parsing error"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1624 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1625 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1626 v = Py_BuildValue("(ziiz)", err->filename, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1627 err->lineno, err->offset, err->text); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1628 w = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1629 if (v != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1630 w = Py_BuildValue("(sO)", msg, v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1631 Py_XDECREF(u); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1632 Py_XDECREF(v); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1633 PyErr_SetObject(errtype, w); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1634 Py_XDECREF(w); |
|
48024
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1635 cleanup: |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1636 if (err->text != NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1637 PyObject_FREE(err->text); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1638 err->text = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1639 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1640 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1641 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1642 /* Print fatal error message and abort */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1643 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1644 void |
|
24155
9456a2ccda61
The Py_REF_DEBUG/COUNT_ALLOCS/Py_TRACE_REFS macro minefield: added
Tim Peters <tim.peters@gmail.com>
parents:
24071
diff
changeset
|
1645 Py_FatalError(const char *msg) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1646 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1647 fprintf(stderr, "Fatal Python error: %s\n", msg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1648 fflush(stderr); /* it helps in Windows debug build */ |
|
52604
5cf74137c0f8
Issue 5619: Pass MS CRT debug flags into subprocesses
Jesse Noller <jnoller@gmail.com>
parents:
52233
diff
changeset
|
1649 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
1650 #ifdef MS_WINDOWS |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1651 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1652 size_t len = strlen(msg); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1653 WCHAR* buffer; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1654 size_t i; |
|
50460
636a0ac9607b
Issue #4075: Use OutputDebugStringW in Py_FatalError.
Martin v. Löwis <martin@v.loewis.de>
parents:
49818
diff
changeset
|
1655 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1656 /* Convert the message to wchar_t. This uses a simple one-to-one |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1657 conversion, assuming that the this error message actually uses ASCII |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1658 only. If this ceases to be true, we will have to convert. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1659 buffer = alloca( (len+1) * (sizeof *buffer)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1660 for( i=0; i<=len; ++i) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1661 buffer[i] = msg[i]; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1662 OutputDebugStringW(L"Fatal Python error: "); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1663 OutputDebugStringW(buffer); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1664 OutputDebugStringW(L"\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1665 } |
|
8988
070de4d39ddd
Add DebugBreak() call to Py_FatalError() for Mark Hammond (only on
Guido van Rossum <guido@python.org>
parents:
7967
diff
changeset
|
1666 #ifdef _DEBUG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1667 DebugBreak(); |
|
2529
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
1668 #endif |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
1669 #endif /* MS_WINDOWS */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1670 abort(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1671 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1672 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1673 /* Clean up and exit */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1674 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1675 #ifdef WITH_THREAD |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9192
diff
changeset
|
1676 #include "pythread.h" |
|
961
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
941
diff
changeset
|
1677 #endif |
|
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
941
diff
changeset
|
1678 |
|
56645
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1679 /* Wait until threading._shutdown completes, provided |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1680 the threading module was imported in the first place. |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1681 The shutdown routine will wait until all non-daemon |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1682 "threading" threads have completed. */ |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1683 static void |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1684 wait_for_thread_shutdown(void) |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1685 { |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1686 #ifdef WITH_THREAD |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1687 PyObject *result; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1688 PyThreadState *tstate = PyThreadState_GET(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1689 PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1690 "threading"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1691 if (threading == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1692 /* threading not imported */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1693 PyErr_Clear(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1694 return; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1695 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1696 result = PyObject_CallMethod(threading, "_shutdown", ""); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1697 if (result == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1698 PyErr_WriteUnraisable(threading); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1699 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1700 Py_DECREF(result); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1701 Py_DECREF(threading); |
|
56645
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1702 #endif |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1703 } |
|
12079c3d4b77
Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
Antoine Pitrou <solipsis@pitrou.net>
parents:
52817
diff
changeset
|
1704 |
|
9192
ac6c29d1f10c
On second though, NEXITFUNCS should be defined here and not in
Guido van Rossum <guido@python.org>
parents:
9161
diff
changeset
|
1705 #define NEXITFUNCS 32 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1706 static void (*exitfuncs[NEXITFUNCS])(void); |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1707 static int nexitfuncs = 0; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1708 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1709 int Py_AtExit(void (*func)(void)) |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1710 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1711 if (nexitfuncs >= NEXITFUNCS) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1712 return -1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1713 exitfuncs[nexitfuncs++] = func; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1714 return 0; |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1715 } |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1716 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1717 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1718 call_sys_exitfunc(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1719 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1720 PyObject *exitfunc = PySys_GetObject("exitfunc"); |
|
1015
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1721 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1722 if (exitfunc) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1723 PyObject *res; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1724 Py_INCREF(exitfunc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1725 PySys_SetObject("exitfunc", (PyObject *)NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1726 res = PyEval_CallObject(exitfunc, (PyObject *)NULL); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1727 if (res == NULL) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1728 if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1729 PySys_WriteStderr("Error in sys.exitfunc:\n"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1730 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1731 PyErr_Print(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1732 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1733 Py_DECREF(exitfunc); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1734 } |
|
1015
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1735 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1736 if (Py_FlushLine()) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1737 PyErr_Clear(); |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1738 } |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1739 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1740 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1741 call_ll_exitfuncs(void) |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1742 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1743 while (nexitfuncs > 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1744 (*exitfuncs[--nexitfuncs])(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
1745 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1746 fflush(stdout); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1747 fflush(stderr); |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1748 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1749 |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1750 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1751 Py_Exit(int sts) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1752 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1753 Py_Finalize(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1754 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1755 exit(sts); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1756 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1757 |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1289
diff
changeset
|
1758 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1759 initsigs(void) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1760 { |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1761 #ifdef SIGPIPE |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1762 PyOS_setsig(SIGPIPE, SIG_IGN); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1763 #endif |
| 19295 | 1764 #ifdef SIGXFZ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1765 PyOS_setsig(SIGXFZ, SIG_IGN); |
| 19295 | 1766 #endif |
| 23252 | 1767 #ifdef SIGXFSZ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1768 PyOS_setsig(SIGXFSZ, SIG_IGN); |
| 23252 | 1769 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1770 PyOS_InitInterrupts(); /* May imply initsignal() */ |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1771 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1772 |
|
5108
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1773 |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1774 /* |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1775 * The file descriptor fd is considered ``interactive'' if either |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1776 * a) isatty(fd) is TRUE, or |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1777 * b) the -i flag was given, and the filename associated with |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1778 * the descriptor is NULL or "<stdin>" or "???". |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1779 */ |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1780 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1781 Py_FdIsInteractive(FILE *fp, const char *filename) |
|
5108
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1782 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1783 if (isatty((int)fileno(fp))) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1784 return 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1785 if (!Py_InteractiveFlag) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1786 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1787 return (filename == NULL) || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1788 (strcmp(filename, "<stdin>") == 0) || |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1789 (strcmp(filename, "???") == 0); |
|
5108
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1790 } |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1791 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1792 |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1793 #if defined(USE_STACKCHECK) |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1794 #if defined(WIN32) && defined(_MSC_VER) |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1795 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1796 /* Stack checking for Microsoft C */ |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1797 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1798 #include <malloc.h> |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1799 #include <excpt.h> |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1800 |
|
14278
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1801 /* |
|
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1802 * Return non-zero when we run out of memory on the stack; zero otherwise. |
|
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1803 */ |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1804 int |
|
14280
68b61aa1aa4a
PyOS_CheckStack(): Better ANSI'fy this while we're at it.
Fred Drake <fdrake@acm.org>
parents:
14278
diff
changeset
|
1805 PyOS_CheckStack(void) |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1806 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1807 __try { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1808 /* alloca throws a stack overflow exception if there's |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1809 not enough space left on the stack */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1810 alloca(PYOS_STACK_MARGIN * sizeof(void*)); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1811 return 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1812 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ? |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1813 EXCEPTION_EXECUTE_HANDLER : |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1814 EXCEPTION_CONTINUE_SEARCH) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1815 int errcode = _resetstkoflw(); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1816 if (errcode == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1817 { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1818 Py_FatalError("Could not reset the stack!"); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1819 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1820 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1821 return 1; |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1822 } |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1823 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1824 #endif /* WIN32 && _MSC_VER */ |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1825 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1826 /* Alternate implementations can be added here... */ |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1827 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1828 #endif /* USE_STACKCHECK */ |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1829 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1830 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1831 /* Wrappers around sigaction() or signal(). */ |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1832 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1833 PyOS_sighandler_t |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1834 PyOS_getsig(int sig) |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1835 { |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1836 #ifdef HAVE_SIGACTION |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1837 struct sigaction context; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1838 if (sigaction(sig, NULL, &context) == -1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1839 return SIG_ERR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1840 return context.sa_handler; |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1841 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1842 PyOS_sighandler_t handler; |
|
35961
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1843 /* Special signal handling for the secure CRT in Visual Studio 2005 */ |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1844 #if defined(_MSC_VER) && _MSC_VER >= 1400 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1845 switch (sig) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1846 /* Only these signals are valid */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1847 case SIGINT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1848 case SIGILL: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1849 case SIGFPE: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1850 case SIGSEGV: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1851 case SIGTERM: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1852 case SIGBREAK: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1853 case SIGABRT: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1854 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1855 /* Don't call signal() with other values or it will assert */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1856 default: |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1857 return SIG_ERR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1858 } |
|
35961
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1859 #endif /* _MSC_VER && _MSC_VER >= 1400 */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1860 handler = signal(sig, SIG_IGN); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1861 if (handler != SIG_ERR) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1862 signal(sig, handler); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1863 return handler; |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1864 #endif |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1865 } |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1866 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1867 PyOS_sighandler_t |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1868 PyOS_setsig(int sig, PyOS_sighandler_t handler) |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1869 { |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1870 #ifdef HAVE_SIGACTION |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1871 /* Some code in Modules/signalmodule.c depends on sigaction() being |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1872 * used here if HAVE_SIGACTION is defined. Fix that if this code |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1873 * changes to invalidate that assumption. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1874 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1875 struct sigaction context, ocontext; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1876 context.sa_handler = handler; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1877 sigemptyset(&context.sa_mask); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1878 context.sa_flags = 0; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1879 if (sigaction(sig, &context, &ocontext) == -1) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1880 return SIG_ERR; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1881 return ocontext.sa_handler; |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1882 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1883 PyOS_sighandler_t oldhandler; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1884 oldhandler = signal(sig, handler); |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1885 #ifdef HAVE_SIGINTERRUPT |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1886 siginterrupt(sig, 1); |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1887 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1888 return oldhandler; |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1889 #endif |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1890 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1891 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1892 /* Deprecated C API functions still provided for binary compatiblity */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1893 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1894 #undef PyParser_SimpleParseFile |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1895 PyAPI_FUNC(node *) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1896 PyParser_SimpleParseFile(FILE *fp, const char *filename, int start) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1897 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1898 return PyParser_SimpleParseFileFlags(fp, filename, start, 0); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1899 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1900 |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1901 #undef PyParser_SimpleParseString |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1902 PyAPI_FUNC(node *) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1903 PyParser_SimpleParseString(const char *str, int start) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1904 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1905 return PyParser_SimpleParseStringFlags(str, start, 0); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1906 } |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
1907 |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1908 #undef PyRun_AnyFile |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1909 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1910 PyRun_AnyFile(FILE *fp, const char *name) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1911 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1912 return PyRun_AnyFileExFlags(fp, name, 0, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1913 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1914 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1915 #undef PyRun_AnyFileEx |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1916 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1917 PyRun_AnyFileEx(FILE *fp, const char *name, int closeit) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1918 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1919 return PyRun_AnyFileExFlags(fp, name, closeit, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1920 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1921 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1922 #undef PyRun_AnyFileFlags |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1923 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1924 PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1925 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1926 return PyRun_AnyFileExFlags(fp, name, 0, flags); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1927 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1928 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1929 #undef PyRun_File |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1930 PyAPI_FUNC(PyObject *) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1931 PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1932 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1933 return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1934 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1935 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1936 #undef PyRun_FileEx |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1937 PyAPI_FUNC(PyObject *) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1938 PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1939 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1940 return PyRun_FileExFlags(fp, p, s, g, l, c, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1941 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1942 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1943 #undef PyRun_FileFlags |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1944 PyAPI_FUNC(PyObject *) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1945 PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1946 PyCompilerFlags *flags) |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1947 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1948 return PyRun_FileExFlags(fp, p, s, g, l, 0, flags); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1949 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1950 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1951 #undef PyRun_SimpleFile |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1952 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1953 PyRun_SimpleFile(FILE *f, const char *p) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1954 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1955 return PyRun_SimpleFileExFlags(f, p, 0, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1956 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1957 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1958 #undef PyRun_SimpleFileEx |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1959 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1960 PyRun_SimpleFileEx(FILE *f, const char *p, int c) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1961 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1962 return PyRun_SimpleFileExFlags(f, p, c, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1963 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1964 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1965 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1966 #undef PyRun_String |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1967 PyAPI_FUNC(PyObject *) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1968 PyRun_String(const char *str, int s, PyObject *g, PyObject *l) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1969 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1970 return PyRun_StringFlags(str, s, g, l, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1971 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1972 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1973 #undef PyRun_SimpleString |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1974 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1975 PyRun_SimpleString(const char *s) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1976 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1977 return PyRun_SimpleStringFlags(s, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1978 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1979 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1980 #undef Py_CompileString |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1981 PyAPI_FUNC(PyObject *) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1982 Py_CompileString(const char *str, const char *p, int s) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1983 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1984 return Py_CompileStringFlags(str, p, s, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1985 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1986 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1987 #undef PyRun_InteractiveOne |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1988 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1989 PyRun_InteractiveOne(FILE *f, const char *p) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1990 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1991 return PyRun_InteractiveOneFlags(f, p, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1992 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1993 |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1994 #undef PyRun_InteractiveLoop |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1995 PyAPI_FUNC(int) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1996 PyRun_InteractiveLoop(FILE *f, const char *p) |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1997 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
61441
diff
changeset
|
1998 return PyRun_InteractiveLoopFlags(f, p, NULL); |
|
37845
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1999 } |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
2000 |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
2001 #ifdef __cplusplus |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
2002 } |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
2003 #endif |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
2004 |
