create_subprocess_exec should treat env={} as empty environment (#439) (#454)

* Empty env dict represents empty environment.
* Allow 0-length cstring array

Co-authored-by: Fantix King <fantix.king@gmail.com>
This commit is contained in:
Bill Fisher 2022-08-31 15:05:24 -07:00 committed by GitHub
parent e7934c8820
commit e04637e088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -50,6 +50,22 @@ class _TestProcess:
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'

View File

@ -217,9 +217,6 @@ cdef class UVProcess(UVHandle):
char **ret
if UVLOOP_DEBUG:
assert arr_len > 0
ret = <char **>PyMem_RawMalloc((arr_len + 1) * sizeof(char *))
if ret is NULL:
raise MemoryError()
@ -285,7 +282,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]