diff options
author | Dmitrii <[email protected]> | 2025-01-10 13:30:46 +0800 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-01-14 12:24:37 +0900 |
commit | f1f81e86159221dbfce29e8e64ca8963391256fa (patch) | |
tree | 3ebd3de4ee0a058964c041feeeba41e017212213 | |
parent | ed0a213608f3f764b00e484ef31476fd1ff43172 (diff) |
[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 <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12568
-rw-r--r-- | ext/fiddle/lib/fiddle/cparser.rb | 2 | ||||
-rw-r--r-- | test/fiddle/test_cparser.rb | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/ext/fiddle/lib/fiddle/cparser.rb b/ext/fiddle/lib/fiddle/cparser.rb index 264ca166dd..cdd139d515 100644 --- a/ext/fiddle/lib/fiddle/cparser.rb +++ b/ext/fiddle/lib/fiddle/cparser.rb @@ -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 diff --git a/test/fiddle/test_cparser.rb b/test/fiddle/test_cparser.rb index f1b67476ba..2052911507 100644 --- a/test/fiddle/test_cparser.rb +++ b/test/fiddle/test_cparser.rb @@ -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 |