From: eregontp@... Date: 2021-06-05T09:21:04+00:00 Subject: [ruby-core:104173] [Ruby master Misc#17502] C vs Ruby Issue #17502 has been updated by Eregon (Benoit Daloze). @ko1 Could you reply to this? I feel C code in the middle of Ruby code is not so great, and if moving C code to strings in Ruby is just to add `Primitive.attr! 'inline'` (like for `Float#zero?`), it seems much simpler and nicer to add `rb_impl_define_method_inline()` or so (private API, not public C API of course). For instance, there is no syntax highlighting for C code in Ruby code (`Primitive.cexpr! 'flo_iszero(self) ? Qtrue : Qfalse'`), looking at callers of flo_iszero() would only reveal generated code, not the `Primitive.cexpr!`, etc. ---------------------------------------- Misc #17502: C vs Ruby https://bugs.ruby-lang.org/issues/17502#change-92350 * Author: marcandre (Marc-Andre Lafortune) * Status: Open * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- 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: