Skip to content

Commit

Permalink
fix for error "#unsafe_fetch(index : Int)` must be implemented ..."
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaWertun committed May 10, 2020
1 parent 00db954 commit 4012779
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions builtin_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ short: { binding_type: Int16, kind: Struct, builtin: true }
int: { binding_type: Int32, kind: Struct, builtin: true }
unsigned: { binding_type: UInt32, kind: Struct, builtin: true }
"unsigned int": { binding_type: UInt32, kind: Struct, builtin: true }
_Int: { binding_type: Int, crystal_type: Int, cpp_type: int, kind: Struct, builtin: true }

# Long types
"long": { binding_type: "LibC::Long", kind: Struct, builtin: true }
Expand Down
9 changes: 8 additions & 1 deletion src/bindgen/call_builder/crystal_wrapper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ module Bindgen
# type.
result = call.result unless call.origin.any_constructor?

arguments = call.arguments
if call.name == "unsafe_fetch" && arguments.size == 1 && arguments[0].name == "index"
idx_type = Parser::Type.builtin_type("_Int")
idx_arg = Parser::Argument.new("index", idx_type)
arguments = Crystal::Pass.new(@db).arguments_to_wrapper([idx_arg])
end

head_line = method.prototype(
name: call.name,
arguments: call.arguments,
arguments: arguments,
result: result,
static: call.origin.static_method?,
abstract: call.origin.pure?,
Expand Down

0 comments on commit 4012779

Please sign in to comment.