diff --git a/llvm/_core.cpp b/llvm/_core.cpp index 7a87c5c..5acfa83 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -280,7 +280,7 @@ _wLLVMLinkModules(PyObject *self, PyObject *args) PyObject *ret; char *errmsg; - if (!LLVMLinkModules(dest, src, (LLVMLinkerMode)mode, &errmsg)) { + if (LLVMLinkModules(dest, src, (LLVMLinkerMode)mode, &errmsg)) { if (errmsg) { ret = PyUnicode_FromString(errmsg); LLVMDisposeMessage(errmsg); diff --git a/llvm/core.py b/llvm/core.py index 3baae95..66d7fbc 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -466,10 +466,12 @@ class Module(llvm.Ownable, llvm.Cacheable): check_is_module(other) if not preserve: other.forget() # remove it from object cache - _core.LLVMLinkModules(self.ptr, other.ptr, int(bool(preserve))) + result = _core.LLVMLinkModules(self.ptr, other.ptr, int(bool(preserve))) + if result is not None: + raise llvm.LLVMException(result) if not preserve: - # Do not try to destroy the other module's llvm::Module*. - other._own(llvm.DummyOwner()) + # Prevent user from using the other module + del other.ptr def get_type_named(self, name): """Return a Type object with the given name.""" @@ -1865,8 +1867,9 @@ class Builder(object): def branch(self, bblk): check_is_basic_block(bblk) - for instr in self.basic_block.instructions: - assert not instr.is_terminator, "BasicBlock can only have one terminator" + if __debug__: + for instr in self.basic_block.instructions: + assert not instr.is_terminator, "BasicBlock can only have one terminator" return _make_value(_core.LLVMBuildBr(self.ptr, bblk.ptr)) def cbranch(self, if_value, then_blk, else_blk):