diff --git a/engine/builtin.c b/engine/builtin.c index ccb878d..e5637e4 100644 --- a/engine/builtin.c +++ b/engine/builtin.c @@ -3074,7 +3074,7 @@ static int PH7_builtin_nl2br(ph7_context *pCtx, int nArg, ph7_value **apArg) { * The format string is composed of zero or more directives: ordinary characters * (excluding %) that are copied directly to the result, and conversion * specifications, each of which results in fetching its own parameter. - * This applies to both sprintf() and printf(). + * This applies to sprintf(). * Each conversion specification consists of a percent sign (%), followed by one * or more of these elements, in order: * An optional sign specifier that forces a sign (- or +) to be used on a number. diff --git a/engine/classes.c b/engine/classes.c index 7c2f2cf..90539c5 100644 --- a/engine/classes.c +++ b/engine/classes.c @@ -5,6 +5,7 @@ * @DESCRIPTION Native declarations for the built-in classes * @DEVELOPERS Rafal Kupiec */ +#include #include "ph7int.h" /* Calls use the ordinary language dispatcher, including its exception result. */ @@ -621,38 +622,44 @@ PH7_PRIVATE sxi32 PH7_VmInstallBuiltinClasses(ph7_vm *pVm) { { .zName = "__toString", .sResult = { PH7_TYPE_STRING, 0, 0 }, .xFunc = StdConvert, .pUserData = (void *)&aConversion[3] }, { .zName = "__construct", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = aValueParam, .nParam = 1, .xFunc = StdConstruct, .iFlags = PH7_MEMBER_PRIVATE } }; - static ph7_constant_def aIoConst[] = { + static const ph7_constant_def tIoConst[] = { { .zName = "ERROR_NONE", .iFlags = PH7_MEMBER_PUBLIC }, { .zName = "ERROR_ARGUMENT", .iFlags = PH7_MEMBER_PUBLIC }, { .zName = "ERROR_IO", .iFlags = PH7_MEMBER_PUBLIC } }; - static ph7_param_def aIoParam[] = { + static const ph7_param_def tIoParam[] = { { .zName = "message", .sType = { PH7_TYPE_STRING, 0, 0 } }, { .zName = "code", .sType = { PH7_TYPE_INT, 0, 0 } } }; static const ph7_param_def aIoDescParam[] = { { .zName = "code", .sType = { PH7_TYPE_INT, 0, 0 } } }; - static ph7_param_def aPrintLineParam[] = { + static const ph7_param_def tPrintLineParam[] = { { .zName = "value", .sType = { PH7_TYPE_MIXED, 0, 0 } } }; - static const ph7_method_def aIoMethod[] = { - { .zName = "__construct", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = aIoParam, .nParam = 2, .xFunc = IOExceptionConstruct }, + static const ph7_method_def tIoMethod[] = { + { .zName = "__construct", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = tIoParam, .nParam = 2, .xFunc = IOExceptionConstruct }, { .zName = "GetDescription", .sResult = { PH7_TYPE_STRING, 0, 0 }, .aParam = aIoDescParam, .nParam = 1, .xFunc = IOExceptionDescription, .iFlags = PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC } }; static const ph7_field_def aTextWriterField[] = { { .zName = "handle", .sType = { PH7_TYPE_RESOURCE, 0, 0 }, .iFlags = PH7_MEMBER_PRIVATE } }; - static const ph7_method_def aTextWriterMethod[] = { + static const ph7_method_def tTextWriterMethod[] = { { .zName = "__construct", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = aValueParam, .nParam = 1, .xFunc = TextWriterConstruct, .iFlags = PH7_MEMBER_PRIVATE }, { .zName = "__destruct", .sResult = { PH7_TYPE_VOID, 0, 0 }, .xFunc = TextWriterDestruct }, { .zName = "__clone", .sResult = { PH7_TYPE_VOID, 0, 0 }, .xFunc = TextWriterClone, .iFlags = PH7_MEMBER_PRIVATE }, { .zName = "Print", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = aValueParam, .nParam = 1, .xFunc = TextWriterPrint, .iFlags = PH7_MEMBER_PUBLIC | PH7_MEMBER_VARIADIC }, - { .zName = "PrintLine", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = aPrintLineParam, .nParam = 1, .xFunc = TextWriterPrintLine, .iFlags = PH7_MEMBER_PUBLIC | PH7_MEMBER_VARIADIC }, + { .zName = "PrintLine", .sResult = { PH7_TYPE_VOID, 0, 0 }, .aParam = tPrintLineParam, .nParam = 1, .xFunc = TextWriterPrintLine, .iFlags = PH7_MEMBER_PUBLIC | PH7_MEMBER_VARIADIC }, { .zName = "Flush", .sResult = { PH7_TYPE_VOID, 0, 0 }, .xFunc = TextWriterFlush } }; static const char *const aIoBase[] = { "Exception" }; + /* Mutable registration data lives on the stack; the templates stay const. */ + ph7_constant_def aIoConst[SX_ARRAYSIZE(tIoConst)]; + ph7_param_def aIoParam[SX_ARRAYSIZE(tIoParam)]; + ph7_param_def aPrintLineParam[SX_ARRAYSIZE(tPrintLineParam)]; + ph7_method_def aIoMethod[SX_ARRAYSIZE(tIoMethod)]; + ph7_method_def aTextWriterMethod[SX_ARRAYSIZE(tTextWriterMethod)]; ph7_class_def aClass[] = { { .nSize = sizeof(ph7_class_def), .nVersion = PH7_CLASS_DEF_VERSION, .zName = "Exception", .aField = aExceptionField, .nField = SX_ARRAYSIZE(aExceptionField), .aMethod = aExceptionMethod, .nMethod = SX_ARRAYSIZE(aExceptionMethod) }, { .nSize = sizeof(ph7_class_def), .nVersion = PH7_CLASS_DEF_VERSION, .zName = "IOException", .aConstant = aIoConst, .nConstant = SX_ARRAYSIZE(aIoConst), .aMethod = aIoMethod, .nMethod = SX_ARRAYSIZE(aIoMethod), .azBase = aIoBase, .nBase = 1 }, @@ -666,6 +673,21 @@ PH7_PRIVATE sxi32 PH7_VmInstallBuiltinClasses(ph7_vm *pVm) { ph7_value *apIoValue[SX_ARRAYSIZE(aIoConst)] = { 0 }; sxi32 rc = PH7_NOMEM; sxu32 n; + memcpy(aIoConst, tIoConst, sizeof(tIoConst)); + memcpy(aIoParam, tIoParam, sizeof(tIoParam)); + memcpy(aPrintLineParam, tPrintLineParam, sizeof(tPrintLineParam)); + memcpy(aIoMethod, tIoMethod, sizeof(tIoMethod)); + memcpy(aTextWriterMethod, tTextWriterMethod, sizeof(tTextWriterMethod)); + for(n = 0; n < SX_ARRAYSIZE(aIoMethod); ++n) { + if(aIoMethod[n].xFunc == IOExceptionConstruct) { + aIoMethod[n].aParam = aIoParam; + } + } + for(n = 0; n < SX_ARRAYSIZE(aTextWriterMethod); ++n) { + if(aTextWriterMethod[n].xFunc == TextWriterPrintLine) { + aTextWriterMethod[n].aParam = aPrintLineParam; + } + } for(n = 0; n < SX_ARRAYSIZE(apValue); n++) { apValue[n] = ph7_new_scalar(pVm); if(apValue[n] == 0) { @@ -705,6 +727,9 @@ PH7_PRIVATE sxi32 PH7_VmInstallBuiltinClasses(ph7_vm *pVm) { } } Cleanup: + aIoParam[0].pDefault = 0; + aIoParam[1].pDefault = 0; + aPrintLineParam[0].pDefault = 0; for(n = 0; n < SX_ARRAYSIZE(apIoValue); n++) { if(apIoValue[n]) { ph7_release_value(pVm, apIoValue[n]); diff --git a/engine/hashmap.c b/engine/hashmap.c index 48013ed..798ec5e 100644 --- a/engine/hashmap.c +++ b/engine/hashmap.c @@ -1583,7 +1583,7 @@ PH7_PRIVATE void PH7_HashmapExtractNodeKey(ph7_hashmap_node *pNode, ph7_value *p } /* * Store the address of nodes value in the given container. - * Refer to the [vfprintf(),vprintf(),vsprintf()] implementations + * Refer to the [vfprintf(),vsprintf()] implementations * defined in 'builtin.c' for more information. */ PH7_PRIVATE int PH7_HashmapValuesToSet(ph7_hashmap *pMap, SySet *pOut) { diff --git a/engine/vm.c b/engine/vm.c index 1e639c5..2cf21fa 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -2510,8 +2510,6 @@ PH7_PRIVATE sxi32 PH7_VmInit( PH7_MemObjInit(pVm, &pVm->sPendingTransfer); /* Default assertion flags */ pVm->iAssertFlags = PH7_ASSERT_WARNING; /* Issue a warning for each failed assertion */ - /* JSON return status */ - pVm->json_rc = JSON_ERROR_NONE; /* PRNG context */ SyRandomnessInit(&pVm->sPrng, 0, 0); /* Install the null constant */ @@ -2711,7 +2709,9 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady( /* Zero the reference table */ SyZero(pVm->apRefObj, sizeof(VmRefObj *) * pVm->nRefSize); } - /* Register special functions first [i.e: print, json_encode(), func_get_args(), etc.] */ + /* Register special functions first [i.e: module_loaded(), function_exists(), + * class_exists(), get_class(), rand(), var_dump(), print_r(), get_include_path(), + * debug_backtrace(), ...] */ rc = VmRegisterSpecialFunction(&(*pVm)); if(rc != SXRET_OK) { /* Don't worry about freeing memory, everything will be released shortly */ @@ -3670,7 +3670,7 @@ PH7_PRIVATE sxi32 PH7_VmConfigure( n = (sxu32)SyStrlen(zValue); nText = SyBlobLength(&pVm->sArgv); nEntries = SyBlobLength(&pVm->sArgvEntries); - /* Keep exact entries separately from getopt's legacy flat text. */ + /* Keep exact argument entries separately from the flat $argv text. */ rc = SyBlobAppend(&pVm->sArgvEntries, zValue, n + 1); if(rc == SXRET_OK && n > 0) { if(nText > 0) { diff --git a/include/ph7int.h b/include/ph7int.h index a467c47..60aca2f 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -1248,7 +1248,7 @@ struct ph7_vm { SyHash hSuper; /* Superglobals hashtable */ SyHash hDBAL; /* DBAL installed drivers */ SyBlob sConsumer; /* Default VM consumer [i.e Redirect all VM output to this blob] */ - SyBlob sArgv; /* $argv[] collector [refer to the [getopt()] implementation for more information] */ + SyBlob sArgv; /* $argv[] collector: space-separated argument text */ SyBlob sArgvEntries; /* VM-owned argument list, each entry terminated by NUL */ SySet aModules; /* Set of loaded modules */ SySet aModuleHandles; /* Libraries retained after initialization attempts */ @@ -1281,7 +1281,6 @@ struct ph7_vm { ph7_value sPendingTransfer; int nExceptDepth; /* Exception depth */ int closure_cnt; /* Loaded closures counter */ - int json_rc; /* JSON return status [refer to json_encode()/json_decode()] */ ph7_output_consumer sVmConsumer; /* Registered output consumer callback */ int iAssertFlags; /* Assertion flags */ ph7_value sAssertCallback; /* Callback to call on failed assertions */ diff --git a/modules/char/char.c b/modules/char/char.c index ae53358..1154b6d 100644 --- a/modules/char/char.c +++ b/modules/char/char.c @@ -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; } diff --git a/modules/console/console.c b/modules/console/console.c index b898a45..fcd1e47 100644 --- a/modules/console/console.c +++ b/modules/console/console.c @@ -149,8 +149,8 @@ static void ConsoleEmit(ph7_context *pCtx, const char *zData) { /* ------------------------------------------------------------------ */ /* Writer backends */ /* ------------------------------------------------------------------ */ -/* Standard output reuses the VM output consumer, so output buffers and - * host consumers observe these bytes exactly as they observe print(). */ +/* Standard output reuses the VM output consumer, so host buffers see + * Console/TextWriter bytes through the same path as ordinary script output. */ static int ConsoleOutWrite(void *pUserData, const void *pData, unsigned int nByte) { ph7_vm *pVm = (ph7_vm *)pUserData; SyString sData; @@ -220,8 +220,8 @@ static int ConsolePrintImpl(ph7_context *pCtx, int nArg, ph7_value **apArg, int /* ------------------------------------------------------------------ */ /* Console method callbacks */ /* ------------------------------------------------------------------ */ -/* Keep the legacy print() contract: the call is an expression whose value is - * NULL, which matters for default-parameter sentinels. */ +/* Keep the Console::Print()/TextWriter::Print() contract: the call is an + * expression whose value is NULL, which matters for default-parameter sentinels. */ static int ConsoleNullResult(ph7_context *pCtx, int rc) { return rc == SXRET_OK ? ph7_result_null(pCtx) : rc; } @@ -568,7 +568,7 @@ static int Console_ResetColor(ph7_context *pCtx, int nArg, ph7_value **apArg) { static sxi32 ConsoleRegister(ph7_vm *pVm) { #define CTY(T) { PH7_TYPE_##T, 0, 0 } #define CONST_(N,V) { N, 0, PH7_MEMBER_PUBLIC, 0, 0 } - static ph7_constant_def aConst[] = { + static const ph7_constant_def tConst[] = { CONST_("COLOR_BLACK", 0), CONST_("COLOR_DARK_BLUE", 1), CONST_("COLOR_DARK_GREEN", 2), CONST_("COLOR_DARK_CYAN", 3), CONST_("COLOR_DARK_RED", 4), CONST_("COLOR_DARK_MAGENTA", 5), @@ -617,6 +617,8 @@ static sxi32 ConsoleRegister(ph7_vm *pVm) { SM("GetBackgroundColor", INT, 0, 0, Console_GetBackgroundColor), SM("ResetColor", VOID, 0, 0, Console_ResetColor) }; + /* Mutable registration data lives on the stack; the template stays const. */ + ph7_constant_def aConst[SX_ARRAYSIZE(tConst)]; ph7_class_def sClass = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, "Console", 0, 0, aConst, SX_ARRAYSIZE(aConst), @@ -627,6 +629,7 @@ static sxi32 ConsoleRegister(ph7_vm *pVm) { sxu32 n; sxi32 rc = PH7_OK; SyZero(apValue, sizeof(apValue)); + memcpy(aConst, tConst, sizeof(tConst)); for(n = 0 ; n < SX_ARRAYSIZE(apValue) ; ++n) { apValue[n] = ph7_new_scalar(pVm); if(apValue[n] == 0) { diff --git a/modules/json/json.c b/modules/json/json.c index 47b02e3..64f8d6d 100644 --- a/modules/json/json.c +++ b/modules/json/json.c @@ -2792,7 +2792,7 @@ static int JsonSerializeFn(ph7_context *pCtx, int nArg, ph7_value **apArg) { /* ------------------------------------------------------------------ */ /* Native class registration */ /* ------------------------------------------------------------------ */ -static ph7_constant_def aNodeTypeConst[] = { +static const ph7_constant_def tNodeTypeConst[] = { { "OBJECT", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ARRAY", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "STRING", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -2804,7 +2804,7 @@ static const int aNodeTypeValue[] = { JSON_NODE_OBJECT, JSON_NODE_ARRAY, JSON_NODE_STRING, JSON_NODE_NUMBER, JSON_NODE_BOOLEAN, JSON_NODE_NULL_NODE }; -static ph7_constant_def aExceptionConst[] = { +static const ph7_constant_def tExceptionConst[] = { { "ERROR_NONE", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_DEPTH", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_STATE_MISMATCH", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -2825,7 +2825,7 @@ static const int aExceptionValue[] = { JSON_ERROR_INDEX_OUT_OF_RANGE, JSON_ERROR_DUPLICATE_KEY, JSON_ERROR_INVALID_OPERATION, JSON_ERROR_INVALID_OPTION, JSON_ERROR_READONLY_OPTION }; -static ph7_constant_def aOptionsConst[] = { +static const ph7_constant_def tOptionsConst[] = { { "KEEP_LAST", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "KEEP_FIRST", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "REJECT", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -2833,7 +2833,7 @@ static ph7_constant_def aOptionsConst[] = { static const int aOptionsValue[] = { JSON_DUP_KEEP_LAST, JSON_DUP_KEEP_FIRST, JSON_DUP_REJECT }; static sxi32 JsonRegisterClasses(ph7_vm *pVm) { - static ph7_param_def aExcCtor[] = { + static const ph7_param_def tExcCtor[] = { JP("message", STRING), JP("code", INT), JPN("inputLine", JTY(INT)), JPN("inputColumn", JTY(INT)), JPN("path", JTY(STRING)) }; @@ -2852,22 +2852,22 @@ static sxi32 JsonRegisterClasses(ph7_vm *pVm) { static const ph7_param_def aNodeCtorFloat[] = { JP("value", FLOAT) }; static const ph7_param_def aNodeCtorRaw[] = { JP("rawNumber", STRING) }; static const ph7_param_def aNodeCtorBool[] = { JP("value", BOOL) }; - static ph7_param_def aToJson[] = { JPO("options", JNM("JsonOptions"), 0) }; + static const ph7_param_def tToJson[] = { JPO("options", JNM("JsonOptions"), 0) }; static const ph7_param_def aSetBool[] = { JP("value", BOOL) }; static const ph7_param_def aSetInt[] = { JP("value", INT) }; static const ph7_param_def aSetStr[] = { JP("value", STRING) }; - static ph7_param_def aParse[] = { + static const ph7_param_def tParse[] = { JP("text", STRING), JPO("options", JNM("JsonOptions"), 0) }; - static ph7_param_def aDocParse[] = { + static const ph7_param_def tDocParse[] = { JP("text", STRING), JPO("options", JNM("JsonOptions"), 0) }; - static ph7_param_def aDocToJson[] = { JPO("options", JNM("JsonOptions"), 0) }; - static ph7_param_def aSerialize[] = { + static const ph7_param_def tDocToJson[] = { JPO("options", JNM("JsonOptions"), 0) }; + static const ph7_param_def tSerialize[] = { JPN("node", JNM("JsonNode")), JPO("options", JNM("JsonOptions"), 0) }; - static const ph7_method_def aExcMethod[] = { - { "__construct", JTY(VOID), aExcCtor, 5, JsonExceptionConstruct, 0, 0 }, + static const ph7_method_def tExcMethod[] = { + { "__construct", JTY(VOID), tExcCtor, 5, JsonExceptionConstruct, 0, 0 }, { "GetInputLine", JTY(INT), 0, 0, JsonExceptionField, (void *)"inputLine", PH7_MEMBER_PUBLIC }, { "GetInputColumn", JTY(INT), 0, 0, JsonExceptionField, (void *)"inputColumn", PH7_MEMBER_PUBLIC }, { "GetPath", JTY(STRING), 0, 0, JsonExceptionField, (void *)"path", PH7_MEMBER_PUBLIC }, @@ -2880,7 +2880,7 @@ static sxi32 JsonRegisterClasses(ph7_vm *pVm) { { "path", JTY(STRING), 0, PH7_MEMBER_PRIVATE, 0, 0 }, }; static const char *const aExcBase[] = { "Exception" }; - static const ph7_method_def aNodeMethod[] = { + static const ph7_method_def tNodeMethod[] = { { "GetNodeType", JTY(INT), 0, 0, JsonNodeGetIntField, (void *)"kind", PH7_MEMBER_PUBLIC }, { "GetPath", JTY(STRING), 0, 0, JsonNodeGetStrField, (void *)"path", PH7_MEMBER_PUBLIC }, { "GetDepth", JTY(INT), 0, 0, JsonNodeGetDepth, 0, PH7_MEMBER_PUBLIC }, @@ -2902,10 +2902,10 @@ static sxi32 JsonRegisterClasses(ph7_vm *pVm) { { "GetBool", JTY(BOOL), 0, 0, JsonNodeGetBool, 0, PH7_MEMBER_PUBLIC }, { "GetRawNumber", JTY(STRING), 0, 0, JsonNodeGetRawNumber, 0, PH7_MEMBER_PUBLIC }, { "IsNull", JTY(BOOL), 0, 0, JsonNodeIsNull, 0, PH7_MEMBER_PUBLIC }, - { "ToJson", JTY(STRING), aToJson, 1, JsonNodeToJson, 0, PH7_MEMBER_PUBLIC }, + { "ToJson", JTY(STRING), tToJson, 1, JsonNodeToJson, 0, PH7_MEMBER_PUBLIC }, { "__toString", JTY(STRING), 0, 0, JsonNodeToString, 0, 0 }, }; - static ph7_field_def aNodeField[] = { + static const ph7_field_def tNodeField[] = { { "kind", JTY(INT), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "path", JTY(STRING), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "text", JTY(STRING), 0, PH7_MEMBER_PRIVATE, 0, 0 }, @@ -2938,7 +2938,7 @@ static sxi32 JsonRegisterClasses(ph7_vm *pVm) { static const ph7_method_def aNullMethod[] = { { "__construct", JTY(VOID), 0, 0, JsonNodeConstruct, (void *)(long)JSON_NODE_NULL_NODE, 0 } }; - static ph7_field_def aOptField[] = { + static const ph7_field_def tOptField[] = { { "prettyPrint", JTY(BOOL), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "unescapedUnicode", JTY(BOOL), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "unescapedSlashes", JTY(BOOL), 0, PH7_MEMBER_PRIVATE, 0, 0 }, @@ -2990,21 +2990,37 @@ static sxi32 JsonRegisterClasses(ph7_vm *pVm) { { "GetIndent", JTY(STRING), 0, 0, JsonOptionsGet, (void *)"indent", PH7_MEMBER_PUBLIC }, { "SetIndent", JTY(VOID), aSetStr, 1, JsonOptionsSetIndent, 0, PH7_MEMBER_PUBLIC }, }; - static const ph7_method_def aDocMethod[] = { + static const ph7_method_def tDocMethod[] = { { "__construct", JTY(VOID), 0, 0, JsonDocumentConstruct, 0, 0 }, - { "Parse", JTY(VOID), aDocParse, 2, JsonDocumentParse, 0, PH7_MEMBER_PUBLIC }, + { "Parse", JTY(VOID), tDocParse, 2, JsonDocumentParse, 0, PH7_MEMBER_PUBLIC }, { "GetRoot", JNM("JsonNode"), 0, 0, JsonDocumentGetRoot, 0, PH7_MEMBER_PUBLIC }, - { "SetRoot", JTY(VOID), aSerialize, 1, JsonDocumentSetRoot, 0, PH7_MEMBER_PUBLIC }, - { "ToJson", JTY(STRING), aDocToJson, 1, JsonDocumentToJson, 0, PH7_MEMBER_PUBLIC }, + { "SetRoot", JTY(VOID), tSerialize, 1, JsonDocumentSetRoot, 0, PH7_MEMBER_PUBLIC }, + { "ToJson", JTY(STRING), tDocToJson, 1, JsonDocumentToJson, 0, PH7_MEMBER_PUBLIC }, }; static const ph7_field_def aDocField[] = { { "root", JNM("JsonNode"), 0, PH7_MEMBER_PRIVATE, 0, 0 }, }; - static const ph7_method_def aFacadeMethod[] = { - { "Parse", JNM("JsonDocument"), aParse, 2, JsonParse, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "ParseNode", JNM("JsonNode"), aParse, 2, JsonParseNode, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "Serialize", JTY(STRING), aSerialize, 2, JsonSerializeFn, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + static const ph7_method_def tFacadeMethod[] = { + { "Parse", JNM("JsonDocument"), tParse, 2, JsonParse, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "ParseNode", JNM("JsonNode"), tParse, 2, JsonParseNode, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "Serialize", JTY(STRING), tSerialize, 2, JsonSerializeFn, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, }; + /* Mutable registration data lives on the stack; the templates stay const. */ + ph7_constant_def aNodeTypeConst[SX_ARRAYSIZE(tNodeTypeConst)]; + ph7_constant_def aExceptionConst[SX_ARRAYSIZE(tExceptionConst)]; + ph7_constant_def aOptionsConst[SX_ARRAYSIZE(tOptionsConst)]; + ph7_param_def aExcCtor[SX_ARRAYSIZE(tExcCtor)]; + ph7_param_def aToJson[SX_ARRAYSIZE(tToJson)]; + ph7_param_def aParse[SX_ARRAYSIZE(tParse)]; + ph7_param_def aDocParse[SX_ARRAYSIZE(tDocParse)]; + ph7_param_def aDocToJson[SX_ARRAYSIZE(tDocToJson)]; + ph7_param_def aSerialize[SX_ARRAYSIZE(tSerialize)]; + ph7_field_def aNodeField[SX_ARRAYSIZE(tNodeField)]; + ph7_field_def aOptField[SX_ARRAYSIZE(tOptField)]; + ph7_method_def aExcMethod[SX_ARRAYSIZE(tExcMethod)]; + ph7_method_def aNodeMethod[SX_ARRAYSIZE(tNodeMethod)]; + ph7_method_def aDocMethod[SX_ARRAYSIZE(tDocMethod)]; + ph7_method_def aFacadeMethod[SX_ARRAYSIZE(tFacadeMethod)]; ph7_class_def sExc = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, JCLS_EXC, aExcField, SX_ARRAYSIZE(aExcField), aExceptionConst, SX_ARRAYSIZE(aExceptionConst), aExcMethod, SX_ARRAYSIZE(aExcMethod), 0, aExcBase, 1, 0, 0, 0, 0 }; @@ -3049,6 +3065,43 @@ static sxi32 JsonRegisterClasses(ph7_vm *pVm) { SyZero(apOptConst, sizeof(apOptConst)); SyZero(apInit, sizeof(apInit)); SyZero(apCtorDef, sizeof(apCtorDef)); + memcpy(aNodeTypeConst, tNodeTypeConst, sizeof(tNodeTypeConst)); + memcpy(aExceptionConst, tExceptionConst, sizeof(tExceptionConst)); + memcpy(aOptionsConst, tOptionsConst, sizeof(tOptionsConst)); + memcpy(aExcCtor, tExcCtor, sizeof(tExcCtor)); + memcpy(aToJson, tToJson, sizeof(tToJson)); + memcpy(aParse, tParse, sizeof(tParse)); + memcpy(aDocParse, tDocParse, sizeof(tDocParse)); + memcpy(aDocToJson, tDocToJson, sizeof(tDocToJson)); + memcpy(aSerialize, tSerialize, sizeof(tSerialize)); + memcpy(aNodeField, tNodeField, sizeof(tNodeField)); + memcpy(aOptField, tOptField, sizeof(tOptField)); + memcpy(aExcMethod, tExcMethod, sizeof(tExcMethod)); + memcpy(aNodeMethod, tNodeMethod, sizeof(tNodeMethod)); + memcpy(aDocMethod, tDocMethod, sizeof(tDocMethod)); + memcpy(aFacadeMethod, tFacadeMethod, sizeof(tFacadeMethod)); + aExcMethod[0].aParam = aExcCtor; + for(n = 0 ; n < SX_ARRAYSIZE(aNodeMethod) ; ++n) { + if(aNodeMethod[n].xFunc == JsonNodeToJson) { + aNodeMethod[n].aParam = aToJson; + } + } + for(n = 0 ; n < SX_ARRAYSIZE(aDocMethod) ; ++n) { + if(aDocMethod[n].xFunc == JsonDocumentParse) { + aDocMethod[n].aParam = aDocParse; + } else if(aDocMethod[n].xFunc == JsonDocumentSetRoot) { + aDocMethod[n].aParam = aSerialize; + } else if(aDocMethod[n].xFunc == JsonDocumentToJson) { + aDocMethod[n].aParam = aDocToJson; + } + } + for(n = 0 ; n < SX_ARRAYSIZE(aFacadeMethod) ; ++n) { + if(aFacadeMethod[n].xFunc == JsonParse || aFacadeMethod[n].xFunc == JsonParseNode) { + aFacadeMethod[n].aParam = aParse; + } else if(aFacadeMethod[n].xFunc == JsonSerializeFn) { + aFacadeMethod[n].aParam = aSerialize; + } + } /* Allocate constant and default snapshots. */ for(n = 0 ; n < SX_ARRAYSIZE(apExc) ; ++n) { apExc[n] = ph7_new_scalar(pVm); diff --git a/modules/math/math.c b/modules/math/math.c index 22ff807..ebaf644 100644 --- a/modules/math/math.c +++ b/modules/math/math.c @@ -8,6 +8,7 @@ */ #include #include +#include #include "math.h" /* DBL_TRUE_MIN is C11; the module is compiled as C99 with GNU extensions. */ @@ -557,7 +558,7 @@ static int MathRound(ph7_context *pCtx, int nArg, ph7_value **apArg) { /* ------------------------------------------------------------------ */ /* Native class registration */ /* ------------------------------------------------------------------ */ -static ph7_constant_def aMathConst[] = { +static const ph7_constant_def tMathConst[] = { { "PI", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "E", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "TAU", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -578,7 +579,7 @@ static const double aMathValue[] = { MATH_PI, MATH_E, MATH_TAU, MATH_LN2, MATH_LN10, MATH_LOG2E, MATH_LOG10E, MATH_SQRT2, MATH_SQRT1_2, MATH_EULER_GAMMA }; -static ph7_constant_def aExceptionConst[] = { +static const ph7_constant_def tExceptionConst[] = { { "ERROR_NONE", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_ARGUMENT_OUT_OF_RANGE", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_ARGUMENT", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -591,7 +592,7 @@ static const int aExceptionValue[] = { MATH_ERROR_OVERFLOW, MATH_ERROR_ARITHMETIC, MATH_ERROR_DIVIDE_BY_ZERO }; static sxi32 MathRegisterClasses(ph7_vm *pVm) { - static ph7_param_def aExcCtor[] = { + static const ph7_param_def tExcCtor[] = { MP("message", STRING), MP("code", INT) }; static const ph7_param_def aExcDesc[] = { MP("code", INT) }; @@ -600,21 +601,21 @@ static sxi32 MathRegisterClasses(ph7_vm *pVm) { static const ph7_param_def aThree[] = { MP("x", MIXED), MP("y", MIXED), MP("z", MIXED) }; - static ph7_param_def aRound[] = { + static const ph7_param_def tRound[] = { MP("value", MIXED), MP("digits", INT), MP("mode", INT) }; - static ph7_param_def aLog[] = { + static const ph7_param_def tLog[] = { MP("value", MIXED), MPN("newBase", MTY(MIXED)) }; static const ph7_param_def aScaleB[] = { MP("x", MIXED), MP("n", INT) }; - static const ph7_method_def aExcMethod[] = { - { "__construct", MTY(VOID), aExcCtor, 2, MathExceptionConstruct, 0, 0 }, + static const ph7_method_def tExcMethod[] = { + { "__construct", MTY(VOID), tExcCtor, 2, MathExceptionConstruct, 0, 0 }, { "GetDescription", MTY(STRING), aExcDesc, 1, MathExceptionDescription, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC } }; - static const ph7_method_def aMathMethod[] = { + static const ph7_method_def tMathMethod[] = { { "Abs", MTY(MIXED), aOne, 1, MathAbs, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Acos", MTY(FLOAT), aOne, 1, MathAcos, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Acosh", MTY(FLOAT), aOne, 1, MathAcosh, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, @@ -639,7 +640,7 @@ static sxi32 MathRegisterClasses(ph7_vm *pVm) { { "Hypot", MTY(FLOAT), aTwo, 2, MathHypot, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "IEEERemainder", MTY(FLOAT), aTwo, 2, MathIEEEremainder, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "ILogB", MTY(INT), aOne, 1, MathILogB, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "Log", MTY(FLOAT), aLog, 2, MathLog, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "Log", MTY(FLOAT), tLog, 2, MathLog, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Log10", MTY(FLOAT), aOne, 1, MathLog10, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Log2", MTY(FLOAT), aOne, 1, MathLog2, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Max", MTY(MIXED), aTwo, 2, MathMax, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, @@ -648,7 +649,7 @@ static sxi32 MathRegisterClasses(ph7_vm *pVm) { { "MinMagnitude", MTY(FLOAT), aTwo, 2, MathMinMagnitude, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Pow", MTY(FLOAT), aTwo, 2, MathPow, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Remainder", MTY(FLOAT), aTwo, 2, MathRemainder, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "Round", MTY(FLOAT), aRound, 3, MathRound, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "Round", MTY(FLOAT), tRound, 3, MathRound, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "ScaleB", MTY(FLOAT), aScaleB, 2, MathScaleB, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Sign", MTY(INT), aOne, 1, MathSign, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, { "Sin", MTY(FLOAT), aOne, 1, MathSin, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, @@ -661,6 +662,14 @@ static sxi32 MathRegisterClasses(ph7_vm *pVm) { { "Truncate", MTY(FLOAT), aOne, 1, MathTruncate, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, }; static const char *const aExcBase[] = { "Exception" }; + /* Mutable registration data lives on the stack; the templates stay const. */ + ph7_constant_def aMathConst[SX_ARRAYSIZE(tMathConst)]; + ph7_constant_def aExceptionConst[SX_ARRAYSIZE(tExceptionConst)]; + ph7_param_def aExcCtor[SX_ARRAYSIZE(tExcCtor)]; + ph7_param_def aRound[SX_ARRAYSIZE(tRound)]; + ph7_param_def aLog[SX_ARRAYSIZE(tLog)]; + ph7_method_def aExcMethod[SX_ARRAYSIZE(tExcMethod)]; + ph7_method_def aMathMethod[SX_ARRAYSIZE(tMathMethod)]; ph7_class_def sExc = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, MCLS_EXC, 0, 0, aExceptionConst, SX_ARRAYSIZE(aExceptionConst), aExcMethod, SX_ARRAYSIZE(aExcMethod), 0, aExcBase, 1, 0, 0, 0, 0 }; @@ -676,6 +685,21 @@ static sxi32 MathRegisterClasses(ph7_vm *pVm) { SyZero(apMath, sizeof(apMath)); SyZero(apExc, sizeof(apExc)); SyZero(apDefault, sizeof(apDefault)); + memcpy(aMathConst, tMathConst, sizeof(tMathConst)); + memcpy(aExceptionConst, tExceptionConst, sizeof(tExceptionConst)); + memcpy(aExcCtor, tExcCtor, sizeof(tExcCtor)); + memcpy(aRound, tRound, sizeof(tRound)); + memcpy(aLog, tLog, sizeof(tLog)); + memcpy(aExcMethod, tExcMethod, sizeof(tExcMethod)); + memcpy(aMathMethod, tMathMethod, sizeof(tMathMethod)); + aExcMethod[0].aParam = aExcCtor; + for(n = 0 ; n < SX_ARRAYSIZE(aMathMethod) ; ++n) { + if(aMathMethod[n].xFunc == MathLog) { + aMathMethod[n].aParam = aLog; + } else if(aMathMethod[n].xFunc == MathRound) { + aMathMethod[n].aParam = aRound; + } + } /* Constant and default snapshots. A fresh scalar is NULL, which is the * exact default required for Log()'s optional newBase. */ for(n = 0 ; n < SX_ARRAYSIZE(apMath) ; ++n) { diff --git a/modules/system/system.c b/modules/system/system.c index 16532b9..47b5725 100644 --- a/modules/system/system.c +++ b/modules/system/system.c @@ -50,7 +50,8 @@ static int SystemIoError(ph7_context *pCtx, const char *zMsg) { static int SystemEnvName(ph7_context *pCtx, ph7_value *pArg, const char **pzName) { const char *zData; int nByte = 0; - if(pArg == 0 || (pArg->nType & MEMOBJ_NULL) || !ph7_value_is_string(pArg)) { + if(pArg == 0 || (pArg->nType & (MEMOBJ_NULL | MEMOBJ_VOID)) || + !ph7_value_is_string(pArg)) { return SystemArgError(pCtx, "Environment variable name must be a string"); } zData = ph7_value_to_string(pArg, &nByte); @@ -386,7 +387,7 @@ static int System_GetMemoryLimit(ph7_context *pCtx, int nArg, ph7_value **apArg) } static int System_Sleep(ph7_context *pCtx, int nArg, ph7_value **apArg) { ph7_int64 iMs; - if(nArg < 1 || apArg[0] == 0 || (apArg[0]->nType & MEMOBJ_NULL) || + if(nArg < 1 || apArg[0] == 0 || (apArg[0]->nType & (MEMOBJ_NULL | MEMOBJ_VOID)) || !ph7_value_is_int(apArg[0])) { return SystemArgError(pCtx, "Sleep() expects an integer number of milliseconds"); } @@ -402,7 +403,7 @@ static int System_Sleep(ph7_context *pCtx, int nArg, ph7_value **apArg) { static int System_Exit(ph7_context *pCtx, int nArg, ph7_value **apArg) { sxi32 iStatus = 0; if(nArg > 0) { - if(apArg[0] == 0 || (apArg[0]->nType & MEMOBJ_NULL) || + if(apArg[0] == 0 || (apArg[0]->nType & (MEMOBJ_NULL | MEMOBJ_VOID)) || !ph7_value_is_int(apArg[0])) { return SystemArgError(pCtx, "Exit() expects an integer status code"); } @@ -696,27 +697,33 @@ static sxi32 SystemRegisterClasses(ph7_vm *pVm) { #define SYSC(N) { N, 0, PH7_MEMBER_PUBLIC, 0, 0 } #define SYSM(NAME,RET,PARAMS,NPARAM,FUNC) \ { NAME, STY(RET), PARAMS, NPARAM, FUNC, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC } - static ph7_constant_def aConst[] = { + static const ph7_constant_def tConst[] = { SYSC("ERROR_NONE"), SYSC("ERROR_ARGUMENT"), SYSC("ERROR_IO"), SYSC("NEW_LINE") }; static const int aConstValue[] = { SYS_ERROR_NONE, SYS_ERROR_ARGUMENT, SYS_ERROR_IO }; - static ph7_param_def aExcCtor[] = { + static const ph7_param_def tExcCtor[] = { { "message", STY(STRING), 0, 0, 0, 0 }, { "code", STY(INT), 0, 0, 0, 0 } }; - static const ph7_param_def aNameParam[] = { { "name", STY(STRING), 0, 0, 0, 0 } }; /* MIXED, not STRING: a STRING formal casts NULL to "" before the callback, - * but NULL is the "remove variable" sentinel here. */ + * but a wrong type or NULL must reach SystemEnvName() as-is so it can raise + * SystemException(ERROR_ARGUMENT) instead of a VM overload error. */ + static const ph7_param_def aNameParam[] = { { "name", STY(MIXED), 0, 0, 0, 0 } }; + /* MIXED, not STRING: a STRING formal casts NULL to "" before the callback, + * but NULL is the "remove variable" sentinel here. The name is MIXED too, + * so a wrong type reaches the shared SystemEnvName() validator. */ static const ph7_param_def aSetParam[] = { - { "name", STY(STRING), 0, 0, 0, 0 }, + { "name", STY(MIXED), 0, 0, 0, 0 }, { "value", STY(MIXED), 0, 0, 0, 0 } }; - static const ph7_param_def aIntParam[] = { { "milliseconds", STY(INT), 0, 0, 0, 0 } }; + /* MIXED so a wrong-typed delay reaches System_Sleep() and raises + * SystemException(ERROR_ARGUMENT) instead of a VM overload error. */ + static const ph7_param_def aIntParam[] = { { "milliseconds", STY(MIXED), 0, 0, 0, 0 } }; /* MIXED so a wrong-typed status reaches System_Exit() and raises * SystemException(ERROR_ARGUMENT) instead of a VM overload error. */ - static ph7_param_def aExitParam[] = { { "code", STY(MIXED), 0, 0, 0, 0 } }; - static const ph7_method_def aExcMethod[] = { - { "__construct", STY(VOID), aExcCtor, 2, SystemExceptionConstruct, 0, 0 } + static const ph7_param_def tExitParam[] = { { "code", STY(MIXED), 0, 0, 0, 0 } }; + static const ph7_method_def tExcMethod[] = { + { "__construct", STY(VOID), tExcCtor, 2, SystemExceptionConstruct, 0, 0 } }; static const ph7_method_def aMethodCommon[] = { { "__construct", STY(VOID), 0, 0, SystemConstruct, 0, PH7_MEMBER_PRIVATE }, @@ -732,7 +739,7 @@ static sxi32 SystemRegisterClasses(ph7_vm *pVm) { SYSM("GetPeakMemoryUsage", INT, 0, 0, System_GetPeakMemoryUsage), SYSM("GetMemoryLimit", INT, 0, 0, System_GetMemoryLimit), SYSM("Sleep", VOID, aIntParam, 1, System_Sleep), - SYSM("Exit", VOID, aExitParam, 1, System_Exit) + SYSM("Exit", VOID, tExitParam, 1, System_Exit) }; static const ph7_method_def aMethodCli[] = { { "GetEnvironmentVariables", { PH7_TYPE_STRING, 0, 1 }, 0, 0, @@ -745,6 +752,11 @@ static sxi32 SystemRegisterClasses(ph7_vm *pVm) { SYSM("GetOSVersion", STRING, 0, 0, System_GetOSVersion) }; static const char *const aExcBase[] = { "Exception" }; + /* Mutable registration data lives on the stack; the templates above stay const. */ + ph7_constant_def aConst[SX_ARRAYSIZE(tConst)]; + ph7_param_def aExcCtor[SX_ARRAYSIZE(tExcCtor)]; + ph7_param_def aExitParam[SX_ARRAYSIZE(tExitParam)]; + ph7_method_def aExcMethod[SX_ARRAYSIZE(tExcMethod)]; ph7_method_def aMethod[SX_ARRAYSIZE(aMethodCommon) + SX_ARRAYSIZE(aMethodCli)]; ph7_class_def sExc = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, SCLS_EXC, @@ -762,6 +774,11 @@ static sxi32 SystemRegisterClasses(ph7_vm *pVm) { sxi32 rc = PH7_OK; SyZero(apConst, sizeof(apConst)); SyZero(apDefault, sizeof(apDefault)); + memcpy(aConst, tConst, sizeof(tConst)); + memcpy(aExcCtor, tExcCtor, sizeof(tExcCtor)); + memcpy(aExitParam, tExitParam, sizeof(tExitParam)); + memcpy(aExcMethod, tExcMethod, sizeof(tExcMethod)); + aExcMethod[0].aParam = aExcCtor; /* Constant and default snapshots; ph7_create_class() deep-copies them. */ for(n = 0 ; n < SX_ARRAYSIZE(apConst) ; ++n) { apConst[n] = ph7_new_scalar(pVm); @@ -800,6 +817,12 @@ static sxi32 SystemRegisterClasses(ph7_vm *pVm) { memcpy(aMethod + SX_ARRAYSIZE(aMethodCommon), aMethodCli, sizeof(aMethodCli)); sSystem.nMethod += SX_ARRAYSIZE(aMethodCli); } + /* aExitParam is a local copy: point Exit() at it, not at the const template. */ + for(n = 0 ; n < sSystem.nMethod ; ++n) { + if(aMethod[n].xFunc == System_Exit) { + aMethod[n].aParam = aExitParam; + } + } rc = ph7_create_class(pVm, &sExc); if(rc == PH7_OK) { rc = ph7_create_class(pVm, &sSystem); diff --git a/modules/xml/xml.c b/modules/xml/xml.c index 6c33284..111aece 100644 --- a/modules/xml/xml.c +++ b/modules/xml/xml.c @@ -8,6 +8,7 @@ */ #include #include +#include #include "xml.h" /* @@ -826,7 +827,7 @@ static int XmlReaderParse(ph7_context *pCtx, int nArg, ph7_value **apArg) { pEngine->nErrLine, pEngine->nErrCol); } if(pEngine->bAbort) { - return PH7_ABORT; /* e.g. exit() from OnDoctype rejects the document */ + return PH7_ABORT; /* e.g. System::Exit() from OnDoctype rejects the document */ } return PH7_OK; /* void */ } @@ -1018,9 +1019,9 @@ static int XmlReaderClearHandler(ph7_context *pCtx, int nArg, ph7_value **apArg) #define XNM(N) { PH7_TYPE_NAMED, N, 0 } #define XP(N,T) { N, XTY(T), 0, 0, 0, 0 } -/* The pValue pointers are filled in per VM registration and cleared again - * afterwards: these tables are static and must never retain a stale value. */ -static ph7_constant_def aExceptionConst[] = { +/* Immutable template: each registration copies it to a local array and fills + * those pValue pointers there, so no static object ever holds a VM value. */ +static const ph7_constant_def tExceptionConst[] = { { "ERROR_NONE", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_NO_MEMORY", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_SYNTAX", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -1064,10 +1065,10 @@ static sxi32 XmlRegisterClasses(ph7_vm *pVm) { static const ph7_param_def aReaderInt[] = { XP("index", INT) }; static const ph7_param_def aReaderString[] = { XP("name", STRING) }; static const ph7_param_def aReaderPrefix[] = { XP("prefix", STRING) }; - static ph7_param_def aCtor[] = { XP("namespaces", BOOL) }; + static const ph7_param_def tCtor[] = { XP("namespaces", BOOL) }; static const ph7_param_def aParse[] = { XP("data", MIXED) }; static const ph7_param_def aSetHandler[] = { { "handler", XNM("IXmlHandler"), 0, 0, 0, 0 } }; - static ph7_param_def aExcCtor[] = { + static const ph7_param_def tExcCtor[] = { XP("message", STRING), XP("code", INT), XP("inputLine", INT), XP("inputColumn", INT) }; static const ph7_param_def aExcDesc[] = { XP("code", INT) }; @@ -1131,16 +1132,16 @@ static sxi32 XmlRegisterClasses(ph7_vm *pVm) { { "inputColumn", XTY(INT), 0, PH7_MEMBER_PRIVATE, 0, 0 } }; static const char *const aExcBase[] = { "Exception" }; - static const ph7_method_def aExcMethod[] = { - { "__construct", XTY(VOID), aExcCtor, 4, XmlExceptionConstruct, 0, 0 }, + static const ph7_method_def tExcMethod[] = { + { "__construct", XTY(VOID), tExcCtor, 4, XmlExceptionConstruct, 0, 0 }, { "GetInputLine", XTY(INT), 0, 0, XmlExceptionField, (void *)"inputLine", PH7_MEMBER_PUBLIC }, { "GetInputColumn", XTY(INT), 0, 0, XmlExceptionField, (void *)"inputColumn", PH7_MEMBER_PUBLIC }, { "GetDescription", XTY(STRING), aExcDesc, 1, XmlExceptionGetDescription, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC } }; /* XmlReader methods */ - static const ph7_method_def aReaderMethod[] = { - { "__construct", XTY(VOID), aCtor, 1, XmlReaderConstruct, 0, 0 }, + static const ph7_method_def tReaderMethod[] = { + { "__construct", XTY(VOID), tCtor, 1, XmlReaderConstruct, 0, 0 }, { "Parse", XTY(VOID), aParse, 1, XmlReaderParse, 0, PH7_MEMBER_PUBLIC }, { "Close", XTY(VOID), 0, 0, XmlReaderClose, 0, PH7_MEMBER_PUBLIC }, { "__destruct", XTY(VOID), 0, 0, XmlReaderDestruct, 0, 0 }, @@ -1164,6 +1165,12 @@ static sxi32 XmlRegisterClasses(ph7_vm *pVm) { static const ph7_field_def aReaderField[] = { { "resource", XTY(RESOURCE), 0, PH7_MEMBER_PRIVATE, 0, 0 } }; + /* Mutable registration data lives on the stack; the templates stay const. */ + ph7_constant_def aExceptionConst[SX_ARRAYSIZE(tExceptionConst)]; + ph7_param_def aCtor[SX_ARRAYSIZE(tCtor)]; + ph7_param_def aExcCtor[SX_ARRAYSIZE(tExcCtor)]; + ph7_method_def aExcMethod[SX_ARRAYSIZE(tExcMethod)]; + ph7_method_def aReaderMethod[SX_ARRAYSIZE(tReaderMethod)]; ph7_class_def sIface = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, "IXmlHandler", 0, 0, 0, 0, aIfaceMethod, SX_ARRAYSIZE(aIfaceMethod), PH7_DECL_INTERFACE, 0, 0, 0, 0, 0, 0 }; @@ -1181,6 +1188,13 @@ static sxi32 XmlRegisterClasses(ph7_vm *pVm) { ph7_value *apErrVal[SX_ARRAYSIZE(aExceptionConst)]; sxu32 n; sxi32 rc; + memcpy(aExceptionConst, tExceptionConst, sizeof(tExceptionConst)); + memcpy(aCtor, tCtor, sizeof(tCtor)); + memcpy(aExcCtor, tExcCtor, sizeof(tExcCtor)); + memcpy(aExcMethod, tExcMethod, sizeof(tExcMethod)); + memcpy(aReaderMethod, tReaderMethod, sizeof(tReaderMethod)); + aExcMethod[0].aParam = aExcCtor; + aReaderMethod[0].aParam = aCtor; for(n = 0 ; n < SX_ARRAYSIZE(aDefault) ; ++n) { aDefault[n] = ph7_new_scalar(pVm); if(aDefault[n] == 0) { @@ -1219,7 +1233,7 @@ static sxi32 XmlRegisterClasses(ph7_vm *pVm) { if(rc == PH7_OK) rc = ph7_create_class(pVm, &sReader); for(n = 0 ; n < SX_ARRAYSIZE(aExceptionConst) ; ++n) { ph7_release_value(pVm, apErrVal[n]); - aExceptionConst[n].pValue = 0; /* static table: no dangling pointer across VMs */ + aExceptionConst[n].pValue = 0; /* local copy: no dangling pointer across VMs */ } aCtor[0].pDefault = 0; aExcCtor[2].pDefault = 0; diff --git a/modules/yaml/yaml.c b/modules/yaml/yaml.c index 11977aa..db08d1a 100644 --- a/modules/yaml/yaml.c +++ b/modules/yaml/yaml.c @@ -5272,7 +5272,7 @@ static int YamlSerializeAllFn(ph7_context *pCtx, int nArg, ph7_value **apArg) { /* ------------------------------------------------------------------ */ /* Native class registration */ /* ------------------------------------------------------------------ */ -static ph7_constant_def aNodeTypeConst[] = { +static const ph7_constant_def tNodeTypeConst[] = { { "MAPPING", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "SEQUENCE", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "STRING", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -5285,7 +5285,7 @@ static const int aNodeTypeValue[] = { YAML_NODE_MAPPING, YAML_NODE_SEQUENCE, YAML_NODE_STRING, YAML_NODE_INT, YAML_NODE_FLOAT, YAML_NODE_BOOLEAN, YAML_NODE_NULL_NODE }; -static ph7_constant_def aExceptionConst[] = { +static const ph7_constant_def tExceptionConst[] = { { "ERROR_NONE", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_DEPTH", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "ERROR_SYNTAX", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -5310,7 +5310,7 @@ static const int aExceptionValue[] = { YAML_ERROR_READONLY_OPTION, YAML_ERROR_UNDEFINED_ALIAS, YAML_ERROR_ALIAS_LIMIT, YAML_ERROR_UNKNOWN_TAG, YAML_ERROR_UNSUPPORTED, YAML_ERROR_ALIAS_NOT_ALLOWED }; -static ph7_constant_def aOptionsConst[] = { +static const ph7_constant_def tOptionsConst[] = { { "KEEP_LAST", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "KEEP_FIRST", 0, PH7_MEMBER_PUBLIC, 0, 0 }, { "REJECT", 0, PH7_MEMBER_PUBLIC, 0, 0 }, @@ -5330,7 +5330,7 @@ static const int aOptionsValue[] = { }; static sxi32 YamlRegisterClasses(ph7_vm *pVm) { - static ph7_param_def aExcCtor[] = { + static const ph7_param_def tExcCtor[] = { YP("message", STRING), YP("code", INT), YPN("inputLine", YTY(INT)), YPN("inputColumn", YTY(INT)), YPN("path", YTY(STRING)) }; @@ -5348,34 +5348,34 @@ static sxi32 YamlRegisterClasses(ph7_vm *pVm) { static const ph7_param_def aNodeCtorInt[] = { YP("value", INT) }; static const ph7_param_def aNodeCtorFloat[] = { YP("value", FLOAT) }; static const ph7_param_def aNodeCtorBool[] = { YP("value", BOOL) }; - static ph7_param_def aToYaml[] = { YPO("options", YNM(YCLS_OPTIONS), 0) }; + static const ph7_param_def tToYaml[] = { YPO("options", YNM(YCLS_OPTIONS), 0) }; static const ph7_param_def aSetBool[] = { YP("value", BOOL) }; static const ph7_param_def aSetInt[] = { YP("value", INT) }; - static ph7_param_def aParse[] = { + static const ph7_param_def tParse[] = { YP("text", STRING), YPO("options", YNM(YCLS_OPTIONS), 0) }; - static ph7_param_def aSetRoot[] = { YPN("node", YNM(YCLS_NODE)) }; - static ph7_param_def aSerialize[] = { + static const ph7_param_def aSetRoot[] = { YPN("node", YNM(YCLS_NODE)) }; + static const ph7_param_def tSerialize[] = { YPN("node", YNM(YCLS_NODE)), YPO("options", YNM(YCLS_OPTIONS), 0) }; - static ph7_param_def aSerializeAll[] = { + static const ph7_param_def tSerializeAll[] = { YPN("documents", YAR(YCLS_DOC)), YPO("options", YNM(YCLS_OPTIONS), 0) }; - static const ph7_method_def aExcMethod[] = { - { "__construct", YTY(VOID), aExcCtor, 5, YamlExceptionConstruct, 0, 0 }, + static const ph7_method_def tExcMethod[] = { + { "__construct", YTY(VOID), tExcCtor, 5, YamlExceptionConstruct, 0, 0 }, { "GetInputLine", YTY(INT), 0, 0, YamlExceptionField, (void *)"inputLine", PH7_MEMBER_PUBLIC }, { "GetInputColumn", YTY(INT), 0, 0, YamlExceptionField, (void *)"inputColumn", PH7_MEMBER_PUBLIC }, { "GetPath", YTY(STRING), 0, 0, YamlExceptionField, (void *)"path", PH7_MEMBER_PUBLIC }, { "GetDescription", YTY(STRING), aExcDesc, 1, YamlExceptionDescription, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC } }; - static ph7_field_def aExcField[] = { + static const ph7_field_def aExcField[] = { { "inputLine", YTY(INT), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "inputColumn", YTY(INT), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "path", YTY(STRING), 0, PH7_MEMBER_PRIVATE, 0, 0 }, }; static const char *const aExcBase[] = { "Exception" }; - static const ph7_method_def aNodeMethod[] = { + static const ph7_method_def tNodeMethod[] = { { "GetNodeType", YTY(INT), 0, 0, YamlNodeGetIntField, (void *)"kind", PH7_MEMBER_PUBLIC }, { "GetPath", YTY(STRING), 0, 0, YamlNodeGetStrField, (void *)"path", PH7_MEMBER_PUBLIC }, { "GetDepth", YTY(INT), 0, 0, YamlNodeGetDepth, 0, PH7_MEMBER_PUBLIC }, @@ -5398,10 +5398,10 @@ static sxi32 YamlRegisterClasses(ph7_vm *pVm) { { "GetBool", YTY(BOOL), 0, 0, YamlNodeGetBool, 0, PH7_MEMBER_PUBLIC }, { "GetRawValue", YTY(STRING), 0, 0, YamlNodeGetRawValue, 0, PH7_MEMBER_PUBLIC }, { "IsNull", YTY(BOOL), 0, 0, YamlNodeIsNull, 0, PH7_MEMBER_PUBLIC }, - { "ToYaml", YTY(STRING), aToYaml, 1, YamlNodeToYaml, 0, PH7_MEMBER_PUBLIC }, + { "ToYaml", YTY(STRING), tToYaml, 1, YamlNodeToYaml, 0, PH7_MEMBER_PUBLIC }, { "__toString", YTY(STRING), 0, 0, YamlNodeToString, 0, 0 }, }; - static ph7_field_def aNodeField[] = { + static const ph7_field_def tNodeField[] = { { "kind", YTY(INT), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "path", YTY(STRING), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "text", YTY(STRING), 0, PH7_MEMBER_PRIVATE, 0, 0 }, @@ -5436,7 +5436,7 @@ static sxi32 YamlRegisterClasses(ph7_vm *pVm) { static const ph7_method_def aNullMethod[] = { { "__construct", YTY(VOID), 0, 0, YamlNodeConstruct, (void *)(long)YAML_NODE_NULL_NODE, 0 } }; - static ph7_field_def aOptField[] = { + static const ph7_field_def tOptField[] = { { "allowUnicode", YTY(BOOL), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "allowAliases", YTY(BOOL), 0, PH7_MEMBER_PRIVATE, 0, 0 }, { "maxAliasExpansion", YTY(INT), 0, PH7_MEMBER_PRIVATE, 0, 0 }, @@ -5491,23 +5491,38 @@ static sxi32 YamlRegisterClasses(ph7_vm *pVm) { { "GetIndent", YTY(INT), 0, 0, YamlOptionsGet, (void *)"indent", PH7_MEMBER_PUBLIC }, { "SetIndent", YTY(VOID), aSetInt, 1, YamlOptionsSetInt, (void *)"indent", PH7_MEMBER_PUBLIC }, }; - static const ph7_method_def aDocMethod[] = { + static const ph7_method_def tDocMethod[] = { { "__construct", YTY(VOID), 0, 0, YamlDocumentConstruct, 0, 0 }, - { "Parse", YTY(VOID), aParse, 2, YamlDocumentParse, 0, PH7_MEMBER_PUBLIC }, + { "Parse", YTY(VOID), tParse, 2, YamlDocumentParse, 0, PH7_MEMBER_PUBLIC }, { "GetRoot", YNM(YCLS_NODE), 0, 0, YamlDocumentGetRoot, 0, PH7_MEMBER_PUBLIC }, { "SetRoot", YTY(VOID), aSetRoot, 1, YamlDocumentSetRoot, 0, PH7_MEMBER_PUBLIC }, - { "ToYaml", YTY(STRING), aToYaml, 1, YamlDocumentToYaml, 0, PH7_MEMBER_PUBLIC }, + { "ToYaml", YTY(STRING), tToYaml, 1, YamlDocumentToYaml, 0, PH7_MEMBER_PUBLIC }, }; - static ph7_field_def aDocField[] = { + static const ph7_field_def aDocField[] = { { "root", YNM(YCLS_NODE), 0, PH7_MEMBER_PRIVATE, 0, 0 }, }; - static const ph7_method_def aFacadeMethod[] = { - { "Parse", YNM(YCLS_DOC), aParse, 2, YamlParse, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "ParseAll", YAR(YCLS_DOC), aParse, 2, YamlParseAll, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "ParseNode", YNM(YCLS_NODE), aParse, 2, YamlParseNode, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "Serialize", YTY(STRING), aSerialize, 2, YamlSerializeFn, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, - { "SerializeAll", YTY(STRING), aSerializeAll, 2, YamlSerializeAllFn, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + static const ph7_method_def tFacadeMethod[] = { + { "Parse", YNM(YCLS_DOC), tParse, 2, YamlParse, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "ParseAll", YAR(YCLS_DOC), tParse, 2, YamlParseAll, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "ParseNode", YNM(YCLS_NODE), tParse, 2, YamlParseNode, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "Serialize", YTY(STRING), tSerialize, 2, YamlSerializeFn, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, + { "SerializeAll", YTY(STRING), tSerializeAll, 2, YamlSerializeAllFn, 0, PH7_MEMBER_PUBLIC | PH7_MEMBER_STATIC }, }; + /* Mutable registration data lives on the stack; the templates stay const. */ + ph7_constant_def aNodeTypeConst[SX_ARRAYSIZE(tNodeTypeConst)]; + ph7_constant_def aExceptionConst[SX_ARRAYSIZE(tExceptionConst)]; + ph7_constant_def aOptionsConst[SX_ARRAYSIZE(tOptionsConst)]; + ph7_param_def aExcCtor[SX_ARRAYSIZE(tExcCtor)]; + ph7_param_def aToYaml[SX_ARRAYSIZE(tToYaml)]; + ph7_param_def aParse[SX_ARRAYSIZE(tParse)]; + ph7_param_def aSerialize[SX_ARRAYSIZE(tSerialize)]; + ph7_param_def aSerializeAll[SX_ARRAYSIZE(tSerializeAll)]; + ph7_field_def aNodeField[SX_ARRAYSIZE(tNodeField)]; + ph7_field_def aOptField[SX_ARRAYSIZE(tOptField)]; + ph7_method_def aExcMethod[SX_ARRAYSIZE(tExcMethod)]; + ph7_method_def aNodeMethod[SX_ARRAYSIZE(tNodeMethod)]; + ph7_method_def aDocMethod[SX_ARRAYSIZE(tDocMethod)]; + ph7_method_def aFacadeMethod[SX_ARRAYSIZE(tFacadeMethod)]; ph7_class_def sExc = { sizeof(ph7_class_def), PH7_CLASS_DEF_VERSION, YCLS_EXC, aExcField, SX_ARRAYSIZE(aExcField), aExceptionConst, SX_ARRAYSIZE(aExceptionConst), aExcMethod, SX_ARRAYSIZE(aExcMethod), 0, aExcBase, 1, 0, 0, 0, 0 }; @@ -5554,6 +5569,43 @@ static sxi32 YamlRegisterClasses(ph7_vm *pVm) { SyZero(apOptConst, sizeof(apOptConst)); SyZero(apInit, sizeof(apInit)); SyZero(apCtorDef, sizeof(apCtorDef)); + memcpy(aNodeTypeConst, tNodeTypeConst, sizeof(tNodeTypeConst)); + memcpy(aExceptionConst, tExceptionConst, sizeof(tExceptionConst)); + memcpy(aOptionsConst, tOptionsConst, sizeof(tOptionsConst)); + memcpy(aExcCtor, tExcCtor, sizeof(tExcCtor)); + memcpy(aToYaml, tToYaml, sizeof(tToYaml)); + memcpy(aParse, tParse, sizeof(tParse)); + memcpy(aSerialize, tSerialize, sizeof(tSerialize)); + memcpy(aSerializeAll, tSerializeAll, sizeof(tSerializeAll)); + memcpy(aNodeField, tNodeField, sizeof(tNodeField)); + memcpy(aOptField, tOptField, sizeof(tOptField)); + memcpy(aExcMethod, tExcMethod, sizeof(tExcMethod)); + memcpy(aNodeMethod, tNodeMethod, sizeof(tNodeMethod)); + memcpy(aDocMethod, tDocMethod, sizeof(tDocMethod)); + memcpy(aFacadeMethod, tFacadeMethod, sizeof(tFacadeMethod)); + aExcMethod[0].aParam = aExcCtor; + for(n = 0 ; n < SX_ARRAYSIZE(aNodeMethod) ; ++n) { + if(aNodeMethod[n].xFunc == YamlNodeToYaml) { + aNodeMethod[n].aParam = aToYaml; + } + } + for(n = 0 ; n < SX_ARRAYSIZE(aDocMethod) ; ++n) { + if(aDocMethod[n].xFunc == YamlDocumentParse) { + aDocMethod[n].aParam = aParse; + } else if(aDocMethod[n].xFunc == YamlDocumentToYaml) { + aDocMethod[n].aParam = aToYaml; + } + } + for(n = 0 ; n < SX_ARRAYSIZE(aFacadeMethod) ; ++n) { + if(aFacadeMethod[n].xFunc == YamlParse || aFacadeMethod[n].xFunc == YamlParseAll || + aFacadeMethod[n].xFunc == YamlParseNode) { + aFacadeMethod[n].aParam = aParse; + } else if(aFacadeMethod[n].xFunc == YamlSerializeFn) { + aFacadeMethod[n].aParam = aSerialize; + } else if(aFacadeMethod[n].xFunc == YamlSerializeAllFn) { + aFacadeMethod[n].aParam = aSerializeAll; + } + } /* Allocate constant and default snapshots. */ for(n = 0 ; n < SX_ARRAYSIZE(apExc) ; ++n) { apExc[n] = ph7_new_scalar(pVm);