diff options
author | Zachary Turner <zturner@google.com> | 2015-10-15 19:35:48 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2015-10-15 19:35:48 +0000 |
commit | 9c40264fdadbb229ce311c9bda898981d7ac8eae (patch) | |
tree | 93437006427295b7cd98fd7e8a3ddd14a4410b9f /lldb/unittests/ScriptInterpreter/Python | |
parent | b26d8070333117beb92bde3007ddd37729929c3e (diff) | |
download | bcm5719-llvm-9c40264fdadbb229ce311c9bda898981d7ac8eae.tar.gz bcm5719-llvm-9c40264fdadbb229ce311c9bda898981d7ac8eae.zip |
Introduce a `PythonFile` object, and use it everywhere.
Python file handling got an overhaul in Python 3, and it affects
the way we have to interact with files. Notably:
1) `PyFile_FromFile` no longer exists, and instead we have to use
`PyFile_FromFd`. This means having a way to get an fd from
a FILE*. For this we reuse the lldb_private::File class to
convert between FILE*s and fds, since there are some subtleties
regarding ownership rules when FILE*s and fds refer to the same
file.
2) PyFile is no longer a builtin type, so there is no such thing as
`PyFile_Check`. Instead, files in Python 3 are just instances
of `io.IOBase`. So the logic for checking if something is a file
in Python 3 is to check if it is a subclass of that module.
Additionally, some unit tests are added to verify that `PythonFile`
works as expected on Python 2 and Python 3, and
`ScriptInterpreterPython` is updated to use `PythonFile` instead of
manual calls to the various `PyFile_XXX` methods.
llvm-svn: 250444
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python')
-rw-r--r-- | lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp index 01f6b92a4d1..3502640c547 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp @@ -9,6 +9,8 @@ #include "gtest/gtest.h" +#include "lldb/Host/File.h" +#include "lldb/Host/FileSystem.h" #include "lldb/Host/HostInfo.h" #include "Plugins/ScriptInterpreter/Python/lldb-python.h" #include "Plugins/ScriptInterpreter/Python/PythonDataObjects.h" @@ -373,3 +375,10 @@ TEST_F(PythonDataObjectsTest, TestPythonDictionaryToStructuredDictionary) EXPECT_STREQ(string_value0, string_sp->GetValue().c_str()); EXPECT_EQ(int_value1, int_sp->GetValue()); } + +TEST_F(PythonDataObjectsTest, TestPythonFile) +{ + File file(FileSystem::DEV_NULL, File::eOpenOptionRead); + PythonFile py_file(file, "r"); + EXPECT_TRUE(PythonFile::Check(py_file.get())); +} |