lib/prism/ffi.rb in prism-0.21.0 vs lib/prism/ffi.rb in prism-0.22.0

- old
+ new

@@ -158,11 +158,16 @@ # Yields a pm_string_t pointer to the given block. def self.with(filepath, &block) pointer = FFI::MemoryPointer.new(SIZEOF) begin - raise unless LibRubyParser.pm_string_mapped_init(pointer, filepath) - yield new(pointer) + raise TypeError unless filepath.is_a?(String) + + if LibRubyParser.pm_string_mapped_init(pointer, filepath) + yield new(pointer) + else + raise SystemCallError.new(filepath, FFI.errno) + end ensure LibRubyParser.pm_string_free(pointer) pointer.free end end