Use absolute stack offset when exiting from a native call

This commit is contained in:
K. Lange 2022-07-03 07:09:48 +09:00
parent 2000161d34
commit ed9b522697

View File

@ -833,9 +833,10 @@ static inline int _callNative(KrkNative* callee, int argCount, int returnDepth)
krk_pop();
krk_push(result);
} else {
size_t stackOffsetAfterCall = (krk_currentThread.stackTop - krk_currentThread.stack) - argCount - returnDepth;
KrkValue result = krk_callNativeOnStack(argCount, krk_currentThread.stackTop - argCount, 0, native);
if (unlikely(krk_currentThread.stackTop == krk_currentThread.stack)) return 0;
krk_currentThread.stackTop -= argCount + returnDepth;
krk_currentThread.stackTop = krk_currentThread.stack + stackOffsetAfterCall;
krk_push(result);
}
return 2;