Ruby 2.7: rb_define_method and C++

Jason Roelofs <[email protected]> Sat, 28 Dec 2019 19:59:25 -0500
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>
--===============1647595705==
Content-Type: multipart/alternative;
	boundary="Apple-Mail=_8CFDA703-9561-44D6-A789-B8E92F87568C"


--Apple-Mail=_8CFDA703-9561-44D6-A789-B8E92F87568C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Hey,

I'm the maintainer of the Rice gem[0] which provides a higher level way =
for exposing C++ APIs into Ruby, and I've got a problem getting Rice to =
work with Ruby 2.7 and wondering if I can get some help or pointers.

The short of it is, rb_define_method, when compiled under C++, is now =
redefined as a templated struct that takes the arity parameter as the =
template argument to pick the right overload at compile time[1]. This =
has led to a straight up compilation error in Rice under Ruby 2.7 [2] =
because as a C++ wrapper library, Rice builds up a wrapper object around =
each defined method to properly wrap and convert parameters and return =
values to and from Ruby, as well as providing a path from a templated =
C++ function or method to a plain C-usable function. That wrapper object =
is then provided to rb_define_method to properly expose the requested =
function/method to Ruby [3].

=46rom what I can see, rb_define_method is now completely redefined to =
be this templated macro and I have found no way to directly call the =
underlying, original function. Does anyone here know why this change was =
made, if there were thoughts about keeping this function exposed for =
dynamic use, or if it still is, how I can call it (I've read through the =
source a few times, tried a few different defines, nothing seems to =
work)?

Thanks

Jason

[0] https://github.com/jasonroelofs/rice =
<https://github.com/jasonroelofs/rice>
[1] =
https://github.com/ruby/ruby/commit/9c0d5e51cb3726455560c34ad595ab82f651da=
48#diff-3b256c5581538dcd834697c766a2b1aaR2770 =
<https://github.com/ruby/ruby/commit/9c0d5e51cb3726455560c34ad595ab82f651d=
a48#diff-3b256c5581538dcd834697c766a2b1aaR2770>
[2] https://github.com/jasonroelofs/rice/issues/119 =
<https://github.com/jasonroelofs/rice/issues/119>
[3] =
https://github.com/jasonroelofs/rice/blob/master/rice/detail/method_data.c=
pp#L78 =
<https://github.com/jasonroelofs/rice/blob/master/rice/detail/method_data.=
cpp#L78>=

--Apple-Mail=_8CFDA703-9561-44D6-A789-B8E92F87568C
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=us-ascii

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;" =
class=3D"">Hey,<div class=3D""><br class=3D""></div><div class=3D"">I'm =
the maintainer of the Rice gem[0] which provides a higher level way for =
exposing C++ APIs into Ruby, and I've got a problem getting Rice to work =
with Ruby 2.7 and wondering if I can get some help or =
pointers.</div><div class=3D""><br class=3D""></div><div class=3D"">The =
short of it is, rb_define_method, when compiled under C++, is now =
redefined as a templated struct that takes the arity parameter as the =
template argument to pick the right overload at compile time[1]. This =
has led to a straight up compilation error in Rice under Ruby 2.7 [2] =
because as a C++ wrapper library, Rice builds up a wrapper object around =
each defined method to properly wrap and convert parameters and return =
values to and from Ruby, as well as providing a path from a templated =
C++ function or method to a plain C-usable function. That wrapper object =
is then provided to rb_define_method to properly expose the requested =
function/method to Ruby [3].</div><div class=3D""><br =
class=3D""></div><div class=3D"">=46rom what I can see, rb_define_method =
is now completely redefined to be this templated macro and I have found =
no way to directly call the underlying, original function. Does anyone =
here know why this change was made, if there were thoughts about keeping =
this function exposed for dynamic use, or if it still is, how I can call =
it (I've read through the source a few times, tried a few different =
defines, nothing seems to work)?</div><div class=3D""><br =
class=3D""></div><div class=3D"">Thanks</div><div class=3D""><br =
class=3D""></div><div class=3D"">Jason</div><div class=3D""><br =
class=3D""></div><div class=3D"">[0]&nbsp;<a =
href=3D"https://github.com/jasonroelofs/rice" =
class=3D"">https://github.com/jasonroelofs/rice</a></div><div =
class=3D"">[1]&nbsp;<a =
href=3D"https://github.com/ruby/ruby/commit/9c0d5e51cb3726455560c34ad595ab=
82f651da48#diff-3b256c5581538dcd834697c766a2b1aaR2770" =
class=3D"">https://github.com/ruby/ruby/commit/9c0d5e51cb3726455560c34ad59=
5ab82f651da48#diff-3b256c5581538dcd834697c766a2b1aaR2770</a></div><div =
class=3D"">[2]&nbsp;<a =
href=3D"https://github.com/jasonroelofs/rice/issues/119" =
class=3D"">https://github.com/jasonroelofs/rice/issues/119</a></div><div =
class=3D"">[3]&nbsp;<a =
href=3D"https://github.com/jasonroelofs/rice/blob/master/rice/detail/metho=
d_data.cpp#L78" =
class=3D"">https://github.com/jasonroelofs/rice/blob/master/rice/detail/me=
thod_data.cpp#L78</a></div></body></html>=

--Apple-Mail=_8CFDA703-9561-44D6-A789-B8E92F87568C--

--===============1647595705==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--===============1647595705==--