Permalink
Browse files

Fix LLVM.with_message_output.

One should first check for the return value, which is consistently
LLVMBool with True indicating an error, and only then try to fetch
the message.
  • Loading branch information...
1 parent c167b6a commit 6dcebc12399c81d782b83e32b05b5920332e733c @whitequark whitequark committed Jan 21, 2013
Showing with 7 additions and 5 deletions.
  1. +7 −5 lib/llvm/core.rb
View
@@ -15,20 +15,22 @@ module C
# @yield [FFI::MemoryPointer]
# @return [String, nil]
def self.with_message_output
- result = nil
+ message = nil
FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |str|
- yield str
+ result = yield str
msg_ptr = str.read_pointer
- unless msg_ptr.null?
- result = msg_ptr.read_string
+ if result != 0
+ raise RuntimeError, "Error is signalled, but msg_ptr is null" if msg_ptr.null?
+
+ message = msg_ptr.read_string
C.dispose_message msg_ptr
end
end
- result
+ message
end
# Same as #with_message_output, but raises a RuntimeError with the

0 comments on commit 6dcebc1

Please sign in to comment.