Skip to content

Commit 948ed8c

Browse files
tonybaloneyvstinner
authored andcommitted
bpo-36814: ensure os.posix_spawn() handles None (GH-13144)
Fix an issue where os.posix_spawn() would incorrectly raise a TypeError when file_actions is None.
1 parent fce5ff1 commit 948ed8c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/test/test_posix.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,15 @@ def test_specify_environment(self):
15501550
with open(envfile) as f:
15511551
self.assertEqual(f.read(), 'bar')
15521552

1553+
def test_none_file_actions(self):
1554+
pid = self.spawn_func(
1555+
self.NOOP_PROGRAM[0],
1556+
self.NOOP_PROGRAM,
1557+
os.environ,
1558+
file_actions=None
1559+
)
1560+
self.assertEqual(os.waitpid(pid, 0), (pid, 0))
1561+
15531562
def test_empty_file_actions(self):
15541563
pid = self.spawn_func(
15551564
self.NOOP_PROGRAM[0],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix an issue where os.posix_spawnp() would incorrectly raise a TypeError when file_actions is None.

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5465,7 +5465,7 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
54655465
goto exit;
54665466
}
54675467

5468-
if (file_actions != NULL) {
5468+
if (file_actions != NULL && file_actions != Py_None) {
54695469
/* There is a bug in old versions of glibc that makes some of the
54705470
* helper functions for manipulating file actions not copy the provided
54715471
* buffers. The problem is that posix_spawn_file_actions_addopen does not

0 commit comments

Comments
 (0)