From 24223eb24c74a116e1a3eb704d28e61454719a74 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 4 Sep 2019 18:59:10 +0000 Subject: [PATCH] [Python] Implement truth testing for lldb.value Python 3 calls __bool__() instead of __len__() and lldb.value only implemented the __len__ method. This adds the __bool__() implementation. Differential revision: https://reviews.llvm.org/D67183 llvm-svn: 370953 --- lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py | 4 ++++ lldb/scripts/Python/python-extensions.swig | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py b/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py index 9fc025a..d67905a 100644 --- a/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py +++ b/lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py @@ -160,6 +160,10 @@ class ValueAPITestCase(TestBase): val_i.GetType()).AddressOf(), VALID_VARIABLE) + # Check that lldb.value implements truth testing. + self.assertFalse(lldb.value(frame0.FindVariable('bogus'))) + self.assertTrue(lldb.value(frame0.FindVariable('uinthex'))) + self.assertTrue(int(lldb.value(frame0.FindVariable('uinthex'))) == 3768803088, 'uinthex == 3768803088') self.assertTrue(int(lldb.value(frame0.FindVariable('sinthex'))) diff --git a/lldb/scripts/Python/python-extensions.swig b/lldb/scripts/Python/python-extensions.swig index 25fec92..13bb582 100644 --- a/lldb/scripts/Python/python-extensions.swig +++ b/lldb/scripts/Python/python-extensions.swig @@ -980,6 +980,9 @@ class value(object): def __nonzero__(self): return self.sbvalue.__nonzero__() + def __bool__(self): + return self.sbvalue.__bool__() + def __str__(self): return self.sbvalue.__str__() -- 2.7.4