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

This commit is contained in:
2026-11-24 15:44:06 +01:00
parent 1db842fe0f
commit 0802b294b4
12 changed files with 311 additions and 108 deletions
+8 -5
View File
@@ -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) {