[qwaq] Save and restore params around event handler

It turns out the parameter pointer save/restore I had done for detoured
functions is required for all nested calls. However, I had actually
completely forgotten about it. I updated the docs for that section.
This commit is contained in:
Bill Currie 2024-02-01 11:09:22 +09:00
parent 5fef8e6edb
commit d409e595a8
2 changed files with 6 additions and 3 deletions

View file

@ -99,14 +99,15 @@ void PR_RunError (progs_t *pr, const char *error, ...) __attribute__((format(PRI
*/
#define PR_RESET_PARAMS(pr) PR_SetupParams (pr, PR_MAX_PARAMS, 1)
/** \name Detouring Function Calls
/** \name Nested Function Calls
These functions allow a builtin function that uses PR_CallFunction() to
safely insert a call to another VM function. The +initialize diversion
required by Objective-QuakeC uses this.
required by Objective-QuakeC uses this, but any other nested call will
be similar.
PR_PushFrame (pr);
__auto_type params = PR_SaveParams (pr);
auto params = PR_SaveParams (pr);
... set up parameters to detour_function
PR_ExecuteProgram (pr, detour_function)
PR_RestoreParams (pr, params);

View file

@ -171,12 +171,14 @@ event_handler (const IE_event_t *ie_event, void *_pr)
num_params = (num_params + 3) / 4 + 2;
PR_PushFrame (pr);
auto params = PR_SaveParams (pr);
PR_SetupParams (pr, num_params, 2);
auto event = &P_PACKED (pr, IE_event_t, 2);
P_POINTER (pr, 0) = PR_SetPointer (pr, event);
P_POINTER (pr, 1) = qcevent_data;
*event = *ie_event;
PR_ExecuteProgram (pr, qcevent);
PR_RestoreParams (pr, params);
PR_PopFrame (pr);
return R_INT (pr);
}