diff options
| author | Serge Guelton <sguelton@quarkslab.com> | 2019-01-03 15:43:14 +0000 |
|---|---|---|
| committer | Serge Guelton <sguelton@quarkslab.com> | 2019-01-03 15:43:14 +0000 |
| commit | dd84c9d6638a9bd8adba22d14b3c616a5e36c409 (patch) | |
| tree | 523c4e0d792db8ff069121bbb7b6cf3d8b819006 /llvm/bindings | |
| parent | 9ff50013b1643c0fbb2530ce1ac7047f0f724879 (diff) | |
| download | bcm5719-llvm-dd84c9d6638a9bd8adba22d14b3c616a5e36c409.tar.gz bcm5719-llvm-dd84c9d6638a9bd8adba22d14b3c616a5e36c409.zip | |
Python compat - iterator protocol
In Python2 next() is used wile it's __next__ in Python3.
Differential Revision: https://reviews.llvm.org/D56250
llvm-svn: 350326
Diffstat (limited to 'llvm/bindings')
| -rw-r--r-- | llvm/bindings/python/llvm/core.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/bindings/python/llvm/core.py b/llvm/bindings/python/llvm/core.py index 43a318f2efb..81e354af062 100644 --- a/llvm/bindings/python/llvm/core.py +++ b/llvm/bindings/python/llvm/core.py @@ -19,6 +19,8 @@ from ctypes import byref from ctypes import c_char_p from ctypes import c_uint +import sys + __all__ = [ "lib", "Enums", @@ -236,7 +238,7 @@ class Module(LLVMObject): def __iter__(self): return self - def next(self): + def __next__(self): if not isinstance(self.function, Function): raise StopIteration("") result = self.function @@ -245,7 +247,10 @@ class Module(LLVMObject): else: self.function = self.function.next return result - + + if sys.version_info.major == 2: + next = __next__ + def __iter__(self): return Module.__function_iterator(self) @@ -304,7 +309,7 @@ class Function(Value): def __iter__(self): return self - def next(self): + def __next__(self): if not isinstance(self.bb, BasicBlock): raise StopIteration("") result = self.bb @@ -313,6 +318,9 @@ class Function(Value): else: self.bb = self.bb.next return result + + if sys.version_info.major == 2: + next = __next__ def __iter__(self): return Function.__bb_iterator(self) @@ -381,7 +389,7 @@ class BasicBlock(LLVMObject): def __iter__(self): return self - def next(self): + def __next__(self): if not isinstance(self.inst, Instruction): raise StopIteration("") result = self.inst @@ -390,7 +398,10 @@ class BasicBlock(LLVMObject): else: self.inst = self.inst.next return result - + + if sys.version_info.major == 2: + next = __next__ + def __iter__(self): return BasicBlock.__inst_iterator(self) |

