3 ms·
Can this be made to work on ARM as well?
by cozzyd 6y ago
Can this be made to work on ARM as well?
- warmwaffles 6y agoARM implementation would be fun to look at as well.
- jart 6y agoYes, absolutely! In the case of Arm, it would need to be a pure macro (i.e. no external __defer function) since ARM ABI uses a register to store the return address. Then the unwind code would need to save the return registers x0 to x7 each time it calls free() or whatever function is being deferred. I'd write it for you, but I don't use ARM.
- liuliu 6y agoYou need to disable inlining. __builtin_frame_address can give surprising addresses when inline enabled. The code itself is likely not be wrong, but you won't confined to the lexical scope as if you see in the code (the defer can be triggered when the parent function returned). Disclaimer: I haven't looked at the code too closely.
- jart 6y agoInlining gives you the ability to control how "pooled" the free() operations end up being. You don't need to disable inlining. You just have to be mindful of how much power this macro gives you. For example, if a function that calls gc() is being called from within a loop, then it's a good idea to make sure that function isn't static.