Replies: 2 comments 1 reply
-
|
@uvlad7 Thank you for Thanks for the nice idea.
Indeed! I enabled discussion in org and convert this issue to discussion. I will try to respond later regarding the other items in order to summarize my thoughts. |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
I took a look again an think it's better to use libffi (libgoffi or sbinet/go-ffi or or achille-roussel/go-ffi or any other wrapper) for that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First, it's not an actual issue, but you don't have discussions enabled, so here we are.
Second, I'm not an experienced Go or C developer, in fact I only wrote one simple Go program; I can write simple C code, but not some "hacks", that can work safely.
That being said, I believe varargs functions like
rb_sprintfare must to have, and that hack used forRbRaiseis useless, as these are usually needed for the extensions likePRIsVALUE. I suppose even version that accepts two args,StringandC.VALUEwould be useful, as is still possible - though less effective - to concatenate multiple strings and to use Go'sfmt.Sprintf()for types other thanVALUE.But I suppose it's also possible to create varargs Go function that accepts interface, but in fact only allows a few types (plus
VALUE, plus maybe native Go types directly convertible to C types) and auto-generate C functions that simply call varargs. Yeah, event for 1-3 args and 19 types it's gonna be 7239 functions (can be less if poiters aren't needed), and very slow if Go func has to check each arg type through if-s (I don't know ifswitchis possble), but still worth a shot.Another, hacky, approach is to try to construct
va_listor it's functional analog. It's probably possible to write all Go's varargs into a raw piece of memory, then pass it and its size into a C function, which would createva_listand callv-analog of the Ruby function (rb_vsprintfinstead ofrb_sprintf). I know, hacking aroundva_listcannot be a portable solution, it'd depend on ABI (then OS) and architecture (shouldn't depend on the compiler, but anyway Go only supports gcc and clang, if I know right), and even only Linux + MacOs support on x64 and ARM64 would be good enough. As of the hack, I found it's possible to useallocafor that. Ifva_listis really just achar*, it may work. Anyway, it must be possible to achieve with asm, taking architecture and calling conventions into account. Definitely would worth the effortBeta Was this translation helpful? Give feedback.
All reactions