From e8a957d2a91d02af0b9c3808b31067d236b22196 Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Sun, 17 Nov 2013 15:40:57 +0000 Subject: python: Fix check for disasm creation failure Check should be for pointer being NULL, not what it points to. Also adds a test for this case. Reviewed By: indygreg Differential Revision: http://llvm-reviews.chandlerc.com/D1878 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194965 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/llvm/disassembler.py | 2 +- bindings/python/llvm/tests/test_disassembler.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'bindings') diff --git a/bindings/python/llvm/disassembler.py b/bindings/python/llvm/disassembler.py index 9e781ae..f2df275 100644 --- a/bindings/python/llvm/disassembler.py +++ b/bindings/python/llvm/disassembler.py @@ -75,7 +75,7 @@ class Disassembler(LLVMObject): ptr = lib.LLVMCreateDisasm(c_char_p(triple), c_void_p(None), c_int(0), callbacks['op_info'](0), callbacks['symbol_lookup'](0)) - if not ptr.contents: + if not ptr: raise Exception('Could not obtain disassembler for triple: %s' % triple) diff --git a/bindings/python/llvm/tests/test_disassembler.py b/bindings/python/llvm/tests/test_disassembler.py index 46d12f7..e960dc0 100644 --- a/bindings/python/llvm/tests/test_disassembler.py +++ b/bindings/python/llvm/tests/test_disassembler.py @@ -16,6 +16,10 @@ class TestDisassembler(TestBase): self.assertEqual(count, 3) self.assertEqual(s, '\tjcxz\t-127') + def test_nonexistant_triple(self): + with self.assertRaisesRegexp(Exception, "Could not obtain disassembler for triple"): + Disassembler("nonexistant-triple-raises") + def test_get_instructions(self): sequence = '\x67\xe3\x81\x01\xc7' # jcxz -127; addl %eax, %edi -- cgit v1.1