forked from OSchip/llvm-project
Fix some issues with swig & string conversion.
This patch fixes two issues: 1) Popen needs to be used with universal_newlines=True by default. This elicits automatic decoding from bytes -> string in Py3, and has no negative effects in other Py versions. 2) The swig typemaps for converting between string and (char*, int) did not work correctly when the length of the string was 0, indicating an error. In this case we would try to construct a string from uninitialized data. 3) Ironically, the bug mentioned in #2 led to a test passing on Windows that was actually broken, because the test was written such that the assertion was never even getting checked, so it passed by default. So we additionally fix this test to also fail if the method errors. By fixing this test it's now broken on Windows, so we also xfail it. llvm-svn: 253487
This commit is contained in:
parent
f08e184815
commit
48ef8d4c37
|
@ -192,10 +192,16 @@ class ProcessLaunchTestCase(TestBase):
|
||||||
process = target.LaunchSimple(None, ['EVIL=' + evil_var], self.get_process_working_directory())
|
process = target.LaunchSimple(None, ['EVIL=' + evil_var], self.get_process_working_directory())
|
||||||
self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
|
self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)
|
||||||
|
|
||||||
out = process.GetSTDOUT(len(evil_var))[:len(evil_var)]
|
out = process.GetSTDOUT(len(evil_var))
|
||||||
|
self.assertIsNotNone(out, "Encountered an error reading the process's output")
|
||||||
|
|
||||||
|
out = out[:len(evil_var)]
|
||||||
if out != evil_var:
|
if out != evil_var:
|
||||||
self.fail('The environment variable was mis-coded: %s\n' % repr(out))
|
self.fail('The environment variable was mis-coded: %s\n' % repr(out))
|
||||||
|
|
||||||
newline = process.GetSTDOUT(1)[0]
|
newline = process.GetSTDOUT(1)
|
||||||
|
self.assertIsNotNone(newline, "Encountered an error reading the process's output")
|
||||||
|
|
||||||
|
newline = newline[0]
|
||||||
if newline != '\r' and newline != '\n':
|
if newline != '\r' and newline != '\n':
|
||||||
self.fail('Garbage at end of environment variable')
|
self.fail('Garbage at end of environment variable')
|
||||||
|
|
|
@ -32,6 +32,7 @@ class CppVirtualMadness(TestBase):
|
||||||
self.line = line_number(self.source, '// Set first breakpoint here.')
|
self.line = line_number(self.source, '// Set first breakpoint here.')
|
||||||
|
|
||||||
@expectedFailureIcc('llvm.org/pr16808') # lldb does not call the correct virtual function with icc
|
@expectedFailureIcc('llvm.org/pr16808') # lldb does not call the correct virtual function with icc
|
||||||
|
@expectedFailureAll(oslist=['windows'])
|
||||||
def test_virtual_madness(self):
|
def test_virtual_madness(self):
|
||||||
"""Test that expression works correctly with virtual inheritance as well as virtual function."""
|
"""Test that expression works correctly with virtual inheritance as well as virtual function."""
|
||||||
self.build()
|
self.build()
|
||||||
|
@ -60,6 +61,8 @@ class CppVirtualMadness(TestBase):
|
||||||
# series of printf statements.
|
# series of printf statements.
|
||||||
stdout = process.GetSTDOUT(1024)
|
stdout = process.GetSTDOUT(1024)
|
||||||
|
|
||||||
|
self.assertIsNotNone(stdout, "Encountered an error reading the process's output")
|
||||||
|
|
||||||
# This golden list contains a list of "my_expr = 'value' pairs extracted
|
# This golden list contains a list of "my_expr = 'value' pairs extracted
|
||||||
# from the golden output.
|
# from the golden output.
|
||||||
gl = []
|
gl = []
|
||||||
|
|
|
@ -388,7 +388,7 @@ def system(commands, **kwargs):
|
||||||
raise ValueError('stdout argument not allowed, it will be overridden.')
|
raise ValueError('stdout argument not allowed, it will be overridden.')
|
||||||
if 'shell' in kwargs and kwargs['shell']==False:
|
if 'shell' in kwargs and kwargs['shell']==False:
|
||||||
raise ValueError('shell=False not allowed')
|
raise ValueError('shell=False not allowed')
|
||||||
process = Popen(shellCommand, stdout=PIPE, stderr=PIPE, shell=True, **kwargs)
|
process = Popen(shellCommand, stdout=PIPE, stderr=PIPE, shell=True, universal_newlines=True, **kwargs)
|
||||||
pid = process.pid
|
pid = process.pid
|
||||||
this_output, this_error = process.communicate()
|
this_output, this_error = process.communicate()
|
||||||
retcode = process.poll()
|
retcode = process.poll()
|
||||||
|
|
|
@ -151,8 +151,14 @@
|
||||||
// See also SBThread::GetStopDescription.
|
// See also SBThread::GetStopDescription.
|
||||||
%typemap(argout) (char *dst, size_t dst_len) {
|
%typemap(argout) (char *dst, size_t dst_len) {
|
||||||
Py_XDECREF($result); /* Blow away any previous result */
|
Py_XDECREF($result); /* Blow away any previous result */
|
||||||
lldb_private::PythonString str($1);
|
if (result == 0) {
|
||||||
$result = str.release();
|
$result = Py_None;
|
||||||
|
Py_INCREF($result);
|
||||||
|
} else {
|
||||||
|
llvm::StringRef ref(static_cast<const char*>($1), result);
|
||||||
|
lldb_private::PythonString string(ref);
|
||||||
|
$result = string.release();
|
||||||
|
}
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,9 +248,14 @@
|
||||||
// See also SBProcess::ReadMemory.
|
// See also SBProcess::ReadMemory.
|
||||||
%typemap(argout) (void *buf, size_t size) {
|
%typemap(argout) (void *buf, size_t size) {
|
||||||
Py_XDECREF($result); /* Blow away any previous result */
|
Py_XDECREF($result); /* Blow away any previous result */
|
||||||
llvm::StringRef ref(static_cast<const char*>($1), result);
|
if (result == 0) {
|
||||||
lldb_private::PythonString string(ref);
|
$result = Py_None;
|
||||||
$result = string.release();
|
Py_INCREF($result);
|
||||||
|
} else {
|
||||||
|
llvm::StringRef ref(static_cast<const char*>($1), result);
|
||||||
|
lldb_private::PythonString string(ref);
|
||||||
|
$result = string.release();
|
||||||
|
}
|
||||||
free($1);
|
free($1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue