Skip to content

Commit 7a8c2e3

Browse files
committed
Remove ffi-clang monkey-patches and upgrade to version 0.15.0
1 parent a5d5e5d commit 7a8c2e3

File tree

8 files changed

+7
-87
lines changed

8 files changed

+7
-87
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ source 'https://rubygems.org'
22

33
gemspec
44

5+
gem 'ffi-clang', path: '/mnt/c/Source/ffi-clang'
56
gem 'simplecov', require: false

lib/ruby-bindgen/parser.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ def initialize(inputter, clang_args, libclang: nil)
1616
# Lazy-load ffi-clang and its refinements so CMake format doesn't need libclang
1717
require 'ffi/clang'
1818
require 'ruby-bindgen/refinements/cursor'
19-
require 'ruby-bindgen/refinements/source_range'
2019
require 'ruby-bindgen/refinements/type'
2120

22-
@index = FFI::Clang::Index.new(false, true)
21+
@index = FFI::Clang::Index.new(exclude_declarations_from_pch: false, display_diagnostics: true)
2322
end
2423

2524
def generate(visitor)

lib/ruby-bindgen/refinements/cursor.rb

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'set'
2-
31
module FFI
42
module Clang
53
class Cursor
@@ -69,52 +67,6 @@ def anonymous_definer
6967
result
7068
end
7169

72-
# Monkey patch to handle extern "C" linkage spec in qualified names.
73-
# See https://github.com/ioquatix/ffi-clang/pull/97
74-
def qualified_name
75-
if self.kind != :cursor_translation_unit
76-
if self.semantic_parent.kind == :cursor_invalid_file
77-
raise(ArgumentError, "Invalid semantic parent: #{self}")
78-
end
79-
if self.kind == :cursor_linkage_spec
80-
return self.semantic_parent.qualified_name
81-
end
82-
result = self.semantic_parent.qualified_name
83-
result && !result.empty? ? "#{result}::#{self.spelling}" : self.spelling
84-
end
85-
end
86-
87-
# Find first child cursor matching any of the given kinds.
88-
# Short-circuits on first match via :break to properly terminate
89-
# clang_visitChildren (a non-local return would skip CXChildVisit_Break
90-
# and corrupt the outer visitor state).
91-
def find_first_by_kind(recurse, *kinds)
92-
result = nil
93-
kinds_set = kinds.to_set
94-
self.each(recurse) do |child, parent|
95-
if kinds_set.include?(child.kind)
96-
result = child
97-
next :break
98-
end
99-
end
100-
result
101-
end
102-
103-
# Monkey patch to use Set for faster lookup and support block/enumerator.
104-
# See https://github.com/ioquatix/ffi-clang/pull/99
105-
def find_by_kind(recurse, *kinds, &block)
106-
unless (recurse == nil || recurse == true || recurse == false)
107-
raise("Recurse parameter must be nil or a boolean value. Value was: #{recurse}")
108-
end
109-
110-
return enum_for(__method__, recurse, *kinds) unless block_given?
111-
112-
kinds_set = kinds.to_set
113-
114-
self.each(recurse) do |child, parent|
115-
yield child if kinds_set.include?(child.kind)
116-
end
117-
end
11870
end
11971
end
12072
end

lib/ruby-bindgen/refinements/source_range.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/ruby-bindgen/refinements/type.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ module FFI
88
module Clang
99
module Types
1010
class Type
11-
# Monkey patch to expose template argument methods.
12-
# See https://github.com/ioquatix/ffi-clang/pull/93
13-
unless method_defined?(:num_template_arguments)
14-
Lib.attach_function :get_num_template_arguments, :clang_Type_getNumTemplateArguments, [Lib::CXType.by_value], :int
15-
Lib.attach_function :get_template_argument_as_type, :clang_Type_getTemplateArgumentAsType, [Lib::CXType.by_value, :uint], Lib::CXType.by_value
16-
17-
def template_argument_type(index)
18-
Type.create Lib.get_template_argument_as_type(@type, index), @translation_unit
19-
end
20-
21-
def num_template_arguments
22-
Lib.get_num_template_arguments(@type)
23-
end
24-
end
25-
2611
# Returns the type spelling with full namespace qualification.
2712
#
2813
# Combines the declaration's qualified_name (which has the namespace) with

ruby-bindgen.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
3636
spec.homepage = 'https://github.com/ruby-rice/ruby-bindgen'
3737

3838
spec.add_dependency 'ffi', '>= 1.16'
39-
spec.add_dependency 'ffi-clang', '>= 0.14'
39+
spec.add_dependency 'ffi-clang', '>= 0.15'
4040

4141
spec.add_development_dependency 'logger'
4242
spec.add_development_dependency 'minitest'

test/bindings/cpp/unions-rb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ void Init_Unions()
1717
.define_attr("i", &Unions::SimpleUnion::i)
1818
.define_attr("d", &Unions::SimpleUnion::d);
1919

20-
Rice::Data_Type<Unions::NestedUnion::Inner> inner = define_class<Unions::NestedUnion::Inner>("Inner")
20+
Rice::Data_Type<Unions::NestedUnion::Inner> inner = define_class_under<Unions::NestedUnion::Inner>(rb_mUnions, "Inner")
2121
.define_attr("x", &Unions::NestedUnion::Inner::x)
2222
.define_attr("y", &Unions::NestedUnion::Inner::y);
2323

2424
Rice::Data_Type<Unions::NestedUnion> nested_union = define_class_under<Unions::NestedUnion>(rb_mUnions, "NestedUnion")
2525
.define_attr("inner", &Unions::NestedUnion::inner)
2626
.define_attr("z", &Unions::NestedUnion::z);
2727

28-
Rice::Data_Type<Unions::UnionWithStruct::Data> rb_cUnionsUnionWithStructData = define_class<Unions::UnionWithStruct::Data>("Data")
28+
Rice::Data_Type<Unions::UnionWithStruct::Data> rb_cUnionsUnionWithStructData = define_class_under<Unions::UnionWithStruct::Data>(rb_mUnions, "Data")
2929
.define_constructor(Constructor<Unions::UnionWithStruct::Data>())
3030
.define_attr("a", &Unions::UnionWithStruct::Data::a)
3131
.define_attr("b", &Unions::UnionWithStruct::Data::b);

test/bindings/cpp_project/unions-rb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ void Init_Unions()
1717
.define_attr("i", &Unions::SimpleUnion::i)
1818
.define_attr("d", &Unions::SimpleUnion::d);
1919

20-
Rice::Data_Type<Unions::NestedUnion::Inner> inner = define_class<Unions::NestedUnion::Inner>("Inner")
20+
Rice::Data_Type<Unions::NestedUnion::Inner> inner = define_class_under<Unions::NestedUnion::Inner>(rb_mUnions, "Inner")
2121
.define_attr("x", &Unions::NestedUnion::Inner::x)
2222
.define_attr("y", &Unions::NestedUnion::Inner::y);
2323

2424
Rice::Data_Type<Unions::NestedUnion> nested_union = define_class_under<Unions::NestedUnion>(rb_mUnions, "NestedUnion")
2525
.define_attr("inner", &Unions::NestedUnion::inner)
2626
.define_attr("z", &Unions::NestedUnion::z);
2727

28-
Rice::Data_Type<Unions::UnionWithStruct::Data> rb_cUnionsUnionWithStructData = define_class<Unions::UnionWithStruct::Data>("Data")
28+
Rice::Data_Type<Unions::UnionWithStruct::Data> rb_cUnionsUnionWithStructData = define_class_under<Unions::UnionWithStruct::Data>(rb_mUnions, "Data")
2929
.define_constructor(Constructor<Unions::UnionWithStruct::Data>())
3030
.define_attr("a", &Unions::UnionWithStruct::Data::a)
3131
.define_attr("b", &Unions::UnionWithStruct::Data::b);

0 commit comments

Comments
 (0)