Skip to content

Commit 6bc88a0

Browse files
wallacerunnerkou
authored andcommitted
[ruby/fiddle] add regex for bool parsing & test struct w/ bool
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]>
1 parent a44a260 commit 6bc88a0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

ext/fiddle/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
return TYPE_INTPTR_T
248248
when /\Auintptr_t(?:\s+\w+)?\z/
249249
return TYPE_UINTPTR_T
250-
when "bool"
250+
when /\Abool(?:\s+\w+)?\z/
251251
return TYPE_BOOL
252252
when /\*/, /\[[\s\d]*\]/
253253
return TYPE_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+
def test_struct_bool
281+
assert_equal([[TYPE_INT, TYPE_BOOL], ['x', 'toggle']],
282+
parse_struct_signature('int x; bool toggle'))
283+
end
284+
280285
def test_struct_undefined
281286
assert_raise(DLError) { parse_struct_signature(['int i', 'DWORD cb']) }
282287
end

0 commit comments

Comments
 (0)