mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-23 12:11:49 +00:00
[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:
parent
5fef8e6edb
commit
d409e595a8
2 changed files with 6 additions and 3 deletions
|
@ -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)
|
#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
|
These functions allow a builtin function that uses PR_CallFunction() to
|
||||||
safely insert a call to another VM function. The +initialize diversion
|
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);
|
PR_PushFrame (pr);
|
||||||
__auto_type params = PR_SaveParams (pr);
|
auto params = PR_SaveParams (pr);
|
||||||
... set up parameters to detour_function
|
... set up parameters to detour_function
|
||||||
PR_ExecuteProgram (pr, detour_function)
|
PR_ExecuteProgram (pr, detour_function)
|
||||||
PR_RestoreParams (pr, params);
|
PR_RestoreParams (pr, params);
|
||||||
|
|
|
@ -171,12 +171,14 @@ event_handler (const IE_event_t *ie_event, void *_pr)
|
||||||
num_params = (num_params + 3) / 4 + 2;
|
num_params = (num_params + 3) / 4 + 2;
|
||||||
|
|
||||||
PR_PushFrame (pr);
|
PR_PushFrame (pr);
|
||||||
|
auto params = PR_SaveParams (pr);
|
||||||
PR_SetupParams (pr, num_params, 2);
|
PR_SetupParams (pr, num_params, 2);
|
||||||
auto event = &P_PACKED (pr, IE_event_t, 2);
|
auto event = &P_PACKED (pr, IE_event_t, 2);
|
||||||
P_POINTER (pr, 0) = PR_SetPointer (pr, event);
|
P_POINTER (pr, 0) = PR_SetPointer (pr, event);
|
||||||
P_POINTER (pr, 1) = qcevent_data;
|
P_POINTER (pr, 1) = qcevent_data;
|
||||||
*event = *ie_event;
|
*event = *ie_event;
|
||||||
PR_ExecuteProgram (pr, qcevent);
|
PR_ExecuteProgram (pr, qcevent);
|
||||||
|
PR_RestoreParams (pr, params);
|
||||||
PR_PopFrame (pr);
|
PR_PopFrame (pr);
|
||||||
return R_INT (pr);
|
return R_INT (pr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue