Skip to content

bpo-42639: Cleanup atexitmodule.c #23770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Include/cpython/pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ PyAPI_FUNC(int) Py_RunMain(void);

PyAPI_FUNC(void) _Py_NO_RETURN Py_ExitStatusException(PyStatus err);

/* Py_PyAtExit is for the atexit module, Py_AtExit is for low-level
* exit functions.
*/
PyAPI_FUNC(void) _Py_PyAtExit(void (*func)(PyObject *), PyObject *);

/* Restore signals that the interpreter has called SIG_IGN on to SIG_DFL. */
PyAPI_FUNC(void) _Py_RestoreSignals(void);

Expand Down
4 changes: 2 additions & 2 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ struct _is {
PyObject *after_forkers_child;
#endif
/* AtExit module */
void (*pyexitfunc)(PyObject *);
PyObject *pyexitmodule;
void (*atexit_func)(PyObject *);
PyObject *atexit_module;

uint64_t tstate_next_unique_id;

Expand Down
23 changes: 12 additions & 11 deletions Lib/test/test_atexit.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sys
import unittest
import io
import atexit
import io
import os
import sys
import textwrap
import unittest
from test import support
from test.support import script_helper

Expand Down Expand Up @@ -156,15 +157,15 @@ def test_bound_methods(self):

def test_shutdown(self):
# Actually test the shutdown mechanism in a subprocess
code = """if 1:
code = textwrap.dedent("""
import atexit

def f(msg):
print(msg)

atexit.register(f, "one")
atexit.register(f, "two")
"""
""")
res = script_helper.assert_python_ok("-c", code)
self.assertEqual(res.out.decode().splitlines(), ["two", "one"])
self.assertFalse(res.err)
Expand All @@ -178,13 +179,13 @@ def test_callbacks_leak(self):
# take care to free callbacks in its per-subinterpreter module
# state.
n = atexit._ncallbacks()
code = r"""if 1:
code = textwrap.dedent(r"""
import atexit
def f():
pass
atexit.register(f)
del atexit
"""
""")
ret = support.run_in_subinterp(code)
self.assertEqual(ret, 0)
self.assertEqual(atexit._ncallbacks(), n)
Expand All @@ -193,13 +194,13 @@ def test_callbacks_leak_refcycle(self):
# Similar to the above, but with a refcycle through the atexit
# module.
n = atexit._ncallbacks()
code = r"""if 1:
code = textwrap.dedent(r"""
import atexit
def f():
pass
atexit.register(f)
atexit.__atexit = atexit
"""
""")
ret = support.run_in_subinterp(code)
self.assertEqual(ret, 0)
self.assertEqual(atexit._ncallbacks(), n)
Expand All @@ -210,13 +211,13 @@ def test_callback_on_subinterpreter_teardown(self):
expected = b"The test has passed!"
r, w = os.pipe()

code = r"""if 1:
code = textwrap.dedent(r"""
import os
import atexit
def callback():
os.write({:d}, b"The test has passed!")
atexit.register(callback)
""".format(w)
""".format(w))
ret = support.run_in_subinterp(code)
os.close(w)
self.assertEqual(os.read(r, len(expected)), expected)
Expand Down
Loading