Mercurial > cpython-lru_cache-weakref
annotate Python/pythonrun.c @ 59867:a366d631a629 3.1
Revert my change on initsite(): don't change import site error handler in 3.1,
as I did for 2.6. But fix the other bugs :-)
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Sun, 21 Mar 2010 21:57:42 +0000 |
| parents | c2d2e26bcf7f |
| children | 677511edf05c |
| 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" |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
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" |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
20 #include "osdefs.h" |
|
56652
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
21 #include "abstract.h" |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
23 #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
|
24 #include <signal.h> |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
25 #endif |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
26 |
|
50559
6f30b97148b6
Merged revisions 68178 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50558
diff
changeset
|
27 #ifdef MS_WINDOWS |
|
50558
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
28 #include "malloc.h" /* for alloca */ |
|
50559
6f30b97148b6
Merged revisions 68178 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50558
diff
changeset
|
29 #endif |
|
50558
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
30 |
|
28174
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
31 #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
|
32 #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
|
33 #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
|
34 #endif |
|
3f90d21debe9
Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
Martin v. Löwis <martin@v.loewis.de>
parents:
28065
diff
changeset
|
35 |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
36 #ifdef MS_WINDOWS |
|
2529
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
37 #undef BYTE |
|
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
38 #include "windows.h" |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
39 #define PATH_MAX MAXPATHLEN |
|
2529
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
40 #endif |
|
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
41 |
|
36837
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
42 #ifndef Py_REF_DEBUG |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
43 #define PRINT_TOTAL_REFS() |
|
36837
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
44 #else /* Py_REF_DEBUG */ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
45 #define PRINT_TOTAL_REFS() fprintf(stderr, \ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
46 "[%" PY_FORMAT_SIZE_T "d refs]\n", \ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
47 _Py_GetRefTotal()) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
48 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
49 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
50 #ifdef __cplusplus |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
51 extern "C" { |
|
36837
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
52 #endif |
|
3a3aed49b245
Use Py_ssize_t for _Py_RefTotal.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36836
diff
changeset
|
53 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
54 extern wchar_t *Py_GetPath(void); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
56 extern grammar _PyParser_Grammar; /* From graminit.c */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
1391
7c3245c18677
* ceval.c, longobject.c, methodobject.c, listnode.c, arraymodule.c,
Guido van Rossum <guido@python.org>
parents:
1347
diff
changeset
|
58 /* Forward */ |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
59 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
|
60 static void initsite(void); |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
61 static int initstdio(void); |
|
46395
6196529afd73
Add a NEWS entry for issue2221.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46318
diff
changeset
|
62 static void flush_io(void); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
63 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
|
64 PyCompilerFlags *, PyArena *); |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
65 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
|
66 PyCompilerFlags *); |
|
13447
a89f7f268de4
Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
67 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
|
68 static void initsigs(void); |
|
41253
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
69 static void call_py_exitfuncs(void); |
|
56652
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
70 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
|
71 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
|
72 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
|
73 extern void _PyUnicode_Fini(void); |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
74 extern int _PyLong_Init(void); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
75 extern void PyLong_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
|
76 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
77 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
78 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
|
79 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
|
80 #endif /* WITH_THREAD */ |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
81 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
82 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
|
83 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
|
84 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
85 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
|
86 int Py_NoSiteFlag; /* Suppress 'import site' */ |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
87 int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */ |
|
44587
fb5a6330f71b
Merged revisions 59822-59841 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44486
diff
changeset
|
88 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
|
89 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
|
90 int Py_FrozenFlag; /* Needed by getpath.c */ |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
91 int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */ |
|
46708
74b9c85361f8
Merged revisions 62774-62775,62785,62787-62788 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46694
diff
changeset
|
92 int Py_NoUserSiteDirectory = 0; /* for -s and site.py */ |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
93 int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 |
|
46430
47d9bbe10897
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46395
diff
changeset
|
95 /* PyModule_GetWarningsModule is no longer necessary as of 2.6 |
|
47d9bbe10897
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46395
diff
changeset
|
96 since _warnings is builtin. This API should not be used. */ |
|
47d9bbe10897
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46395
diff
changeset
|
97 PyObject * |
|
47d9bbe10897
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46395
diff
changeset
|
98 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
|
99 { |
|
46430
47d9bbe10897
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46395
diff
changeset
|
100 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
|
101 } |
|
27958
e07b21ea3c45
Fix bug 683658 - PyErr_Warn may cause import deadlock.
Mark Hammond <mhammond@skippinet.com.au>
parents:
27878
diff
changeset
|
102 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
103 static int initialized = 0; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 |
|
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
|
105 /* 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
|
106 |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
107 int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
108 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
|
109 { |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
110 return initialized; |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
111 } |
|
57045f51dd12
Added new Py_IsInitalized() API function to test the 'initialized' flag.
Guido van Rossum <guido@python.org>
parents:
6117
diff
changeset
|
112 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
113 /* 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
|
114 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
|
115 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
|
116 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
|
117 been created. |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
119 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
|
120 (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
|
121 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
|
122 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
123 */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
124 |
|
20401
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
125 static int |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
126 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
|
127 { |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
128 int env = atoi(envs); |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
129 if (flag < env) |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
130 flag = env; |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
131 if (flag < 1) |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
132 flag = 1; |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
133 return flag; |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
134 } |
|
b74610c92d8b
SF patch #467455 : Enhanced environment variables, by Toby Dickenson.
Guido van Rossum <guido@python.org>
parents:
19633
diff
changeset
|
135 |
|
49611
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
136 #if defined(HAVE_LANGINFO_H) && defined(CODESET) |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
137 static char* |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
138 get_codeset(void) |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
139 { |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
140 char* codeset; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
141 PyObject *codec, *name; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
142 |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
143 codeset = nl_langinfo(CODESET); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
144 if (!codeset || codeset[0] == '\0') |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
145 return NULL; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
146 |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
147 codec = _PyCodec_Lookup(codeset); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
148 if (!codec) |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
149 goto error; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
150 |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
151 name = PyObject_GetAttrString(codec, "name"); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
152 Py_CLEAR(codec); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
153 if (!name) |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
154 goto error; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
155 |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
156 codeset = strdup(_PyUnicode_AsString(name)); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
157 Py_DECREF(name); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
158 return codeset; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
159 |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
160 error: |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
161 Py_XDECREF(codec); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
162 PyErr_Clear(); |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
163 return NULL; |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
164 } |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
165 #endif |
|
9fc573fbaf5e
Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8.
Christian Heimes <christian@cheimes.de>
parents:
49035
diff
changeset
|
166 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
167 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
|
168 Py_InitializeEx(int install_sigs) |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
169 { |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
170 PyInterpreterState *interp; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
171 PyThreadState *tstate; |
|
43718
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
172 PyObject *bimod, *sysmod, *pstderr; |
|
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 char *p; |
|
41587
15b810e21fe9
Get rid of all #ifdef Py_USING_UNICODE (it is always present now).
Guido van Rossum <guido@python.org>
parents:
41558
diff
changeset
|
174 #if defined(HAVE_LANGINFO_H) && defined(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
|
175 char *codeset; |
|
a88e6dfbfd6d
Move initialization of sys.std{in,out}.encoding to Py_Initialize.
Martin v. Löwis <martin@v.loewis.de>
parents:
29879
diff
changeset
|
176 #endif |
| 19295 | 177 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
|
178 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
179 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
|
180 return; |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
181 initialized = 1; |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
182 |
|
42539
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
183 #ifdef HAVE_SETLOCALE |
|
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
184 /* Set up the LC_CTYPE locale, so we can obtain |
|
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
185 the locale's charset without having to switch |
|
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
186 locales. */ |
|
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
187 setlocale(LC_CTYPE, ""); |
|
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
188 #endif |
|
43e32b2b4004
Set sys.stdout.encoding properly.
Martin v. Löwis <martin@v.loewis.de>
parents:
42180
diff
changeset
|
189 |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
18630
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 Py_OptimizeFlag = add_flag(Py_OptimizeFlag, p); |
|
44587
fb5a6330f71b
Merged revisions 59822-59841 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44486
diff
changeset
|
196 if ((p = Py_GETENV("PYTHONDONTWRITEBYTECODE")) && *p != '\0') |
|
fb5a6330f71b
Merged revisions 59822-59841 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44486
diff
changeset
|
197 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
|
198 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
199 interp = PyInterpreterState_New(); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
200 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
|
201 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
|
202 |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
203 tstate = PyThreadState_New(interp); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
204 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
|
205 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
|
206 (void) PyThreadState_Swap(tstate); |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
207 |
| 19295 | 208 _Py_ReadyTypes(); |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
18933
diff
changeset
|
209 |
|
26923
dbfc3ef7d003
Since the *_Init() are private, prefix with _, suggested by Skip
Neal Norwitz <nnorwitz@gmail.com>
parents:
26889
diff
changeset
|
210 if (!_PyFrame_Init()) |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
211 Py_FatalError("Py_Initialize: can't init frames"); |
|
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
212 |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
213 if (!_PyLong_Init()) |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
214 Py_FatalError("Py_Initialize: can't init longs"); |
|
26889
12753e7b15f7
SF #561244, Micro optimizations
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
215 |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47072
diff
changeset
|
216 if (!PyByteArray_Init()) |
|
53994
3416721480b2
bytes -> bytearray
Benjamin Peterson <benjamin@python.org>
parents:
53767
diff
changeset
|
217 Py_FatalError("Py_Initialize: can't init bytearray"); |
|
40978
61fee1853ca8
SF patch #1669633, add methods for bytes from Pete Shinners.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40949
diff
changeset
|
218 |
| 34972 | 219 _PyFloat_Init(); |
| 220 | |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
221 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
|
222 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
|
223 Py_FatalError("Py_Initialize: can't make modules dictionary"); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
224 interp->modules_reloading = PyDict_New(); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
225 if (interp->modules_reloading == NULL) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
226 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
|
227 |
|
11977
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
228 /* 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
|
229 _PyUnicode_Init(); |
|
8b88e1bc0e1b
Marc-Andre Lemburg: add calls to initialize and finalize Unicode and
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
230 |
|
12754
5213abfe5230
Py_Initialize(): Now that standard exceptions are builtin, we don't
Barry Warsaw <barry@python.org>
parents:
12576
diff
changeset
|
231 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
|
232 if (bimod == NULL) |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44066
diff
changeset
|
233 Py_FatalError("Py_Initialize: can't initialize builtins modules"); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47496
diff
changeset
|
234 _PyImport_FixupExtension(bimod, "builtins", "builtins"); |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
235 interp->builtins = PyModule_GetDict(bimod); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
236 if (interp->builtins == NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
237 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
|
238 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
|
239 |
|
43848
e162e881ea5f
Moved the initalization of the exception before the initialization of sys.
Christian Heimes <christian@cheimes.de>
parents:
43842
diff
changeset
|
240 /* initialize builtin exceptions */ |
|
e162e881ea5f
Moved the initalization of the exception before the initialization of sys.
Christian Heimes <christian@cheimes.de>
parents:
43842
diff
changeset
|
241 _PyExc_Init(); |
|
e162e881ea5f
Moved the initalization of the exception before the initialization of sys.
Christian Heimes <christian@cheimes.de>
parents:
43842
diff
changeset
|
242 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
243 sysmod = _PySys_Init(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
244 if (sysmod == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
245 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
|
246 interp->sysdict = PyModule_GetDict(sysmod); |
|
39610
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
247 if (interp->sysdict == NULL) |
|
3674f20ac781
Merge current trunk into p3yk. This includes the PyNumber_Index API change,
Thomas Wouters <thomas@python.org>
parents:
39442
diff
changeset
|
248 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
|
249 Py_INCREF(interp->sysdict); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47496
diff
changeset
|
250 _PyImport_FixupExtension(sysmod, "sys", "sys"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
251 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
|
252 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
|
253 interp->modules); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
254 |
|
43718
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
255 /* Set up a preliminary stderr printer until we have enough |
|
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
256 infrastructure for the io module in place. */ |
|
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
257 pstderr = PyFile_NewStdPrinter(fileno(stderr)); |
|
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
258 if (pstderr == NULL) |
|
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
259 Py_FatalError("Py_Initialize: can't set preliminary stderr"); |
|
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
260 PySys_SetObject("stderr", pstderr); |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
261 PySys_SetObject("__stderr__", pstderr); |
|
43718
e510b716bd80
Patch 1352 (continued in issue 1329) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43712
diff
changeset
|
262 |
|
11113
be8ec828c072
Marc-Andre Lemburg discovered that the switch from .pyc to .pyo files,
Guido van Rossum <guido@python.org>
parents:
10534
diff
changeset
|
263 _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
|
264 |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26643
diff
changeset
|
265 _PyImportHooks_Init(); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26643
diff
changeset
|
266 |
|
53767
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
267 #if defined(HAVE_LANGINFO_H) && defined(CODESET) |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
268 /* On Unix, set the file system encoding according to the |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
269 user's preference, if the CODESET names a well-known |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
270 Python codec, and Py_FileSystemDefaultEncoding isn't |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
271 initialized by other means. Also set the encoding of |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
272 stdin and stdout if these are terminals. */ |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
273 |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
274 codeset = get_codeset(); |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
275 if (codeset) { |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
276 if (!Py_FileSystemDefaultEncoding) |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
277 Py_FileSystemDefaultEncoding = codeset; |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
278 else |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
279 free(codeset); |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
280 } |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
281 #endif |
|
ac209f132b17
Issue #5915: Implement PEP 383, Non-decodable Bytes in
Martin v. Löwis <martin@v.loewis.de>
parents:
52819
diff
changeset
|
282 |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
283 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
|
284 initsigs(); /* Signal handling stuff, including initintr() */ |
|
46430
47d9bbe10897
Merged revisions 62260-62261,62266,62271,62277-62279,62289-62290,62293-62298,62302-62306,62308,62311,62313-62315,62319-62321 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46395
diff
changeset
|
285 |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
286 /* Initialize warnings. */ |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
287 _PyWarnings_Init(); |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
288 if (PySys_HasWarnOptions()) { |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
289 PyObject *warnings_module = PyImport_ImportModule("warnings"); |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
290 if (!warnings_module) |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
291 PyErr_Clear(); |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
292 Py_XDECREF(warnings_module); |
|
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
293 } |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
294 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
295 initmain(); /* Module __main__ */ |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
296 if (initstdio() < 0) |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
297 Py_FatalError( |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
298 "Py_Initialize: can't initialize sys standard streams"); |
|
28065
c61ef183ce2f
Addendum to #683658:
Just van Rossum <just@letterror.com>
parents:
27958
diff
changeset
|
299 |
|
28694
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
300 /* 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
|
301 #ifdef WITH_THREAD |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
302 _PyGILState_Init(interp, tstate); |
|
a4154dd5939a
New PyGILState_ API - implements pep 311, from patch 684256.
Mark Hammond <mhammond@skippinet.com.au>
parents:
28653
diff
changeset
|
303 #endif /* WITH_THREAD */ |
|
59865
c2d2e26bcf7f
Merged revisions 78872 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57498
diff
changeset
|
304 |
|
c2d2e26bcf7f
Merged revisions 78872 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57498
diff
changeset
|
305 if (!Py_NoSiteFlag) |
|
c2d2e26bcf7f
Merged revisions 78872 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57498
diff
changeset
|
306 initsite(); /* Module site */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
307 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
308 |
|
33189
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
309 void |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
310 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
|
311 { |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
312 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
|
313 } |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
314 |
|
de804edf8bcd
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
Martin v. Löwis <martin@v.loewis.de>
parents:
32781
diff
changeset
|
315 |
|
9641
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
316 #ifdef COUNT_ALLOCS |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
317 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
|
318 #endif |
|
d152adf3f094
Move the prototype for dump_counts() to before where it is used.
Guido van Rossum <guido@python.org>
parents:
9285
diff
changeset
|
319 |
|
42167
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
320 /* Flush stdout and stderr */ |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
321 |
|
42893
2c02ba72714b
Make some internal functions static
Neal Norwitz <nnorwitz@gmail.com>
parents:
42822
diff
changeset
|
322 static void |
|
42180
9f99ea4f81e9
Silence compiler warning.
Guido van Rossum <guido@python.org>
parents:
42167
diff
changeset
|
323 flush_std_files(void) |
|
42167
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
324 { |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
325 PyObject *fout = PySys_GetObject("stdout"); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
326 PyObject *ferr = PySys_GetObject("stderr"); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
327 PyObject *tmp; |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
328 |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
329 if (fout != NULL && fout != Py_None) { |
|
42167
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
330 tmp = PyObject_CallMethod(fout, "flush", ""); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
331 if (tmp == NULL) |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
332 PyErr_Clear(); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
333 else |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
334 Py_DECREF(tmp); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
335 } |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
336 |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
337 if (ferr != NULL || ferr != Py_None) { |
|
42167
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
338 tmp = PyObject_CallMethod(ferr, "flush", ""); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
339 if (tmp == NULL) |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
340 PyErr_Clear(); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
341 else |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
342 Py_DECREF(tmp); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
343 } |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
344 } |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
345 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
346 /* 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
|
347 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 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
|
352 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
353 (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
|
354 threads.) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
355 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
356 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
357 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
358 */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
359 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
360 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
361 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
|
362 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
363 PyInterpreterState *interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
364 PyThreadState *tstate; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
365 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
366 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
|
367 return; |
|
16073
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
368 |
|
56652
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
369 wait_for_thread_shutdown(); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
370 |
|
16073
713ed6c6bcb5
Bug #128475: mimetools.encode (sometimes) fails when called from a thread.
Tim Peters <tim.peters@gmail.com>
parents:
15963
diff
changeset
|
371 /* 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
|
372 * 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
|
373 * 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
|
374 * 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
|
375 * 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
|
376 * 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
|
377 * 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
|
378 * 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
|
379 */ |
|
41253
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
380 call_py_exitfuncs(); |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
381 initialized = 0; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
382 |
|
42167
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
383 /* Flush stdout+stderr */ |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
384 flush_std_files(); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
385 |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
386 /* 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
|
387 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
|
388 interp = tstate->interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
389 |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
390 /* Disable signal handling */ |
|
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
391 PyOS_FiniInterrupts(); |
|
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
392 |
|
45026
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44587
diff
changeset
|
393 /* Clear type lookup cache */ |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44587
diff
changeset
|
394 PyType_ClearCache(); |
|
ebfbaa1051e2
Merged revisions 60364-60378 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44587
diff
changeset
|
395 |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
396 /* 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
|
397 * 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
|
398 * 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
|
399 * 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
|
400 * 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
|
401 * 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
|
402 * 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
|
403 * 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
|
404 * 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
|
405 * 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
|
406 * XXX I haven't seen a real-life report of either of these. |
| 36836 | 407 */ |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
408 PyGC_Collect(); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
409 #ifdef COUNT_ALLOCS |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
410 /* With COUNT_ALLOCS, it helps to run GC multiple times: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
411 each collection might release some types from the type |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
412 list, so they become garbage. */ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
413 while (PyGC_Collect() > 0) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
414 /* nothing */; |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
415 #endif |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
416 |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
417 /* 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
|
418 PyImport_Cleanup(); |
|
6547
724382af5339
Two independent changes (alas):
Guido van Rossum <guido@python.org>
parents:
6376
diff
changeset
|
419 |
|
42167
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
420 /* Flush stdout+stderr (again, in case more was printed) */ |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
421 flush_std_files(); |
|
29ba6c399090
Upon exit, flush stdout and stderr (twice: before and after the code that
Guido van Rossum <guido@python.org>
parents:
42071
diff
changeset
|
422 |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
423 /* 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
|
424 * 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
|
425 * 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
|
426 * 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
|
427 * 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
|
428 * 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
|
429 * 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
|
430 * 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
|
431 * 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
|
432 * 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
|
433 * 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
|
434 * 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
|
435 * 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
|
436 * 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
|
437 */ |
|
f69589179c55
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
Tim Peters <tim.peters@gmail.com>
parents:
30979
diff
changeset
|
438 #if 0 |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
439 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
|
440 #endif |
|
28651
7fda09f751ad
- New C API PyGC_Collect(), same as calling gc.collect().
Guido van Rossum <guido@python.org>
parents:
28649
diff
changeset
|
441 |
|
6786
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
442 /* 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
|
443 _PyImport_Fini(); |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
444 |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
445 /* Debugging stuff */ |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
446 #ifdef COUNT_ALLOCS |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
447 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
|
448 #endif |
|
bc007cf1d6ba
Changed the finalization order again so that the reference count
Guido van Rossum <guido@python.org>
parents:
6661
diff
changeset
|
449 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
450 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
|
451 |
|
28647
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
452 #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
|
453 /* 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
|
454 * __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
|
455 * 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
|
456 * up later. |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
457 */ |
|
28653
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
458 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
|
459 _Py_PrintReferences(stderr); |
|
9d4e138494fb
Py_Finalize(): Reverted recent changes that tried to move the
Tim Peters <tim.peters@gmail.com>
parents:
28616
diff
changeset
|
460 #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
|
461 |
|
28613
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
462 /* 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
|
463 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
|
464 |
|
34834
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
465 /* 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
|
466 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
|
467 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
|
468 raised. |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
469 */ |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
470 |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
471 _PyExc_Fini(); |
|
7cfda9898863
Move exception finalisation later in the shutdown process - this
Anthony Baxter <anthonybaxter@gmail.com>
parents:
34664
diff
changeset
|
472 |
|
44066
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44064
diff
changeset
|
473 /* Cleanup auto-thread-state */ |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44064
diff
changeset
|
474 #ifdef WITH_THREAD |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44064
diff
changeset
|
475 _PyGILState_Fini(); |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44064
diff
changeset
|
476 #endif /* WITH_THREAD */ |
|
28c802837252
Merged revisions 59226-59233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44064
diff
changeset
|
477 |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
478 /* 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
|
479 PyThreadState_Swap(NULL); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
480 PyInterpreterState_Delete(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
481 |
|
28613
b1671550c7e1
Move the call to _Py_PrintReferences() a bit further down. This
Guido van Rossum <guido@python.org>
parents:
28574
diff
changeset
|
482 /* 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
|
483 PyMethod_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
484 PyFrame_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
485 PyCFunction_Fini(); |
|
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
486 PyTuple_Fini(); |
|
33679
55fba88930bc
Finalize the freelist of list objects.
Raymond Hettinger <python@rcn.com>
parents:
33189
diff
changeset
|
487 PyList_Fini(); |
|
35297
26bf6c27e9ce
* Improve code for the empty frozenset singleton:
Raymond Hettinger <python@rcn.com>
parents:
34972
diff
changeset
|
488 PySet_Fini(); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
489 PyBytes_Fini(); |
|
47300
96b34263e448
Renamed PyBytes to PyByteArray
Christian Heimes <christian@cheimes.de>
parents:
47072
diff
changeset
|
490 PyByteArray_Fini(); |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
491 PyLong_Fini(); |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
492 PyFloat_Fini(); |
|
45244
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45026
diff
changeset
|
493 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
|
494 |
|
22883
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
495 /* Cleanup Unicode implementation */ |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
496 _PyUnicode_Fini(); |
|
d8bc68cb17e0
Move Unicode finalization further down in the chain.
Marc-André Lemburg <mal@egenix.com>
parents:
22721
diff
changeset
|
497 |
|
44064
00048fedbaa0
Partial fix for bug #1306
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
498 /* reset file system default encoding */ |
|
00048fedbaa0
Partial fix for bug #1306
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
499 if (!Py_HasFileSystemDefaultEncoding) { |
|
00048fedbaa0
Partial fix for bug #1306
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
500 free((char*)Py_FileSystemDefaultEncoding); |
|
45914
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
501 Py_FileSystemDefaultEncoding = NULL; |
|
44064
00048fedbaa0
Partial fix for bug #1306
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
502 } |
|
00048fedbaa0
Partial fix for bug #1306
Christian Heimes <christian@cheimes.de>
parents:
43866
diff
changeset
|
503 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
504 /* 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
|
505 - 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
|
506 - 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
|
507 - 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
|
508 */ |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
509 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
510 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
|
511 |
|
28653
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
512 #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
|
513 /* 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
|
514 * 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
|
515 * 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
|
516 */ |
|
56006d97bcef
_Py_PrintReferences(): Changed to print object address at start of each
Tim Peters <tim.peters@gmail.com>
parents:
28651
diff
changeset
|
517 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
|
518 _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
|
519 #endif /* Py_TRACE_REFS */ |
|
23020
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
520 #ifdef PYMALLOC_DEBUG |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
521 if (Py_GETENV("PYTHONMALLOCSTATS")) |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
522 _PyObject_DebugMallocStats(); |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
523 #endif |
|
e2848618bd19
_PyObject_DebugDumpStats: renamed to _PyObject_DebugMallocStats.
Tim Peters <tim.peters@gmail.com>
parents:
22883
diff
changeset
|
524 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
525 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
|
526 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
527 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
528 /* 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
|
529 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
|
530 first. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
531 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
532 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
|
533 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
|
534 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
|
535 thread. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
536 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
537 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
538 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
539 */ |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
540 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
541 PyThreadState * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
542 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
|
543 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
544 PyInterpreterState *interp; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
545 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
|
546 PyObject *bimod, *sysmod; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
547 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
548 if (!initialized) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
549 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
|
550 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
551 interp = PyInterpreterState_New(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
552 if (interp == NULL) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
553 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
554 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
555 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
|
556 if (tstate == NULL) { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
557 PyInterpreterState_Delete(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
558 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
559 } |
|
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 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
|
562 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
563 /* 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
|
564 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
565 interp->modules = PyDict_New(); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
566 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
|
567 |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44066
diff
changeset
|
568 bimod = _PyImport_FindExtension("builtins", "builtins"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
569 if (bimod != NULL) { |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
570 interp->builtins = PyModule_GetDict(bimod); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
571 if (interp->builtins == NULL) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
572 goto handle_error; |
|
6557
b331cd47e0bc
Undo half of the previous change :-(
Guido van Rossum <guido@python.org>
parents:
6547
diff
changeset
|
573 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
|
574 } |
|
49613
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
575 |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
576 /* initialize builtin exceptions */ |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
577 _PyExc_Init(); |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
578 |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
579 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
|
580 if (bimod != NULL && sysmod != NULL) { |
|
49613
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
581 PyObject *pstderr; |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
582 interp->sysdict = PyModule_GetDict(sysmod); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
583 if (interp->sysdict == NULL) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
584 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
|
585 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
|
586 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
|
587 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
|
588 interp->modules); |
|
49613
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
589 /* Set up a preliminary stderr printer until we have enough |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
590 infrastructure for the io module in place. */ |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
591 pstderr = PyFile_NewStdPrinter(fileno(stderr)); |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
592 if (pstderr == NULL) |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
593 Py_FatalError("Py_Initialize: can't set preliminary stderr"); |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
594 PySys_SetObject("stderr", pstderr); |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
595 PySys_SetObject("__stderr__", pstderr); |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
596 |
|
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(); |
|
49613
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
598 if (initstdio() < 0) |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
599 Py_FatalError( |
|
efef5fc45a9a
Issue 3723: Fixed initialization of subinterpreters
Christian Heimes <christian@cheimes.de>
parents:
49611
diff
changeset
|
600 "Py_Initialize: can't initialize sys standard streams"); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
601 initmain(); |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
602 if (!Py_NoSiteFlag) |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
603 initsite(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
604 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
605 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
606 if (!PyErr_Occurred()) |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
607 return tstate; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
608 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
609 handle_error: |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
610 /* 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
|
611 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
612 PyErr_Print(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
613 PyThreadState_Clear(tstate); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
614 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
|
615 PyThreadState_Delete(tstate); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
616 PyInterpreterState_Delete(interp); |
|
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 return NULL; |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
619 } |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
620 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
621 /* 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
|
622 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
|
623 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
|
624 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
|
625 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
626 (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
|
627 everything, regardless.) |
|
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 Locking: as above. |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
630 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
631 */ |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
632 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
633 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
634 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
|
635 { |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
636 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
|
637 |
|
31797
846b3ee7e106
Changed random calls to PyThreadState_Get() to use the macro
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31771
diff
changeset
|
638 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
|
639 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
|
640 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
|
641 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
|
642 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
|
643 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
|
644 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
645 PyImport_Cleanup(); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
646 PyInterpreterState_Clear(interp); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
647 PyThreadState_Swap(NULL); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
648 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
|
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 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
651 static wchar_t *progname = L"python"; |
|
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 void |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
654 Py_SetProgramName(wchar_t *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
|
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 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
|
657 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
|
658 } |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
659 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
660 wchar_t * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
661 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
|
662 { |
|
6f67a1bda15a
Moved some stuff here from main.c (part of a big restructuring - wait
Guido van Rossum <guido@python.org>
parents:
5611
diff
changeset
|
663 return progname; |
|
5405
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
664 } |
|
b7871ca930ad
Massive changes for separate thread state management.
Guido van Rossum <guido@python.org>
parents:
5234
diff
changeset
|
665 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
666 static wchar_t *default_home = NULL; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
667 static wchar_t env_home[PATH_MAX+1]; |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
668 |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
669 void |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
670 Py_SetPythonHome(wchar_t *home) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
671 { |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
672 default_home = home; |
|
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 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
675 wchar_t * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
676 Py_GetPythonHome(void) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
677 { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
678 wchar_t *home = default_home; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
679 if (home == NULL && !Py_IgnoreEnvironmentFlag) { |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
680 char* chome = Py_GETENV("PYTHONHOME"); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
681 if (chome) { |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
682 size_t r = mbstowcs(env_home, chome, PATH_MAX+1); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
683 if (r != (size_t)-1 && r <= PATH_MAX) |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
684 home = env_home; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
685 } |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
686 |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
46299
diff
changeset
|
687 } |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
688 return home; |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
689 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
690 |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
691 /* Create __main__ module */ |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
692 |
|
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
693 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
694 initmain(void) |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
695 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
696 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
|
697 m = PyImport_AddModule("__main__"); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
698 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
|
699 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
|
700 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
|
701 if (PyDict_GetItemString(d, "__builtins__") == NULL) { |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44066
diff
changeset
|
702 PyObject *bimod = PyImport_ImportModule("builtins"); |
|
6600
83ccf44bf195
Two changes (here we go again :-( ).
Guido van Rossum <guido@python.org>
parents:
6557
diff
changeset
|
703 if (bimod == NULL || |
|
83ccf44bf195
Two changes (here we go again :-( ).
Guido van Rossum <guido@python.org>
parents:
6557
diff
changeset
|
704 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
|
705 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
|
706 Py_DECREF(bimod); |
|
2098
b7be0382f9ee
__builtins__ mods (and sys_checkinterval for ceval.c)
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
707 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
708 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
709 |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
710 /* Import the site module (not into __main__ though) */ |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
711 |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
712 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
713 initsite(void) |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
714 { |
|
59867
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
715 PyObject *m, *f; |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
716 m = PyImport_ImportModule("site"); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
717 if (m == NULL) { |
|
59867
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
718 f = PySys_GetObject("stderr"); |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
719 if (f == NULL || f == Py_None) |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
720 return; |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
721 if (Py_VerboseFlag) { |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
722 PyFile_WriteString( |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
723 "'import site' failed; traceback:\n", f); |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
724 PyErr_Print(); |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
725 } |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
726 else { |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
727 PyFile_WriteString( |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
728 "'import site' failed; use -v for traceback\n", f); |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
729 PyErr_Clear(); |
|
a366d631a629
Revert my change on initsite(): don't change import site error handler in 3.1,
Victor Stinner <victor.stinner@haypocalc.com>
parents:
59865
diff
changeset
|
730 } |
|
6201
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
731 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
732 else { |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
733 Py_DECREF(m); |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
734 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
735 } |
|
dc974b3a6cf4
Two independent changes (oops):
Guido van Rossum <guido@python.org>
parents:
6197
diff
changeset
|
736 |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
737 static PyObject* |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
738 create_stdio(PyObject* io, |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
739 int fd, int write_mode, char* name, |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
740 char* encoding, char* errors) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
741 { |
|
50678
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
742 PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res; |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
743 const char* mode; |
|
50678
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
744 PyObject *line_buffering; |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
745 int buffering, isatty; |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
746 |
|
51082
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
747 /* stdin is always opened in buffered mode, first because it shouldn't |
|
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
748 make a difference in common use cases, second because TextIOWrapper |
|
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
749 depends on the presence of a read1() method which only exists on |
|
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
750 buffered streams. |
|
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
751 */ |
|
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
752 if (Py_UnbufferedStdioFlag && write_mode) |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
753 buffering = 0; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
754 else |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
755 buffering = -1; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
756 if (write_mode) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
757 mode = "wb"; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
758 else |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
759 mode = "rb"; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
760 buf = PyObject_CallMethod(io, "open", "isiOOOi", |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
761 fd, mode, buffering, |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
762 Py_None, Py_None, Py_None, 0); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
763 if (buf == NULL) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
764 goto error; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
765 |
|
51082
14c3ab9bd706
Merged revisions 68977,68981 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50678
diff
changeset
|
766 if (buffering) { |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
767 raw = PyObject_GetAttrString(buf, "raw"); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
768 if (raw == NULL) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
769 goto error; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
770 } |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
771 else { |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
772 raw = buf; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
773 Py_INCREF(raw); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
774 } |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
775 |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
776 text = PyUnicode_FromString(name); |
|
51991
3049ac17e256
merge the io-c branch: C implementation of the io module
Benjamin Peterson <benjamin@python.org>
parents:
51956
diff
changeset
|
777 if (text == NULL || PyObject_SetAttrString(raw, "name", text) < 0) |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
778 goto error; |
|
50678
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
779 res = PyObject_CallMethod(raw, "isatty", ""); |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
780 if (res == NULL) |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
781 goto error; |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
782 isatty = PyObject_IsTrue(res); |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
783 Py_DECREF(res); |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
784 if (isatty == -1) |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
785 goto error; |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
786 if (isatty || Py_UnbufferedStdioFlag) |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
787 line_buffering = Py_True; |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
788 else |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
789 line_buffering = Py_False; |
|
9c2bd647b646
Merged revisions 68463 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50666
diff
changeset
|
790 |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
791 Py_CLEAR(raw); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
792 Py_CLEAR(text); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
793 |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
794 stream = PyObject_CallMethod(io, "TextIOWrapper", "OsssO", |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
795 buf, encoding, errors, |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
796 "\n", line_buffering); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
797 Py_CLEAR(buf); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
798 if (stream == NULL) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
799 goto error; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
800 |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
801 if (write_mode) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
802 mode = "w"; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
803 else |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
804 mode = "r"; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
805 text = PyUnicode_FromString(mode); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
806 if (!text || PyObject_SetAttrString(stream, "mode", text) < 0) |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
807 goto error; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
808 Py_CLEAR(text); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
809 return stream; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
810 |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
811 error: |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
812 Py_XDECREF(buf); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
813 Py_XDECREF(stream); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
814 Py_XDECREF(text); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
815 Py_XDECREF(raw); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
816 return NULL; |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
817 } |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
818 |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44066
diff
changeset
|
819 /* Initialize sys.stdin, stdout, stderr and builtins.open */ |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
820 static int |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
821 initstdio(void) |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
822 { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
823 PyObject *iomod = NULL, *wrapper; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
824 PyObject *bimod = NULL; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
825 PyObject *m; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
826 PyObject *std = NULL; |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
827 int status = 0, fd; |
|
45914
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
828 PyObject * encoding_attr; |
|
47599
e2eb70235392
Issue 1342: Python could not start if installed in a directory
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
829 char *encoding = NULL, *errors; |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
830 |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
831 /* Hack to avoid a nasty recursion issue when Python is invoked |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
832 in verbose mode: pre-import the Latin-1 and UTF-8 codecs */ |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
833 if ((m = PyImport_ImportModule("encodings.utf_8")) == NULL) { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
834 goto error; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
835 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
836 Py_DECREF(m); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
837 |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
838 if (!(m = PyImport_ImportModule("encodings.latin_1"))) { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
839 goto error; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
840 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
841 Py_DECREF(m); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
842 |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44066
diff
changeset
|
843 if (!(bimod = PyImport_ImportModule("builtins"))) { |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
844 goto error; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
845 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
846 |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
847 if (!(iomod = PyImport_ImportModule("io"))) { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
848 goto error; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
849 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
850 if (!(wrapper = PyObject_GetAttrString(iomod, "OpenWrapper"))) { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
851 goto error; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
852 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
853 |
|
44098
0889daf6d0d9
#1535: rename __builtin__ module to builtins.
Georg Brandl <georg@python.org>
parents:
44066
diff
changeset
|
854 /* Set builtins.open */ |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
855 if (PyObject_SetAttrString(bimod, "open", wrapper) == -1) { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
856 goto error; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
857 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
858 |
|
47444
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
859 encoding = Py_GETENV("PYTHONIOENCODING"); |
|
47446
b6b534b828b3
Fix uninitialized variable access, release memory.
Martin v. Löwis <martin@v.loewis.de>
parents:
47444
diff
changeset
|
860 errors = NULL; |
|
47444
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
861 if (encoding) { |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
862 encoding = strdup(encoding); |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
863 errors = strchr(encoding, ':'); |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
864 if (errors) { |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
865 *errors = '\0'; |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
866 errors++; |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
867 } |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
868 } |
|
bb2c4bdc3c68
Forward-port PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents:
47301
diff
changeset
|
869 |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
870 /* Set sys.stdin */ |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
871 fd = fileno(stdin); |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
872 /* Under some conditions stdin, stdout and stderr may not be connected |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
873 * and fileno() may point to an invalid file descriptor. For example |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
874 * GUI apps don't have valid standard streams by default. |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
875 */ |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
876 if (fd < 0) { |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
877 #ifdef MS_WINDOWS |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
878 std = Py_None; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
879 Py_INCREF(std); |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
880 #else |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
881 goto error; |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
882 #endif |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
883 } |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
884 else { |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
885 std = create_stdio(iomod, fd, 0, "<stdin>", encoding, errors); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
886 if (std == NULL) |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
887 goto error; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
888 } /* if (fd < 0) */ |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
889 PySys_SetObject("__stdin__", std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
890 PySys_SetObject("stdin", std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
891 Py_DECREF(std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
892 |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
893 /* Set sys.stdout */ |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
894 fd = fileno(stdout); |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
895 if (fd < 0) { |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
896 #ifdef MS_WINDOWS |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
897 std = Py_None; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
898 Py_INCREF(std); |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
899 #else |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
900 goto error; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
901 #endif |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
902 } |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
903 else { |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
904 std = create_stdio(iomod, fd, 1, "<stdout>", encoding, errors); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
905 if (std == NULL) |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
906 goto error; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
907 } /* if (fd < 0) */ |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
908 PySys_SetObject("__stdout__", std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
909 PySys_SetObject("stdout", std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
910 Py_DECREF(std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
911 |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
912 #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ |
|
43712
00b136b7da84
Patch 1329 (partial) by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43632
diff
changeset
|
913 /* Set sys.stderr, replaces the preliminary stderr */ |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
914 fd = fileno(stderr); |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
915 if (fd < 0) { |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
916 #ifdef MS_WINDOWS |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
917 std = Py_None; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
918 Py_INCREF(std); |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
919 #else |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
920 goto error; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
921 #endif |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
922 } |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
923 else { |
|
50666
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
924 std = create_stdio(iomod, fd, 1, "<stderr>", encoding, "backslashreplace"); |
|
b98fe8dc8acd
Merged revisions 68451 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
50559
diff
changeset
|
925 if (std == NULL) |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
926 goto error; |
|
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
927 } /* if (fd < 0) */ |
|
45914
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
928 |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
929 /* Same as hack above, pre-import stderr's codec to avoid recursion |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
930 when import.c tries to write to stderr in verbose mode. */ |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
931 encoding_attr = PyObject_GetAttrString(std, "encoding"); |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
932 if (encoding_attr != NULL) { |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
933 const char * encoding; |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
934 encoding = _PyUnicode_AsString(encoding_attr); |
|
45914
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
935 if (encoding != NULL) { |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
936 _PyCodec_Lookup(encoding); |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
937 } |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
938 } |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
939 PyErr_Clear(); /* Not a fatal error if codec isn't available */ |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
940 |
|
43842
241281123fd8
Fixed space -> tab
Christian Heimes <christian@cheimes.de>
parents:
43841
diff
changeset
|
941 PySys_SetObject("__stderr__", std); |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
942 PySys_SetObject("stderr", std); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
943 Py_DECREF(std); |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
944 #endif |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
945 |
|
43841
ccceaec11442
Fix for #1415 pythonw.exe fails because std streams a missing
Christian Heimes <christian@cheimes.de>
parents:
43777
diff
changeset
|
946 if (0) { |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
947 error: |
|
43842
241281123fd8
Fixed space -> tab
Christian Heimes <christian@cheimes.de>
parents:
43841
diff
changeset
|
948 status = -1; |
|
241281123fd8
Fixed space -> tab
Christian Heimes <christian@cheimes.de>
parents:
43841
diff
changeset
|
949 } |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
950 |
|
47446
b6b534b828b3
Fix uninitialized variable access, release memory.
Martin v. Löwis <martin@v.loewis.de>
parents:
47444
diff
changeset
|
951 if (encoding) |
|
b6b534b828b3
Fix uninitialized variable access, release memory.
Martin v. Löwis <martin@v.loewis.de>
parents:
47444
diff
changeset
|
952 free(encoding); |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
953 Py_XDECREF(bimod); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
954 Py_XDECREF(iomod); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
955 return status; |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
956 } |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
957 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
958 /* Parse input from a file and execute it */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
959 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
960 int |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
961 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
|
962 PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
963 { |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
964 if (filename == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
965 filename = "???"; |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
966 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
|
967 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
|
968 if (closeit) |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
969 fclose(fp); |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
970 return err; |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
971 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
972 else |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
973 return PyRun_SimpleFileExFlags(fp, filename, closeit, flags); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
974 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
975 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
976 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
977 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
|
978 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
979 PyObject *v; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
980 int ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
981 PyCompilerFlags local_flags; |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
982 |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
983 if (flags == NULL) { |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
984 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
|
985 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
|
986 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
987 v = PySys_GetObject("ps1"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
988 if (v == NULL) { |
| 42822 | 989 PySys_SetObject("ps1", v = PyUnicode_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
|
990 Py_XDECREF(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
991 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
992 v = PySys_GetObject("ps2"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
993 if (v == NULL) { |
| 42822 | 994 PySys_SetObject("ps2", v = PyUnicode_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
|
995 Py_XDECREF(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
996 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
997 for (;;) { |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
998 ret = PyRun_InteractiveOneFlags(fp, filename, flags); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
999 PRINT_TOTAL_REFS(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1000 if (ret == E_EOF) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1001 return 0; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1002 /* |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1003 if (ret == E_NOMEM) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1004 return -1; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1005 */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1006 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1007 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1008 |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22121
diff
changeset
|
1009 /* compute parser flags based on compiler flags */ |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1010 static int PARSER_FLAGS(PyCompilerFlags *flags) |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1011 { |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1012 int parser_flags = 0; |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1013 if (!flags) |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1014 return 0; |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1015 if (flags->cf_flags & PyCF_DONT_IMPLY_DEDENT) |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1016 parser_flags |= PyPARSE_DONT_IMPLY_DEDENT; |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1017 if (flags->cf_flags & PyCF_IGNORE_COOKIE) |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1018 parser_flags |= PyPARSE_IGNORE_COOKIE; |
|
52641
0530aadff696
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents:
52609
diff
changeset
|
1019 if (flags->cf_flags & CO_FUTURE_BARRY_AS_BDFL) |
|
0530aadff696
The BDFL has retired! Long live the FLUFL (Friendly Language Uncle For Life)!
Brett Cannon <bcannon@gmail.com>
parents:
52609
diff
changeset
|
1020 parser_flags |= PyPARSE_BARRY_AS_BDFL; |
|
51956
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1021 return parser_flags; |
|
8fe2988cf550
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Benjamin Peterson <benjamin@python.org>
parents:
51082
diff
changeset
|
1022 } |
|
22468
eebae4f60d05
Disable the parser hacks that enabled the "yield" keyword using a future
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
22121
diff
changeset
|
1023 |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1024 #if 0 |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1025 /* Keep an example of flags with future keyword support. */ |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1026 #define PARSER_FLAGS(flags) \ |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1027 ((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \ |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1028 PyPARSE_DONT_IMPLY_DEDENT : 0) \ |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1029 | ((flags)->cf_flags & CO_FUTURE_WITH_STATEMENT ? \ |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1030 PyPARSE_WITH_IS_KEYWORD : 0)) : 0) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1031 #endif |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39610
diff
changeset
|
1032 |
|
16916
b0456d3a0f1f
Useful future statement support for the interactive interpreter
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16845
diff
changeset
|
1033 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1034 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
|
1035 { |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1036 PyObject *m, *d, *v, *w, *oenc = NULL; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1037 mod_ty mod; |
| 36836 | 1038 PyArena *arena; |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1039 char *ps1 = "", *ps2 = "", *enc = NULL; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1040 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
|
1041 |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1042 if (fp == stdin) { |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1043 /* Fetch encoding from sys.stdin */ |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1044 v = PySys_GetObject("stdin"); |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
1045 if (v == NULL || v == Py_None) |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1046 return -1; |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1047 oenc = PyObject_GetAttrString(v, "encoding"); |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1048 if (!oenc) |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1049 return -1; |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1050 enc = _PyUnicode_AsString(oenc); |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1051 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1052 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
|
1053 if (v != NULL) { |
|
43866
8ed0280c2ab6
Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents:
43855
diff
changeset
|
1054 v = PyObject_Str(v); |
|
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
|
1055 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
|
1056 PyErr_Clear(); |
|
43525
b9d19d51de36
get rid of some more PyString uses.
Guido van Rossum <guido@python.org>
parents:
43225
diff
changeset
|
1057 else if (PyUnicode_Check(v)) |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1058 ps1 = _PyUnicode_AsString(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1059 } |
|
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
|
1060 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
|
1061 if (w != NULL) { |
|
43866
8ed0280c2ab6
Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents:
43855
diff
changeset
|
1062 w = PyObject_Str(w); |
|
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
|
1063 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
|
1064 PyErr_Clear(); |
|
43525
b9d19d51de36
get rid of some more PyString uses.
Guido van Rossum <guido@python.org>
parents:
43225
diff
changeset
|
1065 else if (PyUnicode_Check(w)) |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1066 ps2 = _PyUnicode_AsString(w); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1067 } |
| 36836 | 1068 arena = PyArena_New(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1069 if (arena == NULL) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1070 Py_XDECREF(v); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1071 Py_XDECREF(w); |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1072 Py_XDECREF(oenc); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1073 return -1; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1074 } |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1075 mod = PyParser_ASTFromFile(fp, filename, enc, |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1076 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
|
1077 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
|
1078 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
|
1079 Py_XDECREF(w); |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1080 Py_XDECREF(oenc); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1081 if (mod == NULL) { |
| 36836 | 1082 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1083 if (errcode == E_EOF) { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1084 PyErr_Clear(); |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1085 return E_EOF; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1086 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1087 PyErr_Print(); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1088 return -1; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1089 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1090 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
|
1091 if (m == NULL) { |
| 36836 | 1092 PyArena_Free(arena); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1093 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
|
1094 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1095 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
|
1096 v = run_mod(mod, filename, d, d, flags, arena); |
| 36836 | 1097 PyArena_Free(arena); |
|
46395
6196529afd73
Add a NEWS entry for issue2221.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46318
diff
changeset
|
1098 flush_io(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1099 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
|
1100 PyErr_Print(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1101 return -1; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1102 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1103 Py_DECREF(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1104 return 0; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1105 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1106 |
|
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
|
1107 /* 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
|
1108 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
|
1109 |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
1110 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1111 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
|
1112 { |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
1113 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
|
1114 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
|
1115 |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
1116 /* 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
|
1117 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
|
1118 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
|
1119 /* 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
|
1120 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
|
1121 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
|
1122 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
|
1123 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
|
1124 /* 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
|
1125 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
|
1126 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
|
1127 and a x-platform nightmare. |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
1128 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
|
1129 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
|
1130 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
|
1131 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
|
1132 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
|
1133 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
|
1134 */ |
|
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
1135 int ispyc = 0; |
|
16648
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
1136 if (ftell(fp) == 0) { |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
1137 if (fread(buf, 1, 2, fp) == 2 && |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1138 ((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
|
1139 ispyc = 1; |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
1140 rewind(fp); |
|
a51b9961f3bb
Bug #132850 unix line terminator on windows.
Tim Peters <tim.peters@gmail.com>
parents:
16560
diff
changeset
|
1141 } |
|
16560
e8e636cc1a09
Ugly fix for SF bug 131239 (-x flag busted).
Tim Peters <tim.peters@gmail.com>
parents:
16421
diff
changeset
|
1142 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
|
1143 } |
|
76caf0855d1f
Recognize pyc files even if they don't end in pyc.
Martin v. Löwis <martin@v.loewis.de>
parents:
14637
diff
changeset
|
1144 return 0; |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1145 } |
|
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
|
1146 |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
1147 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1148 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
|
1149 PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1150 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1151 PyObject *m, *d, *v; |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1152 const char *ext; |
|
52819
73a7e6aba7b2
Merged revisions 71152 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
52641
diff
changeset
|
1153 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
|
1154 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1155 m = PyImport_AddModule("__main__"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1156 if (m == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1157 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
|
1158 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
|
1159 if (PyDict_GetItemString(d, "__file__") == NULL) { |
|
43569
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43525
diff
changeset
|
1160 PyObject *f; |
|
19319e70fc3e
Patch #1272, by Christian Heimes and Alexandre Vassalotti.
Guido van Rossum <guido@python.org>
parents:
43525
diff
changeset
|
1161 f = PyUnicode_DecodeFSDefault(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
|
1162 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
|
1163 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
|
1164 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
|
1165 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
|
1166 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
|
1167 } |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1168 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
|
1169 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
|
1170 } |
|
52819
73a7e6aba7b2
Merged revisions 71152 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
52641
diff
changeset
|
1171 len = strlen(filename); |
|
73a7e6aba7b2
Merged revisions 71152 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents:
52641
diff
changeset
|
1172 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
|
1173 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
|
1174 /* 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
|
1175 if (closeit) |
|
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
1176 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
|
1177 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
|
1178 fprintf(stderr, "python: Can't reopen .pyc file\n"); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1179 ret = -1; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1180 goto done; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1181 } |
|
5234
07ed52e200db
Allow passing a .pyo file.
Guido van Rossum <guido@python.org>
parents:
5170
diff
changeset
|
1182 /* 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
|
1183 if (strcmp(ext, ".pyo") == 0) |
|
07ed52e200db
Allow passing a .pyo file.
Guido van Rossum <guido@python.org>
parents:
5170
diff
changeset
|
1184 Py_OptimizeFlag = 1; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1185 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
|
1186 } else { |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1187 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
|
1188 closeit, flags); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1189 } |
|
46395
6196529afd73
Add a NEWS entry for issue2221.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46318
diff
changeset
|
1190 flush_io(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1191 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
|
1192 PyErr_Print(); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1193 ret = -1; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1194 goto done; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1195 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1196 Py_DECREF(v); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1197 ret = 0; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1198 done: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1199 if (set_file_name && PyDict_DelItemString(d, "__file__")) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1200 PyErr_Clear(); |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1201 return ret; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1202 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1203 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1204 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1205 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
|
1206 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1207 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
|
1208 m = PyImport_AddModule("__main__"); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1209 if (m == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1210 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
|
1211 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
|
1212 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
|
1213 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
|
1214 PyErr_Print(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1215 return -1; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1216 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1217 Py_DECREF(v); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1218 return 0; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1219 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1220 |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1221 static int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1222 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
|
1223 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
|
1224 { |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1225 long hold; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1226 PyObject *v; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1227 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1228 /* old style errors */ |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1229 if (PyTuple_Check(err)) |
|
22721
253de588f2fb
Get rid of another use of PyArg_Parse()
Neal Norwitz <nnorwitz@gmail.com>
parents:
22468
diff
changeset
|
1230 return PyArg_ParseTuple(err, "O(ziiz)", message, filename, |
| 36836 | 1231 lineno, offset, text); |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1232 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1233 /* 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
|
1234 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1235 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
|
1236 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1237 *message = v; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1238 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1239 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
|
1240 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1241 if (v == Py_None) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1242 *filename = NULL; |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1243 else if (! (*filename = _PyUnicode_AsString(v))) |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1244 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1245 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1246 Py_DECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1247 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
|
1248 goto finally; |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1249 hold = PyLong_AsLong(v); |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1250 Py_DECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1251 v = NULL; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1252 if (hold < 0 && PyErr_Occurred()) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1253 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1254 *lineno = (int)hold; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1255 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1256 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
|
1257 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
|
1258 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
|
1259 *offset = -1; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1260 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
|
1261 v = NULL; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1262 } else { |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1263 hold = PyLong_AsLong(v); |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1264 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
|
1265 v = NULL; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1266 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
|
1267 goto finally; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1268 *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
|
1269 } |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1270 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1271 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
|
1272 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1273 if (v == Py_None) |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1274 *text = NULL; |
|
43525
b9d19d51de36
get rid of some more PyString uses.
Guido van Rossum <guido@python.org>
parents:
43225
diff
changeset
|
1275 else if (!PyUnicode_Check(v) || |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1276 !(*text = _PyUnicode_AsString(v))) |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1277 goto finally; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1278 Py_DECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1279 return 1; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1280 |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1281 finally: |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1282 Py_XDECREF(v); |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1283 return 0; |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1284 } |
|
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1285 |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1286 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1287 PyErr_Print(void) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1288 { |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1289 PyErr_PrintEx(1); |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1290 } |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1291 |
|
16831
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1292 static void |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1293 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
|
1294 { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1295 char *nl; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1296 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
|
1297 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
|
1298 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1299 for (;;) { |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1300 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
|
1301 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
|
1302 break; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36078
diff
changeset
|
1303 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
|
1304 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
|
1305 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1306 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
|
1307 text++; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1308 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1309 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1310 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1311 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
|
1312 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
|
1313 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
|
1314 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
|
1315 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
|
1316 return; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1317 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
|
1318 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1319 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
|
1320 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
|
1321 offset--; |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1322 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1323 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
|
1324 } |
|
27f04d714ecb
Print the offending line of code in the traceback for SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16648
diff
changeset
|
1325 |
|
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
|
1326 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
|
1327 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
|
1328 { |
| 36836 | 1329 PyObject *exception, *value, *tb; |
| 1330 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
|
1331 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1332 if (Py_InspectFlag) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1333 /* Don't exit if -i flag was given. This flag is set to 0 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1334 * when entering interactive mode for inspecting. */ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1335 return; |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1336 |
|
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
|
1337 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
|
1338 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
|
1339 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
|
1340 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
|
1341 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
|
1342 /* 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
|
1343 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
|
1344 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
|
1345 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
|
1346 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
|
1347 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
|
1348 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
|
1349 } |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1350 /* 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
|
1351 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
|
1352 } |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1353 if (PyLong_Check(value)) |
|
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
44098
diff
changeset
|
1354 exitcode = (int)PyLong_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
|
1355 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
|
1356 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
|
1357 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
|
1358 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
|
1359 } |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1360 done: |
| 36836 | 1361 /* Restore and clear the exception info, in order to properly decref |
| 1362 * the exception, value, and traceback. If we just exit instead, | |
| 1363 * these leak, which confuses PYTHONDUMPREFS output, and may prevent | |
| 1364 * some finalizers from running. | |
| 1365 */ | |
|
28698
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1366 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
|
1367 PyErr_Clear(); |
|
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1368 Py_Exit(exitcode); |
|
aef01a076ef9
handle_system_exit(): This leaked the current exception info, in
Tim Peters <tim.peters@gmail.com>
parents:
28694
diff
changeset
|
1369 /* 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
|
1370 } |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1371 |
|
eb06a02e0507
Allow sys.excepthook and sys.exitfunc to quietly exit with a sys.exit().
Ka-Ping Yee <ping@zesty.ca>
parents:
17168
diff
changeset
|
1372 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1373 PyErr_PrintEx(int set_sys_last_vars) |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1374 { |
| 17164 | 1375 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
|
1376 |
|
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
|
1377 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
|
1378 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
|
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 PyErr_Fetch(&exception, &v, &tb); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1381 if (exception == NULL) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1382 return; |
|
6197
7da7ba5c6525
Added Py_UseClassExceptionsFlag, the variable containing the state of
Barry Warsaw <barry@python.org>
parents:
6165
diff
changeset
|
1383 PyErr_NormalizeException(&exception, &v, &tb); |
|
48874
4db1f5098175
#3663: extra DECREF on syntax errors.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48839
diff
changeset
|
1384 if (tb == NULL) { |
|
4db1f5098175
#3663: extra DECREF on syntax errors.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48839
diff
changeset
|
1385 tb = Py_None; |
|
4db1f5098175
#3663: extra DECREF on syntax errors.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48839
diff
changeset
|
1386 Py_INCREF(tb); |
|
4db1f5098175
#3663: extra DECREF on syntax errors.
Antoine Pitrou <solipsis@pitrou.net>
parents:
48839
diff
changeset
|
1387 } |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1388 PyException_SetTraceback(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
|
1389 if (exception == NULL) |
|
5611
5ed3a21cc122
Can't return 0 from void function...
Guido van Rossum <guido@python.org>
parents:
5607
diff
changeset
|
1390 return; |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
1391 /* Now we know v != NULL too */ |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1392 if (set_sys_last_vars) { |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1393 PySys_SetObject("last_type", exception); |
|
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1394 PySys_SetObject("last_value", v); |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1395 PySys_SetObject("last_traceback", tb); |
|
7206
3f255aedf621
Ehm, three unrelated changes.
Guido van Rossum <guido@python.org>
parents:
7113
diff
changeset
|
1396 } |
| 17164 | 1397 hook = PySys_GetObject("excepthook"); |
| 1398 if (hook) { | |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1399 PyObject *args = PyTuple_Pack(3, exception, v, tb); |
| 17164 | 1400 PyObject *result = PyEval_CallObject(hook, args); |
| 1401 if (result == NULL) { | |
| 1402 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
|
1403 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
|
1404 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
|
1405 } |
| 17164 | 1406 PyErr_Fetch(&exception2, &v2, &tb2); |
| 1407 PyErr_NormalizeException(&exception2, &v2, &tb2); | |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1408 /* It should not be possible for exception2 or v2 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1409 to be NULL. However PyErr_Display() can't |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1410 tolerate NULLs, so just be safe. */ |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1411 if (exception2 == NULL) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1412 exception2 = Py_None; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1413 Py_INCREF(exception2); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1414 } |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1415 if (v2 == NULL) { |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1416 v2 = Py_None; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1417 Py_INCREF(v2); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1418 } |
| 17164 | 1419 fflush(stdout); |
| 1420 PySys_WriteStderr("Error in sys.excepthook:\n"); | |
| 1421 PyErr_Display(exception2, v2, tb2); | |
| 1422 PySys_WriteStderr("\nOriginal exception was:\n"); | |
| 1423 PyErr_Display(exception, v, tb); | |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1424 Py_DECREF(exception2); |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1425 Py_DECREF(v2); |
|
21284
43b8a962a32a
Missing DECREFs when exception is raised in sys.excepthook.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
21251
diff
changeset
|
1426 Py_XDECREF(tb2); |
| 17164 | 1427 } |
| 1428 Py_XDECREF(result); | |
| 1429 Py_XDECREF(args); | |
| 1430 } else { | |
| 1431 PySys_WriteStderr("sys.excepthook is missing\n"); | |
| 1432 PyErr_Display(exception, v, tb); | |
| 1433 } | |
| 1434 Py_XDECREF(exception); | |
| 1435 Py_XDECREF(v); | |
| 1436 Py_XDECREF(tb); | |
| 1437 } | |
| 1438 | |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1439 static void |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1440 print_exception(PyObject *f, PyObject *value) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1441 { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1442 int err = 0; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1443 PyObject *type, *tb; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1444 |
|
48839
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1445 if (!PyExceptionInstance_Check(value)) { |
|
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1446 PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f); |
|
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1447 PyFile_WriteString(Py_TYPE(value)->tp_name, f); |
|
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1448 PyFile_WriteString(" found\n", f); |
|
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1449 return; |
|
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1450 } |
|
587cd4f66c2d
fix #3653 Python could segfault if invalid values were passed to sys.excepthook
Benjamin Peterson <benjamin@python.org>
parents:
48660
diff
changeset
|
1451 |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1452 Py_INCREF(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1453 fflush(stdout); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1454 type = (PyObject *) Py_TYPE(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1455 tb = PyException_GetTraceback(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1456 if (tb && tb != Py_None) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1457 err = PyTraceBack_Print(tb, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1458 if (err == 0 && |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1459 PyObject_HasAttrString(value, "print_file_and_line")) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1460 { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1461 PyObject *message; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1462 const char *filename, *text; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1463 int lineno, offset; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1464 if (!parse_syntax_error(value, &message, &filename, |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1465 &lineno, &offset, &text)) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1466 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1467 else { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1468 char buf[10]; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1469 PyFile_WriteString(" File \"", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1470 if (filename == NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1471 PyFile_WriteString("<string>", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1472 else |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1473 PyFile_WriteString(filename, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1474 PyFile_WriteString("\", line ", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1475 PyOS_snprintf(buf, sizeof(buf), "%d", lineno); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1476 PyFile_WriteString(buf, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1477 PyFile_WriteString("\n", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1478 if (text != NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1479 print_error_text(f, offset, text); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1480 Py_DECREF(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1481 value = message; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1482 /* Can't be bothered to check all those |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1483 PyFile_WriteString() calls */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1484 if (PyErr_Occurred()) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1485 err = -1; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1486 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1487 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1488 if (err) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1489 /* Don't do anything else */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1490 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1491 else { |
|
48477
e26c724d5e23
Make these files to compile again under Windows.
Thomas Heller <theller@ctypes.org>
parents:
48474
diff
changeset
|
1492 PyObject* moduleName; |
|
e26c724d5e23
Make these files to compile again under Windows.
Thomas Heller <theller@ctypes.org>
parents:
48474
diff
changeset
|
1493 char* className; |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1494 assert(PyExceptionClass_Check(type)); |
|
48477
e26c724d5e23
Make these files to compile again under Windows.
Thomas Heller <theller@ctypes.org>
parents:
48474
diff
changeset
|
1495 className = PyExceptionClass_Name(type); |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1496 if (className != NULL) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1497 char *dot = strrchr(className, '.'); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1498 if (dot != NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1499 className = dot+1; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1500 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1501 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1502 moduleName = PyObject_GetAttrString(type, "__module__"); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1503 if (moduleName == NULL || !PyUnicode_Check(moduleName)) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1504 { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1505 Py_DECREF(moduleName); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1506 err = PyFile_WriteString("<unknown>", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1507 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1508 else { |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1509 char* modstr = _PyUnicode_AsString(moduleName); |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1510 if (modstr && strcmp(modstr, "builtins")) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1511 { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1512 err = PyFile_WriteString(modstr, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1513 err += PyFile_WriteString(".", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1514 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1515 Py_DECREF(moduleName); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1516 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1517 if (err == 0) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1518 if (className == NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1519 err = PyFile_WriteString("<unknown>", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1520 else |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1521 err = PyFile_WriteString(className, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1522 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1523 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1524 if (err == 0 && (value != Py_None)) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1525 PyObject *s = PyObject_Str(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1526 /* only print colon if the str() of the |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1527 object is not the empty string |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1528 */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1529 if (s == NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1530 err = -1; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1531 else if (!PyUnicode_Check(s) || |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1532 PyUnicode_GetSize(s) != 0) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1533 err = PyFile_WriteString(": ", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1534 if (err == 0) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1535 err = PyFile_WriteObject(s, f, Py_PRINT_RAW); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1536 Py_XDECREF(s); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1537 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1538 /* try to write a newline in any case */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1539 err += PyFile_WriteString("\n", f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1540 Py_XDECREF(tb); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1541 Py_DECREF(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1542 /* If an error happened here, don't show it. |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1543 XXX This is wrong, but too many callers rely on this behavior. */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1544 if (err != 0) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1545 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1546 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1547 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1548 static const char *cause_message = |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1549 "\nThe above exception was the direct cause " |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1550 "of the following exception:\n\n"; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1551 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1552 static const char *context_message = |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1553 "\nDuring handling of the above exception, " |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1554 "another exception occurred:\n\n"; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1555 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1556 static void |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1557 print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1558 { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1559 int err = 0, res; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1560 PyObject *cause, *context; |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1561 |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1562 if (seen != NULL) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1563 /* Exception chaining */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1564 if (PySet_Add(seen, value) == -1) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1565 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1566 else if (PyExceptionInstance_Check(value)) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1567 cause = PyException_GetCause(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1568 context = PyException_GetContext(value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1569 if (cause) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1570 res = PySet_Contains(seen, cause); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1571 if (res == -1) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1572 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1573 if (res == 0) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1574 print_exception_recursive( |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1575 f, cause, seen); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1576 err |= PyFile_WriteString( |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1577 cause_message, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1578 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1579 } |
|
57498
4bed796ee0d7
Merged revisions 76573 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56652
diff
changeset
|
1580 else if (context) { |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1581 res = PySet_Contains(seen, context); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1582 if (res == -1) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1583 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1584 if (res == 0) { |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1585 print_exception_recursive( |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1586 f, context, seen); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1587 err |= PyFile_WriteString( |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1588 context_message, f); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1589 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1590 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1591 Py_XDECREF(context); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1592 Py_XDECREF(cause); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1593 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1594 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1595 print_exception(f, value); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1596 if (err != 0) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1597 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1598 } |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1599 |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1600 void |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1601 PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) |
| 17164 | 1602 { |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1603 PyObject *seen; |
| 17164 | 1604 PyObject *f = PySys_GetObject("stderr"); |
|
43855
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
1605 if (f == Py_None) { |
|
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
1606 /* pass */ |
|
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
1607 } |
|
ee081609cee8
Added some additional checks for sys.std?? is None, see #1440
Christian Heimes <christian@cheimes.de>
parents:
43848
diff
changeset
|
1608 else if (f == NULL) { |
|
42013
cd125fe83051
Make identifiers str (not str8) objects throughout.
Martin v. Löwis <martin@v.loewis.de>
parents:
41587
diff
changeset
|
1609 _PyObject_Dump(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
|
1610 fprintf(stderr, "lost sys.stderr\n"); |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
1611 } |
|
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
|
1612 else { |
|
48474
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1613 /* We choose to ignore seen being possibly NULL, and report |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1614 at least the main exception (it could be a MemoryError). |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1615 */ |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1616 seen = PySet_New(NULL); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1617 if (seen == NULL) |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1618 PyErr_Clear(); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1619 print_exception_recursive(f, value, seen); |
|
2ee09afee126
implement chained exception tracebacks
Benjamin Peterson <benjamin@python.org>
parents:
47611
diff
changeset
|
1620 Py_XDECREF(seen); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1621 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1622 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1623 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1624 PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1625 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
|
1626 PyObject *locals, PyCompilerFlags *flags) |
|
14228
20377f15b96a
Add three new APIs: PyRun_AnyFileEx(), PyRun_SimpleFileEx(),
Guido van Rossum <guido@python.org>
parents:
14227
diff
changeset
|
1627 { |
|
36835
9109b1a0d265
Get rid of run_err_mod(). It was only used in two places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36807
diff
changeset
|
1628 PyObject *ret = NULL; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1629 mod_ty mod; |
| 36836 | 1630 PyArena *arena = PyArena_New(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1631 if (arena == NULL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1632 return NULL; |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
1633 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1634 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
|
1635 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
|
1636 ret = run_mod(mod, "<string>", globals, locals, flags, arena); |
| 36836 | 1637 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1638 return ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1639 } |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1640 |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1641 PyObject * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1642 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
|
1643 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
|
1644 { |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1645 PyObject *ret; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1646 mod_ty mod; |
| 36836 | 1647 PyArena *arena = PyArena_New(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1648 if (arena == NULL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1649 return NULL; |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
1650 |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1651 mod = PyParser_ASTFromFile(fp, filename, NULL, start, 0, 0, |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1652 flags, NULL, arena); |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1653 if (closeit) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41253
diff
changeset
|
1654 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
|
1655 if (mod == NULL) { |
| 36836 | 1656 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1657 return NULL; |
| 36836 | 1658 } |
|
36835
9109b1a0d265
Get rid of run_err_mod(). It was only used in two places.
Neal Norwitz <nnorwitz@gmail.com>
parents:
36807
diff
changeset
|
1659 ret = run_mod(mod, filename, globals, locals, flags, arena); |
| 36836 | 1660 PyArena_Free(arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1661 return ret; |
|
17125
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1662 } |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1663 |
|
44162
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1664 static void |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1665 flush_io(void) |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1666 { |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1667 PyObject *f, *r; |
|
46299
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1668 PyObject *type, *value, *traceback; |
|
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1669 |
|
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1670 /* Save the current exception */ |
|
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1671 PyErr_Fetch(&type, &value, &traceback); |
|
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1672 |
|
44162
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1673 f = PySys_GetObject("stderr"); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1674 if (f != NULL) { |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1675 r = PyObject_CallMethod(f, "flush", ""); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1676 if (r) |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1677 Py_DECREF(r); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1678 else |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1679 PyErr_Clear(); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1680 } |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1681 f = PySys_GetObject("stdout"); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1682 if (f != NULL) { |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1683 r = PyObject_CallMethod(f, "flush", ""); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1684 if (r) |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1685 Py_DECREF(r); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1686 else |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1687 PyErr_Clear(); |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1688 } |
|
46299
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1689 |
|
e8916c64df4c
Issue2221: in Idle, exec('xx') raised a SystemError('error return without exception set')
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
46126
diff
changeset
|
1690 PyErr_Restore(type, value, traceback); |
|
44162
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1691 } |
|
ef5399b353c9
Solve issue 1400 at least in part -- whenever we run Python code, at the end
Guido van Rossum <guido@python.org>
parents:
44134
diff
changeset
|
1692 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1693 static PyObject * |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1694 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
|
1695 PyCompilerFlags *flags, PyArena *arena) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1696 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1697 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
|
1698 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
|
1699 co = PyAST_Compile(mod, filename, flags, arena); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1700 if (co == NULL) |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1701 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
|
1702 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
|
1703 Py_DECREF(co); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1704 return v; |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1705 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1706 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1707 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1708 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
|
1709 PyObject *locals, PyCompilerFlags *flags) |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
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 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
|
1712 PyObject *v; |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1713 long magic; |
|
14278
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
1714 long PyImport_GetMagicNumber(void); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1715 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1716 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
|
1717 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
|
1718 PyErr_SetString(PyExc_RuntimeError, |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1719 "Bad magic number in .pyc file"); |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1720 return NULL; |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
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 (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
|
1723 v = PyMarshal_ReadLastObjectFromFile(fp); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1724 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
|
1725 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
|
1726 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
|
1727 PyErr_SetString(PyExc_RuntimeError, |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1728 "Bad code object in .pyc file"); |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1729 return NULL; |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1730 } |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1731 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
|
1732 v = PyEval_EvalCode(co, globals, locals); |
|
19158
97a3d3d7029f
Refactor future feature handling
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19099
diff
changeset
|
1733 if (v && flags) |
|
97a3d3d7029f
Refactor future feature handling
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19099
diff
changeset
|
1734 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
|
1735 Py_DECREF(co); |
|
1886
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1736 return v; |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1737 } |
|
ac6a9f90f6fd
* Import/pythonrun.h, Python/{import,pythonrun}.c,
Guido van Rossum <guido@python.org>
parents:
1870
diff
changeset
|
1738 |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1739 PyObject * |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
1740 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
|
1741 PyCompilerFlags *flags) |
|
2054cea38754
Extend support for from __future__ import nested_scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16916
diff
changeset
|
1742 { |
|
5170
f5d707ce4223
Greatly renamed. Not a very thorough job -- I'm going to restructure
Guido van Rossum <guido@python.org>
parents:
5108
diff
changeset
|
1743 PyCodeObject *co; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1744 mod_ty mod; |
| 36836 | 1745 PyArena *arena = PyArena_New(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1746 if (arena == NULL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1747 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1748 |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1749 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
|
1750 if (mod == NULL) { |
| 36836 | 1751 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
|
1752 return NULL; |
| 36836 | 1753 } |
|
36662
2ab9270ef19a
Check whether there are flags.
Martin v. Löwis <martin@v.loewis.de>
parents:
36660
diff
changeset
|
1754 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
|
1755 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
|
1756 PyArena_Free(arena); |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1757 return result; |
|
3c0b26113df6
Generate code to recursively copy an AST into
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
1758 } |
|
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
|
1759 co = PyAST_Compile(mod, filename, flags, arena); |
| 36836 | 1760 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
|
1761 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
|
1762 } |
|
65a1e4e9cd54
* Fixed some subtleties with fastlocals. You can no longer access
Guido van Rossum <guido@python.org>
parents:
1262
diff
changeset
|
1763 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1764 struct symtable * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1765 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
|
1766 { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1767 struct symtable *st; |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1768 mod_ty mod; |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1769 PyCompilerFlags flags; |
| 36836 | 1770 PyArena *arena = PyArena_New(); |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1771 if (arena == NULL) |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1772 return NULL; |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38669
diff
changeset
|
1773 |
|
46125
36d828d27c36
Merged revisions 61954,61956-61957 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46120
diff
changeset
|
1774 flags.cf_flags = 0; |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1775 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
|
1776 if (mod == NULL) { |
| 36836 | 1777 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
|
1778 return NULL; |
| 36836 | 1779 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1780 st = PySymtable_Build(mod, filename, 0); |
| 36836 | 1781 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
|
1782 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
|
1783 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16311
diff
changeset
|
1784 |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1785 /* Preferred access to parser is through AST. */ |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1786 mod_ty |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1787 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
|
1788 PyCompilerFlags *flags, PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1789 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1790 mod_ty mod; |
|
49624
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1791 PyCompilerFlags localflags; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1792 perrdetail err; |
|
46126
b06a15efdc6d
Merged revisions 61958-61959 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46125
diff
changeset
|
1793 int iflags = PARSER_FLAGS(flags); |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1794 |
|
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1795 node *n = PyParser_ParseStringFlagsFilenameEx(s, filename, |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1796 &_PyParser_Grammar, start, &err, |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1797 &iflags); |
|
49624
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1798 if (flags == NULL) { |
|
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1799 localflags.cf_flags = 0; |
|
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1800 flags = &localflags; |
|
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1801 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1802 if (n) { |
|
49624
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1803 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
|
1804 mod = PyAST_FromNode(n, flags, filename, arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1805 PyNode_Free(n); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1806 return mod; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1807 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1808 else { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1809 err_input(&err); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1810 return NULL; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1811 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1812 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1813 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1814 mod_ty |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1815 PyParser_ASTFromFile(FILE *fp, const char *filename, const char* enc, |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1816 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
|
1817 char *ps2, PyCompilerFlags *flags, int *errcode, |
| 36836 | 1818 PyArena *arena) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1819 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1820 mod_ty mod; |
|
49624
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1821 PyCompilerFlags localflags; |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1822 perrdetail err; |
|
46126
b06a15efdc6d
Merged revisions 61958-61959 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
46125
diff
changeset
|
1823 int iflags = PARSER_FLAGS(flags); |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1824 |
|
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1825 node *n = PyParser_ParseFileFlagsEx(fp, filename, enc, |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1826 &_PyParser_Grammar, |
|
46120
78504d604b44
Merged revisions 61952-61953 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45914
diff
changeset
|
1827 start, ps1, ps2, &err, &iflags); |
|
49624
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1828 if (flags == NULL) { |
|
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1829 localflags.cf_flags = 0; |
|
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1830 flags = &localflags; |
|
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1831 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1832 if (n) { |
|
49624
f3234e43e1fe
Merged revisions 67066 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
49613
diff
changeset
|
1833 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
|
1834 mod = PyAST_FromNode(n, flags, filename, arena); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1835 PyNode_Free(n); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1836 return mod; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1837 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1838 else { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1839 err_input(&err); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1840 if (errcode) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1841 *errcode = err.error; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1842 return NULL; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1843 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1844 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1845 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1846 /* 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
|
1847 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1848 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1849 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
|
1850 { |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1851 perrdetail err; |
|
43225
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1852 node *n = PyParser_ParseFileFlags(fp, filename, NULL, |
|
38f3f9ef193d
Convert code from sys.stdin.encoding to UTF-8 in
Martin v. Löwis <martin@v.loewis.de>
parents:
43147
diff
changeset
|
1853 &_PyParser_Grammar, |
|
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
|
1854 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
|
1855 if (n == NULL) |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1856 err_input(&err); |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
1857 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1858 return n; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1859 } |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1860 |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1861 /* 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
|
1862 |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1863 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1864 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
|
1865 { |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1866 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
|
1867 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
|
1868 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
|
1869 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
|
1870 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
|
1871 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
|
1872 } |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1873 |
|
0a90e5ec61b6
Ugly. A pile of new xxxFlags() functions, to communicate to the parser
Tim Peters <tim.peters@gmail.com>
parents:
18612
diff
changeset
|
1874 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1875 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
|
1876 int start, int flags) |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1877 { |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1878 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
|
1879 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
|
1880 &_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
|
1881 if (n == NULL) |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1882 err_input(&err); |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1883 return n; |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1884 } |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1885 |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1886 node * |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
1887 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
|
1888 { |
|
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
|
1889 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
|
1890 } |
|
cb728141ae12
Fix SF Bug 564931: compile() traceback must include filename.
Thomas Heller <theller@ctypes.org>
parents:
24155
diff
changeset
|
1891 |
|
28649
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1892 /* 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
|
1893 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
|
1894 |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1895 void |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1896 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
|
1897 { |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1898 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
|
1899 } |
|
04b172843292
A missing piece of the PEP 269 patch: add PyParser_SetError(), a
Guido van Rossum <guido@python.org>
parents:
28648
diff
changeset
|
1900 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1901 /* 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
|
1902 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1903 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
1904 err_input(perrdetail *err) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1905 { |
|
43147
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1906 PyObject *v, *w, *errtype, *errtext; |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1907 PyObject* u = NULL; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1908 char *msg = NULL; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1909 errtype = PyExc_SyntaxError; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1910 switch (err->error) { |
|
59865
c2d2e26bcf7f
Merged revisions 78872 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57498
diff
changeset
|
1911 case E_ERROR: |
|
c2d2e26bcf7f
Merged revisions 78872 via svnmerge from
Victor Stinner <victor.stinner@haypocalc.com>
parents:
57498
diff
changeset
|
1912 return; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1913 case E_SYNTAX: |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1914 errtype = PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1915 if (err->expected == INDENT) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1916 msg = "expected an indented block"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1917 else if (err->token == INDENT) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1918 msg = "unexpected indent"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1919 else if (err->token == DEDENT) |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1920 msg = "unexpected unindent"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1921 else { |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1922 errtype = PyExc_SyntaxError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1923 msg = "invalid syntax"; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1924 } |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1925 break; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1926 case E_TOKEN: |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1927 msg = "invalid token"; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1928 break; |
|
24839
17e95cc06f69
provide less mysterious error messages when seeing end-of-line in
Skip Montanaro <skip@pobox.com>
parents:
24539
diff
changeset
|
1929 case E_EOFS: |
|
47072
0c7142c56d7e
Merged revisions 63066-63076,63079,63081-63085,63087-63097,63099,63101-63104 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46708
diff
changeset
|
1930 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
|
1931 break; |
|
17e95cc06f69
provide less mysterious error messages when seeing end-of-line in
Skip Montanaro <skip@pobox.com>
parents:
24539
diff
changeset
|
1932 case E_EOLS: |
|
47072
0c7142c56d7e
Merged revisions 63066-63076,63079,63081-63085,63087-63097,63099,63101-63104 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46708
diff
changeset
|
1933 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
|
1934 break; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1935 case E_INTR: |
| 32526 | 1936 if (!PyErr_Occurred()) |
| 1937 PyErr_SetNone(PyExc_KeyboardInterrupt); | |
|
48563
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
1938 goto cleanup; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1939 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
|
1940 PyErr_NoMemory(); |
|
48563
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
1941 goto cleanup; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1942 case E_EOF: |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1943 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
|
1944 break; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1945 case E_TABSPACE: |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1946 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
|
1947 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
|
1948 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
|
1949 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
|
1950 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
|
1951 break; |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1952 case E_DEDENT: |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1953 errtype = PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1954 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
|
1955 break; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1956 case E_TOODEEP: |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1957 errtype = PyExc_IndentationError; |
|
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
1958 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
|
1959 break; |
|
35417
e48fcd4c358d
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
35297
diff
changeset
|
1960 case E_DECODE: { |
|
e48fcd4c358d
Forward UnicodeDecodeError into SyntaxError for source encoding errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
35297
diff
changeset
|
1961 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
|
1962 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
|
1963 if (value != NULL) { |
|
43866
8ed0280c2ab6
Replace PyObject_Unicode with PyObject_Str everywhere, and remove the
Thomas Heller <theller@ctypes.org>
parents:
43855
diff
changeset
|
1964 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
|
1965 if (u != NULL) { |
|
48660
85b67fb5672b
Rename PyUnicode_AsString -> _PyUnicode_AsString and
Marc-André Lemburg <mal@egenix.com>
parents:
48563
diff
changeset
|
1966 msg = _PyUnicode_AsString(u); |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1967 } |
|
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1968 } |
|
32781
caaef302f1e3
Patch #984714: Properly diagnose E_DECODE errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
32526
diff
changeset
|
1969 if (msg == NULL) |
|
caaef302f1e3
Patch #984714: Properly diagnose E_DECODE errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
32526
diff
changeset
|
1970 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
|
1971 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
|
1972 Py_XDECREF(value); |
|
35666
b8e571e6de2e
- Fix segfault with invalid coding.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35417
diff
changeset
|
1973 Py_XDECREF(tb); |
|
32781
caaef302f1e3
Patch #984714: Properly diagnose E_DECODE errors.
Martin v. Löwis <martin@v.loewis.de>
parents:
32526
diff
changeset
|
1974 break; |
|
24539
06f1e2fd05bc
Patch #534304: Implement phase 1 of PEP 263.
Martin v. Löwis <martin@v.loewis.de>
parents:
24162
diff
changeset
|
1975 } |
|
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
|
1976 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
|
1977 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
|
1978 break; |
|
42597
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42539
diff
changeset
|
1979 |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42539
diff
changeset
|
1980 case E_IDENTIFIER: |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42539
diff
changeset
|
1981 msg = "invalid character in identifier"; |
|
20477cbfd996
Implement PEP 3131. Add isidentifier to str.
Martin v. Löwis <martin@v.loewis.de>
parents:
42539
diff
changeset
|
1982 break; |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1983 default: |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1984 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
|
1985 msg = "unknown parsing error"; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1986 break; |
|
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
1987 } |
|
43147
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1988 /* err->text may not be UTF-8 in case of decoding errors. |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1989 Explicitly convert to an object. */ |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1990 if (!err->text) { |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1991 errtext = Py_None; |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1992 Py_INCREF(Py_None); |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1993 } else { |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1994 errtext = PyUnicode_DecodeUTF8(err->text, strlen(err->text), |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1995 "replace"); |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1996 } |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1997 v = Py_BuildValue("(ziiN)", err->filename, |
|
06dc4321a56a
Explicitly convert err->text to Unicode. Fixes #1069.
Martin v. Löwis <martin@v.loewis.de>
parents:
42893
diff
changeset
|
1998 err->lineno, err->offset, errtext); |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
1999 w = NULL; |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2000 if (v != NULL) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2001 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
|
2002 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
|
2003 Py_XDECREF(v); |
|
13539
feab677269e0
Create two new exceptions: IndentationError and TabError. These are
Fred Drake <fdrake@acm.org>
parents:
13447
diff
changeset
|
2004 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
|
2005 Py_XDECREF(w); |
|
48563
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
2006 cleanup: |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
2007 if (err->text != NULL) { |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
2008 PyObject_FREE(err->text); |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
2009 err->text = NULL; |
|
b51cd5d3795c
Merged revisions 65012,65035,65037-65040,65048,65057,65077,65091-65095,65097-65099,65127-65128,65131,65133-65136,65139,65149-65151,65155,65158-65159,65176-65178,65183-65184,65187-65190,65192,65194 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48494
diff
changeset
|
2010 } |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2011 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2012 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2013 /* Print fatal error message and abort */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2014 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2015 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
|
2016 Py_FatalError(const char *msg) |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2017 { |
|
1911
a7f269610ec2
* Python/pythonrun.c: add string "Python" to fatal error message
Guido van Rossum <guido@python.org>
parents:
1898
diff
changeset
|
2018 fprintf(stderr, "Fatal Python error: %s\n", msg); |
|
52609
111352112afa
Merged revisions 70908 via svnmerge from
Jesse Noller <jnoller@gmail.com>
parents:
51991
diff
changeset
|
2019 fflush(stderr); /* it helps in Windows debug build */ |
|
43605
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
2020 if (PyErr_Occurred()) { |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
2021 PyErr_Print(); |
|
a2bb76d11d66
Patch 1267 by Christian Heimes.
Guido van Rossum <guido@python.org>
parents:
43569
diff
changeset
|
2022 } |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
2023 #ifdef MS_WINDOWS |
|
50558
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2024 { |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2025 size_t len = strlen(msg); |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2026 WCHAR* buffer; |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2027 size_t i; |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2028 |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2029 /* Convert the message to wchar_t. This uses a simple one-to-one |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2030 conversion, assuming that the this error message actually uses ASCII |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2031 only. If this ceases to be true, we will have to convert. */ |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2032 buffer = alloca( (len+1) * (sizeof *buffer)); |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2033 for( i=0; i<=len; ++i) |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2034 buffer[i] = msg[i]; |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2035 OutputDebugStringW(L"Fatal Python error: "); |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2036 OutputDebugStringW(buffer); |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2037 OutputDebugStringW(L"\n"); |
|
fbf7f53f4888
Merged revisions 68175 via svnmerge from
Georg Brandl <georg@python.org>
parents:
49819
diff
changeset
|
2038 } |
|
8988
070de4d39ddd
Add DebugBreak() call to Py_FatalError() for Mark Hammond (only on
Guido van Rossum <guido@python.org>
parents:
7967
diff
changeset
|
2039 #ifdef _DEBUG |
|
070de4d39ddd
Add DebugBreak() call to Py_FatalError() for Mark Hammond (only on
Guido van Rossum <guido@python.org>
parents:
7967
diff
changeset
|
2040 DebugBreak(); |
|
2529
16ea57c38c4f
In NT, write fatal() msg to debugging device
Guido van Rossum <guido@python.org>
parents:
2318
diff
changeset
|
2041 #endif |
|
24071
8142f8d668a0
Patch #569753: Remove support for WIN16.
Martin v. Löwis <martin@v.loewis.de>
parents:
23252
diff
changeset
|
2042 #endif /* MS_WINDOWS */ |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2043 abort(); |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2044 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2045 |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2046 /* Clean up and exit */ |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2047 |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2048 #ifdef WITH_THREAD |
|
9203
07dae6fdae79
Renamed thread.h to pythread.h.
Guido van Rossum <guido@python.org>
parents:
9192
diff
changeset
|
2049 #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
|
2050 #endif |
|
a31e07847063
New thread.c from Sjoerd, supports _exit_prog(). Use this in goaway()
Guido van Rossum <guido@python.org>
parents:
941
diff
changeset
|
2051 |
|
41253
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2052 static void (*pyexitfunc)(void) = NULL; |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2053 /* For the atexit module. */ |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2054 void _Py_PyAtExit(void (*func)(void)) |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2055 { |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2056 pyexitfunc = func; |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2057 } |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2058 |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2059 static void |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2060 call_py_exitfuncs(void) |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2061 { |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43718
diff
changeset
|
2062 if (pyexitfunc == NULL) |
|
41253
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2063 return; |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2064 |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2065 (*pyexitfunc)(); |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2066 PyErr_Clear(); |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2067 } |
|
f29f1a8b7869
Patch #1680961: remove sys.exitfunc and replace it with a private C API. Also, reimplement atexit in C so it can take advantage of this private API.
Collin Winter <collinw@gmail.com>
parents:
40978
diff
changeset
|
2068 |
|
56652
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2069 /* Wait until threading._shutdown completes, provided |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2070 the threading module was imported in the first place. |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2071 The shutdown routine will wait until all non-daemon |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2072 "threading" threads have completed. */ |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2073 static void |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2074 wait_for_thread_shutdown(void) |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2075 { |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2076 #ifdef WITH_THREAD |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2077 PyObject *result; |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2078 PyThreadState *tstate = PyThreadState_GET(); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2079 PyObject *threading = PyMapping_GetItemString(tstate->interp->modules, |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2080 "threading"); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2081 if (threading == NULL) { |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2082 /* threading not imported */ |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2083 PyErr_Clear(); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2084 return; |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2085 } |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2086 result = PyObject_CallMethod(threading, "_shutdown", ""); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2087 if (result == NULL) { |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2088 PyErr_WriteUnraisable(threading); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2089 } |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2090 else { |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2091 Py_DECREF(result); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2092 } |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2093 Py_DECREF(threading); |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2094 #endif |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2095 } |
|
29b3e126c0c2
Merged revisions 75571,75576-75577 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
53994
diff
changeset
|
2096 |
|
9192
ac6c29d1f10c
On second though, NEXITFUNCS should be defined here and not in
Guido van Rossum <guido@python.org>
parents:
9161
diff
changeset
|
2097 #define NEXITFUNCS 32 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2098 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
|
2099 static int nexitfuncs = 0; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2100 |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2101 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
|
2102 { |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2103 if (nexitfuncs >= NEXITFUNCS) |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2104 return -1; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2105 exitfuncs[nexitfuncs++] = func; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2106 return 0; |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2107 } |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2108 |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
2109 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2110 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
|
2111 { |
|
1870
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2112 while (nexitfuncs > 0) |
|
61738ed6cc10
added Py_AtExit() -- register cleanup functions for C modules
Guido van Rossum <guido@python.org>
parents:
1839
diff
changeset
|
2113 (*exitfuncs[--nexitfuncs])(); |
|
5926
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
2114 |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
2115 fflush(stdout); |
|
8d2194e22e67
The last of the mass checkins for separate (sub)interpreters.
Guido van Rossum <guido@python.org>
parents:
5850
diff
changeset
|
2116 fflush(stderr); |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
2117 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
2118 |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
2119 void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2120 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
|
2121 { |
|
5939
2c65bb6ab87c
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
Guido van Rossum <guido@python.org>
parents:
5926
diff
changeset
|
2122 Py_Finalize(); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2123 |
|
3235
3df9ab03badf
Moved mac-specific exit handling to macmain.c
Jack Jansen <jack.jansen@cwi.nl>
parents:
3152
diff
changeset
|
2124 exit(sts); |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2125 } |
|
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2126 |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1289
diff
changeset
|
2127 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
2128 initsigs(void) |
|
1079
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
2129 { |
|
1839
1f4a86dbcd79
* Python/pythonrun.c (print_error): added INCREF/DECREF pair --
Guido van Rossum <guido@python.org>
parents:
1413
diff
changeset
|
2130 #ifdef SIGPIPE |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2131 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
|
2132 #endif |
| 19295 | 2133 #ifdef SIGXFZ |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2134 PyOS_setsig(SIGXFZ, SIG_IGN); |
| 19295 | 2135 #endif |
| 23252 | 2136 #ifdef SIGXFSZ |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2137 PyOS_setsig(SIGXFSZ, SIG_IGN); |
| 23252 | 2138 #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
|
2139 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
|
2140 } |
|
e4c6a0dd5c2b
* bltinmodule.c: added built-in function cmp(a, b)
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
2141 |
|
5108
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2142 |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2143 /* |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2144 * 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
|
2145 * 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
|
2146 * 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
|
2147 * 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
|
2148 */ |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2149 int |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
26263
diff
changeset
|
2150 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
|
2151 { |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2152 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
|
2153 return 1; |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2154 if (!Py_InteractiveFlag) |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2155 return 0; |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2156 return (filename == NULL) || |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2157 (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
|
2158 (strcmp(filename, "???") == 0); |
|
a9a6d416b945
Added new global flag variable Py_InteractiveFlag and new function
Guido van Rossum <guido@python.org>
parents:
4596
diff
changeset
|
2159 } |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2160 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2161 |
|
28648
0e8416be208e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
28647
diff
changeset
|
2162 #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
|
2163 #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
|
2164 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2165 /* 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
|
2166 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2167 #include <malloc.h> |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2168 #include <excpt.h> |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2169 |
|
14278
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
2170 /* |
|
fb8fb53a2eff
Add a comment explaining the return value of PyOS_CheckStack().
Fred Drake <fdrake@acm.org>
parents:
14231
diff
changeset
|
2171 * 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
|
2172 */ |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2173 int |
|
14280
68b61aa1aa4a
PyOS_CheckStack(): Better ANSI'fy this while we're at it.
Fred Drake <fdrake@acm.org>
parents:
14278
diff
changeset
|
2174 PyOS_CheckStack(void) |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2175 { |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2176 __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
|
2177 /* 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
|
2178 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
|
2179 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
|
2180 return 0; |
|
45399
15d5776f2703
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45244
diff
changeset
|
2181 } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ? |
|
45914
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
2182 EXCEPTION_EXECUTE_HANDLER : |
|
4284718fb631
Issue2297: Fix a stack overflow in Windows caused by -v and -vv. When python is invoked with -v or -vv under Windows, the process of importing the codec for sys.stderr causes a message to be written to stderr, which in turn causes the codec to be recursively imported. Sometimes the stack overflow exception is swallowed, other times it is not. The bug depends on the particular locale settings of the Windows machine.
Trent Nelson <trent.nelson@snakebite.org>
parents:
45399
diff
changeset
|
2183 EXCEPTION_CONTINUE_SEARCH) { |
|
45399
15d5776f2703
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45244
diff
changeset
|
2184 int errcode = _resetstkoflw(); |
|
49819
630c174b465e
Merged revisions 67295,67301-67302,67318,67330,67342-67343 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49624
diff
changeset
|
2185 if (errcode == 0) |
|
45399
15d5776f2703
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45244
diff
changeset
|
2186 { |
|
15d5776f2703
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45244
diff
changeset
|
2187 Py_FatalError("Could not reset the stack!"); |
|
15d5776f2703
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45244
diff
changeset
|
2188 } |
|
14227
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2189 } |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2190 return 1; |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2191 } |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2192 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2193 #endif /* WIN32 && _MSC_VER */ |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2194 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2195 /* 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
|
2196 |
|
9f9f3280dc68
implements PyOS_CheckStack for Windows and MSVC. this fixes a
Fredrik Lundh <fredrik@pythonware.com>
parents:
14195
diff
changeset
|
2197 #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
|
2198 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2199 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2200 /* 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
|
2201 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2202 PyOS_sighandler_t |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2203 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
|
2204 { |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2205 #ifdef HAVE_SIGACTION |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2206 struct sigaction context; |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2207 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
|
2208 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
|
2209 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
|
2210 #else |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2211 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
|
2212 /* 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
|
2213 #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
|
2214 switch (sig) { |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2215 /* 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
|
2216 case SIGINT: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2217 case SIGILL: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2218 case SIGFPE: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2219 case SIGSEGV: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2220 case SIGTERM: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2221 case SIGBREAK: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2222 case SIGABRT: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2223 break; |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2224 /* 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
|
2225 default: |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2226 return SIG_ERR; |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2227 } |
|
72555a967d6a
Patch #1350409: Port signal handling to VS 2005.
Martin v. Löwis <martin@v.loewis.de>
parents:
35742
diff
changeset
|
2228 #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
|
2229 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
|
2230 if (handler != SIG_ERR) |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2231 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
|
2232 return handler; |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2233 #endif |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2234 } |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2235 |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2236 PyOS_sighandler_t |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2237 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
|
2238 { |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2239 #ifdef HAVE_SIGACTION |
|
33747
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2240 struct sigaction context, ocontext; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2241 context.sa_handler = handler; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2242 sigemptyset(&context.sa_mask); |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2243 context.sa_flags = 0; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2244 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
|
2245 return SIG_ERR; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2246 return ocontext.sa_handler; |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2247 #else |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2248 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
|
2249 oldhandler = signal(sig, handler); |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2250 #ifdef HAVE_SIGINTERRUPT |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2251 siginterrupt(sig, 1); |
|
b0ec4c9d595b
Patch #975056 - fixes for restartable signals on *BSD. In addition,
Anthony Baxter <anthonybaxter@gmail.com>
parents:
33715
diff
changeset
|
2252 #endif |
|
14637
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2253 return oldhandler; |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2254 #endif |
|
37397bd1f8a8
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
Guido van Rossum <guido@python.org>
parents:
14375
diff
changeset
|
2255 } |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2256 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2257 /* 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
|
2258 |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2259 #undef PyParser_SimpleParseFile |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2260 PyAPI_FUNC(node *) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2261 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
|
2262 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2263 return PyParser_SimpleParseFileFlags(fp, filename, start, 0); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2264 } |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2265 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2266 #undef PyParser_SimpleParseString |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2267 PyAPI_FUNC(node *) |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2268 PyParser_SimpleParseString(const char *str, int start) |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2269 { |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2270 return PyParser_SimpleParseStringFlags(str, start, 0); |
|
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35666
diff
changeset
|
2271 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2272 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2273 #undef PyRun_AnyFile |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2274 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2275 PyRun_AnyFile(FILE *fp, const char *name) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2276 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2277 return PyRun_AnyFileExFlags(fp, name, 0, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2278 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2279 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2280 #undef PyRun_AnyFileEx |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2281 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2282 PyRun_AnyFileEx(FILE *fp, const char *name, int closeit) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2283 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2284 return PyRun_AnyFileExFlags(fp, name, closeit, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2285 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2286 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2287 #undef PyRun_AnyFileFlags |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2288 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2289 PyRun_AnyFileFlags(FILE *fp, const char *name, PyCompilerFlags *flags) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2290 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2291 return PyRun_AnyFileExFlags(fp, name, 0, flags); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2292 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2293 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2294 #undef PyRun_File |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2295 PyAPI_FUNC(PyObject *) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2296 PyRun_File(FILE *fp, const char *p, int s, PyObject *g, PyObject *l) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2297 { |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
2298 return PyRun_FileExFlags(fp, p, s, g, l, 0, NULL); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2299 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2300 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2301 #undef PyRun_FileEx |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2302 PyAPI_FUNC(PyObject *) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2303 PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, int c) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2304 { |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
2305 return PyRun_FileExFlags(fp, p, s, g, l, c, NULL); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2306 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2307 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2308 #undef PyRun_FileFlags |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2309 PyAPI_FUNC(PyObject *) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2310 PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2311 PyCompilerFlags *flags) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2312 { |
|
48494
aca5b2e6a66f
Merged revisions 64623,64640,64665,64687,64689-64690,64719,64721,64735,64742,64744-64746,64756-64761,64767-64769,64771-64772,64774-64775,64788,64793,64835-64836 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48477
diff
changeset
|
2313 return PyRun_FileExFlags(fp, p, s, g, l, 0, flags); |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2314 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2315 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2316 #undef PyRun_SimpleFile |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2317 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2318 PyRun_SimpleFile(FILE *f, const char *p) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2319 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2320 return PyRun_SimpleFileExFlags(f, p, 0, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2321 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2322 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2323 #undef PyRun_SimpleFileEx |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2324 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2325 PyRun_SimpleFileEx(FILE *f, const char *p, int c) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2326 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2327 return PyRun_SimpleFileExFlags(f, p, c, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2328 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2329 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2330 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2331 #undef PyRun_String |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2332 PyAPI_FUNC(PyObject *) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2333 PyRun_String(const char *str, int s, PyObject *g, PyObject *l) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2334 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2335 return PyRun_StringFlags(str, s, g, l, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2336 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2337 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2338 #undef PyRun_SimpleString |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2339 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2340 PyRun_SimpleString(const char *s) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2341 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2342 return PyRun_SimpleStringFlags(s, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2343 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2344 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2345 #undef Py_CompileString |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2346 PyAPI_FUNC(PyObject *) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2347 Py_CompileString(const char *str, const char *p, int s) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2348 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2349 return Py_CompileStringFlags(str, p, s, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2350 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2351 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2352 #undef PyRun_InteractiveOne |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2353 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2354 PyRun_InteractiveOne(FILE *f, const char *p) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2355 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2356 return PyRun_InteractiveOneFlags(f, p, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2357 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2358 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2359 #undef PyRun_InteractiveLoop |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2360 PyAPI_FUNC(int) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2361 PyRun_InteractiveLoop(FILE *f, const char *p) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2362 { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2363 return PyRun_InteractiveLoopFlags(f, p, NULL); |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2364 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2365 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2366 #ifdef __cplusplus |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2367 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37056
diff
changeset
|
2368 #endif |
