[PATCH] python: Properly initialize before trying to create disasm
Anders Waldenborg
anders at 0x63.nu
Fri Nov 15 04:18:13 PST 2013
I'm planning to give the proper and clean have-initializers-as-proper-symbols-in-shared-lib a third try, but this atleast makes the disassembler interface in the python bindings work again.
Hi indygreg,
http://llvm-reviews.chandlerc.com/D1879
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1879?vs=4788&id=5568#toc
Files:
bindings/python/llvm/disassembler.py
Index: bindings/python/llvm/disassembler.py
===================================================================
--- bindings/python/llvm/disassembler.py
+++ bindings/python/llvm/disassembler.py
@@ -33,6 +33,29 @@
# Constants for set_options
Option_UseMarkup = 1
+
+
+_initialized = False
+_targets = ['AArch64', 'ARM', 'Hexagon', 'MSP430', 'Mips', 'NVPTX', 'PowerPC', 'R600', 'Sparc', 'SystemZ', 'X86', 'XCore']
+def _ensure_initialized():
+ global _initialized
+ if not _initialized:
+ # Here one would want to call the functions
+ # LLVMInitializeAll{TargetInfo,TargetMC,Disassembler}s, but
+ # unfortunately they are only defined as static inline
+ # functions in the header files of llvm-c, so they don't exist
+ # as symbols in the shared library.
+ # So until that is fixed use this hack to initialize them all
+ for tgt in _targets:
+ for initializer in ("TargetInfo", "TargetMC", "Disassembler"):
+ try:
+ f = getattr(lib, "LLVMInitialize" + tgt + initializer)
+ except AttributeError:
+ continue
+ f()
+ _initialized = True
+
+
class Disassembler(LLVMObject):
"""Represents a disassembler instance.
@@ -47,6 +70,9 @@
The triple argument is the triple to create the disassembler for. This
is something like 'i386-apple-darwin9'.
"""
+
+ _ensure_initialized()
+
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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1879.2.patch
Type: text/x-patch
Size: 1654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131115/8e530c2e/attachment.bin>
More information about the llvm-commits
mailing list