Skip to content

Commit 7160744

Browse files
wallacerunnerkou
andauthored
add regex for bool parsing & test struct w/ bool parsing (#169)
GitHub: fixGH-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>
1 parent 2131aa1 commit 7160744

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

‎lib/fiddle/cparser.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def parse_ctype(ty, tymap=nil)
247247
returnTYPE_INTPTR_T
248248
when/\Auintptr_t(?:\s+\w+)?\z/
249249
returnTYPE_UINTPTR_T
250-
when"bool"
250+
when/\Abool(?:\s+\w+)?\z/
251251
returnTYPE_BOOL
252252
when/\*/,/\[[\s\d]*\]/
253253
returnTYPE_VOIDP

‎test/fiddle/test_cparser.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ def test_struct_string
277277
assert_equal[[TYPE_INT,TYPE_VOIDP,TYPE_VOIDP],['x','cb','name']],parse_struct_signature('int x; void (*cb)(); const char* name')
278278
end
279279

280+
deftest_struct_bool
281+
assert_equal([[TYPE_INT,TYPE_BOOL],['x','toggle']],
282+
parse_struct_signature('int x; bool toggle'))
283+
end
284+
280285
deftest_struct_undefined
281286
assert_raise(DLError){parse_struct_signature(['int i','DWORD cb'])}
282287
end

0 commit comments

Comments
 (0)