Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 5939:2c65bb6ab87c legacy-trunk
Merge Py_Cleanup() into Py_Finalize(). Call the various small Fini()
functions.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 05 Aug 1997 02:22:03 +0000 |
| parents | 8d2194e22e67 |
| children | 98a282cfb013 |
comparison
equal
deleted
inserted
replaced
| 5938:222faeb43d02 | 5939:2c65bb6ab87c |
|---|---|
| 67 static PyObject *run_pyc_file Py_PROTO((FILE *fp, char *filename, | 67 static PyObject *run_pyc_file Py_PROTO((FILE *fp, char *filename, |
| 68 PyObject *globals, PyObject *locals)); | 68 PyObject *globals, PyObject *locals)); |
| 69 static void err_input Py_PROTO((perrdetail *)); | 69 static void err_input Py_PROTO((perrdetail *)); |
| 70 static void initsigs Py_PROTO((void)); | 70 static void initsigs Py_PROTO((void)); |
| 71 static void finisigs Py_PROTO((void)); | 71 static void finisigs Py_PROTO((void)); |
| 72 static void call_sys_exitfunc Py_PROTO((void)); | |
| 73 static void call_ll_exitfuncs Py_PROTO((void)); | |
| 72 | 74 |
| 73 int Py_DebugFlag; /* Needed by parser.c */ | 75 int Py_DebugFlag; /* Needed by parser.c */ |
| 74 int Py_VerboseFlag; /* Needed by import.c */ | 76 int Py_VerboseFlag; /* Needed by import.c */ |
| 75 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ | 77 int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ |
| 76 | 78 |
| 160 Py_Finalize() | 162 Py_Finalize() |
| 161 { | 163 { |
| 162 PyInterpreterState *interp; | 164 PyInterpreterState *interp; |
| 163 PyThreadState *tstate; | 165 PyThreadState *tstate; |
| 164 | 166 |
| 167 call_sys_exitfunc(); | |
| 168 | |
| 165 if (!initialized) | 169 if (!initialized) |
| 166 Py_FatalError("Py_Finalize: not initialized"); | 170 Py_FatalError("Py_Finalize: not initialized"); |
| 167 initialized = 0; | 171 initialized = 0; |
| 168 | 172 |
| 169 tstate = PyThreadState_Get(); | 173 tstate = PyThreadState_Get(); |
| 175 PyInterpreterState_Delete(interp); | 179 PyInterpreterState_Delete(interp); |
| 176 | 180 |
| 177 finisigs(); | 181 finisigs(); |
| 178 _PyImport_Fini(); | 182 _PyImport_Fini(); |
| 179 _PyBuiltin_Fini(); | 183 _PyBuiltin_Fini(); |
| 184 PyMethod_Fini(); | |
| 185 PyFrame_Fini(); | |
| 186 PyCFunction_Fini(); | |
| 187 PyTuple_Fini(); | |
| 180 PyString_Fini(); | 188 PyString_Fini(); |
| 189 PyInt_Fini(); | |
| 190 PyFloat_Fini(); | |
| 191 | |
| 192 /* XXX Still allocated: | |
| 193 - various static ad-hoc pointers to interned strings | |
| 194 - int and float free list blocks | |
| 195 - whatever various modules and libraries allocate | |
| 196 */ | |
| 181 | 197 |
| 182 PyGrammar_RemoveAccelerators(&_PyParser_Grammar); | 198 PyGrammar_RemoveAccelerators(&_PyParser_Grammar); |
| 199 | |
| 200 call_ll_exitfuncs(); | |
| 201 | |
| 202 #ifdef COUNT_ALLOCS | |
| 203 dump_counts(); | |
| 204 #endif | |
| 205 | |
| 206 #ifdef Py_REF_DEBUG | |
| 207 fprintf(stderr, "[%ld refs]\n", _Py_RefTotal); | |
| 208 #endif | |
| 209 | |
| 210 #ifdef Py_TRACE_REFS | |
| 211 if (_Py_AskYesNo("Print left references?")) { | |
| 212 _Py_PrintReferences(stderr); | |
| 213 } | |
| 214 _Py_ResetReferences(); | |
| 215 #endif /* Py_TRACE_REFS */ | |
| 183 } | 216 } |
| 184 | 217 |
| 185 /* Create and initialize a new interpreter and thread, and return the | 218 /* Create and initialize a new interpreter and thread, and return the |
| 186 new thread. This requires that Py_Initialize() has been called | 219 new thread. This requires that Py_Initialize() has been called |
| 187 first. | 220 first. |
| 294 char * | 327 char * |
| 295 Py_GetProgramName() | 328 Py_GetProgramName() |
| 296 { | 329 { |
| 297 return progname; | 330 return progname; |
| 298 } | 331 } |
| 299 | |
| 300 /* | |
| 301 Py_Initialize() | |
| 302 -- do everything, no-op on second call, call fatal on failure, set path | |
| 303 | |
| 304 #2 | |
| 305 -- create new interp+tstate & make it current, return NULL on failure, | |
| 306 make it current, do all setup, set path | |
| 307 | |
| 308 #3 | |
| 309 -- #2 without set path | |
| 310 | |
| 311 #4 | |
| 312 -- is there any point to #3 for caller-provided current interp+tstate? | |
| 313 | |
| 314 */ | |
| 315 | 332 |
| 316 /* Create __main__ module */ | 333 /* Create __main__ module */ |
| 317 | 334 |
| 318 static void | 335 static void |
| 319 initmain() | 336 initmain() |
| 829 return -1; | 846 return -1; |
| 830 exitfuncs[nexitfuncs++] = func; | 847 exitfuncs[nexitfuncs++] = func; |
| 831 return 0; | 848 return 0; |
| 832 } | 849 } |
| 833 | 850 |
| 834 void | 851 static void |
| 835 Py_Cleanup() | 852 call_sys_exitfunc() |
| 836 { | 853 { |
| 837 PyObject *exitfunc = PySys_GetObject("exitfunc"); | 854 PyObject *exitfunc = PySys_GetObject("exitfunc"); |
| 838 | 855 |
| 839 if (exitfunc) { | 856 if (exitfunc) { |
| 840 PyObject *res; | 857 PyObject *res; |
| 847 } | 864 } |
| 848 Py_DECREF(exitfunc); | 865 Py_DECREF(exitfunc); |
| 849 } | 866 } |
| 850 | 867 |
| 851 Py_FlushLine(); | 868 Py_FlushLine(); |
| 852 | 869 } |
| 853 Py_Finalize(); | 870 |
| 854 | 871 static void |
| 872 call_ll_exitfuncs() | |
| 873 { | |
| 855 while (nexitfuncs > 0) | 874 while (nexitfuncs > 0) |
| 856 (*exitfuncs[--nexitfuncs])(); | 875 (*exitfuncs[--nexitfuncs])(); |
| 857 | 876 |
| 858 fflush(stdout); | 877 fflush(stdout); |
| 859 fflush(stderr); | 878 fflush(stderr); |
| 865 | 884 |
| 866 void | 885 void |
| 867 Py_Exit(sts) | 886 Py_Exit(sts) |
| 868 int sts; | 887 int sts; |
| 869 { | 888 { |
| 870 Py_Cleanup(); | 889 Py_Finalize(); |
| 871 | |
| 872 #ifdef COUNT_ALLOCS | |
| 873 dump_counts(); | |
| 874 #endif | |
| 875 | |
| 876 #ifdef Py_REF_DEBUG | |
| 877 fprintf(stderr, "[%ld refs]\n", _Py_RefTotal); | |
| 878 #endif | |
| 879 | |
| 880 #ifdef Py_TRACE_REFS | |
| 881 if (_Py_AskYesNo("Print left references?")) { | |
| 882 _Py_PrintReferences(stderr); | |
| 883 } | |
| 884 #endif /* Py_TRACE_REFS */ | |
| 885 | 890 |
| 886 #ifdef macintosh | 891 #ifdef macintosh |
| 887 PyMac_Exit(sts); | 892 PyMac_Exit(sts); |
| 888 #else | 893 #else |
| 889 exit(sts); | 894 exit(sts); |
| 894 static RETSIGTYPE | 899 static RETSIGTYPE |
| 895 sighandler(sig) | 900 sighandler(sig) |
| 896 int sig; | 901 int sig; |
| 897 { | 902 { |
| 898 signal(sig, SIG_DFL); /* Don't catch recursive signals */ | 903 signal(sig, SIG_DFL); /* Don't catch recursive signals */ |
| 899 Py_Cleanup(); /* Do essential clean-up */ | 904 /* Do essential exit processing only */ |
| 905 call_sys_exitfunc(); | |
| 906 call_ll_exitfuncs(); | |
| 900 #ifdef HAVE_KILL | 907 #ifdef HAVE_KILL |
| 901 kill(getpid(), sig); /* Pretend the signal killed us */ | 908 kill(getpid(), sig); /* Pretend the signal killed us */ |
| 902 #else | 909 #else |
| 903 exit(1); | 910 exit(1); |
| 904 #endif | 911 #endif |
