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:
+32
-7
@@ -5,6 +5,7 @@
|
||||
* @DESCRIPTION Native declarations for the built-in classes
|
||||
* @DEVELOPERS Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
*/
|
||||
#include <string.h>
|
||||
#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]);
|
||||
|
||||
Reference in New Issue
Block a user