[PATCH] python: Fix check for disasm creation failure

Anders Waldenborg anders at 0x63.nu
Wed Oct 9 13:35:29 PDT 2013


Hi indygreg, gottesmm,

Check should be for pointer being NULL, not what it points to.

Also adds a test for this case.

http://llvm-reviews.chandlerc.com/D1878

Files:
  bindings/python/llvm/disassembler.py
  bindings/python/llvm/tests/test_disassembler.py

Index: bindings/python/llvm/disassembler.py
===================================================================
--- bindings/python/llvm/disassembler.py
+++ bindings/python/llvm/disassembler.py
@@ -66,7 +66,7 @@
 
         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)
 
Index: bindings/python/llvm/tests/test_disassembler.py
===================================================================
--- bindings/python/llvm/tests/test_disassembler.py
+++ bindings/python/llvm/tests/test_disassembler.py
@@ -16,6 +16,10 @@
         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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1878.1.patch
Type: text/x-patch
Size: 1167 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131009/c1cf29e5/attachment.bin>


More information about the llvm-commits mailing list