Skip to content

Commit e04637e

Browse files
byllyfishfantix
andauthored
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 <[email protected]>
1 parent e7934c8 commit e04637e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

Diff for: tests/test_process.py

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ async def test():
5050

5151
self.loop.run_until_complete(test())
5252

53+
def test_process_env_2(self):
54+
async def test():
55+
cmd = 'env'
56+
env = {} # empty environment
57+
proc = await asyncio.create_subprocess_exec(
58+
cmd,
59+
env=env,
60+
stdout=subprocess.PIPE,
61+
stderr=subprocess.PIPE)
62+
63+
out, _ = await proc.communicate()
64+
self.assertEqual(out, b'')
65+
self.assertEqual(proc.returncode, 0)
66+
67+
self.loop.run_until_complete(test())
68+
5369
def test_process_cwd_1(self):
5470
async def test():
5571
cmd = 'pwd'

Diff for: uvloop/handles/process.pyx

+1-4
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ cdef class UVProcess(UVHandle):
217217

218218
char **ret
219219

220-
if UVLOOP_DEBUG:
221-
assert arr_len > 0
222-
223220
ret = <char **>PyMem_RawMalloc((arr_len + 1) * sizeof(char *))
224221
if ret is NULL:
225222
raise MemoryError()
@@ -285,7 +282,7 @@ cdef class UVProcess(UVHandle):
285282
self.uv_opt_args = self.__to_cstring_array(self.__args)
286283

287284
cdef _init_env(self, dict env):
288-
if env is not None and len(env):
285+
if env is not None:
289286
self.__env = list()
290287
for key in env:
291288
val = env[key]

0 commit comments

Comments
 (0)