Mercurial > cpython-lru_cache-weakref
annotate Python/pythonrun.c @ 57662:aee8eb7f5f02 2.6
Blocked revisions 76755 via svnmerge
........
r76755 | mark.dickinson | 2009-12-11 17:29:33 +0000 (Fri, 11 Dec 2009) | 2 lines
Issue #3366: Add lgamma function to math module.
........
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Fri, 11 Dec 2009 20:18:18 +0000 |
| parents | 2abc3b4bce7c |
| children | 8d8c9bf2a04e |
| 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" |
|
56781
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
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 |
|
50522
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
26 #ifdef MS_WINDOWS |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
27 #include "malloc.h" /* for alloca */ |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
28 #endif |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
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 */ |
|
37290
89142cadcfb9
In format strings slinging Py_ssize_t, unconditionally
Tim Peters <tim.peters@gmail.com>
parents:
37229
diff
changeset
|
43 #define PRINT_TOTAL_REFS() fprintf(stderr, \ |
|
89142cadcfb9
In format strings slinging Py_ssize_t, unconditionally
Tim Peters <tim.peters@gmail.com>
parents:
37229
diff
changeset
|
44 "[%" PY_FORMAT_SIZE_T "d refs]\n", \ |
|
37638
65ecb83ea7dd
Ignore the references to the dummy objects used as deleted keys
Armin Rigo <arigo@tunes.org>
parents:
37423
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 *, |
|
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
|
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 *, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
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); |
|
56781
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
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 { |
|
46414
840064802952
Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents:
46123
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 { |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
108 return initialized; |
|
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 { |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
126 int env = atoi(envs); |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
127 if (flag < env) |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
128 flag = env; |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
129 if (flag < 1) |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
130 flag = 1; |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
131 return flag; |
|
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 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
137 PyInterpreterState *interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
138 PyThreadState *tstate; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
139 PyObject *bimod, *sysmod; |
|
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
|
140 char *p; |
| 48847 | 141 char *icodeset = NULL; /* On Windows, input codeset may theoretically |
| 142 differ from output codeset. */ | |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
143 char *codeset = NULL; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
144 char *errors = NULL; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
145 int free_codeset = 0; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
146 int overridden = 0; |
|
47415
622cabbaf2bc
Move sys_stream and sys_isatty out of the have-langinfo block.
Martin v. Löwis <martin@v.loewis.de>
parents:
47413
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) |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
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 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
152 char ibuf[128]; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
153 char buf[128]; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
154 #endif |
| 19295 | 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 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
157 if (initialized) |
|
6117
98a282cfb013
Use a counter instead of a Boolean to check for initialized; n calls
Guido van Rossum <guido@python.org>
parents:
5939
diff
changeset
|
158 return; |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
159 initialized = 1; |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
160 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
161 if ((p = Py_GETENV("PYTHONDEBUG")) && *p != '\0') |
|
20401
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
162 Py_DebugFlag = add_flag(Py_DebugFlag, p); |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
163 if ((p = Py_GETENV("PYTHONVERBOSE")) && *p != '\0') |
|
20401
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
164 Py_VerboseFlag = add_flag(Py_VerboseFlag, p); |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
165 if ((p = Py_GETENV("PYTHONOPTIMIZE")) && *p != '\0') |
|
20401
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
166 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p); |
|
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
|
167 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0') |
|
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
|
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 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
170 interp = PyInterpreterState_New(); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
171 if (interp == NULL) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
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 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
174 tstate = PyThreadState_New(interp); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
175 if (tstate == NULL) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
176 Py_FatalError("Py_Initialize: can't make first thread"); |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
177 (void) PyThreadState_Swap(tstate); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
178 |
| 19295 | 179 _Py_ReadyTypes(); |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
180 |
|
26923
dbfc3ef7d003
Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents:
26889
diff
changeset
|
181 if (!_PyFrame_Init()) |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
182 Py_FatalError("Py_Initialize: can't init frames"); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
183 |
|
26923
dbfc3ef7d003
Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents:
26889
diff
changeset
|
184 if (!_PyInt_Init()) |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
185 Py_FatalError("Py_Initialize: can't init ints"); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
186 |
|
47291
04bd3690fb1f
First step of the C API rename:
Christian Heimes <christian@cheimes.de>
parents:
46889
diff
changeset
|
187 if (!PyByteArray_Init()) |
|
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
|
188 Py_FatalError("Py_Initialize: can't init bytearray"); |
|
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
|
189 |
| 34972 | 190 _PyFloat_Init(); |
| 191 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
192 interp->modules = PyDict_New(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
193 if (interp->modules == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
194 Py_FatalError("Py_Initialize: can't make modules dictionary"); |
|
41128
45ce388ec59a
Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Collin Winter <collinw@gmail.com>
parents:
41126
diff
changeset
|
195 interp->modules_reloading = PyDict_New(); |
|
45ce388ec59a
Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Collin Winter <collinw@gmail.com>
parents:
41126
diff
changeset
|
196 if (interp->modules_reloading == NULL) |
|
45ce388ec59a
Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Collin Winter <collinw@gmail.com>
parents:
41126
diff
changeset
|
197 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
|
198 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19296
diff
changeset
|
199 #ifdef Py_USING_UNICODE |
|
11977
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
200 /* Init Unicode implementation; relies on the codec registry */ |
|
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
201 _PyUnicode_Init(); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19296
diff
changeset
|
202 #endif |
|
11977
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
203 |
|
12754
5213abfe5230
Py_Initialize(): Now that standard exceptions are builtin, we don't
Barry Warsaw <barry@python.org>
parents:
12576
diff
changeset
|
204 bimod = _PyBuiltin_Init(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
205 if (bimod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
206 Py_FatalError("Py_Initialize: can't initialize __builtin__"); |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
207 interp->builtins = PyModule_GetDict(bimod); |
|
39458
deb748f33c1d
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
208 if (interp->builtins == NULL) |
|
deb748f33c1d
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
209 Py_FatalError("Py_Initialize: can't initialize builtins dict"); |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
210 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
|
211 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
212 sysmod = _PySys_Init(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
213 if (sysmod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
214 Py_FatalError("Py_Initialize: can't initialize sys"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
215 interp->sysdict = PyModule_GetDict(sysmod); |
|
39458
deb748f33c1d
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
216 if (interp->sysdict == NULL) |
|
deb748f33c1d
PyModule_GetDict() can fail, produce fatal errors if this happens on startup.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39455
diff
changeset
|
217 Py_FatalError("Py_Initialize: can't initialize sys dict"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
218 Py_INCREF(interp->sysdict); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
219 _PyImport_FixupExtension("sys", "sys"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
220 PySys_SetPath(Py_GetPath()); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
221 PyDict_SetItemString(interp->sysdict, "modules", |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
222 interp->modules); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
223 |
|
11113
be8ec828c072
Marc-Andre Lemburg discovered that the switch from .pyc to .pyo files,
Guido van Rossum <guido@python.org>
parents:
10534
diff
changeset
|
224 _PyImport_Init(); |
|
be8ec828c072
Marc-Andre Lemburg discovered that the switch from .pyc to .pyo files,
Guido van Rossum <guido@python.org>
parents:
10534
diff
changeset
|
225 |
|
12754
5213abfe5230
Py_Initialize(): Now that standard exceptions are builtin, we don't
Barry Warsaw <barry@python.org>
parents:
12576
diff
changeset
|
226 /* initialize builtin exceptions */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
18808
diff
changeset
|
227 _PyExc_Init(); |
|
19237
e110cd4fc3c6
Py_Initialize(): Apply patch by Jürgen Hermann to call
Barry Warsaw <barry@python.org>
parents:
19158
diff
changeset
|
228 _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
|
229 |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
230 /* phase 2 of builtins */ |
|
6328
dfeaf965f48a
Py_Initialize(): move the call to _PyImport_FixupExtension() to after
Barry Warsaw <barry@python.org>
parents:
6322
diff
changeset
|
231 _PyImport_FixupExtension("__builtin__", "__builtin__"); |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
232 |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26643
diff
changeset
|
233 _PyImportHooks_Init(); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26643
diff
changeset
|
234 |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
235 if (install_sigs) |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
236 initsigs(); /* Signal handling stuff, including initintr() */ |
|
46414
840064802952
Re-implement the 'warnings' module in C. This allows for usage of the
Brett Cannon <bcannon@gmail.com>
parents:
46123
diff
changeset
|
237 |
| 47887 | 238 /* Initialize warnings. */ |
| 239 _PyWarnings_Init(); | |
| 240 if (PySys_HasWarnOptions()) { | |
| 241 PyObject *warnings_module = PyImport_ImportModule("warnings"); | |
| 242 if (!warnings_module) | |
| 243 PyErr_Clear(); | |
| 244 Py_XDECREF(warnings_module); | |
| 245 } | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
246 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
247 initmain(); /* Module __main__ */ |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
248 if (!Py_NoSiteFlag) |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
249 initsite(); /* Module site */ |
|
28065
c61ef183ce2f
Addendum to #683658:
Just van Rossum <just@letterror.com>
parents:
27958
diff
changeset
|
250 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
251 /* auto-thread-state API, if available */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
252 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
253 _PyGILState_Init(interp, tstate); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
254 #endif /* WITH_THREAD */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
255 |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
256 if ((p = Py_GETENV("PYTHONIOENCODING")) && *p != '\0') { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
257 p = icodeset = codeset = strdup(p); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
258 free_codeset = 1; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
259 errors = strchr(p, ':'); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
260 if (errors) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
261 *errors = '\0'; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
262 errors++; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
263 } |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
264 overridden = 1; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
265 } |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
266 |
|
28174
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
267 #if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET) |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
268 /* On Unix, set the file system encoding according to the |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
269 user's preference, if the CODESET names a well-known |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
270 Python codec, and Py_FileSystemDefaultEncoding isn't |
|
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
|
271 initialized by other means. Also set the encoding of |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
272 stdin and stdout if these are terminals, unless overridden. */ |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
273 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
274 if (!overridden || !Py_FileSystemDefaultEncoding) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
275 saved_locale = strdup(setlocale(LC_CTYPE, NULL)); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
276 setlocale(LC_CTYPE, ""); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
277 loc_codeset = nl_langinfo(CODESET); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
278 if (loc_codeset && *loc_codeset) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
279 PyObject *enc = PyCodec_Encoder(loc_codeset); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
280 if (enc) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
281 loc_codeset = strdup(loc_codeset); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
282 Py_DECREF(enc); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
283 } else { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
284 loc_codeset = NULL; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
285 PyErr_Clear(); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
286 } |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
287 } else |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
288 loc_codeset = NULL; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
289 setlocale(LC_CTYPE, saved_locale); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
290 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
|
291 |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
292 if (!overridden) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
293 codeset = icodeset = loc_codeset; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
294 free_codeset = 1; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
295 } |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
296 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
297 /* Initialize Py_FileSystemDefaultEncoding from |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
298 locale even if PYTHONIOENCODING is set. */ |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
299 if (!Py_FileSystemDefaultEncoding) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
300 Py_FileSystemDefaultEncoding = loc_codeset; |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
301 if (!overridden) |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
302 free_codeset = 0; |
|
28174
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
303 } |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
304 } |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
305 #endif |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
306 |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
307 #ifdef MS_WINDOWS |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
308 if (!overridden) { |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
309 icodeset = ibuf; |
|
47416
2a63ab3595a1
Typo: encoding -> codeset.
Martin v. Löwis <martin@v.loewis.de>
parents:
47415
diff
changeset
|
310 codeset = buf; |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
311 sprintf(ibuf, "cp%d", GetConsoleCP()); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
312 sprintf(buf, "cp%d", GetConsoleOutputCP()); |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
313 } |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
314 #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
|
315 |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
316 if (codeset) { |
|
30122
210676ec9d5f
Fix refcounting and cut & paste error (?) in last checkin.
Michael W. Hudson <mwh@python.net>
parents:
30108
diff
changeset
|
317 sys_stream = PySys_GetObject("stdin"); |
|
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
|
318 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
319 if (!sys_isatty) |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
320 PyErr_Clear(); |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
321 if ((overridden || |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
322 (sys_isatty && PyObject_IsTrue(sys_isatty))) && |
|
40699
86ab2f20a333
SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
Thomas Wouters <thomas@python.org>
parents:
39779
diff
changeset
|
323 PyFile_Check(sys_stream)) { |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
324 if (!PyFile_SetEncodingAndErrors(sys_stream, icodeset, errors)) |
|
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
|
325 Py_FatalError("Cannot set codeset of stdin"); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
326 } |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
327 Py_XDECREF(sys_isatty); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
328 |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
329 sys_stream = PySys_GetObject("stdout"); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
330 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
331 if (!sys_isatty) |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
332 PyErr_Clear(); |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
333 if ((overridden || |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
334 (sys_isatty && PyObject_IsTrue(sys_isatty))) && |
|
40699
86ab2f20a333
SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
Thomas Wouters <thomas@python.org>
parents:
39779
diff
changeset
|
335 PyFile_Check(sys_stream)) { |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
336 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors)) |
|
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 Py_FatalError("Cannot set codeset of stdout"); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
338 } |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
339 Py_XDECREF(sys_isatty); |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
340 |
|
37423
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
341 sys_stream = PySys_GetObject("stderr"); |
|
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
342 sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); |
|
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
343 if (!sys_isatty) |
|
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
344 PyErr_Clear(); |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
345 if((overridden || |
|
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
346 (sys_isatty && PyObject_IsTrue(sys_isatty))) && |
|
40699
86ab2f20a333
SF patch #1630975: Fix crash when replacing sys.stdout in sitecustomize
Thomas Wouters <thomas@python.org>
parents:
39779
diff
changeset
|
347 PyFile_Check(sys_stream)) { |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
348 if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors)) |
|
37423
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
349 Py_FatalError("Cannot set codeset of stderr"); |
|
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
350 } |
|
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
351 Py_XDECREF(sys_isatty); |
|
57b1ff138995
Bug #1421664: Set sys.stderr.encoding
Martin v. Löwis <martin@v.loewis.de>
parents:
37290
diff
changeset
|
352 |
|
47413
1062b7dec95b
New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47294
diff
changeset
|
353 if (free_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
|
354 free(codeset); |
|
28174
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
355 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
356 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
357 |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
358 void |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
359 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
|
360 { |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
361 Py_InitializeEx(1); |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
362 } |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
363 |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
364 |
|
9641
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
365 #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
|
366 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
|
367 #endif |
|
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
368 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
369 /* 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
|
370 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 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
|
375 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
376 (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
|
377 threads.) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
378 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
379 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
380 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
381 */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
382 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
383 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
384 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
|
385 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
386 PyInterpreterState *interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
387 PyThreadState *tstate; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
388 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
389 if (!initialized) |
|
6117
98a282cfb013
Use a counter instead of a Boolean to check for initialized; n calls
Guido van Rossum <guido@python.org>
parents:
5939
diff
changeset
|
390 return; |
|
16073
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
391 |
|
56781
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
392 wait_for_thread_shutdown(); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
393 |
|
16073
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
394 /* The interpreter is still entirely intact at this point, and the |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
395 * exit funcs may be relying on that. In particular, if some thread |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
396 * or exit func is still waiting to do an import, the import machinery |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
397 * expects Py_IsInitialized() to return true. So don't say the |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
398 * interpreter is uninitialized until after the exit funcs have run. |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
399 * Note that Threading.py uses an exit func to do a join on all the |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
400 * threads created thru it, so this also protects pending imports in |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
401 * the threads created via Threading. |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
402 */ |
|
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
403 call_sys_exitfunc(); |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
404 initialized = 0; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
405 |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
406 /* Get current thread state and interpreter pointer */ |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31771
diff
changeset
|
407 tstate = PyThreadState_GET(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
408 interp = tstate->interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
409 |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
410 /* Disable signal handling */ |
|
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
411 PyOS_FiniInterrupts(); |
|
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
412 |
|
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
|
413 /* Clear type lookup cache */ |
|
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
|
414 PyType_ClearCache(); |
|
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
|
415 |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
416 /* Collect garbage. This may call finalizers; it's nice to call these |
|
31057
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
417 * before all modules are destroyed. |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
418 * XXX If a __del__ or weakref callback is triggered here, and tries to |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
419 * XXX import a module, bad things can happen, because Python no |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
420 * XXX longer believes it's initialized. |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
421 * XXX Fatal Python error: Interpreter not initialized (version mismatch?) |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
422 * XXX is easy to provoke that way. I've also seen, e.g., |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
423 * XXX Exception exceptions.ImportError: 'No module named sha' |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
424 * XXX in <function callback at 0x008F5718> ignored |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
425 * XXX but I'm unclear on exactly how that one happens. In any case, |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
426 * XXX I haven't seen a real-life report of either of these. |
| 36836 | 427 */ |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
428 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
|
429 #ifdef COUNT_ALLOCS |
|
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
430 /* With COUNT_ALLOCS, it helps to run GC multiple times: |
|
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
431 each collection might release some types from the type |
|
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
432 list, so they become garbage. */ |
|
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
433 while (PyGC_Collect() > 0) |
|
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
434 /* nothing */; |
|
d82dced6f1fa
Remove types from type_list if they have no objects
Martin v. Löwis <martin@v.loewis.de>
parents:
37655
diff
changeset
|
435 #endif |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
436 |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
437 /* Destroy all modules */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
438 PyImport_Cleanup(); |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
439 |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
440 /* Collect final garbage. This disposes of cycles created by |
|
31057
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
441 * new-style class definitions, for example. |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
442 * XXX This is disabled because it caused too many problems. If |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
443 * XXX a __del__ or weakref callback triggers here, Python code has |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
444 * XXX a hard time running, because even the sys module has been |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
445 * XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc). |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
446 * XXX One symptom is a sequence of information-free messages |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
447 * XXX coming from threads (if a __del__ or callback is invoked, |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
448 * XXX other threads can execute too, and any exception they encounter |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
449 * XXX triggers a comedy of errors as subsystem after subsystem |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
450 * XXX fails to find what it *expects* to find in sys to help report |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
451 * XXX the exception and consequent unexpected failures). I've also |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
452 * XXX seen segfaults then, after adding print statements to the |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
453 * XXX Python code getting called. |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
454 */ |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
455 #if 0 |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
456 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
|
457 #endif |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
458 |
|
6786
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
459 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
460 _PyImport_Fini(); |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
461 |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
462 /* Debugging stuff */ |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
463 #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
|
464 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
|
465 #endif |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
466 |
|
37290
89142cadcfb9
In format strings slinging Py_ssize_t, unconditionally
Tim Peters <tim.peters@gmail.com>
parents:
37229
diff
changeset
|
467 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
|
468 |
|
28647
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
469 #ifdef Py_TRACE_REFS |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
470 /* Display all objects still alive -- this can invoke arbitrary |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
471 * __repr__ overrides, so requires a mostly-intact interpreter. |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
472 * Alas, a lot of stuff may still be alive now that will be cleaned |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
473 * up later. |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
474 */ |
|
28653
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
475 if (Py_GETENV("PYTHONDUMPREFS")) |
|
28647
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
476 _Py_PrintReferences(stderr); |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
477 #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
|
478 |
|
28613
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
479 /* Clear interpreter state */ |
|
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
480 PyInterpreterState_Clear(interp); |
|
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
481 |
|
34834
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
482 /* Now we decref the exception classes. After this point nothing |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
483 can raise an exception. That's okay, because each Fini() method |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
484 below has been checked to make sure no exceptions are ever |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
485 raised. |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
486 */ |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
487 |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
488 _PyExc_Fini(); |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
489 |
|
44063
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
490 /* Cleanup auto-thread-state */ |
|
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
491 #ifdef WITH_THREAD |
|
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
492 _PyGILState_Fini(); |
|
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
493 #endif /* WITH_THREAD */ |
|
4417ab5b351e
Issue #1402: PyInterpreterState_Clear() may still invoke user code
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41526
diff
changeset
|
494 |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
495 /* Delete current thread */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
496 PyThreadState_Swap(NULL); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
497 PyInterpreterState_Delete(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
498 |
|
28613
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
499 /* Sundry finalizers */ |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
500 PyMethod_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
501 PyFrame_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
502 PyCFunction_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
503 PyTuple_Fini(); |
|
33679
55fba88930bc
Finalize the freelist of list objects.
Raymond Hettinger <python@rcn.com>
parents:
33189
diff
changeset
|
504 PyList_Fini(); |
|
35297
26bf6c27e9ce
* Improve code for the empty frozenset singleton:
Raymond Hettinger <python@rcn.com>
parents:
34972
diff
changeset
|
505 PySet_Fini(); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
506 PyString_Fini(); |
|
47291
04bd3690fb1f
First step of the C API rename:
Christian Heimes <christian@cheimes.de>
parents:
46889
diff
changeset
|
507 PyByteArray_Fini(); |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
508 PyInt_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
509 PyFloat_Fini(); |
|
45229
262263737bce
Deallocate content of the dict free list on interpreter shutdown
Christian Heimes <christian@cheimes.de>
parents:
45025
diff
changeset
|
510 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
|
511 |
|
22883
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
512 #ifdef Py_USING_UNICODE |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
513 /* Cleanup Unicode implementation */ |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
514 _PyUnicode_Fini(); |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
515 #endif |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
516 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
517 /* XXX Still allocated: |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
518 - various static ad-hoc pointers to interned strings |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
519 - int and float free list blocks |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
520 - whatever various modules and libraries allocate |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
521 */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
522 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
523 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
|
524 |
|
28653
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
525 #ifdef Py_TRACE_REFS |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
526 /* Display addresses (& refcnts) of all objects still alive. |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
527 * An address can be used to find the repr of the object, printed |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
528 * above by _Py_PrintReferences. |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
529 */ |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
530 if (Py_GETENV("PYTHONDUMPREFS")) |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
531 _Py_PrintReferenceAddresses(stderr); |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
532 #endif /* Py_TRACE_REFS */ |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
533 #ifdef PYMALLOC_DEBUG |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
534 if (Py_GETENV("PYTHONMALLOCSTATS")) |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
535 _PyObject_DebugMallocStats(); |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
536 #endif |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
537 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
538 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
|
539 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
540 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
541 /* 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
|
542 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
|
543 first. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
544 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 thread. |
|
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 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
551 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
552 */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
553 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
554 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
555 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
|
556 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
557 PyInterpreterState *interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
558 PyThreadState *tstate, *save_tstate; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
559 PyObject *bimod, *sysmod; |
|
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 if (!initialized) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
562 Py_FatalError("Py_NewInterpreter: call Py_Initialize first"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
563 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
564 interp = PyInterpreterState_New(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
565 if (interp == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
566 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
567 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
568 tstate = PyThreadState_New(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
569 if (tstate == NULL) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
570 PyInterpreterState_Delete(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
571 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
572 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
573 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
574 save_tstate = PyThreadState_Swap(tstate); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
575 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
576 /* XXX The following is lax in error checking */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
577 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
578 interp->modules = PyDict_New(); |
|
41128
45ce388ec59a
Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Collin Winter <collinw@gmail.com>
parents:
41126
diff
changeset
|
579 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
|
580 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
581 bimod = _PyImport_FindExtension("__builtin__", "__builtin__"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
582 if (bimod != NULL) { |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
583 interp->builtins = PyModule_GetDict(bimod); |
|
39614
9dee81dcb9b4
Handle a few more error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39458
diff
changeset
|
584 if (interp->builtins == NULL) |
|
9dee81dcb9b4
Handle a few more error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39458
diff
changeset
|
585 goto handle_error; |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
586 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
|
587 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
588 sysmod = _PyImport_FindExtension("sys", "sys"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
589 if (bimod != NULL && sysmod != NULL) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
590 interp->sysdict = PyModule_GetDict(sysmod); |
|
39614
9dee81dcb9b4
Handle a few more error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39458
diff
changeset
|
591 if (interp->sysdict == NULL) |
|
9dee81dcb9b4
Handle a few more error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39458
diff
changeset
|
592 goto handle_error; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
593 Py_INCREF(interp->sysdict); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
594 PySys_SetPath(Py_GetPath()); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
595 PyDict_SetItemString(interp->sysdict, "modules", |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
596 interp->modules); |
|
27340
8b53b0ce06d4
Patch #671459: Invoke import hooks in Py_NewInterpreter.
Martin v. Löwis <martin@v.loewis.de>
parents:
26923
diff
changeset
|
597 _PyImportHooks_Init(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
598 initmain(); |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
599 if (!Py_NoSiteFlag) |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
600 initsite(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
601 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
602 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
603 if (!PyErr_Occurred()) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
604 return tstate; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
605 |
|
39614
9dee81dcb9b4
Handle a few more error conditions.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39458
diff
changeset
|
606 handle_error: |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
607 /* Oops, it didn't work. Undo it all. */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
608 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
609 PyErr_Print(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
610 PyThreadState_Clear(tstate); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
611 PyThreadState_Swap(save_tstate); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
612 PyThreadState_Delete(tstate); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
613 PyInterpreterState_Delete(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
614 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
615 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
616 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
617 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
618 /* 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
|
619 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
|
620 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
|
621 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
|
622 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
623 (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
|
624 everything, regardless.) |
|
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 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
627 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
628 */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
629 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
630 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
631 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
|
632 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
633 PyInterpreterState *interp = tstate->interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
634 |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31771
diff
changeset
|
635 if (tstate != PyThreadState_GET()) |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
636 Py_FatalError("Py_EndInterpreter: thread is not current"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
637 if (tstate->frame != NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
638 Py_FatalError("Py_EndInterpreter: thread still has a frame"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
639 if (tstate != interp->tstate_head || tstate->next != NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
640 Py_FatalError("Py_EndInterpreter: not the last thread"); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
641 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
642 PyImport_Cleanup(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
643 PyInterpreterState_Clear(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
644 PyThreadState_Swap(NULL); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
645 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
|
646 } |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
647 |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
648 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
|
649 |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
650 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
651 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
|
652 { |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
653 if (pn && *pn) |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
654 progname = pn; |
|
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 char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
658 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
|
659 { |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
660 return progname; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
661 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
662 |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
663 static char *default_home = NULL; |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
664 |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
665 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
666 Py_SetPythonHome(char *home) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
667 { |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
668 default_home = home; |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
669 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
670 |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
671 char * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
672 Py_GetPythonHome(void) |
|
7206
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 char *home = default_home; |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
675 if (home == NULL && !Py_IgnoreEnvironmentFlag) |
|
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
676 home = Py_GETENV("PYTHONHOME"); |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
677 return home; |
|
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 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
680 /* Create __main__ module */ |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
681 |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
682 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
683 initmain(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
684 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
685 PyObject *m, *d; |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
686 m = PyImport_AddModule("__main__"); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
687 if (m == NULL) |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
688 Py_FatalError("can't create __main__ module"); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
689 d = PyModule_GetDict(m); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
690 if (PyDict_GetItemString(d, "__builtins__") == NULL) { |
|
6600
83ccf44bf195
Two changes (here we go again :-( ).
Guido van Rossum <guido@python.org>
parents:
6557
diff
changeset
|
691 PyObject *bimod = PyImport_ImportModule("__builtin__"); |
|
83ccf44bf195
Two changes (here we go again :-( ).
Guido van Rossum <guido@python.org>
parents:
6557
diff
changeset
|
692 if (bimod == NULL || |
|
83ccf44bf195
Two changes (here we go again :-( ).
Guido van Rossum <guido@python.org>
parents:
6557
diff
changeset
|
693 PyDict_SetItemString(d, "__builtins__", bimod) != 0) |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
694 Py_FatalError("can't add __builtins__ to __main__"); |
|
10024
caf2c65a6bcf
initmain(): Nailed a memory leak. bimod must be DECREF'd!
Barry Warsaw <barry@python.org>
parents:
9965
diff
changeset
|
695 Py_DECREF(bimod); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
696 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
697 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
698 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
699 /* Import the site module (not into __main__ though) */ |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
700 |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
701 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
702 initsite(void) |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
703 { |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
704 PyObject *m, *f; |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
705 m = PyImport_ImportModule("site"); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
706 if (m == NULL) { |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
707 f = PySys_GetObject("stderr"); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
708 if (Py_VerboseFlag) { |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
709 PyFile_WriteString( |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
710 "'import site' failed; traceback:\n", f); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
711 PyErr_Print(); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
712 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
713 else { |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
714 PyFile_WriteString( |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
715 "'import site' failed; use -v for traceback\n", f); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
716 PyErr_Clear(); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
717 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
718 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
719 else { |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
720 Py_DECREF(m); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
721 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
722 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
723 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
724 /* Parse input from a file and execute it */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
725 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
726 int |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
727 PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
728 PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
729 { |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
730 if (filename == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
731 filename = "???"; |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
732 if (Py_FdIsInteractive(fp, filename)) { |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
733 int err = PyRun_InteractiveLoopFlags(fp, filename, flags); |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
734 if (closeit) |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
735 fclose(fp); |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
736 return err; |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
737 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
738 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
739 return PyRun_SimpleFileExFlags(fp, filename, closeit, flags); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
740 } |
|
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 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
743 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
|
744 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
745 PyObject *v; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
746 int ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
747 PyCompilerFlags local_flags; |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
748 |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
749 if (flags == NULL) { |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
750 flags = &local_flags; |
|
18611
fdb36a0c7e6e
Part way to allowing "from __future__ import generators" to communicate
Tim Peters <tim.peters@gmail.com>
parents:
18101
diff
changeset
|
751 local_flags.cf_flags = 0; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
752 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
753 v = PySys_GetObject("ps1"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
754 if (v == NULL) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
755 PySys_SetObject("ps1", v = PyString_FromString(">>> ")); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
756 Py_XDECREF(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
757 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
758 v = PySys_GetObject("ps2"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
759 if (v == NULL) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
760 PySys_SetObject("ps2", v = PyString_FromString("... ")); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
761 Py_XDECREF(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
762 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
763 for (;;) { |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
764 ret = PyRun_InteractiveOneFlags(fp, filename, flags); |
|
37290
89142cadcfb9
In format strings slinging Py_ssize_t, unconditionally
Tim Peters <tim.peters@gmail.com>
parents:
37229
diff
changeset
|
765 PRINT_TOTAL_REFS(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
766 if (ret == E_EOF) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
767 return 0; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
768 /* |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
769 if (ret == E_NOMEM) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
770 return -1; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
771 */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
772 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
773 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
774 |
|
45891
727f743cf630
Backport of the print function, using a __future__ import.
Eric Smith <eric@trueblade.com>
parents:
45389
diff
changeset
|
775 #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
|
776 /* 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
|
777 #define PARSER_FLAGS(flags) \ |
|
36726
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36662
diff
changeset
|
778 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ |
|
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
|
779 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
|
780 #endif |
|
727f743cf630
Backport of the print function, using a __future__ import.
Eric Smith <eric@trueblade.com>
parents:
45389
diff
changeset
|
781 #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
|
782 /* 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
|
783 #define PARSER_FLAGS(flags) \ |
|
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 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ |
|
36726
bbf16fd024df
from __future__ import with_statement addon for 'with', mostly written by
Thomas Wouters <thomas@python.org>
parents:
36662
diff
changeset
|
785 PyPARSE_DONT_IMPLY_DEDENT : 0) \ |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
786 | (((flags)->cf_flags & CO_FUTURE_PRINT_FUNCTION) ? \ |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
787 PyPARSE_PRINT_IS_FUNCTION : 0) \ |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
788 | (((flags)->cf_flags & CO_FUTURE_UNICODE_LITERALS) ? \ |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
789 PyPARSE_UNICODE_LITERALS : 0) \ |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
790 ) : 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
|
791 #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
|
792 |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
793 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
794 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
|
795 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
796 PyObject *m, *d, *v, *w; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
797 mod_ty mod; |
| 36836 | 798 PyArena *arena; |
|
6661
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
799 char *ps1 = "", *ps2 = ""; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
800 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
|
801 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
802 v = PySys_GetObject("ps1"); |
|
6661
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
803 if (v != NULL) { |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
804 v = PyObject_Str(v); |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
805 if (v == NULL) |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
806 PyErr_Clear(); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
807 else if (PyString_Check(v)) |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
808 ps1 = PyString_AsString(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
809 } |
|
6661
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
810 w = PySys_GetObject("ps2"); |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
811 if (w != NULL) { |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
812 w = PyObject_Str(w); |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
813 if (w == NULL) |
|
99955b65408d
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
Guido van Rossum <guido@python.org>
parents:
6600
diff
changeset
|
814 PyErr_Clear(); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
815 else if (PyString_Check(w)) |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
816 ps2 = PyString_AsString(w); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
817 } |
| 36836 | 818 arena = PyArena_New(); |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
819 if (arena == NULL) { |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
820 Py_XDECREF(v); |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
821 Py_XDECREF(w); |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
822 return -1; |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
823 } |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
824 mod = PyParser_ASTFromFile(fp, filename, |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
825 Py_single_input, ps1, ps2, |
|
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
|
826 flags, &errcode, arena); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
827 Py_XDECREF(v); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
828 Py_XDECREF(w); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
829 if (mod == NULL) { |
| 36836 | 830 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
831 if (errcode == E_EOF) { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
832 PyErr_Clear(); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
833 return E_EOF; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
834 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
835 PyErr_Print(); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
836 return -1; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
837 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
838 m = PyImport_AddModule("__main__"); |
|
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
|
839 if (m == NULL) { |
| 36836 | 840 PyArena_Free(arena); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
841 return -1; |
|
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
|
842 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
843 d = PyModule_GetDict(m); |
|
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
|
844 v = run_mod(mod, filename, d, d, flags, arena); |
| 36836 | 845 PyArena_Free(arena); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
846 if (v == NULL) { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
847 PyErr_Print(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
848 return -1; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
849 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
850 Py_DECREF(v); |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
851 if (Py_FlushLine()) |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
852 PyErr_Clear(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
853 return 0; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
854 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
855 |
|
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
|
856 /* 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
|
857 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
|
858 |
|
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 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
860 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
|
861 { |
|
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 if (strcmp(ext, ".pyc") == 0 || strcmp(ext, ".pyo") == 0) |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
863 return 1; |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
864 |
|
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 /* Only look into the file if we are allowed to close it, since |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
866 it then should also be seekable. */ |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
867 if (closeit) { |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
868 /* Read only two bytes of the magic. If the file was opened in |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
869 text mode, the bytes 3 and 4 of the magic (\r\n) might not |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
870 be read as they are on disk. */ |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
871 unsigned int halfmagic = PyImport_GetMagicNumber() & 0xFFFF; |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
872 unsigned char buf[2]; |
|
16560
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
873 /* Mess: In case of -x, the stream is NOT at its start now, |
|
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
874 and ungetc() was used to push back the first newline, |
|
16648
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
875 which makes the current stream position formally undefined, |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
876 and a x-platform nightmare. |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
877 Unfortunately, we have no direct way to know whether -x |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
878 was specified. So we use a terrible hack: if the current |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
879 stream position is not 0, we assume -x was specified, and |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
880 give up. Bug 132850 on SourceForge spells out the |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
881 hopelessness of trying anything else (fseek and ftell |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
882 don't work predictably x-platform for text-mode files). |
|
16560
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
883 */ |
|
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
884 int ispyc = 0; |
|
16648
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
885 if (ftell(fp) == 0) { |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
886 if (fread(buf, 1, 2, fp) == 2 && |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
887 ((unsigned int)buf[1]<<8 | buf[0]) == halfmagic) |
|
16648
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
888 ispyc = 1; |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
889 rewind(fp); |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
890 } |
|
16560
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
891 return ispyc; |
|
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
|
892 } |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
893 return 0; |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
894 } |
|
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
|
895 |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
896 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
897 PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
898 PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
899 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
900 PyObject *m, *d, *v; |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
901 const char *ext; |
|
52818
cb58c973985c
Merged revisions 71152 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
52605
diff
changeset
|
902 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
|
903 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
904 m = PyImport_AddModule("__main__"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
905 if (m == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
906 return -1; |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
907 d = PyModule_GetDict(m); |
|
25827
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
908 if (PyDict_GetItemString(d, "__file__") == NULL) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
909 PyObject *f = PyString_FromString(filename); |
|
25827
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
910 if (f == NULL) |
|
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
911 return -1; |
|
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
912 if (PyDict_SetItemString(d, "__file__", f) < 0) { |
|
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
913 Py_DECREF(f); |
|
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
914 return -1; |
|
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
915 } |
|
41044
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
916 set_file_name = 1; |
|
25827
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
917 Py_DECREF(f); |
|
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
918 } |
|
52818
cb58c973985c
Merged revisions 71152 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
52605
diff
changeset
|
919 len = strlen(filename); |
|
cb58c973985c
Merged revisions 71152 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
52605
diff
changeset
|
920 ext = filename + len - (len > 4 ? 4 : 0); |
|
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
|
921 if (maybe_pyc_file(fp, filename, ext, closeit)) { |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
922 /* Try to run a pyc file. First, re-open in binary */ |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
923 if (closeit) |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
924 fclose(fp); |
|
25827
093fe5b9f6f9
If we have a filename and __main__.__file__ hasn't already been set,
Fred Drake <fdrake@acm.org>
parents:
25573
diff
changeset
|
925 if ((fp = fopen(filename, "rb")) == NULL) { |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
926 fprintf(stderr, "python: Can't reopen .pyc file\n"); |
|
41044
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
927 ret = -1; |
|
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
928 goto done; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
929 } |
|
5234
07ed52e200db
Allow passing a .pyo file.
Guido van Rossum <guido@python.org>
parents:
5170
diff
changeset
|
930 /* Turn on optimization if a .pyo file is given */ |
|
07ed52e200db
Allow passing a .pyo file.
Guido van Rossum <guido@python.org>
parents:
5170
diff
changeset
|
931 if (strcmp(ext, ".pyo") == 0) |
|
07ed52e200db
Allow passing a .pyo file.
Guido van Rossum <guido@python.org>
parents:
5170
diff
changeset
|
932 Py_OptimizeFlag = 1; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
933 v = run_pyc_file(fp, filename, d, d, flags); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
934 } else { |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
935 v = PyRun_FileExFlags(fp, filename, Py_file_input, d, d, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
936 closeit, flags); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
937 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
938 if (v == NULL) { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
939 PyErr_Print(); |
|
41044
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
940 ret = -1; |
|
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
941 goto done; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
942 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
943 Py_DECREF(v); |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
944 if (Py_FlushLine()) |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
945 PyErr_Clear(); |
|
41044
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
946 ret = 0; |
|
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
947 done: |
|
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
948 if (set_file_name && PyDict_DelItemString(d, "__file__")) |
|
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
949 PyErr_Clear(); |
|
c8ed4aea6c58
Patch #703779: unset __file__ in __main__ after running a file. This
Georg Brandl <georg@python.org>
parents:
41043
diff
changeset
|
950 return ret; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
951 } |
|
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 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
954 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
|
955 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
956 PyObject *m, *d, *v; |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
957 m = PyImport_AddModule("__main__"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
958 if (m == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
959 return -1; |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
960 d = PyModule_GetDict(m); |
|
19633
c0a44829bcd5
Add warning mode for classic division, almost exactly as specified in
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
961 v = PyRun_StringFlags(command, Py_file_input, d, d, flags); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
962 if (v == NULL) { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
963 PyErr_Print(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 return -1; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
965 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
966 Py_DECREF(v); |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
967 if (Py_FlushLine()) |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
968 PyErr_Clear(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
969 return 0; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
970 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
971 |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
972 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
973 parse_syntax_error(PyObject *err, PyObject **message, const char **filename, |
|
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
974 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
|
975 { |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
976 long hold; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
977 PyObject *v; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
978 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
979 /* old style errors */ |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
980 if (PyTuple_Check(err)) |
|
22721
253de588f2fb
Get rid of another use of PyArg_Parse()
Neal Norwitz <nnorwitz@gmail.com>
parents:
22468
diff
changeset
|
981 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, |
| 36836 | 982 lineno, offset, text); |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
983 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
984 /* new style errors. `err' is an instance */ |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
985 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
986 if (! (v = PyObject_GetAttrString(err, "msg"))) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
987 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
988 *message = v; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
989 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
990 if (!(v = PyObject_GetAttrString(err, "filename"))) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
991 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
992 if (v == Py_None) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
993 *filename = NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
994 else if (! (*filename = PyString_AsString(v))) |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
995 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
996 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
997 Py_DECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
998 if (!(v = PyObject_GetAttrString(err, "lineno"))) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
999 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1000 hold = PyInt_AsLong(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1001 Py_DECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1002 v = NULL; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1003 if (hold < 0 && PyErr_Occurred()) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1004 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1005 *lineno = (int)hold; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1006 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1007 if (!(v = PyObject_GetAttrString(err, "offset"))) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1008 goto finally; |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1009 if (v == Py_None) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1010 *offset = -1; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1011 Py_DECREF(v); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1012 v = NULL; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1013 } else { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1014 hold = PyInt_AsLong(v); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1015 Py_DECREF(v); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1016 v = NULL; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1017 if (hold < 0 && PyErr_Occurred()) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1018 goto finally; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1019 *offset = (int)hold; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1020 } |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1021 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1022 if (!(v = PyObject_GetAttrString(err, "text"))) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1023 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1024 if (v == Py_None) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1025 *text = NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
1026 else if (! (*text = PyString_AsString(v))) |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1027 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1028 Py_DECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1029 return 1; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1030 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1031 finally: |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1032 Py_XDECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1033 return 0; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1034 } |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1035 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1036 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1037 PyErr_Print(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1038 { |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1039 PyErr_PrintEx(1); |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1040 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1041 |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1042 static void |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1043 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
|
1044 { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1045 char *nl; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1046 if (offset >= 0) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1047 if (offset > 0 && offset == (int)strlen(text)) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1048 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1049 for (;;) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1050 nl = strchr(text, '\n'); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1051 if (nl == NULL || nl-text >= offset) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1052 break; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36078
diff
changeset
|
1053 offset -= (int)(nl+1-text); |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1054 text = nl+1; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1055 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1056 while (*text == ' ' || *text == '\t') { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1057 text++; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1058 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1059 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1060 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1061 PyFile_WriteString(" ", f); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1062 PyFile_WriteString(text, f); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1063 if (*text == '\0' || text[strlen(text)-1] != '\n') |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1064 PyFile_WriteString("\n", f); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1065 if (offset == -1) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1066 return; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1067 PyFile_WriteString(" ", f); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1068 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1069 while (offset > 0) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1070 PyFile_WriteString(" ", f); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1071 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1072 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1073 PyFile_WriteString("^\n", f); |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1074 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1075 |
|
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
|
1076 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
|
1077 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
|
1078 { |
| 36836 | 1079 PyObject *exception, *value, *tb; |
| 1080 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
|
1081 |
|
41043
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
1082 if (Py_InspectFlag) |
|
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
1083 /* Don't exit if -i flag was given. This flag is set to 0 |
|
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
1084 * when entering interactive mode for inspecting. */ |
|
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
1085 return; |
|
728c60e85efa
Variant of patch #697613: don't exit the interpreter on a SystemExit
Georg Brandl <georg@python.org>
parents:
41018
diff
changeset
|
1086 |
|
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
|
1087 PyErr_Fetch(&exception, &value, &tb); |
|
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
|
1088 if (Py_FlushLine()) |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1089 PyErr_Clear(); |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1090 fflush(stdout); |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1091 if (value == NULL || value == Py_None) |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1092 goto done; |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36726
diff
changeset
|
1093 if (PyExceptionInstance_Check(value)) { |
|
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
|
1094 /* The error code should be in the `code' attribute. */ |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1095 PyObject *code = PyObject_GetAttrString(value, "code"); |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1096 if (code) { |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1097 Py_DECREF(value); |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1098 value = code; |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1099 if (value == Py_None) |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1100 goto done; |
|
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
|
1101 } |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1102 /* If we failed to dig out the 'code' attribute, |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1103 just let the else clause below print the error. */ |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1104 } |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1105 if (PyInt_Check(value)) |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1106 exitcode = (int)PyInt_AsLong(value); |
|
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
|
1107 else { |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1108 PyObject_Print(value, stderr, Py_PRINT_RAW); |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1109 PySys_WriteStderr("\n"); |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1110 exitcode = 1; |
|
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
|
1111 } |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1112 done: |
| 36836 | 1113 /* Restore and clear the exception info, in order to properly decref |
| 1114 * the exception, value, and traceback. If we just exit instead, | |
| 1115 * these leak, which confuses PYTHONDUMPREFS output, and may prevent | |
| 1116 * some finalizers from running. | |
| 1117 */ | |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1118 PyErr_Restore(exception, value, tb); |
|
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1119 PyErr_Clear(); |
|
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1120 Py_Exit(exitcode); |
|
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1121 /* 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
|
1122 } |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1123 |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1124 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1125 PyErr_PrintEx(int set_sys_last_vars) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1126 { |
| 17164 | 1127 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
|
1128 |
|
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
|
1129 if (PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
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
|
1130 handle_system_exit(); |
|
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
|
1131 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1132 PyErr_Fetch(&exception, &v, &tb); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1133 if (exception == NULL) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1134 return; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1135 PyErr_NormalizeException(&exception, &v, &tb); |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
2022
diff
changeset
|
1136 if (exception == NULL) |
|
5611
5ed3a21cc122
Can't return 0 from void function...
Guido van Rossum <guido@python.org>
parents:
5607
diff
changeset
|
1137 return; |
| 47887 | 1138 /* Now we know v != NULL too */ |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1139 if (set_sys_last_vars) { |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1140 PySys_SetObject("last_type", exception); |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1141 PySys_SetObject("last_value", v); |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1142 PySys_SetObject("last_traceback", tb); |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1143 } |
| 17164 | 1144 hook = PySys_GetObject("excepthook"); |
| 1145 if (hook) { | |
|
30683
3b59fa5d25b1
Simplify and speedup uses of Py_BuildValue():
Raymond Hettinger <python@rcn.com>
parents:
30122
diff
changeset
|
1146 PyObject *args = PyTuple_Pack(3, |
|
36881
4706b7a1256c
Address an coverity issue. Coverity was complaining about a line that's fine,
Guido van Rossum <guido@python.org>
parents:
36859
diff
changeset
|
1147 exception, v, tb ? tb : Py_None); |
| 17164 | 1148 PyObject *result = PyEval_CallObject(hook, args); |
| 1149 if (result == NULL) { | |
| 1150 PyObject *exception2, *v2, *tb2; | |
|
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
|
1151 if (PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
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
|
1152 handle_system_exit(); |
|
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
|
1153 } |
| 17164 | 1154 PyErr_Fetch(&exception2, &v2, &tb2); |
| 1155 PyErr_NormalizeException(&exception2, &v2, &tb2); | |
|
39105
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1156 /* It should not be possible for exception2 or v2 |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1157 to be NULL. However PyErr_Display() can't |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1158 tolerate NULLs, so just be safe. */ |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1159 if (exception2 == NULL) { |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1160 exception2 = Py_None; |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1161 Py_INCREF(exception2); |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1162 } |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1163 if (v2 == NULL) { |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1164 v2 = Py_None; |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1165 Py_INCREF(v2); |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1166 } |
| 17164 | 1167 if (Py_FlushLine()) |
| 1168 PyErr_Clear(); | |
| 1169 fflush(stdout); | |
| 1170 PySys_WriteStderr("Error in sys.excepthook:\n"); | |
| 1171 PyErr_Display(exception2, v2, tb2); | |
| 1172 PySys_WriteStderr("\nOriginal exception was:\n"); | |
| 1173 PyErr_Display(exception, v, tb); | |
|
39105
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1174 Py_DECREF(exception2); |
|
aa85791f5991
Reported by Klocwork #151.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38716
diff
changeset
|
1175 Py_DECREF(v2); |
|
21284
43b8a962a32a
Missing DECREFs when exception is raised in sys.excepthook.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21251
diff
changeset
|
1176 Py_XDECREF(tb2); |
| 17164 | 1177 } |
| 1178 Py_XDECREF(result); | |
| 1179 Py_XDECREF(args); | |
| 1180 } else { | |
| 1181 PySys_WriteStderr("sys.excepthook is missing\n"); | |
| 1182 PyErr_Display(exception, v, tb); | |
| 1183 } | |
| 1184 Py_XDECREF(exception); | |
| 1185 Py_XDECREF(v); | |
| 1186 Py_XDECREF(tb); | |
| 1187 } | |
| 1188 | |
|
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
|
1189 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
|
1190 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) |
| 17164 | 1191 { |
| 1192 int err = 0; | |
| 1193 PyObject *f = PySys_GetObject("stderr"); | |
| 31771 | 1194 Py_INCREF(value); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1015
diff
changeset
|
1195 if (f == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1015
diff
changeset
|
1196 fprintf(stderr, "lost sys.stderr\n"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1015
diff
changeset
|
1197 else { |
|
7509
b5d52c415b15
Fix the handling of errors in Py_FlushLine() in a few places.
Guido van Rossum <guido@python.org>
parents:
7206
diff
changeset
|
1198 if (Py_FlushLine()) |
|
b5d52c415b15
Fix the handling of errors in Py_FlushLine() in a few places.
Guido van Rossum <guido@python.org>
parents:
7206
diff
changeset
|
1199 PyErr_Clear(); |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1200 fflush(stdout); |
| 17164 | 1201 if (tb && tb != Py_None) |
| 1202 err = PyTraceBack_Print(tb, f); | |
|
6165
29ddf1049842
PyErr_Print(): Use PyErr_GivenExceptionMatches() instead of pointer
Barry Warsaw <barry@python.org>
parents:
6136
diff
changeset
|
1203 if (err == 0 && |
| 31771 | 1204 PyObject_HasAttrString(value, "print_file_and_line")) |
|
6165
29ddf1049842
PyErr_Print(): Use PyErr_GivenExceptionMatches() instead of pointer
Barry Warsaw <barry@python.org>
parents:
6136
diff
changeset
|
1205 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1206 PyObject *message; |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1207 const char *filename, *text; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1208 int lineno, offset; |
| 31771 | 1209 if (!parse_syntax_error(value, &message, &filename, |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1210 &lineno, &offset, &text)) |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1211 PyErr_Clear(); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1212 else { |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1213 char buf[10]; |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1214 PyFile_WriteString(" File \"", f); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1215 if (filename == NULL) |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1216 PyFile_WriteString("<string>", f); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1217 else |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1218 PyFile_WriteString(filename, f); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1219 PyFile_WriteString("\", line ", f); |
|
21077
379fc66f4c96
Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20969
diff
changeset
|
1220 PyOS_snprintf(buf, sizeof(buf), "%d", lineno); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1221 PyFile_WriteString(buf, f); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1222 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
|
1223 if (text != NULL) |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1224 print_error_text(f, offset, text); |
| 31771 | 1225 Py_DECREF(value); |
| 1226 value = message; | |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1227 /* Can't be bothered to check all those |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1228 PyFile_WriteString() calls */ |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1229 if (PyErr_Occurred()) |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1230 err = -1; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1231 } |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1232 } |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1233 if (err) { |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1234 /* Don't do anything else */ |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1235 } |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36726
diff
changeset
|
1236 else if (PyExceptionClass_Check(exception)) { |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1237 PyObject* moduleName; |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36726
diff
changeset
|
1238 char* className = PyExceptionClass_Name(exception); |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1239 if (className != NULL) { |
|
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1240 char *dot = strrchr(className, '.'); |
|
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1241 if (dot != NULL) |
|
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1242 className = dot+1; |
|
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1243 } |
|
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1244 |
|
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
|
1245 moduleName = PyObject_GetAttrString(exception, "__module__"); |
|
6322
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1246 if (moduleName == NULL) |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1247 err = PyFile_WriteString("<unknown>", f); |
|
6322
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1248 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
1249 char* modstr = PyString_AsString(moduleName); |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1250 if (modstr && strcmp(modstr, "exceptions")) |
|
6322
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1251 { |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1252 err = PyFile_WriteString(modstr, f); |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1253 err += PyFile_WriteString(".", f); |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1254 } |
|
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
|
1255 Py_DECREF(moduleName); |
|
6322
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1256 } |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1257 if (err == 0) { |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1258 if (className == NULL) |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1259 err = PyFile_WriteString("<unknown>", f); |
|
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1260 else |
|
36751
8e04de2480e4
PEP 352 implementation. Creates a new base class, BaseException, which has an
Brett Cannon <bcannon@gmail.com>
parents:
36726
diff
changeset
|
1261 err = PyFile_WriteString(className, f); |
|
6322
05d943c4597c
PyErr_Print(): When printing a class exception, try to dig out the
Barry Warsaw <barry@python.org>
parents:
6246
diff
changeset
|
1262 } |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1263 } |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1264 else |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1265 err = PyFile_WriteObject(exception, f, Py_PRINT_RAW); |
|
36807
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1266 if (err == 0 && (value != Py_None)) { |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1267 PyObject *s = PyObject_Str(value); |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1268 /* only print colon if the str() of the |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1269 object is not the empty string |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1270 */ |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1271 if (s == NULL) |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1272 err = -1; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
1273 else if (!PyString_Check(s) || |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
1274 PyString_GET_SIZE(s) != 0) |
|
36807
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1275 err = PyFile_WriteString(": ", f); |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1276 if (err == 0) |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1277 err = PyFile_WriteObject(s, f, Py_PRINT_RAW); |
|
de4816d344ee
Fix refleak in PyErr_Display().
Brett Cannon <bcannon@gmail.com>
parents:
36768
diff
changeset
|
1278 Py_XDECREF(s); |
|
2293
a24146241991
print class name for exceptions that are classes
Guido van Rossum <guido@python.org>
parents:
2279
diff
changeset
|
1279 } |
|
41126
a87bcc37bf0f
Bug #1678647: write a newline after printing an exception in any
Georg Brandl <georg@python.org>
parents:
41044
diff
changeset
|
1280 /* try to write a newline in any case */ |
|
a87bcc37bf0f
Bug #1678647: write a newline after printing an exception in any
Georg Brandl <georg@python.org>
parents:
41044
diff
changeset
|
1281 err += PyFile_WriteString("\n", f); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1282 } |
| 31771 | 1283 Py_DECREF(value); |
|
5607
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1284 /* If an error happened here, don't show it. |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1285 XXX This is wrong, but too many callers rely on this behavior. */ |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1286 if (err != 0) |
|
cbb4e3cf086e
Py_FlushLine and PyFile_WriteString now return error indicators
Guido van Rossum <guido@python.org>
parents:
5593
diff
changeset
|
1287 PyErr_Clear(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1288 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1289 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1290 PyObject * |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1291 PyRun_StringFlags(const char *str, int start, PyObject *globals, |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1292 PyObject *locals, PyCompilerFlags *flags) |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
1293 { |
|
36835
9109b1a0d265
Get rid of run_err_mod(). It was only used in two places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36807
diff
changeset
|
1294 PyObject *ret = NULL; |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1295 mod_ty mod; |
| 36836 | 1296 PyArena *arena = PyArena_New(); |
|
39131
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1297 if (arena == NULL) |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1298 return NULL; |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1299 |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1300 mod = PyParser_ASTFromString(str, "<string>", start, flags, arena); |
|
36835
9109b1a0d265
Get rid of run_err_mod(). It was only used in two places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36807
diff
changeset
|
1301 if (mod != NULL) |
|
9109b1a0d265
Get rid of run_err_mod(). It was only used in two places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36807
diff
changeset
|
1302 ret = run_mod(mod, "<string>", globals, locals, flags, arena); |
| 36836 | 1303 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1304 return ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1305 } |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1306 |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1307 PyObject * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1308 PyRun_FileExFlags(FILE *fp, const char *filename, int start, PyObject *globals, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1309 PyObject *locals, int closeit, PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1310 { |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1311 PyObject *ret; |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1312 mod_ty mod; |
| 36836 | 1313 PyArena *arena = PyArena_New(); |
|
39131
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1314 if (arena == NULL) |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1315 return NULL; |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1316 |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1317 mod = PyParser_ASTFromFile(fp, filename, start, 0, 0, |
|
7c09b66f04bd
Handle more memory allocation failures without crashing.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39105
diff
changeset
|
1318 flags, NULL, arena); |
|
41018
5c08e6460dc5
Bug #1674503: close the file opened by execfile() in an error condition.
Georg Brandl <georg@python.org>
parents:
40699
diff
changeset
|
1319 if (closeit) |
|
5c08e6460dc5
Bug #1674503: close the file opened by execfile() in an error condition.
Georg Brandl <georg@python.org>
parents:
40699
diff
changeset
|
1320 fclose(fp); |
|
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
|
1321 if (mod == NULL) { |
| 36836 | 1322 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1323 return NULL; |
| 36836 | 1324 } |
|
36835
9109b1a0d265
Get rid of run_err_mod(). It was only used in two places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36807
diff
changeset
|
1325 ret = run_mod(mod, filename, globals, locals, flags, arena); |
| 36836 | 1326 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1327 return ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1328 } |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1329 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1330 static PyObject * |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1331 run_mod(mod_ty mod, const char *filename, PyObject *globals, PyObject *locals, |
|
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
|
1332 PyCompilerFlags *flags, PyArena *arena) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1333 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1334 PyCodeObject *co; |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1335 PyObject *v; |
|
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
|
1336 co = PyAST_Compile(mod, filename, flags, arena); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1337 if (co == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1338 return NULL; |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1339 v = PyEval_EvalCode(co, globals, locals); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1340 Py_DECREF(co); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1341 return v; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1342 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1343 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1344 static PyObject * |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1345 run_pyc_file(FILE *fp, const char *filename, PyObject *globals, |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1346 PyObject *locals, PyCompilerFlags *flags) |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1347 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1348 PyCodeObject *co; |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1349 PyObject *v; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1350 long magic; |
|
14278
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1351 long PyImport_GetMagicNumber(void); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1352 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1353 magic = PyMarshal_ReadLongFromFile(fp); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1354 if (magic != PyImport_GetMagicNumber()) { |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1355 PyErr_SetString(PyExc_RuntimeError, |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1356 "Bad magic number in .pyc file"); |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1357 return NULL; |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1358 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1359 (void) PyMarshal_ReadLongFromFile(fp); |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16073
diff
changeset
|
1360 v = PyMarshal_ReadLastObjectFromFile(fp); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1361 fclose(fp); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1362 if (v == NULL || !PyCode_Check(v)) { |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1363 Py_XDECREF(v); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1364 PyErr_SetString(PyExc_RuntimeError, |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1365 "Bad code object in .pyc file"); |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1366 return NULL; |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1367 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1368 co = (PyCodeObject *)v; |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1369 v = PyEval_EvalCode(co, globals, locals); |
|
19158
97a3d3d7029f
Refactor future feature handling
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19099
diff
changeset
|
1370 if (v && flags) |
|
97a3d3d7029f
Refactor future feature handling
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19099
diff
changeset
|
1371 flags->cf_flags |= (co->co_flags & PyCF_MASK); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1372 Py_DECREF(co); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1373 return v; |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1374 } |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1375 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1376 PyObject * |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1377 Py_CompileStringFlags(const char *str, const char *filename, int start, |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1378 PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1379 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1380 PyCodeObject *co; |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1381 mod_ty mod; |
| 36836 | 1382 PyArena *arena = PyArena_New(); |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1383 if (arena == NULL) |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1384 return NULL; |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1385 |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1386 mod = PyParser_ASTFromString(str, filename, start, flags, arena); |
|
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
|
1387 if (mod == NULL) { |
| 36836 | 1388 PyArena_Free(arena); |
|
1263
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1389 return NULL; |
| 36836 | 1390 } |
|
36662
2ab9270ef19a
Check whether there are flags.
Martin v. Löwis <martin@v.loewis.de>
parents:
36660
diff
changeset
|
1391 if (flags && (flags->cf_flags & PyCF_ONLY_AST)) { |
|
36660
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1392 PyObject *result = PyAST_mod2obj(mod); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1393 PyArena_Free(arena); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1394 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1395 } |
|
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
|
1396 co = PyAST_Compile(mod, filename, flags, arena); |
| 36836 | 1397 PyArena_Free(arena); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1398 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
|
1399 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1400 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1401 struct symtable * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1402 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
|
1403 { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1404 struct symtable *st; |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1405 mod_ty mod; |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1406 PyCompilerFlags flags; |
| 36836 | 1407 PyArena *arena = PyArena_New(); |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1408 if (arena == NULL) |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1409 return NULL; |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39131
diff
changeset
|
1410 |
|
46121
d00ded8b2677
Initialize PyCompilerFlags cf_flags with 0
Christian Heimes <christian@cheimes.de>
parents:
46118
diff
changeset
|
1411 flags.cf_flags = 0; |
|
d00ded8b2677
Initialize PyCompilerFlags cf_flags with 0
Christian Heimes <christian@cheimes.de>
parents:
46118
diff
changeset
|
1412 |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1413 mod = PyParser_ASTFromString(str, filename, start, &flags, arena); |
|
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
|
1414 if (mod == NULL) { |
| 36836 | 1415 PyArena_Free(arena); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1416 return NULL; |
| 36836 | 1417 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1418 st = PySymtable_Build(mod, filename, 0); |
| 36836 | 1419 PyArena_Free(arena); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1420 return st; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1421 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1422 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1423 /* Preferred access to parser is through AST. */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1424 mod_ty |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1425 PyParser_ASTFromString(const char *s, const char *filename, int start, |
|
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
|
1426 PyCompilerFlags *flags, PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1427 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1428 mod_ty mod; |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1429 PyCompilerFlags localflags; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1430 perrdetail err; |
|
46123
248676988c54
C89 compliance: Microsoft compilers want variable declarations at the top
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46121
diff
changeset
|
1431 int iflags = PARSER_FLAGS(flags); |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1432 |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1433 node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1434 &_PyParser_Grammar, start, &err, |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1435 &iflags); |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1436 if (flags == NULL) { |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1437 localflags.cf_flags = 0; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1438 flags = &localflags; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1439 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1440 if (n) { |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1441 flags->cf_flags |= iflags & PyCF_MASK; |
|
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
|
1442 mod = PyAST_FromNode(n, flags, filename, arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1443 PyNode_Free(n); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1444 return mod; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1445 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1446 else { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1447 err_input(&err); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1448 return NULL; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1449 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1450 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1451 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1452 mod_ty |
|
38455
1a23706139ca
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
Tim Peters <tim.peters@gmail.com>
parents:
38431
diff
changeset
|
1453 PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1, |
|
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
|
1454 char *ps2, PyCompilerFlags *flags, int *errcode, |
| 36836 | 1455 PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1456 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1457 mod_ty mod; |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1458 PyCompilerFlags localflags; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1459 perrdetail err; |
|
46123
248676988c54
C89 compliance: Microsoft compilers want variable declarations at the top
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46121
diff
changeset
|
1460 int iflags = PARSER_FLAGS(flags); |
|
46118
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1461 |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1462 node *n = PyParser_ParseFileFlagsEx(fp, filename, &_PyParser_Grammar, |
|
c78d3586c474
Patch #2477: Added from __future__ import unicode_literals
Christian Heimes <christian@cheimes.de>
parents:
46107
diff
changeset
|
1463 start, ps1, ps2, &err, &iflags); |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1464 if (flags == NULL) { |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1465 localflags.cf_flags = 0; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1466 flags = &localflags; |
|
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1467 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1468 if (n) { |
|
49623
6cac2e3077a3
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48847
diff
changeset
|
1469 flags->cf_flags |= iflags & PyCF_MASK; |
|
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
|
1470 mod = PyAST_FromNode(n, flags, filename, arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1471 PyNode_Free(n); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1472 return mod; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1473 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1474 else { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1475 err_input(&err); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1476 if (errcode) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1477 *errcode = err.error; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1478 return NULL; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1479 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1480 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1481 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1482 /* 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
|
1483 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1484 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1485 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
|
1486 { |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1487 perrdetail err; |
|
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
|
1488 node *n = PyParser_ParseFileFlags(fp, filename, &_PyParser_Grammar, |
|
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
|
1489 start, NULL, NULL, &err, flags); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1490 if (n == NULL) |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1491 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
|
1492 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1493 return n; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1494 } |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1495 |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1496 /* 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
|
1497 |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1498 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1499 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
|
1500 { |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1501 perrdetail err; |
|
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
|
1502 node *n = PyParser_ParseStringFlags(str, &_PyParser_Grammar, |
|
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
|
1503 start, &err, 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
|
1504 if (n == NULL) |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1505 err_input(&err); |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1506 return n; |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1507 } |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1508 |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1509 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1510 PyParser_SimpleParseStringFlagsFilename(const char *str, const char *filename, |
|
24159
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1511 int start, int flags) |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1512 { |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1513 perrdetail err; |
|
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
|
1514 node *n = PyParser_ParseStringFlagsFilename(str, filename, |
|
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
|
1515 &_PyParser_Grammar, start, &err, flags); |
|
24159
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1516 if (n == NULL) |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1517 err_input(&err); |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1518 return n; |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1519 } |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1520 |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1521 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1522 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
|
1523 { |
|
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
|
1524 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
|
1525 } |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1526 |
|
28649
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1527 /* 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
|
1528 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
|
1529 |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1530 void |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1531 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
|
1532 { |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1533 err_input(err); |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1534 } |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1535 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1536 /* 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
|
1537 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1538 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1539 err_input(perrdetail *err) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1540 { |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1541 PyObject *v, *w, *errtype; |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1542 PyObject* u = NULL; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1543 char *msg = NULL; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1544 errtype = PyExc_SyntaxError; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1545 switch (err->error) { |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1546 case E_SYNTAX: |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1547 errtype = PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1548 if (err->expected == INDENT) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1549 msg = "expected an indented block"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1550 else if (err->token == INDENT) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1551 msg = "unexpected indent"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1552 else if (err->token == DEDENT) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1553 msg = "unexpected unindent"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1554 else { |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1555 errtype = PyExc_SyntaxError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1556 msg = "invalid syntax"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1557 } |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1558 break; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1559 case E_TOKEN: |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1560 msg = "invalid token"; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1561 break; |
|
24839
17e95cc06f69
provide less mysterious error messages when seeing end-of-line in
Skip Montanaro <skip@pobox.com>
parents:
24539
diff
changeset
|
1562 case E_EOFS: |
|
46889
1fdfb29f4fb8
#2816: clarify error messages for EOF while scanning strings.
Georg Brandl <georg@python.org>
parents:
46698
diff
changeset
|
1563 msg = "EOF while scanning triple-quoted string literal"; |
|
24839
17e95cc06f69
provide less mysterious error messages when seeing end-of-line in
Skip Montanaro <skip@pobox.com>
parents:
24539
diff
changeset
|
1564 break; |
|
17e95cc06f69
provide less mysterious error messages when seeing end-of-line in
Skip Montanaro <skip@pobox.com>
parents:
24539
diff
changeset
|
1565 case E_EOLS: |
|
46889
1fdfb29f4fb8
#2816: clarify error messages for EOF while scanning strings.
Georg Brandl <georg@python.org>
parents:
46698
diff
changeset
|
1566 msg = "EOL while scanning string literal"; |
|
24839
17e95cc06f69
provide less mysterious error messages when seeing end-of-line in
Skip Montanaro <skip@pobox.com>
parents:
24539
diff
changeset
|
1567 break; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1568 case E_INTR: |
| 32526 | 1569 if (!PyErr_Occurred()) |
| 1570 PyErr_SetNone(PyExc_KeyboardInterrupt); | |
|
48024
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1571 goto cleanup; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1572 case E_NOMEM: |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1573 PyErr_NoMemory(); |
|
48024
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1574 goto cleanup; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1575 case E_EOF: |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1576 msg = "unexpected EOF while parsing"; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1577 break; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1578 case E_TABSPACE: |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1579 errtype = PyExc_TabError; |
|
7967
bbd2b5d8d0b6
Translate E_INDENT to the clearest error message I can think of.
Guido van Rossum <guido@python.org>
parents:
7847
diff
changeset
|
1580 msg = "inconsistent use of tabs and spaces in indentation"; |
|
bbd2b5d8d0b6
Translate E_INDENT to the clearest error message I can think of.
Guido van Rossum <guido@python.org>
parents:
7847
diff
changeset
|
1581 break; |
|
12970
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12754
diff
changeset
|
1582 case E_OVERFLOW: |
|
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12754
diff
changeset
|
1583 msg = "expression too long"; |
|
63436719d12e
Add new parser error code, E_OVERFLOW. This error is returned when
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12754
diff
changeset
|
1584 break; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1585 case E_DEDENT: |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1586 errtype = PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1587 msg = "unindent does not match any outer indentation level"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1588 break; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1589 case E_TOODEEP: |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1590 errtype = PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1591 msg = "too many levels of indentation"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1592 break; |
|
35417
e48fcd4c358d
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
35297
diff
changeset
|
1593 case E_DECODE: { |
|
e48fcd4c358d
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
35297
diff
changeset
|
1594 PyObject *type, *value, *tb; |
|
e48fcd4c358d
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
35297
diff
changeset
|
1595 PyErr_Fetch(&type, &value, &tb); |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1596 if (value != NULL) { |
|
35417
e48fcd4c358d
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
35297
diff
changeset
|
1597 u = PyObject_Str(value); |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1598 if (u != NULL) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47416
diff
changeset
|
1599 msg = PyString_AsString(u); |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1600 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1601 } |
|
32781
caaef302f1e3
Patch #984714: Properly diagnose E_DECODE errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
32526
diff
changeset
|
1602 if (msg == NULL) |
|
caaef302f1e3
Patch #984714: Properly diagnose E_DECODE errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
32526
diff
changeset
|
1603 msg = "unknown decode error"; |
|
36078
1ff4790b7605
Fix Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36065
diff
changeset
|
1604 Py_XDECREF(type); |
|
1ff4790b7605
Fix Bug #1378022, UTF-8 files with a leading BOM crashed the interpreter.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36065
diff
changeset
|
1605 Py_XDECREF(value); |
|
35666
b8e571e6de2e
- Fix segfault with invalid coding.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35417
diff
changeset
|
1606 Py_XDECREF(tb); |
|
32781
caaef302f1e3
Patch #984714: Properly diagnose E_DECODE errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
32526
diff
changeset
|
1607 break; |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1608 } |
|
34664
3785610ff763
Patch #802188: better parser error message for non-EOL following line cont.
Martin v. Löwis <martin@v.loewis.de>
parents:
33747
diff
changeset
|
1609 case E_LINECONT: |
|
3785610ff763
Patch #802188: better parser error message for non-EOL following line cont.
Martin v. Löwis <martin@v.loewis.de>
parents:
33747
diff
changeset
|
1610 msg = "unexpected character after line continuation character"; |
|
3785610ff763
Patch #802188: better parser error message for non-EOL following line cont.
Martin v. Löwis <martin@v.loewis.de>
parents:
33747
diff
changeset
|
1611 break; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1612 default: |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1613 fprintf(stderr, "error=%d\n", err->error); |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1614 msg = "unknown parsing error"; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1615 break; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1616 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1617 v = Py_BuildValue("(ziiz)", err->filename, |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1618 err->lineno, err->offset, err->text); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1619 w = NULL; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1620 if (v != NULL) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1621 w = Py_BuildValue("(sO)", msg, v); |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1622 Py_XDECREF(u); |
|
17168
0d52358cb288
Fix memory leak with SyntaxError. (The DECREF was originally hidden
Guido van Rossum <guido@python.org>
parents:
17164
diff
changeset
|
1623 Py_XDECREF(v); |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1624 PyErr_SetObject(errtype, w); |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1625 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
|
1626 cleanup: |
|
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1627 if (err->text != NULL) { |
|
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1628 PyObject_FREE(err->text); |
|
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1629 err->text = NULL; |
|
7ad6e4cd7713
#3378: in case of no memory, don't leak even more memory. :)
Georg Brandl <georg@python.org>
parents:
47887
diff
changeset
|
1630 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1631 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1632 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1633 /* Print fatal error message and abort */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1634 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1635 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
|
1636 Py_FatalError(const char *msg) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1637 { |
|
1911
a7f269610ec2
* Python/pythonrun.c: add string "Python" to fatal error message
Guido van Rossum <guido@python.org>
parents:
1898
diff
changeset
|
1638 fprintf(stderr, "Fatal Python error: %s\n", msg); |
|
52605
e2818b9f964b
Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents:
50522
diff
changeset
|
1639 fflush(stderr); /* it helps in Windows debug build */ |
|
e2818b9f964b
Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents:
50522
diff
changeset
|
1640 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
1641 #ifdef MS_WINDOWS |
|
50522
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1642 { |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1643 size_t len = strlen(msg); |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1644 WCHAR* buffer; |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1645 size_t i; |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1646 |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1647 /* Convert the message to wchar_t. This uses a simple one-to-one |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1648 conversion, assuming that the this error message actually uses ASCII |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1649 only. If this ceases to be true, we will have to convert. */ |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1650 buffer = alloca( (len+1) * (sizeof *buffer)); |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1651 for( i=0; i<=len; ++i) |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1652 buffer[i] = msg[i]; |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1653 OutputDebugStringW(L"Fatal Python error: "); |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1654 OutputDebugStringW(buffer); |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1655 OutputDebugStringW(L"\n"); |
|
ee9ced92843a
Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49818
diff
changeset
|
1656 } |
|
8988
070de4d39ddd
Add DebugBreak() call to Py_FatalError() for Mark Hammond (only on
Guido van Rossum <guido@python.org>
parents:
7967
diff
changeset
|
1657 #ifdef _DEBUG |
|
070de4d39ddd
Add DebugBreak() call to Py_FatalError() for Mark Hammond (only on
Guido van Rossum <guido@python.org>
parents:
7967
diff
changeset
|
1658 DebugBreak(); |
|
2529
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
1659 #endif |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
1660 #endif /* MS_WINDOWS */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1661 abort(); |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1662 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1663 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1664 /* Clean up and exit */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1665 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1666 #ifdef WITH_THREAD |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9192
diff
changeset
|
1667 #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
|
1668 #endif |
|
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
941
diff
changeset
|
1669 |
|
56781
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1670 /* Wait until threading._shutdown completes, provided |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1671 the threading module was imported in the first place. |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1672 The shutdown routine will wait until all non-daemon |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1673 "threading" threads have completed. */ |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1674 static void |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1675 wait_for_thread_shutdown(void) |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1676 { |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1677 #ifdef WITH_THREAD |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1678 PyObject *result; |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1679 PyThreadState *tstate = PyThreadState_GET(); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1680 PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1681 "threading"); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1682 if (threading == NULL) { |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1683 /* threading not imported */ |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1684 PyErr_Clear(); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1685 return; |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1686 } |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1687 result = PyObject_CallMethod(threading, "_shutdown", ""); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1688 if (result == NULL) |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1689 PyErr_WriteUnraisable(threading); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1690 else |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1691 Py_DECREF(result); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1692 Py_DECREF(threading); |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1693 #endif |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1694 } |
|
2abc3b4bce7c
Merged revisions 75570,75574,75624 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
52818
diff
changeset
|
1695 |
|
9192
ac6c29d1f10c
On second though, NEXITFUNCS should be defined here and not in
Guido van Rossum <guido@python.org>
parents:
9161
diff
changeset
|
1696 #define NEXITFUNCS 32 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1697 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
|
1698 static int nexitfuncs = 0; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1699 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1700 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
|
1701 { |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1702 if (nexitfuncs >= NEXITFUNCS) |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1703 return -1; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1704 exitfuncs[nexitfuncs++] = func; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1705 return 0; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1706 } |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1707 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1708 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1709 call_sys_exitfunc(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1710 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1711 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
|
1712 |
|
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1713 if (exitfunc) { |
|
17207
16f145aac2ec
call_sys_exitfunc(): Remove unused variable f.
Fred Drake <fdrake@acm.org>
parents:
17191
diff
changeset
|
1714 PyObject *res; |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1715 Py_INCREF(exitfunc); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1716 PySys_SetObject("exitfunc", (PyObject *)NULL); |
|
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1717 res = PyEval_CallObject(exitfunc, (PyObject *)NULL); |
|
1015
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1718 if (res == NULL) { |
|
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
|
1719 if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1720 PySys_WriteStderr("Error in sys.exitfunc:\n"); |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1721 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1722 PyErr_Print(); |
|
1015
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1723 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1724 Py_DECREF(exitfunc); |
|
1015
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1725 } |
|
f3d5e2c3b9a3
Add sys.exitfunc feature. Make askync non-static.
Guido van Rossum <guido@python.org>
parents:
961
diff
changeset
|
1726 |
|
7509
b5d52c415b15
Fix the handling of errors in Py_FlushLine() in a few places.
Guido van Rossum <guido@python.org>
parents:
7206
diff
changeset
|
1727 if (Py_FlushLine()) |
|
b5d52c415b15
Fix the handling of errors in Py_FlushLine() in a few places.
Guido van Rossum <guido@python.org>
parents:
7206
diff
changeset
|
1728 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
|
1729 } |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1730 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1731 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1732 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
|
1733 { |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1734 while (nexitfuncs > 0) |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
1735 (*exitfuncs[--nexitfuncs])(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
1736 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
1737 fflush(stdout); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
1738 fflush(stderr); |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1739 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1740 |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1741 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1742 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
|
1743 { |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
1744 Py_Finalize(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1745 |
|
3235
3df9ab03badf
Moved mac-specific exit handling to macmain.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
3152
diff
changeset
|
1746 exit(sts); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1747 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1748 |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1289
diff
changeset
|
1749 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1750 initsigs(void) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1751 { |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1752 #ifdef SIGPIPE |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1753 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
|
1754 #endif |
| 19295 | 1755 #ifdef SIGXFZ |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1756 PyOS_setsig(SIGXFZ, SIG_IGN); |
| 19295 | 1757 #endif |
| 23252 | 1758 #ifdef SIGXFSZ |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1759 PyOS_setsig(SIGXFSZ, SIG_IGN); |
| 23252 | 1760 #endif |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1761 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
|
1762 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
1763 |
|
5108
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1764 |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1765 /* |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1766 * 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
|
1767 * 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
|
1768 * 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
|
1769 * 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
|
1770 */ |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1771 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1772 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
|
1773 { |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1774 if (isatty((int)fileno(fp))) |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1775 return 1; |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1776 if (!Py_InteractiveFlag) |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1777 return 0; |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1778 return (filename == NULL) || |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1779 (strcmp(filename, "<stdin>") == 0) || |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1780 (strcmp(filename, "???") == 0); |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
1781 } |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1782 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1783 |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1784 #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
|
1785 #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
|
1786 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1787 /* 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
|
1788 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1789 #include <malloc.h> |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1790 #include <excpt.h> |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1791 |
|
14278
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1792 /* |
|
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1793 * 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
|
1794 */ |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1795 int |
|
14280
68b61aa1aa4a
PyOS_CheckStack(): Better ANSI'fy this while we're at it.
Fred Drake <fdrake@acm.org>
parents:
14278
diff
changeset
|
1796 PyOS_CheckStack(void) |
|
14227
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 __try { |
|
25573
0231cc54f87e
s/_alloca/alloca/g; Windows doesn't need the former, at least not unless
Tim Peters <tim.peters@gmail.com>
parents:
24839
diff
changeset
|
1799 /* alloca throws a stack overflow exception if there's |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1800 not enough space left on the stack */ |
|
25573
0231cc54f87e
s/_alloca/alloca/g; Windows doesn't need the former, at least not unless
Tim Peters <tim.peters@gmail.com>
parents:
24839
diff
changeset
|
1801 alloca(PYOS_STACK_MARGIN * sizeof(void*)); |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1802 return 0; |
|
45389
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1803 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ? |
|
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1804 EXCEPTION_EXECUTE_HANDLER : |
|
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1805 EXCEPTION_CONTINUE_SEARCH) { |
|
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1806 int errcode = _resetstkoflw(); |
|
49818
5d9be65e7891
Merged revisions 67343 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49623
diff
changeset
|
1807 if (errcode == 0) |
|
45389
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1808 { |
|
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1809 Py_FatalError("Could not reset the stack!"); |
|
2efcd7f606f8
Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
45229
diff
changeset
|
1810 } |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1811 } |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1812 return 1; |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1813 } |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1814 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1815 #endif /* WIN32 && _MSC_VER */ |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1816 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1817 /* 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
|
1818 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
1819 #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
|
1820 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1821 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1822 /* 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
|
1823 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1824 PyOS_sighandler_t |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1825 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
|
1826 { |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1827 #ifdef HAVE_SIGACTION |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1828 struct sigaction context; |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1829 if (sigaction(sig, NULL, &context) == -1) |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1830 return SIG_ERR; |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1831 return context.sa_handler; |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1832 #else |
|
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 handler; |
|
35961
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1834 /* 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
|
1835 #if defined(_MSC_VER) && _MSC_VER >= 1400 |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1836 switch (sig) { |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1837 /* Only these signals are valid */ |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1838 case SIGINT: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1839 case SIGILL: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1840 case SIGFPE: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1841 case SIGSEGV: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1842 case SIGTERM: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1843 case SIGBREAK: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1844 case SIGABRT: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1845 break; |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1846 /* Don't call signal() with other values or it will assert */ |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1847 default: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1848 return SIG_ERR; |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1849 } |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
1850 #endif /* _MSC_VER && _MSC_VER >= 1400 */ |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1851 handler = signal(sig, SIG_IGN); |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1852 if (handler != SIG_ERR) |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1853 signal(sig, handler); |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1854 return handler; |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1855 #endif |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1856 } |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1857 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1858 PyOS_sighandler_t |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1859 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
|
1860 { |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1861 #ifdef HAVE_SIGACTION |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1862 struct sigaction context, ocontext; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1863 context.sa_handler = handler; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1864 sigemptyset(&context.sa_mask); |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1865 context.sa_flags = 0; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1866 if (sigaction(sig, &context, &ocontext) == -1) |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1867 return SIG_ERR; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1868 return ocontext.sa_handler; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1869 #else |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1870 PyOS_sighandler_t oldhandler; |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1871 oldhandler = signal(sig, handler); |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1872 #ifdef HAVE_SIGINTERRUPT |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1873 siginterrupt(sig, 1); |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
1874 #endif |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1875 return oldhandler; |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1876 #endif |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
1877 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1878 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1879 /* 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
|
1880 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1881 #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
|
1882 PyAPI_FUNC(node *) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1883 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
|
1884 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1885 return PyParser_SimpleParseFileFlags(fp, filename, start, 0); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1886 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1887 |
|
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
|
1888 #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
|
1889 PyAPI_FUNC(node *) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1890 PyParser_SimpleParseString(const char *str, int start) |
|
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 return PyParser_SimpleParseStringFlags(str, start, 0); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1893 } |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
1894 |
|
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 #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
|
1896 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
|
1897 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
|
1898 { |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1899 return PyRun_AnyFileExFlags(fp, name, 0, NULL); |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1900 } |
|
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 |
|
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 #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
|
1903 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
|
1904 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
|
1905 { |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1906 return PyRun_AnyFileExFlags(fp, name, closeit, NULL); |
|
35f27bbd9ad8
Change those parts of the Python-api that were functions in 2.4, and
Thomas Heller <theller@ctypes.org>
parents:
37831
diff
changeset
|
1907 } |
|
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 |
|
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 #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
|
1910 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
|
1911 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
|
1912 { |
|
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 return PyRun_AnyFileExFlags(fp, name, 0, 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
|
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 |
|
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 #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
|
1917 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
|
1918 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
|
1919 { |
| 47887 | 1920 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
|
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 |
|
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 #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
|
1924 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
|
1925 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
|
1926 { |
| 47887 | 1927 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
|
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 |
|
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 #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
|
1931 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
|
1932 PyRun_FileFlags(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
|
1933 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
|
1934 { |
| 47887 | 1935 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
|
1936 } |
|
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 |
|
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 #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
|
1939 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
|
1940 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
|
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 return PyRun_SimpleFileExFlags(f, p, 0, NULL); |
|
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 } |
|
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 |
|
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 #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
|
1946 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
|
1947 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
|
1948 { |
|
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 return PyRun_SimpleFileExFlags(f, p, c, NULL); |
|
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 |
|
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 |
|
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 #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
|
1954 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
|
1955 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
|
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 return PyRun_StringFlags(str, s, g, l, NULL); |
|
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 } |
|
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 |
|
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 #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
|
1961 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
|
1962 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
|
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 return PyRun_SimpleStringFlags(s, NULL); |
|
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 |
|
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 #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
|
1968 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
|
1969 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
|
1970 { |
|
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 return Py_CompileStringFlags(str, p, s, NULL); |
|
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 |
|
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 #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
|
1975 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
|
1976 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
|
1977 { |
|
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 return PyRun_InteractiveOneFlags(f, p, NULL); |
|
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 |
|
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 #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
|
1982 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
|
1983 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
|
1984 { |
|
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 return PyRun_InteractiveLoopFlags(f, p, NULL); |
|
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 |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
1988 #ifdef __cplusplus |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
1989 } |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
1990 #endif |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37638
diff
changeset
|
1991 |
