Limit to number of arguments to inline C function #6696
Replies: 1 comment
-
Posted at 2020-07-30 by @gfwilliams Yes - it's due to the way functions are stored in Espruino. If you're running low, best bet is to put all your arguments into a Uint32Array and then pass a pointer to that. Posted at 2023-03-22 by llakie Hi Gordon, I just came accross this question here and I've the same problem as user113695. I followed your advice, but I just get "garbage" data delivered in my C-function.
And in the code I'm calling it with
The first three parameters are working beautifully. No matter if I'm accessing params[0], params[1], params[2] or params[3], they all seem to have random values stored within. Could you help out Gordon? Posted at 2023-03-22 by llakie I also tried to change my C-function signature to
And pass in an Int32Array. This does not work either. What I noticed is, that whenever I'm returning any of the values from params, I get a static value, which stays the same - so something more like a fixed memory address. But I read that accessing a value by ptr[X] automatically dereferences it and lets me access the value as *(ptr + 0) would do. Posted at 2023-03-22 by user113695 I think I had a similar problem back then. I believe that E.getAddressOf will only return the address to a flat memory area if the Array is above a certain size. Try padding your Uint32Array with a few 0s at the end. Posted at 2023-03-23 by llakie Thank you for your reply. Your advice at least solves part of the problem. Now the first variable in the array params[0] is the expected value. But unfortunately not the others (params[1..n]). Posted at 2023-03-23 by llakie If I'm not passing the array as a flat data area in the ram, the source code says, that I'm getting an array of JSVar pointers instead. So would it be correct to have an **int params parameter then, since it's actually an array of pointers. How do I retrieve the value of this variable then? Is there some param[0]->get_value()? I did not find anything in the source code. Posted at 2023-03-23 by llakie Now it gets really strange: This works, but why?
Accessing data at index 0, 8, 12 and 13. Any other "configuration" using different 0-spacings does not work. I'm completly lost. Posted at 2023-03-23 by @fanoush the
will not last long, the array is not referenced anywhere so will be freed soon, assign it to some variable. The Posted at 2023-03-23 by user113695 Fanoush probably has a point here, regarding the temporary array getting cleaned up in garbage collection. Posted at 2023-03-23 by user113695 Take a look at the source for the View STL app (Bangle 1 only atm) - I use this technique quite a bit in it. Posted at 2023-03-24 by @gfwilliams
That'll be it. As soon as the address it retrieved the data is freed and then it gets overwritten by the next allocated variable! I'd also add a check to make sure that |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-30 by user113695
Hi,
Is there a limit to the number of arguments that can be passed to an inlined C function?
I get a message
when attempting to set up an inline C function with 6 arguments. Everything appears fine up to 4 arguments.
Thanks,
Marko
Beta Was this translation helpful? Give feedback.
All reactions