зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1585702 - [mozprocess] Fix "Embedded null character" error in Windows with Python 3, r=gbrown
This works around a bug in Python: https://bugs.python.org/issue32745 Null characters aren't allowed in 'c_wchar_p' types anymore, but we can get around the issue by allocating a buffer in memory and casting it after the fact. This was discovered via trial and error and I'm not really sure why it works.. But it does. This also enables the tests under Python 3 on Windows (which thankfully all seem to pass). Differential Revision: https://phabricator.services.mozilla.com/D48113 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d2dbcf8eba
Коммит
cb2eb80652
|
@ -721,9 +721,7 @@ falling back to not using job objects for managing child processes""", file=sys.
|
|||
self.keywordargs = kwargs
|
||||
self.read_buffer = ''
|
||||
|
||||
# XXX Bug 1585702 - Setting env is broken on Windows + Python 3. In the
|
||||
# meantime let's at least make sure we don't set it in the default case.
|
||||
if env is None and not (six.PY3 and isWin):
|
||||
if env is None:
|
||||
env = os.environ.copy()
|
||||
self.env = env
|
||||
|
||||
|
|
|
@ -38,7 +38,18 @@ from __future__ import absolute_import, unicode_literals, print_function
|
|||
|
||||
import subprocess
|
||||
import sys
|
||||
from ctypes import c_void_p, POINTER, sizeof, Structure, windll, WinError, WINFUNCTYPE, c_ulong
|
||||
from ctypes import (
|
||||
cast,
|
||||
create_unicode_buffer,
|
||||
c_ulong,
|
||||
c_void_p,
|
||||
POINTER,
|
||||
sizeof,
|
||||
Structure,
|
||||
windll,
|
||||
WinError,
|
||||
WINFUNCTYPE,
|
||||
)
|
||||
from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPCWSTR, LPWSTR, UINT, WORD
|
||||
|
||||
from .qijo import QueryInformationJobObject
|
||||
|
@ -163,8 +174,13 @@ class EnvironmentBlock:
|
|||
if isinstance(v, bytes):
|
||||
v = v.decode(fs_encoding, 'replace')
|
||||
values.append("{}={}".format(k, v))
|
||||
values.append("")
|
||||
self._as_parameter_ = LPCWSTR("\0".join(values))
|
||||
|
||||
# The lpEnvironment parameter of the 'CreateProcess' function expects a series
|
||||
# of null terminated strings followed by a final null terminator. We write this
|
||||
# value to a buffer and then cast it to LPCWSTR to avoid a Python ctypes bug
|
||||
# that probihits embedded null characters (https://bugs.python.org/issue32745).
|
||||
values = create_unicode_buffer("\0".join(values) + "\0")
|
||||
self._as_parameter_ = cast(values, LPCWSTR)
|
||||
|
||||
|
||||
# Error Messages we need to watch for go here
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
[DEFAULT]
|
||||
subsuite = mozbase
|
||||
# Python bug https://bugs.python.org/issue32745
|
||||
skip-if = python == 3 && os == "win" # Bug 1428713 for more info
|
||||
[test_detached.py]
|
||||
skip-if = os == "win" # Bug 1493796
|
||||
[test_kill.py]
|
||||
|
|
Загрузка…
Ссылка в новой задаче