bpo-36814: ensure os.posix_spawn() handles None (GH-13144)
authorAnthony Shaw <anthony.p.shaw@gmail.com>
Fri, 10 May 2019 02:00:06 +0000 (12:00 +1000)
committerVictor Stinner <vstinner@redhat.com>
Fri, 10 May 2019 02:00:06 +0000 (04:00 +0200)
Fix an issue where os.posix_spawn() would incorrectly raise a TypeError
when file_actions is None.

Lib/test/test_posix.py
Misc/NEWS.d/next/Library/2019-05-06-23-13-26.bpo-36814.dSeMz_.rst [new file with mode: 0644]
Modules/posixmodule.c

index 843402930ffc0fc6488a513b96ccb4f9db5aaa6b..5c93d0d507d25274816356c5b19686265e061e46 100644 (file)
@@ -1550,6 +1550,15 @@ class _PosixSpawnMixin:
         with open(envfile) as f:
             self.assertEqual(f.read(), 'bar')
 
+    def test_none_file_actions(self):
+        pid = self.spawn_func(
+            self.NOOP_PROGRAM[0],
+            self.NOOP_PROGRAM,
+            os.environ,
+            file_actions=None
+        )
+        self.assertEqual(os.waitpid(pid, 0), (pid, 0))
+
     def test_empty_file_actions(self):
         pid = self.spawn_func(
             self.NOOP_PROGRAM[0],
diff --git a/Misc/NEWS.d/next/Library/2019-05-06-23-13-26.bpo-36814.dSeMz_.rst b/Misc/NEWS.d/next/Library/2019-05-06-23-13-26.bpo-36814.dSeMz_.rst
new file mode 100644 (file)
index 0000000..3f40011
--- /dev/null
@@ -0,0 +1 @@
+Fix an issue where os.posix_spawnp() would incorrectly raise a TypeError when file_actions is None.
\ No newline at end of file
index 221f7101b21356f02a60745fc244affd17e7367d..aa77094da06a9391fae68b18fcf1d3b6c5285a6d 100644 (file)
@@ -5465,7 +5465,7 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
         goto exit;
     }
 
-    if (file_actions != NULL) {
+    if (file_actions != NULL && file_actions != Py_None) {
         /* There is a bug in old versions of glibc that makes some of the
          * helper functions for manipulating file actions not copy the provided
          * buffers. The problem is that posix_spawn_file_actions_addopen does not