From 6a2496820c6346aa5e4e15d453f65db1a4c2cbfd Mon Sep 17 00:00:00 2001 From: Bill Fisher Date: Thu, 9 Dec 2021 05:10:54 +0000 Subject: [PATCH 1/2] Empty env dict represents empty environment. --- tests/test_process.py | 16 ++++++++++++++++ uvloop/handles/process.pyx | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/test_process.py b/tests/test_process.py index 357d6f0a..26e75eab 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -49,6 +49,22 @@ async def test(): self.loop.run_until_complete(test()) + def test_process_env_2(self): + async def test(): + cmd = 'env' + env = {} # empty environment + proc = await asyncio.create_subprocess_exec( + cmd, + env=env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + out, _ = await proc.communicate() + self.assertEqual(out, b'') + self.assertEqual(proc.returncode, 0) + + self.loop.run_until_complete(test()) + def test_process_cwd_1(self): async def test(): cmd = 'pwd' diff --git a/uvloop/handles/process.pyx b/uvloop/handles/process.pyx index 261aa1f5..286e28cc 100644 --- a/uvloop/handles/process.pyx +++ b/uvloop/handles/process.pyx @@ -288,7 +288,7 @@ cdef class UVProcess(UVHandle): self.uv_opt_args = self.__to_cstring_array(self.__args) cdef _init_env(self, dict env): - if env is not None and len(env): + if env is not None: self.__env = list() for key in env: val = env[key] From ca8669758c0ab1c7dff78a687946bbb58185d277 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Wed, 31 Aug 2022 14:46:15 -0700 Subject: [PATCH 2/2] Allow 0-length cstring array --- uvloop/handles/process.pyx | 3 --- 1 file changed, 3 deletions(-) diff --git a/uvloop/handles/process.pyx b/uvloop/handles/process.pyx index e8549244..1ffbd8ca 100644 --- a/uvloop/handles/process.pyx +++ b/uvloop/handles/process.pyx @@ -217,9 +217,6 @@ cdef class UVProcess(UVHandle): char **ret - if UVLOOP_DEBUG: - assert arr_len > 0 - ret = PyMem_RawMalloc((arr_len + 1) * sizeof(char *)) if ret is NULL: raise MemoryError()