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