[Lldb-commits] [lldb] r116171 - /lldb/trunk/test/lldbutil.py
Johnny Chen
johnny.chen at apple.com
Sun Oct 10 13:25:10 PDT 2010
Author: johnny
Date: Sun Oct 10 15:25:10 2010
New Revision: 116171
URL: http://llvm.org/viewvc/llvm-project?rev=116171&view=rev
Log:
Simplify the generator adaptor to a Python function instead of a class definition,
with the function name 'lldb_iter'. Example:
def disassemble_instructions (insts):
from lldbutil import lldb_iter
for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
print i
Modified:
lldb/trunk/test/lldbutil.py
Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=116171&r1=116170&r2=116171&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Sun Oct 10 15:25:10 2010
@@ -6,28 +6,25 @@
import sys
import StringIO
-class Iterator(object):
+def lldb_iter(obj, getsize, getelem):
"""
A generator adaptor for lldb aggregate data structures.
- API clients pass in the aggregate object, and the names of the methods to
- get the size of the object and its individual element.
+ API clients pass in the aggregate object, the name of the method to get the
+ size of the object, and the name of the method to get the element given an
+ index.
Example usage:
def disassemble_instructions (insts):
- from lldbutil import Iterator
- for i in Iterator(insts, 'GetSize', 'GetInstructionAtIndex'):
+ from lldbutil import lldb_iter
+ for i in lldb_iter(insts, 'GetSize', 'GetInstructionAtIndex'):
print i
"""
- def __init__(self, obj, getsize, getelem):
- self.obj = obj
- self.getsize = getattr(obj, getsize)
- self.getelem = getattr(obj, getelem)
-
- def __iter__(self):
- for i in range(self.getsize()):
- yield self.getelem(i)
+ size = getattr(obj, getsize)
+ elem = getattr(obj, getelem)
+ for i in range(size()):
+ yield elem(i)
########################################################
More information about the lldb-commits
mailing list