Implement a new stack and error handling model for the SourcePawn VM.
This has three major changes to SourcePawn. First, the API now supports the concept of "exceptions". The exception state is a global property of an instance of the SourcePawn VM. Exceptions can be caught or suppressed. Many places in SourceMod have been updated to check exceptions instead of errors. The new API obsoletes major parts of the embedder API - all but one method of invoking functions is obsoleted, and the debug interface has been scrapped. Extensions using the native API will not be affected, however, ThrowNativeError has been deprecated in favor of ReportError. Second, the SourcePawn concept of a "stack" has been unified at the API level. A stack frame iterator now iterates over all SourcePawn invocations, rather than the topmost plugin. This makes error handling more consistent and removes another dependency on context-per-plugin. Finally, the implementation of stack frames has been changed dramatically. Rather than maintain a complicated and expensive return pointer stack, we now rely on the implicit one provided by the CPU. The stack frame iterator now walks the JIT stack directly. This removes many unnecessary bookkeeping instructions from the generated code, in particular making the CALL instruction 40% faster. These changes required some fair surgery to the JIT. Its error paths are now slightly more complicated, as they have to throw an exception rather than return an error code. In addition, any path that can throw an exception is now responsible for creating an "exit frame", which exists to tell the stack frame iterator about transitions from the JIT to the VM.
This commit is contained in:
+11
-56
@@ -52,13 +52,8 @@
|
||||
|
||||
// Assumes message field name is param 2, gets as strField
|
||||
#define GET_FIELD_NAME_OR_ERR() \
|
||||
int err; \
|
||||
char *strField; \
|
||||
if ((err=pCtx->LocalToString(params[2], &strField)) != SP_ERROR_NONE) \
|
||||
{ \
|
||||
pCtx->ThrowNativeErrorEx(err, NULL); \
|
||||
return 0; \
|
||||
}
|
||||
pCtx->LocalToString(params[2], &strField);
|
||||
|
||||
static cell_t smn_PbReadInt(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
@@ -387,11 +382,7 @@ static cell_t smn_PbSetString(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
char *strValue;
|
||||
if ((err=pCtx->LocalToString(params[3], &strValue)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToString(params[3], &strValue);
|
||||
|
||||
int index = params[0] >= 4 ? params[4] : -1;
|
||||
if (index < 0)
|
||||
@@ -418,11 +409,7 @@ static cell_t smn_PbSetColor(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *clrParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &clrParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &clrParams);
|
||||
|
||||
Color clr(
|
||||
clrParams[0],
|
||||
@@ -455,11 +442,7 @@ static cell_t smn_PbSetAngle(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *angParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &angParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &angParams);
|
||||
|
||||
QAngle ang(
|
||||
sp_ctof(angParams[0]),
|
||||
@@ -491,11 +474,7 @@ static cell_t smn_PbSetVector(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *vecParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &vecParams);
|
||||
|
||||
Vector vec(
|
||||
sp_ctof(vecParams[0]),
|
||||
@@ -527,11 +506,7 @@ static cell_t smn_PbSetVector2D(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *vecParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &vecParams);
|
||||
|
||||
Vector2D vec(
|
||||
sp_ctof(vecParams[0]),
|
||||
@@ -602,11 +577,7 @@ static cell_t smn_PbAddString(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
char *strValue;
|
||||
if ((err=pCtx->LocalToString(params[3], &strValue)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToString(params[3], &strValue);
|
||||
|
||||
if (!msg->AddString(strField, strValue))
|
||||
{
|
||||
@@ -622,11 +593,7 @@ static cell_t smn_PbAddColor(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *clrParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &clrParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &clrParams);
|
||||
|
||||
Color clr(
|
||||
clrParams[0],
|
||||
@@ -648,11 +615,7 @@ static cell_t smn_PbAddAngle(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *angParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &angParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &angParams);
|
||||
|
||||
QAngle ang(
|
||||
sp_ctof(angParams[0]),
|
||||
@@ -673,11 +636,7 @@ static cell_t smn_PbAddVector(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *vecParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &vecParams);
|
||||
|
||||
Vector vec(
|
||||
sp_ctof(vecParams[0]),
|
||||
@@ -698,11 +657,7 @@ static cell_t smn_PbAddVector2D(IPluginContext *pCtx, const cell_t *params)
|
||||
GET_FIELD_NAME_OR_ERR();
|
||||
|
||||
cell_t *vecParams;
|
||||
if ((err=pCtx->LocalToPhysAddr(params[3], &vecParams)) != SP_ERROR_NONE)
|
||||
{
|
||||
pCtx->ThrowNativeErrorEx(err, NULL);
|
||||
return 0;
|
||||
}
|
||||
pCtx->LocalToPhysAddr(params[3], &vecParams);
|
||||
|
||||
Vector2D vec(
|
||||
sp_ctof(vecParams[0]),
|
||||
|
||||
Reference in New Issue
Block a user