You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Edit 3: Solved! As I suspected, my C library was wrong and fooling me -- looping over the array to set the struct values, I was adding sizeof(Simple) to the pointer, not recalling the pointer knows it's Simple type and only needs to be incremented. Sorry for the bother.
Hi, all. I'm struggling to read the values of an array of struct malloc'd and returned by a C library. I'm using a pointer to step through the array as kojix2 mentions in their request for a read_array_of_struct#956 but it's not working for me. The first element is fine, all subsequent are gibberish. Returning the array as void * or Simple.byRef makes no difference.
I expect it's something dumb, or even that my C is wrong and misleading me, but I just can't see it. Or maybe there are platform issues I should be looking at? Maybe it's obvious to someone else? Any hints are welcome!
I'm running on a M1 2020 Macbook Pro under Big Sur with ruby 2.6.8p205 (2021-07-07 revision 67951) [arm64-darwin20]. But I get the same results on an intel 2015 Macbook Air under Mojave with ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin20].
Edit: Ah, ok, seems there are tricky snags re Ruby and arm vs x86 and what am I really even running?! Don't know if that's this but I'll have to sort it to find out.
Edit 2: Ok, I've got the gist of the arm vs x86 issue and I've further run my samples on an x86 Linux box with the same results. Back to my original theory, I must be making some dumb little mistake I can't find. Argh.
Edit 3: Solved! As I suspected, my C library was wrong and fooling me -- looping over the array to set the struct values, I was adding sizeof(Simple) to the pointer, not recalling the pointer knows it's Simple type and only needs to be incremented. Sorry for the bother.
Hi, all. I'm struggling to read the values of an array of struct malloc'd and returned by a C library. I'm using a pointer to step through the array as kojix2 mentions in their request for a
read_array_of_struct
#956 but it's not working for me. The first element is fine, all subsequent are gibberish. Returning the array as void * or Simple.byRef makes no difference.I expect it's something dumb, or even that my C is wrong and misleading me, but I just can't see it. Or maybe there are platform issues I should be looking at? Maybe it's obvious to someone else? Any hints are welcome!
I'm running on a M1 2020 Macbook Pro under Big Sur with ruby 2.6.8p205 (2021-07-07 revision 67951) [arm64-darwin20]. But I get the same results on an intel 2015 Macbook Air under Mojave with ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin20].
Edit: Ah, ok, seems there are tricky snags re Ruby and arm vs x86 and what am I really even running?! Don't know if that's this but I'll have to sort it to find out.
Edit 2: Ok, I've got the gist of the arm vs x86 issue and I've further run my samples on an x86 Linux box with the same results. Back to my original theory, I must be making some dumb little mistake I can't find. Argh.
Here are my samples...
C library libpotato with:
C test program potato.c with:
results, as expected:
Ruby gem potato_ffi-0.0.1.gem with:
Ruby test program potato.rb with:
results:
The text was updated successfully, but these errors were encountered: