Skip to content

Commit

Permalink
add regex for bool parsing & test struct w/ bool parsing (#169)
Browse files Browse the repository at this point in the history
GitHub: fix GH-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".

---------

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
  • Loading branch information
wallacerunner and kou authored Jan 10, 2025
1 parent 2131aa1 commit 7160744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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 7160744

Please sign in to comment.