[Lldb-commits] [lldb] r253002 - Fix a bug in PythonExceptionState and add unittest coverage.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 12 17:50:19 PST 2015
Author: zturner
Date: Thu Nov 12 19:50:19 2015
New Revision: 253002
URL: http://llvm.org/viewvc/llvm-project?rev=253002&view=rev
Log:
Fix a bug in PythonExceptionState and add unittest coverage.
I forgot to reset the restore flag when calling member function
`Acquire`. The newly added unittest should cover this case.
Modified:
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.h
lldb/trunk/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp?rev=253002&r1=253001&r2=253002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.cpp Thu Nov 12 19:50:19 2015
@@ -50,6 +50,7 @@ PythonExceptionState::Acquire(bool resto
m_type.Reset(PyRefType::Owned, py_type);
m_value.Reset(PyRefType::Owned, py_value);
m_traceback.Reset(PyRefType::Owned, py_traceback);
+ m_restore_on_exit = restore_on_exit;
}
void
@@ -77,6 +78,15 @@ PythonExceptionState::Discard()
m_traceback.Reset();
}
+void
+PythonExceptionState::Reset()
+{
+ if (m_restore_on_exit)
+ Restore();
+ else
+ Discard();
+}
+
bool
PythonExceptionState::HasErrorOccurred()
{
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.h?rev=253002&r1=253001&r2=253002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.h (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonExceptionState.h Thu Nov 12 19:50:19 2015
@@ -30,6 +30,9 @@ class PythonExceptionState
void
Discard();
+ void
+ Reset();
+
static bool
HasErrorOccurred();
Modified: lldb/trunk/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp?rev=253002&r1=253001&r2=253002&view=diff
==============================================================================
--- lldb/trunk/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp (original)
+++ lldb/trunk/unittests/ScriptInterpreter/Python/PythonExceptionStateTests.cpp Thu Nov 12 19:50:19 2015
@@ -79,6 +79,33 @@ TEST_F(PythonExceptionStateTest, TestDis
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
}
+TEST_F(PythonExceptionStateTest, TestResetSemantics)
+{
+ PyErr_Clear();
+
+ // Resetting when auto-restore is true should restore.
+ RaiseException();
+ PythonExceptionState error(true);
+ EXPECT_TRUE(error.IsError());
+ EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
+ error.Reset();
+ EXPECT_FALSE(error.IsError());
+ EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
+
+ PyErr_Clear();
+
+ // Resetting when auto-restore is false should discard.
+ RaiseException();
+ PythonExceptionState error2(false);
+ EXPECT_TRUE(error2.IsError());
+ EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
+ error2.Reset();
+ EXPECT_FALSE(error2.IsError());
+ EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
+
+ PyErr_Clear();
+}
+
TEST_F(PythonExceptionStateTest, TestManualRestoreSemantics)
{
PyErr_Clear();
@@ -119,3 +146,29 @@ TEST_F(PythonExceptionStateTest, TestAut
PyErr_Clear();
}
+
+TEST_F(PythonExceptionStateTest, TestAutoRestoreChanged)
+{
+ // Test that if we re-acquire with different auto-restore semantics,
+ // that the new semantics are respected.
+ PyErr_Clear();
+
+ RaiseException();
+ PythonExceptionState error(false);
+ EXPECT_TRUE(error.IsError());
+
+ error.Reset();
+ EXPECT_FALSE(error.IsError());
+ EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
+
+ RaiseException();
+ error.Acquire(true);
+ EXPECT_TRUE(error.IsError());
+ EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
+
+ error.Reset();
+ EXPECT_FALSE(error.IsError());
+ EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
+
+ PyErr_Clear();
+}
\ No newline at end of file
More information about the lldb-commits
mailing list