lib/ffi/clang/index.rb in ffi-clang-0.8.0 vs lib/ffi/clang/index.rb in ffi-clang-0.9.0
- old
+ new
@@ -1,15 +1,16 @@
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2010, by Jari Bakken.
# Copyright, 2012, by Hal Brodigan.
-# Copyright, 2013-2022, by Samuel Williams.
+# Copyright, 2013-2024, by Samuel Williams.
# Copyright, 2013, by Carlos MartÃn Nieto.
# Copyright, 2013, by Dave Wilkinson.
# Copyright, 2013, by Takeshi Watanabe.
# Copyright, 2014, by Masahiro Sano.
+# Copyright, 2023, by Charlie Savage.
require_relative 'lib/index'
module FFI
module Clang
@@ -24,14 +25,20 @@
def parse_translation_unit(source_file, command_line_args = nil, unsaved = [], opts = {})
command_line_args = Array(command_line_args)
unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved)
- translation_unit_pointer = Lib.parse_translation_unit(self, source_file, args_pointer_from(command_line_args), command_line_args.size, unsaved_files, unsaved.length, options_bitmask_from(opts))
+ translation_unit_pointer_out = FFI::MemoryPointer.new(:pointer)
- raise Error, "error parsing #{source_file.inspect}" if translation_unit_pointer.null?
+ error_code = Lib.parse_translation_unit2(self, source_file, args_pointer_from(command_line_args), command_line_args.size, unsaved_files, unsaved.length, options_bitmask_from(opts), translation_unit_pointer_out)
+ if error_code != :cx_error_success
+ error_name = Lib::ErrorCodes.from_native(error_code, nil)
+ message = "Error parsing file. Code: #{error_name}. File: #{source_file.inspect}"
+ raise(Error, message)
+ end
+ translation_unit_pointer = translation_unit_pointer_out.read_pointer
TranslationUnit.new translation_unit_pointer, self
end
def create_translation_unit(ast_filename)
translation_unit_pointer = Lib.create_translation_unit(self, ast_filename)
@@ -51,10 +58,10 @@
args_pointer.put_array_of_pointer(0, strings) unless strings.empty?
args_pointer
end
def options_bitmask_from(opts)
- Lib.bitmask_from Lib::TranslationUnitFlags, opts
+ Lib.bitmask_from(Lib::TranslationUnitFlags, opts)
end
end
end
end