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:
+76
-23
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user