Mercurial > cpython-lru_cache-weakref
annotate Modules/atexitmodule.c @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 7c48bb929e6e |
| children | 71b63a32b1e3 |
| rev | line source |
|---|---|
|
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:
diff
changeset
|
1 /* |
|
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:
diff
changeset
|
2 * atexit - allow programmer to define multiple exit functions to be executed |
|
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:
diff
changeset
|
3 * upon normal program termination. |
|
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:
diff
changeset
|
4 * |
|
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:
diff
changeset
|
5 * Translated from atexit.py by Collin Winter. |
|
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:
diff
changeset
|
6 + Copyright 2007 Python Software Foundation. |
|
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:
diff
changeset
|
7 */ |
|
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:
diff
changeset
|
8 |
|
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:
diff
changeset
|
9 #include "Python.h" |
|
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:
diff
changeset
|
10 |
|
41294
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
11 /* Forward declaration (for atexit_cleanup) */ |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
12 static PyObject *atexit_clear(PyObject*, PyObject*); |
|
49276
0de5a388a261
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Skip Montanaro <skip@pobox.com>
parents:
47580
diff
changeset
|
13 /* Forward declaration (for atexit_callfuncs) */ |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
14 static void atexit_cleanup(PyObject*); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
15 /* Forward declaration of module object */ |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
16 static struct PyModuleDef atexitmodule; |
|
41294
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
17 |
|
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:
diff
changeset
|
18 /* ===================================================================== */ |
|
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:
diff
changeset
|
19 /* Callback machinery. */ |
|
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:
diff
changeset
|
20 |
|
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:
diff
changeset
|
21 typedef struct { |
|
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:
diff
changeset
|
22 PyObject *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:
diff
changeset
|
23 PyObject *args; |
|
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:
diff
changeset
|
24 PyObject *kwargs; |
|
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:
diff
changeset
|
25 } atexit_callback; |
|
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:
diff
changeset
|
26 |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
27 typedef struct { |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
28 atexit_callback **atexit_callbacks; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
29 int ncallbacks; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
30 int callback_len; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
31 } atexitmodule_state; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
32 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
33 #define GET_ATEXIT_STATE(mod) ((atexitmodule_state*)PyModule_GetState(mod)) |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
34 |
|
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:
diff
changeset
|
35 |
|
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:
diff
changeset
|
36 /* Installed into pythonrun.c's atexit mechanism */ |
|
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:
diff
changeset
|
37 |
|
49276
0de5a388a261
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Skip Montanaro <skip@pobox.com>
parents:
47580
diff
changeset
|
38 static 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:
diff
changeset
|
39 atexit_callfuncs(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:
diff
changeset
|
40 { |
|
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:
diff
changeset
|
41 PyObject *exc_type = NULL, *exc_value, *exc_tb, *r; |
|
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:
diff
changeset
|
42 atexit_callback *cb; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
43 PyObject *module; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
44 atexitmodule_state *modstate; |
|
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:
diff
changeset
|
45 int i; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
46 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
47 module = PyState_FindModule(&atexitmodule); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
48 if (module == 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:
diff
changeset
|
49 return; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
50 modstate = GET_ATEXIT_STATE(module); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
51 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
52 if (modstate->ncallbacks == 0) |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
53 return; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
54 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
55 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
56 for (i = modstate->ncallbacks - 1; i >= 0; i--) |
|
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:
diff
changeset
|
57 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
58 cb = modstate->atexit_callbacks[i]; |
|
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:
diff
changeset
|
59 if (cb == 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:
diff
changeset
|
60 continue; |
|
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:
diff
changeset
|
61 |
|
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:
diff
changeset
|
62 r = PyObject_Call(cb->func, cb->args, cb->kwargs); |
|
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:
diff
changeset
|
63 Py_XDECREF(r); |
|
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:
diff
changeset
|
64 if (r == NULL) { |
| 41254 | 65 /* Maintain the last exception, but don't leak if there are |
| 66 multiple exceptions. */ | |
|
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:
diff
changeset
|
67 if (exc_type) { |
|
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:
diff
changeset
|
68 Py_DECREF(exc_type); |
| 41254 | 69 Py_XDECREF(exc_value); |
| 70 Py_XDECREF(exc_tb); | |
|
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:
diff
changeset
|
71 } |
|
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:
diff
changeset
|
72 PyErr_Fetch(&exc_type, &exc_value, &exc_tb); |
|
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:
diff
changeset
|
73 if (!PyErr_ExceptionMatches(PyExc_SystemExit)) { |
|
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:
diff
changeset
|
74 PySys_WriteStderr("Error in atexit._run_exitfuncs:\n"); |
|
67369
4a82be47a948
Issue #10756: atexit normalizes the exception before displaying it.
Victor Stinner <victor.stinner@haypocalc.com>
parents:
49610
diff
changeset
|
75 PyErr_NormalizeException(&exc_type, &exc_value, &exc_tb); |
|
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:
diff
changeset
|
76 PyErr_Display(exc_type, exc_value, exc_tb); |
|
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:
diff
changeset
|
77 } |
|
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:
diff
changeset
|
78 } |
|
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:
diff
changeset
|
79 } |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
80 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
81 atexit_cleanup(module); |
|
49276
0de5a388a261
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Skip Montanaro <skip@pobox.com>
parents:
47580
diff
changeset
|
82 |
|
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:
diff
changeset
|
83 if (exc_type) |
|
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:
diff
changeset
|
84 PyErr_Restore(exc_type, exc_value, exc_tb); |
|
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:
diff
changeset
|
85 } |
|
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:
diff
changeset
|
86 |
|
49276
0de5a388a261
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Skip Montanaro <skip@pobox.com>
parents:
47580
diff
changeset
|
87 static void |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
88 atexit_delete_cb(PyObject *self, int i) |
|
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:
diff
changeset
|
89 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
90 atexitmodule_state *modstate; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
91 atexit_callback *cb; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
92 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
93 modstate = GET_ATEXIT_STATE(self); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
94 cb = modstate->atexit_callbacks[i]; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
95 modstate->atexit_callbacks[i] = 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:
diff
changeset
|
96 Py_DECREF(cb->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:
diff
changeset
|
97 Py_DECREF(cb->args); |
|
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:
diff
changeset
|
98 Py_XDECREF(cb->kwargs); |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
99 PyMem_Free(cb); |
|
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:
diff
changeset
|
100 } |
|
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:
diff
changeset
|
101 |
|
49276
0de5a388a261
Fix for issue 3666 - atexit.register with bad inputs segfaults on exit.
Skip Montanaro <skip@pobox.com>
parents:
47580
diff
changeset
|
102 static void |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
103 atexit_cleanup(PyObject *self) |
|
41294
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
104 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
105 PyObject *r = atexit_clear(self, NULL); |
|
41294
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
106 Py_DECREF(r); |
|
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
107 } |
|
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
108 |
|
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:
diff
changeset
|
109 /* ===================================================================== */ |
|
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:
diff
changeset
|
110 /* Module methods. */ |
|
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:
diff
changeset
|
111 |
|
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:
diff
changeset
|
112 PyDoc_STRVAR(atexit_register__doc__, |
|
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:
diff
changeset
|
113 "register(func, *args, **kwargs) -> func\n\ |
|
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:
diff
changeset
|
114 \n\ |
|
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:
diff
changeset
|
115 Register a function to be executed upon normal program termination\n\ |
|
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:
diff
changeset
|
116 \n\ |
|
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:
diff
changeset
|
117 func - function to be called at exit\n\ |
|
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:
diff
changeset
|
118 args - optional arguments to pass to func\n\ |
|
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:
diff
changeset
|
119 kwargs - optional keyword arguments to pass to func\n\ |
|
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:
diff
changeset
|
120 \n\ |
|
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:
diff
changeset
|
121 func is returned to facilitate usage as a decorator."); |
|
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:
diff
changeset
|
122 |
|
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:
diff
changeset
|
123 static PyObject * |
|
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:
diff
changeset
|
124 atexit_register(PyObject *self, PyObject *args, PyObject *kwargs) |
|
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:
diff
changeset
|
125 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
126 atexitmodule_state *modstate; |
|
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:
diff
changeset
|
127 atexit_callback *new_callback; |
|
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:
diff
changeset
|
128 PyObject *func = NULL; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
129 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
130 modstate = GET_ATEXIT_STATE(self); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
131 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
132 if (modstate->ncallbacks >= modstate->callback_len) { |
|
41294
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
133 atexit_callback **r; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
134 modstate->callback_len += 16; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
135 r = (atexit_callback**)PyMem_Realloc(modstate->atexit_callbacks, |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
136 sizeof(atexit_callback*) * modstate->callback_len); |
|
41294
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
137 if (r == NULL) |
|
ef70cd4dba50
Address some XXXs from Neal Norwitz.
Collin Winter <collinw@gmail.com>
parents:
41254
diff
changeset
|
138 return PyErr_NoMemory(); |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
139 modstate->atexit_callbacks = r; |
|
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:
diff
changeset
|
140 } |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
141 |
|
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:
diff
changeset
|
142 if (PyTuple_GET_SIZE(args) == 0) { |
|
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:
diff
changeset
|
143 PyErr_SetString(PyExc_TypeError, |
|
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:
diff
changeset
|
144 "register() takes at least 1 argument (0 given)"); |
|
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:
diff
changeset
|
145 return 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:
diff
changeset
|
146 } |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
147 |
|
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:
diff
changeset
|
148 func = PyTuple_GET_ITEM(args, 0); |
|
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:
diff
changeset
|
149 if (!PyCallable_Check(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:
diff
changeset
|
150 PyErr_SetString(PyExc_TypeError, |
|
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:
diff
changeset
|
151 "the first argument must be callable"); |
|
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:
diff
changeset
|
152 return 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:
diff
changeset
|
153 } |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
154 |
|
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:
diff
changeset
|
155 new_callback = PyMem_Malloc(sizeof(atexit_callback)); |
|
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:
diff
changeset
|
156 if (new_callback == 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:
diff
changeset
|
157 return PyErr_NoMemory(); |
|
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:
diff
changeset
|
158 |
|
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:
diff
changeset
|
159 new_callback->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args)); |
|
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:
diff
changeset
|
160 if (new_callback->args == 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:
diff
changeset
|
161 PyMem_Free(new_callback); |
|
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:
diff
changeset
|
162 return 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:
diff
changeset
|
163 } |
|
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:
diff
changeset
|
164 new_callback->func = 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:
diff
changeset
|
165 new_callback->kwargs = kwargs; |
|
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:
diff
changeset
|
166 Py_INCREF(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:
diff
changeset
|
167 Py_XINCREF(kwargs); |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
168 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
169 modstate->atexit_callbacks[modstate->ncallbacks++] = new_callback; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
170 |
|
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:
diff
changeset
|
171 Py_INCREF(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:
diff
changeset
|
172 return 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:
diff
changeset
|
173 } |
|
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:
diff
changeset
|
174 |
| 42464 | 175 PyDoc_STRVAR(atexit_run_exitfuncs__doc__, |
| 176 "_run_exitfuncs() -> None\n\ | |
| 177 \n\ | |
| 178 Run all registered exit functions."); | |
| 179 | |
|
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:
diff
changeset
|
180 static PyObject * |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
181 atexit_run_exitfuncs(PyObject *self, PyObject *unused) |
|
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:
diff
changeset
|
182 { |
|
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:
diff
changeset
|
183 atexit_callfuncs(); |
|
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:
diff
changeset
|
184 if (PyErr_Occurred()) |
|
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:
diff
changeset
|
185 return 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:
diff
changeset
|
186 Py_RETURN_NONE; |
|
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:
diff
changeset
|
187 } |
|
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:
diff
changeset
|
188 |
| 42464 | 189 PyDoc_STRVAR(atexit_clear__doc__, |
| 190 "_clear() -> None\n\ | |
| 191 \n\ | |
| 192 Clear the list of previously registered exit functions."); | |
| 193 | |
|
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:
diff
changeset
|
194 static PyObject * |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
195 atexit_clear(PyObject *self, PyObject *unused) |
|
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:
diff
changeset
|
196 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
197 atexitmodule_state *modstate; |
|
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:
diff
changeset
|
198 atexit_callback *cb; |
|
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:
diff
changeset
|
199 int i; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
200 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
201 modstate = GET_ATEXIT_STATE(self); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
202 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
203 for (i = 0; i < modstate->ncallbacks; i++) { |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
204 cb = modstate->atexit_callbacks[i]; |
|
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:
diff
changeset
|
205 if (cb == 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:
diff
changeset
|
206 continue; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
207 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
208 atexit_delete_cb(self, i); |
|
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:
diff
changeset
|
209 } |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
210 modstate->ncallbacks = 0; |
|
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:
diff
changeset
|
211 Py_RETURN_NONE; |
|
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:
diff
changeset
|
212 } |
|
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:
diff
changeset
|
213 |
|
75968
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
214 static void |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
215 atexit_free(PyObject *m) |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
216 { |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
217 atexitmodule_state *modstate; |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
218 modstate = GET_ATEXIT_STATE(m); |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
219 PyMem_Free(modstate->atexit_callbacks); |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
220 } |
|
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
221 |
| 42464 | 222 PyDoc_STRVAR(atexit_unregister__doc__, |
| 223 "unregister(func) -> None\n\ | |
| 224 \n\ | |
| 225 Unregister a exit function which was previously registered using\n\ | |
| 226 atexit.register\n\ | |
| 227 \n\ | |
| 228 func - function to be unregistered"); | |
| 229 | |
|
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:
diff
changeset
|
230 static PyObject * |
|
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:
diff
changeset
|
231 atexit_unregister(PyObject *self, PyObject *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:
diff
changeset
|
232 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
233 atexitmodule_state *modstate; |
|
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:
diff
changeset
|
234 atexit_callback *cb; |
|
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:
diff
changeset
|
235 int i, eq; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
236 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
237 modstate = GET_ATEXIT_STATE(self); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
238 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
239 for (i = 0; i < modstate->ncallbacks; i++) |
|
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:
diff
changeset
|
240 { |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
241 cb = modstate->atexit_callbacks[i]; |
|
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:
diff
changeset
|
242 if (cb == 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:
diff
changeset
|
243 continue; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
244 |
|
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:
diff
changeset
|
245 eq = PyObject_RichCompareBool(cb->func, func, Py_EQ); |
|
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:
diff
changeset
|
246 if (eq < 0) |
|
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:
diff
changeset
|
247 return 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:
diff
changeset
|
248 if (eq) |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
249 atexit_delete_cb(self, i); |
|
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:
diff
changeset
|
250 } |
|
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:
diff
changeset
|
251 Py_RETURN_NONE; |
|
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:
diff
changeset
|
252 } |
|
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:
diff
changeset
|
253 |
|
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:
diff
changeset
|
254 static PyMethodDef atexit_methods[] = { |
|
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:
diff
changeset
|
255 {"register", (PyCFunction) atexit_register, METH_VARARGS|METH_KEYWORDS, |
|
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:
diff
changeset
|
256 atexit_register__doc__}, |
|
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:
diff
changeset
|
257 {"_clear", (PyCFunction) atexit_clear, METH_NOARGS, |
| 42464 | 258 atexit_clear__doc__}, |
|
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:
diff
changeset
|
259 {"unregister", (PyCFunction) atexit_unregister, METH_O, |
| 42464 | 260 atexit_unregister__doc__}, |
|
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:
diff
changeset
|
261 {"_run_exitfuncs", (PyCFunction) atexit_run_exitfuncs, METH_NOARGS, |
| 42464 | 262 atexit_run_exitfuncs__doc__}, |
|
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:
diff
changeset
|
263 {NULL, NULL} /* sentinel */ |
|
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:
diff
changeset
|
264 }; |
|
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:
diff
changeset
|
265 |
|
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:
diff
changeset
|
266 /* ===================================================================== */ |
|
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:
diff
changeset
|
267 /* Initialization function. */ |
|
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:
diff
changeset
|
268 |
|
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:
diff
changeset
|
269 PyDoc_STRVAR(atexit__doc__, |
| 42464 | 270 "allow programmer to define multiple exit functions to be executed\ |
|
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:
diff
changeset
|
271 upon normal program termination.\n\ |
|
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:
diff
changeset
|
272 \n\ |
| 42464 | 273 Two public functions, register and unregister, are defined.\n\ |
|
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:
diff
changeset
|
274 "); |
|
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:
diff
changeset
|
275 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
276 |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
277 static struct PyModuleDef atexitmodule = { |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
278 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
279 "atexit", |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
280 atexit__doc__, |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
281 sizeof(atexitmodule_state), |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
282 atexit_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
283 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
284 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
285 NULL, |
|
75968
7c48bb929e6e
Issue #11826: Fix memory leak in atexitmodule.
Stefan Krah <skrah@bytereef.org>
parents:
67369
diff
changeset
|
286 (freefunc)atexit_free |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
287 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
288 |
|
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:
diff
changeset
|
289 PyMODINIT_FUNC |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
290 PyInit_atexit(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:
diff
changeset
|
291 { |
|
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:
diff
changeset
|
292 PyObject *m; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
293 atexitmodule_state *modstate; |
|
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:
diff
changeset
|
294 |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
295 m = PyModule_Create(&atexitmodule); |
|
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:
diff
changeset
|
296 if (m == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
297 return NULL; |
|
49610
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
298 |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
299 modstate = GET_ATEXIT_STATE(m); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
300 modstate->callback_len = 32; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
301 modstate->ncallbacks = 0; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
302 modstate->atexit_callbacks = PyMem_New(atexit_callback*, |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
303 modstate->callback_len); |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
304 if (modstate->atexit_callbacks == NULL) |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
305 return NULL; |
|
d2ec6d5b2db9
Issue #4200: Changed the atexit module to store its state in its PyModuleDef atexitmodule. This fixes a bug with multiple subinterpeters. The bug was found by Graham Dumpletom during his work on a 3.0 port of mod_wsgi. The patch has been reviewed by Benjamin.
Christian Heimes <christian@cheimes.de>
parents:
49276
diff
changeset
|
306 |
|
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:
diff
changeset
|
307 _Py_PyAtExit(atexit_callfuncs); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
42464
diff
changeset
|
308 return m; |
|
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:
diff
changeset
|
309 } |
