Make native class registration use const templates with stack copies, tighten System argument validation and drop unused json_rc
Build / AerScript (push) Successful in 45s
Build / AerScript (push) Successful in 45s
This commit is contained in:
+15
-5
@@ -249,16 +249,16 @@ static int CharConstruct(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
return PH7_ABORT; /* final class: no public construction */
|
||||
}
|
||||
static sxi32 CharRegisterClasses(ph7_vm *pVm) {
|
||||
static ph7_constant_def aExcConst[] = {
|
||||
static const ph7_constant_def tExcConst[] = {
|
||||
{ "ERROR_NONE", 0, PH7_MEMBER_PUBLIC, 0, 0 },
|
||||
{ "ERROR_ARGUMENT", 0, PH7_MEMBER_PUBLIC, 0, 0 }
|
||||
};
|
||||
static const int aExcValue[] = { CHAR_ERROR_NONE, CHAR_ERROR_ARGUMENT };
|
||||
static ph7_constant_def aCharConst[] = {
|
||||
static const ph7_constant_def tCharConst[] = {
|
||||
{ "MIN_VALUE", 0, PH7_MEMBER_PUBLIC, 0, 0 },
|
||||
{ "MAX_VALUE", 0, PH7_MEMBER_PUBLIC, 0, 0 }
|
||||
};
|
||||
static ph7_param_def aExcCtor[] = {
|
||||
static const ph7_param_def tExcCtor[] = {
|
||||
{ "message", CTY(STRING), 0, 0, 0, 0 },
|
||||
{ "code", CTY(INT), 0, 0, 0, 0 }
|
||||
};
|
||||
@@ -267,8 +267,8 @@ static sxi32 CharRegisterClasses(ph7_vm *pVm) {
|
||||
};
|
||||
#define SMV(NAME,RET,FUNC) \
|
||||
{ NAME, CTY(RET), 0, 0, FUNC, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC | PH7_MEMBER_VARIADIC }
|
||||
static const ph7_method_def aExcMethod[] = {
|
||||
{ "__construct", CTY(VOID), aExcCtor, 2, CharExceptionConstruct, 0, 0 },
|
||||
static const ph7_method_def tExcMethod[] = {
|
||||
{ "__construct", CTY(VOID), tExcCtor, 2, CharExceptionConstruct, 0, 0 },
|
||||
{ "GetDescription", CTY(STRING), aExcDesc, 1, CharExceptionDescription, 0,
|
||||
PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }
|
||||
};
|
||||
@@ -305,6 +305,11 @@ static sxi32 CharRegisterClasses(ph7_vm *pVm) {
|
||||
};
|
||||
#undef SMV
|
||||
static const char *const aExcBase[] = { "Exception" };
|
||||
/* Mutable registration data lives on the stack; the templates stay const. */
|
||||
ph7_constant_def aExcConst[SX_ARRAYSIZE(tExcConst)];
|
||||
ph7_constant_def aCharConst[SX_ARRAYSIZE(tCharConst)];
|
||||
ph7_param_def aExcCtor[SX_ARRAYSIZE(tExcCtor)];
|
||||
ph7_method_def aExcMethod[SX_ARRAYSIZE(tExcMethod)];
|
||||
ph7_class_def sExc = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, CCLS_EXC,
|
||||
0, 0, aExcConst, SX_ARRAYSIZE(aExcConst),
|
||||
aExcMethod, SX_ARRAYSIZE(aExcMethod), 0, aExcBase, 1, 0, 0, 0, 0 };
|
||||
@@ -319,6 +324,11 @@ static sxi32 CharRegisterClasses(ph7_vm *pVm) {
|
||||
sxi32 rc = PH7_OK;
|
||||
SyZero(apExc, sizeof(apExc));
|
||||
SyZero(apChar, sizeof(apChar));
|
||||
memcpy(aExcConst, tExcConst, sizeof(tExcConst));
|
||||
memcpy(aCharConst, tCharConst, sizeof(tCharConst));
|
||||
memcpy(aExcCtor, tExcCtor, sizeof(tExcCtor));
|
||||
memcpy(aExcMethod, tExcMethod, sizeof(tExcMethod));
|
||||
aExcMethod[0].aParam = aExcCtor;
|
||||
for(n = 0 ; n < SX_ARRAYSIZE(apExc) ; ++n) {
|
||||
apExc[n] = ph7_new_scalar(pVm);
|
||||
if(apExc[n] == 0) { rc = PH7_NOMEM; goto Cleanup; }
|
||||
|
||||
Reference in New Issue
Block a user