From: marcandre-ruby-core@... Date: 2021-01-02T20:25:28+00:00 Subject: [ruby-core:101881] [Ruby master Misc#17502] C vs Ruby Issue #17502 has been reported by marcandre (Marc-Andre Lafortune). ---------------------------------------- Misc #17502: C vs Ruby https://bugs.ruby-lang.org/issues/17502 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal ---------------------------------------- Some features are coded in a mix of Ruby and C (e.g. ractor.rb). External gems don't have access to this. The C-API to deal with keyword parameters is also very verbose the parsing and the engine does not know it. Moreover, some optimization PRs are simply rewriting C-code into Ruby using pseudo C code. I understand the intentions are great, but changes like https://github.com/ruby/ruby/pull/4018/files seem a symptom that something needs to be improved with the C api. ```diff -static VALUE - flo_zero_p(VALUE num) - { - return flo_iszero(num) ? Qtrue : Qfalse; - } # in different file: + def zero? + Primitive.attr! 'inline' + Primitive.cexpr! 'flo_iszero(self) ? Qtrue : Qfalse' + end ``` It seems to me that this is a way to circumvent a deeper issue. Is this the right direction? Is there a plan for an API that would: 1) be accessible to C extensions 2) can't be re-written any faster in pseuso-C in Ruby 3) has an easy way to define keyword parameters? I realize that RBS may give perfect signatures, but ideally `parameters` would be more informative for C-functions too. ```ruby Ractor.method(:yield).parameters # => [[:req, :obj], [:key, :move]] # good! Fiber.method(:initialize).parameters # => [[:rest]] # not good, should be [[:key, :blocking]] ``` -- https://bugs.ruby-lang.org/ Unsubscribe: