Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bool struct member parsing not working #168

Closed
wallacerunner opened this issue Jan 3, 2025 · 1 comment · Fixed by #169
Closed

bool struct member parsing not working #168

wallacerunner opened this issue Jan 3, 2025 · 1 comment · Fixed by #169

Comments

@wallacerunner
Copy link
Contributor

This script

require 'fiddle/import'

module Test
  extend Fiddle::Importer

  test_struct = struct [
    'int int_member',
    'bool boolean_member'
  ]
end

fails with this error:

PS D:\code\ruby\sdl_test> ruby .\struct_test.rb
C:/Users/Dee/scoop/apps/ruby/3.3.6-2/lib/ruby/3.3.0/fiddle/cparser.rb:261:in `parse_ctype': unknown type: bool (Fiddle::DLError)
        from C:/Users/Dee/scoop/apps/ruby/3.3.6-2/lib/ruby/3.3.0/fiddle/cparser.rb:71:in `block in parse_struct_signature'
        from C:/Users/Dee/scoop/apps/ruby/3.3.6-2/lib/ruby/3.3.0/fiddle/cparser.rb:43:in `each'
        from C:/Users/Dee/scoop/apps/ruby/3.3.6-2/lib/ruby/3.3.0/fiddle/cparser.rb:43:in `parse_struct_signature'
        from C:/Users/Dee/scoop/apps/ruby/3.3.6-2/lib/ruby/3.3.0/fiddle/import.rb:223:in `struct'
        from ./struct_test.rb:6:in `<module:Test>'
        from ./struct_test.rb:3:in `<main>'

Looks like parse_struct_signature passes the whole bool boolean_member string to parse_ctype, where it fails to be parsed because case expression tries to match on "bool" (i.e. a plain string) instead of a regex, something like /\Abool(?:\s+\w+)?\z/:

when "bool"

@kou
Copy link
Member

kou commented Jan 4, 2025

Could you open a PR with a test?

@kou kou closed this as completed in #169 Jan 10, 2025
@kou kou closed this as completed in 7160744 Jan 10, 2025
hsbt pushed a commit to hsbt/ruby that referenced this issue Jan 14, 2025
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]>
hsbt pushed a commit to hsbt/ruby that referenced this issue Jan 14, 2025
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]>
hsbt pushed a commit to ruby/ruby that referenced this issue Jan 14, 2025
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants