Skip to content

Commit

Permalink
[Python] Implement truth testing for lldb.value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JDevlieghere committed Sep 4, 2019
1 parent 5559406 commit 24223eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def test(self):
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')))
Expand Down
3 changes: 3 additions & 0 deletions lldb/scripts/Python/python-extensions.swig
Original file line number Diff line number Diff line change
Expand Up @@ -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__()

Expand Down

0 comments on commit 24223eb

Please sign in to comment.