[ruby/fiddle] add regex for bool parsing & test struct w/ bool

parsing
(https://github.com/ruby/fiddle/pull/169)

GitHub: fix https://github.com/ruby/fiddle/pull/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".

---------

https://github.com/ruby/fiddle/commit/71607446d4

Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
This commit is contained in:
Dmitrii 2025-01-10 13:30:46 +08:00 committed by Hiroshi SHIBATA
parent ed0a213608
commit f1f81e8615
Notes: git 2025-01-14 03:24:59 +00:00
2 changed files with 6 additions and 1 deletions

View File

@ -247,7 +247,7 @@ module Fiddle
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

View File

@ -277,6 +277,11 @@ module Fiddle
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