Skip to content

Commit

Permalink
[ruby/fiddle] add regex for bool parsing & test struct w/ bool
Browse files Browse the repository at this point in the history
parsing
(ruby/fiddle#169)

GitHub: fix ruby/fiddle#168

Struct parsing invokes "parse_ctype" on the whole member signature,
which fails if member type is "bool" due to plain string matching for
it. This change updates "bool" type matching to a regexp, so TYPE_BOOL
is correctly parsed for a whole signature like "bool toggle" as well as
just "bool".

---------

ruby/fiddle@71607446d4

Co-authored-by: Sutou Kouhei <[email protected]>
  • Loading branch information
2 people authored and hsbt committed Jan 14, 2025
1 parent d023add commit 3cd2e9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/fiddle/lib/fiddle/cparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def parse_ctype(ty, tymap=nil)
return TYPE_INTPTR_T
when /\Auintptr_t(?:\s+\w+)?\z/
return TYPE_UINTPTR_T
when "bool"
when /\Abool(?:\s+\w+)?\z/
return TYPE_BOOL
when /\*/, /\[[\s\d]*\]/
return TYPE_VOIDP
Expand Down
5 changes: 5 additions & 0 deletions test/fiddle/test_cparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,11 @@ def test_struct_string
assert_equal [[TYPE_INT,TYPE_VOIDP,TYPE_VOIDP], ['x', 'cb', 'name']], parse_struct_signature('int x; void (*cb)(); const char* name')
end

def test_struct_bool
assert_equal([[TYPE_INT, TYPE_BOOL], ['x', 'toggle']],
parse_struct_signature('int x; bool toggle'))
end

def test_struct_undefined
assert_raise(DLError) { parse_struct_signature(['int i', 'DWORD cb']) }
end
Expand Down

0 comments on commit 3cd2e9c

Please sign in to comment.