ruby / fiddle

A libffi wrapper for Ruby.
BSD 2-Clause "Simplified" License
154 stars 37 forks source link

No bool type #130

Closed eregon closed 10 months ago

eregon commented 1 year ago
/home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/fiddle/cparser.rb:247:in `parse_ctype': unknown type: bool (Fiddle::DLError)
    from /home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/fiddle/cparser.rb:117:in `parse_signature'
    from /home/eregon/.rubies/ruby-3.2.2/lib/ruby/3.2.0/fiddle/import.rb:168:in `extern'

for extern "bool foo(void *buffer)" with extend Fiddle::Importer.

Maybe a workaround is to use typealias, but not sure what would be the correct type then.

kou commented 1 year ago

Good catch. I've implemented it.

eregon commented 1 year ago

Thanks! Ideally extern "bool foo(void *buffer)" would return Ruby true/false, not 1/0 (which are both truthy in Ruby). Do you think Fiddle could handle that?

kou commented 1 year ago

Ah, then we should not implement bool as an alias.

eregon commented 10 months ago

@kou Should we revert https://github.com/ruby/fiddle/commit/bc6c66bbb9fdbb23019287d79d63b79f12e23fea maybe? Because if bool is then implemented properly to use Ruby true/false instead of 1/0 then it would be incompatible when that changes.

kou commented 10 months ago

Is it for Ruby 3.3.0? If I can implement bool <-> Ruby's true/false soon, we don't need to revert the commit, right?

kou commented 10 months ago

Implemented.

eregon commented 10 months ago

Thanks! Yeah, I just wanted to avoid the half-done support for boolean to get in a Fiddle release, or if it did for as short as possible.