Add system module with System class, core native exception helper and remove useless builtins
Build / AerScript (push) Successful in 50s
Build / AerScript (push) Successful in 50s
This commit is contained in:
@@ -431,6 +431,121 @@ PH7_PRIVATE sxi32 PH7_VmThrowIoException(ph7_context *pCtx, int nCode, const cha
|
||||
rc = ph7_result_value(pCtx, pObj);
|
||||
return rc == PH7_OK ? PH7_EXCEPTION : rc;
|
||||
}
|
||||
/* Stamp file/line with the first script frame of the active call stack for the
|
||||
* generic native-exception thrower. Native frames ([NATIVE], line 0) are
|
||||
* skipped so a catch(Exception $e) observes the script location that raised
|
||||
* the error. IOException keeps its own stamp because its constructor already
|
||||
* performs one. */
|
||||
static void NativeExceptionStampSite(ph7_vm *pVm, ph7_class_instance *pInst) {
|
||||
SySet sTrace;
|
||||
VmDebugTrace *pTrace;
|
||||
ph7_value *pField;
|
||||
if(VmExtractDebugTrace(pVm, &sTrace) != SXRET_OK) {
|
||||
return;
|
||||
}
|
||||
while(SySetGetNextEntry(&sTrace, (void **)&pTrace) == SXRET_OK) {
|
||||
if(pTrace->pFile == 0 || pTrace->nLine == 0) {
|
||||
continue;
|
||||
}
|
||||
if(pTrace->pFile->nByte == sizeof("[NATIVE]") - 1 &&
|
||||
SyMemcmp(pTrace->pFile->zString, "[NATIVE]", sizeof("[NATIVE]") - 1) == 0) {
|
||||
continue;
|
||||
}
|
||||
pField = IoInstField(pInst, "file");
|
||||
if(pField) {
|
||||
PH7_MemObjRelease(pField);
|
||||
PH7_MemObjInit(pVm, pField);
|
||||
(void)ph7_value_string(pField, pTrace->pFile->zString, (int)pTrace->pFile->nByte);
|
||||
}
|
||||
pField = IoInstField(pInst, "line");
|
||||
if(pField) {
|
||||
(void)ph7_value_int64(pField, (ph7_int64)pTrace->nLine);
|
||||
}
|
||||
break;
|
||||
}
|
||||
SySetRelease(&sTrace);
|
||||
}
|
||||
/* Core-owned throw used by native modules that publish a custom exception
|
||||
* class (MathException, CharException, ...). The named class constructor is
|
||||
* invoked with (message, code), the instance is stamped and published as the
|
||||
* context result; every temporary is released on all paths. */
|
||||
PH7_PRIVATE sxi32 PH7_VmThrowNativeException(ph7_context *pCtx, const char *zClass,
|
||||
int nCode, const char *zMessage) {
|
||||
ph7_vm *pVm = pCtx->pVm;
|
||||
ph7_class *pClass;
|
||||
ph7_class_instance *pInst;
|
||||
ph7_class_method *pCons;
|
||||
ph7_value *pObj, *apArg[2], *aTmp[2];
|
||||
sxi32 rc;
|
||||
sxu32 n;
|
||||
if(pVm->iPendingTransfer) {
|
||||
return PH7_EXCEPTION; /* a handler exception takes precedence */
|
||||
}
|
||||
pClass = PH7_VmExtractClass(pVm, zClass, (sxu32)SyStrlen(zClass), FALSE);
|
||||
if(pClass == 0) {
|
||||
return PH7_ABORT;
|
||||
}
|
||||
pInst = PH7_NewClassInstance(pVm, pClass);
|
||||
if(pInst == 0) {
|
||||
PH7_VmMemoryError(pVm);
|
||||
return PH7_ABORT;
|
||||
}
|
||||
for(n = 0 ; n < SX_ARRAYSIZE(aTmp) ; ++n) {
|
||||
aTmp[n] = ph7_context_new_scalar(pCtx);
|
||||
if(aTmp[n] == 0) {
|
||||
while(n > 0) {
|
||||
--n;
|
||||
ph7_context_release_value(pCtx, aTmp[n]);
|
||||
}
|
||||
PH7_ClassInstanceUnref(pInst);
|
||||
PH7_VmMemoryError(pVm);
|
||||
return PH7_ABORT;
|
||||
}
|
||||
}
|
||||
pObj = ph7_context_new_scalar(pCtx);
|
||||
if(pObj == 0) {
|
||||
for(n = 0 ; n < SX_ARRAYSIZE(aTmp) ; ++n) {
|
||||
ph7_context_release_value(pCtx, aTmp[n]);
|
||||
}
|
||||
PH7_ClassInstanceUnref(pInst);
|
||||
PH7_VmMemoryError(pVm);
|
||||
return PH7_ABORT;
|
||||
}
|
||||
ph7_value_string(aTmp[0], zMessage, -1);
|
||||
ph7_value_int(aTmp[1], nCode);
|
||||
for(n = 0 ; n < SX_ARRAYSIZE(apArg) ; ++n) {
|
||||
apArg[n] = aTmp[n];
|
||||
}
|
||||
pCons = PH7_ClassExtractMethod(pClass, "__construct", sizeof("__construct") - 1);
|
||||
if(pCons) {
|
||||
rc = PH7_VmCallClassMethod(pVm, pInst, pCons, 0, 2, apArg);
|
||||
if(pInst->iRef < 1) {
|
||||
pInst->iRef = 1;
|
||||
}
|
||||
for(n = 0 ; n < SX_ARRAYSIZE(aTmp) ; ++n) {
|
||||
ph7_context_release_value(pCtx, aTmp[n]);
|
||||
}
|
||||
if(rc != PH7_OK) {
|
||||
ph7_context_release_value(pCtx, pObj);
|
||||
PH7_ClassInstanceUnref(pInst);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
for(n = 0 ; n < SX_ARRAYSIZE(aTmp) ; ++n) {
|
||||
ph7_context_release_value(pCtx, aTmp[n]);
|
||||
}
|
||||
}
|
||||
NativeExceptionStampSite(pVm, pInst);
|
||||
if(pInst->iRef < 1) {
|
||||
pInst->iRef = 1;
|
||||
}
|
||||
PH7_MemObjRelease(pObj);
|
||||
pObj->x.pOther = pInst;
|
||||
MemObjSetType(pObj, MEMOBJ_OBJ);
|
||||
rc = ph7_result_value(pCtx, pObj);
|
||||
ph7_context_release_value(pCtx, pObj);
|
||||
return rc == PH7_OK ? PH7_EXCEPTION : rc;
|
||||
}
|
||||
|
||||
PH7_PRIVATE sxi32 PH7_VmInstallBuiltinClasses(ph7_vm *pVm) {
|
||||
ph7_value *apValue[4] = { 0, 0, 0, 0 };
|
||||
|
||||
+1
-25
@@ -2782,29 +2782,6 @@ static sxi32 PH7_CompileReturn(ph7_gen_state *pGen) {
|
||||
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_DONE, nRet, 0, (void *)1, 0);
|
||||
return SXRET_OK;
|
||||
}
|
||||
/*
|
||||
* Compile the die/exit language construct.
|
||||
* The role of these constructs is to terminate execution of the script.
|
||||
* Shutdown functions will always be executed even if exit() is called.
|
||||
*/
|
||||
static sxi32 PH7_CompileHalt(ph7_gen_state *pGen) {
|
||||
sxi32 nExpr = 0;
|
||||
sxi32 rc;
|
||||
/* Jump the exit keyword */
|
||||
pGen->pIn++;
|
||||
if(pGen->pIn < pGen->pEnd && (pGen->pIn->nType & PH7_TK_SEMI) == 0) {
|
||||
/* Compile the expression */
|
||||
rc = PH7_CompileExpr(&(*pGen), 0, 0);
|
||||
if(rc == SXERR_ABORT) {
|
||||
return SXERR_ABORT;
|
||||
} else if(rc != SXERR_EMPTY) {
|
||||
nExpr = 1;
|
||||
}
|
||||
}
|
||||
/* Emit the HALT instruction */
|
||||
PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_HALT, nExpr, 0, 0, 0);
|
||||
return SXRET_OK;
|
||||
}
|
||||
/*
|
||||
* Compile the var statement.
|
||||
*/
|
||||
@@ -3244,7 +3221,7 @@ static sxi32 PH7_CompileInclude(ph7_gen_state *pGen) {
|
||||
* 3 -) Function overloading!!
|
||||
* Example:
|
||||
* function foo($a) {
|
||||
* return $a.PHP_EOL;
|
||||
* return $a.PHP_INT_MAX;
|
||||
* }
|
||||
* function foo($a, $b) {
|
||||
* return $a + $b;
|
||||
@@ -5762,7 +5739,6 @@ static const LangConstruct aLangConstruct[] = {
|
||||
{ PH7_KEYWORD_RETURN, PH7_CompileReturn }, /* return statement */
|
||||
{ PH7_KEYWORD_SWITCH, PH7_CompileSwitch }, /* Switch statement */
|
||||
{ PH7_KEYWORD_DO, PH7_CompileDoWhile }, /* do{ }while(); statement */
|
||||
{ PH7_KEYWORD_EXIT, PH7_CompileHalt }, /* exit language construct */
|
||||
{ PH7_KEYWORD_TRY, PH7_CompileTry }, /* try statement */
|
||||
{ PH7_KEYWORD_THROW, PH7_CompileThrow }, /* throw statement */
|
||||
{ PH7_KEYWORD_GOTO, PH7_CompileGoto }, /* goto statement */
|
||||
|
||||
@@ -8,50 +8,6 @@
|
||||
*/
|
||||
#include "ph7int.h"
|
||||
/* This file implement built-in constants for the PH7 engine. */
|
||||
/*
|
||||
* PH7_VERSION
|
||||
* Expand the current version of the PH7 Engine.
|
||||
*/
|
||||
static void PH7_VER_Const(ph7_value *pVal, void *pUnused) {
|
||||
SXUNUSED(pUnused);
|
||||
ph7_value_string(pVal, ph7_lib_signature(), -1/*Compute length automatically*/);
|
||||
}
|
||||
#ifdef __WINNT__
|
||||
#include <Windows.h>
|
||||
#elif defined(__UNIXES__)
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
/*
|
||||
* PHP_OS
|
||||
* Expand the name of the host Operating System.
|
||||
*/
|
||||
static void PH7_OS_Const(ph7_value *pVal, void *pUnused) {
|
||||
#if defined(__WINNT__)
|
||||
ph7_value_string(pVal, "WINNT", (int)sizeof("WINNT") - 1);
|
||||
#elif defined(__UNIXES__)
|
||||
struct utsname sInfo;
|
||||
if(uname(&sInfo) != 0) {
|
||||
ph7_value_string(pVal, "Unix", (int)sizeof("Unix") - 1);
|
||||
} else {
|
||||
ph7_value_string(pVal, sInfo.sysname, -1);
|
||||
}
|
||||
#else
|
||||
ph7_value_string(pVal, "Host OS", (int)sizeof("Host OS") - 1);
|
||||
#endif
|
||||
SXUNUSED(pUnused);
|
||||
}
|
||||
/*
|
||||
* PHP_EOL
|
||||
* Expand the correct 'End Of Line' symbol for this platform.
|
||||
*/
|
||||
static void PH7_EOL_Const(ph7_value *pVal, void *pUnused) {
|
||||
SXUNUSED(pUnused);
|
||||
#ifdef __WINNT__
|
||||
ph7_value_string(pVal, "\r\n", (int)sizeof("\r\n") - 1);
|
||||
#else
|
||||
ph7_value_string(pVal, "\n", (int)sizeof(char));
|
||||
#endif
|
||||
}
|
||||
/*
|
||||
* PHP_INT_MAX
|
||||
* Expand the largest integer supported.
|
||||
@@ -1078,9 +1034,6 @@ static void PH7_EXTR_PREFIX_IF_EXISTS_Const(ph7_value *pVal, void *pUserData) {
|
||||
* Table of built-in constants.
|
||||
*/
|
||||
static const ph7_builtin_constant aBuiltIn[] = {
|
||||
{"PH7_VERSION", PH7_VER_Const },
|
||||
{"PHP_OS", PH7_OS_Const },
|
||||
{"PHP_EOL", PH7_EOL_Const },
|
||||
{"PHP_INT_MAX", PH7_INTMAX_Const },
|
||||
{"MAXINT", PH7_INTMAX_Const },
|
||||
{"PHP_INT_SIZE", PH7_INTSIZE_Const },
|
||||
|
||||
@@ -82,9 +82,6 @@ static const char *VmInstrToString(sxi32 nOp) {
|
||||
case PH7_OP_DONE:
|
||||
zOp = "DONE";
|
||||
break;
|
||||
case PH7_OP_HALT:
|
||||
zOp = "HALT";
|
||||
break;
|
||||
case PH7_OP_IMPORT:
|
||||
zOp = "IMPORT";
|
||||
break;
|
||||
|
||||
+6
-5
@@ -1648,11 +1648,12 @@ typedef struct {
|
||||
* [SXERR_ABORT]. The comparator's original status decides what the builtin
|
||||
* hands back to the VM call machinery: an exception value stored into the
|
||||
* result slot plus PH7_EXCEPTION [the VM moves that copy into the throw
|
||||
* transfer and unwinds to catch/finally], or plain PH7_ABORT for exit() or a
|
||||
* fatal raised inside the comparator. The pending carrier is released exactly
|
||||
* once here. iPendingRC == 0 means nothing was pending: internal comparators
|
||||
* [flags, keys, random] never invoke user code and never fill it, and the
|
||||
* FALSE return is kept as a defensive fallback for them. The same fallback
|
||||
* transfer and unwinds to catch/finally], or plain PH7_ABORT for an abort
|
||||
* request [System::Exit()] or a fatal raised inside the comparator. The
|
||||
* pending carrier is released exactly once here. iPendingRC == 0 means nothing
|
||||
* was pending: internal comparators [flags, keys, random] never invoke user
|
||||
* code and never fill it, and the FALSE return is kept as a defensive fallback
|
||||
* for them. The same fallback
|
||||
* also catches any THIRD status PH7_VmCallUserFunction could report beyond
|
||||
* PH7_EXCEPTION/PH7_ABORT [iPendingRC != 0 but neither known value]: every
|
||||
* call site pre-checks callability and reachable call failures abort, so no
|
||||
|
||||
@@ -642,7 +642,6 @@ static sxu32 KeywordCode(const char *z, sxu32 n) {
|
||||
/* Reserved keywords */
|
||||
{"define", PH7_KEYWORD_DEFINE},
|
||||
{"eval", PH7_KEYWORD_EVAL},
|
||||
{"exit", PH7_KEYWORD_EXIT},
|
||||
{"import", PH7_KEYWORD_IMPORT},
|
||||
{"include", PH7_KEYWORD_INCLUDE},
|
||||
{"is", PH7_KEYWORD_IS},
|
||||
|
||||
+3
-3
@@ -752,19 +752,19 @@ done:
|
||||
* {
|
||||
* public function printItem($string)
|
||||
* {
|
||||
* echo 'Foo: ' . $string . PHP_EOL;
|
||||
* echo 'Foo: ' . $string . "\n";
|
||||
* }
|
||||
*
|
||||
* public function printPHP()
|
||||
* {
|
||||
* echo 'PHP is great.' . PHP_EOL;
|
||||
* echo 'PHP is great.' . "\n";
|
||||
* }
|
||||
* }
|
||||
* class bar extends foo
|
||||
* {
|
||||
* public function printItem($string)
|
||||
* {
|
||||
* echo 'Bar: ' . $string . PHP_EOL;
|
||||
* echo 'Bar: ' . $string . "\n";
|
||||
* }
|
||||
* }
|
||||
* $foo = new foo();
|
||||
|
||||
+2
-2
@@ -318,7 +318,7 @@ static sxi32 ExprVerifyNodes(ph7_gen_state *pGen, ph7_expr_node **apNode, sxi32
|
||||
}
|
||||
/*
|
||||
* Collect and assemble tokens holding a namespace path [i.e: namespace\to\const]
|
||||
* or a simple literal [i.e: PHP_EOL].
|
||||
* or a simple literal [i.e: PHP_INT_MAX].
|
||||
*/
|
||||
static void ExprAssembleLiteral(SyToken **ppCur, SyToken *pEnd) {
|
||||
SyToken *pIn = *ppCur;
|
||||
@@ -434,7 +434,7 @@ static sxi32 ExprAssembleClosure(ph7_gen_state *pGen, SyToken **ppCur, SyToken *
|
||||
* When errors,PH7 take care of generating the appropriate error message.
|
||||
* An expression node can be a variable [i.e: $var],an operator [i.e: ++]
|
||||
* an anonymous function [i.e: function(){ return "Hello"; }, a double/single
|
||||
* quoted string, a literal [i.e: PHP_EOL],a namespace path
|
||||
* quoted string, a literal [i.e: PHP_INT_MAX],a namespace path
|
||||
* [i.e: namespaces\path\to..],an array [i.e: {4,5,6}] and so on.
|
||||
*/
|
||||
static sxi32 ExprExtractNode(ph7_gen_state *pGen, ph7_expr_node **ppNode) {
|
||||
|
||||
-467
@@ -366,88 +366,6 @@ static int PH7_vfs_realpath(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int sleep(int $seconds)
|
||||
* Delays the program execution for the given number of seconds.
|
||||
* Parameters
|
||||
* $seconds
|
||||
* Halt time in seconds.
|
||||
* Return
|
||||
* Zero on success or FALSE on failure.
|
||||
*/
|
||||
static int PH7_vfs_sleep(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int rc, nSleep;
|
||||
if(nArg < 1 || !ph7_value_is_int(apArg[0])) {
|
||||
/* Missing/Invalid argument, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xSleep == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Amount to sleep */
|
||||
nSleep = ph7_value_to_int(apArg[0]);
|
||||
if(nSleep < 0) {
|
||||
/* Invalid value, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation (Microseconds) */
|
||||
rc = pVfs->xSleep((unsigned int)(nSleep * SX_USEC_PER_SEC));
|
||||
if(rc != PH7_OK) {
|
||||
/* Return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
/* Return zero */
|
||||
ph7_result_int(pCtx, 0);
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* void usleep(int $micro_seconds)
|
||||
* Delays program execution for the given number of micro seconds.
|
||||
* Parameters
|
||||
* $micro_seconds
|
||||
* Halt time in micro seconds. A micro second is one millionth of a second.
|
||||
* Return
|
||||
* None.
|
||||
*/
|
||||
static int PH7_vfs_usleep(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int nSleep;
|
||||
if(nArg < 1 || !ph7_value_is_int(apArg[0])) {
|
||||
/* Missing/Invalid argument, return immediately */
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xSleep == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Amount to sleep */
|
||||
nSleep = ph7_value_to_int(apArg[0]);
|
||||
if(nSleep < 0) {
|
||||
/* Invalid value, return immediately */
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation (Microseconds) */
|
||||
pVfs->xSleep((unsigned int)nSleep);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool unlink (string $filename)
|
||||
* Delete a file.
|
||||
@@ -1342,115 +1260,6 @@ static int PH7_vfs_lstat(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
* automatically as soon we return from this function. */
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* string getenv(string $varname)
|
||||
* Gets the value of an environment variable.
|
||||
* Parameters
|
||||
* $varname
|
||||
* The variable name.
|
||||
* Return
|
||||
* Returns the value of the environment variable varname, or FALSE if the environment
|
||||
* variable varname does not exist.
|
||||
*/
|
||||
static int PH7_vfs_getenv(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
const char *zEnv;
|
||||
ph7_vfs *pVfs;
|
||||
int iLen;
|
||||
if(nArg < 1 || !ph7_value_is_string(apArg[0])) {
|
||||
/* Missing/Invalid argument, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xGetenv == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Extract the environment variable */
|
||||
zEnv = ph7_value_to_string(apArg[0], &iLen);
|
||||
/* Set a boolean FALSE as the default return value */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
if(iLen < 1) {
|
||||
/* Empty string */
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
pVfs->xGetenv(zEnv, pCtx);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool putenv(string $settings)
|
||||
* Set the value of an environment variable.
|
||||
* Parameters
|
||||
* $setting
|
||||
* The setting, like "FOO=BAR"
|
||||
* Return
|
||||
* TRUE on success or FALSE on failure.
|
||||
*/
|
||||
static int PH7_vfs_putenv(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
const char *zName, *zValue;
|
||||
char *zSettings, *zEnd;
|
||||
ph7_vfs *pVfs;
|
||||
int iLen, rc;
|
||||
if(nArg < 1 || !ph7_value_is_string(apArg[0])) {
|
||||
/* Missing/Invalid argument, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Extract the setting variable */
|
||||
zSettings = (char *)ph7_value_to_string(apArg[0], &iLen);
|
||||
if(iLen < 1) {
|
||||
/* Empty string, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Parse the setting */
|
||||
zEnd = &zSettings[iLen];
|
||||
zValue = 0;
|
||||
zName = zSettings;
|
||||
while(zSettings < zEnd) {
|
||||
if(zSettings[0] == '=') {
|
||||
/* Null terminate the name */
|
||||
zSettings[0] = 0;
|
||||
zValue = &zSettings[1];
|
||||
break;
|
||||
}
|
||||
zSettings++;
|
||||
}
|
||||
/* Install the environment variable in the $_Env array */
|
||||
if(zValue == 0 || zName[0] == 0 || zValue >= zEnd || zName >= zValue) {
|
||||
/* Invalid settings,retun FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
if(zSettings < zEnd) {
|
||||
zSettings[0] = '=';
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
ph7_vm_config(pCtx->pVm, PH7_VM_CONFIG_ENV_ATTR, zName, zValue, (int)(zEnd - zValue));
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xSetenv == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_bool(pCtx, 0);
|
||||
zSettings[0] = '=';
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
rc = pVfs->xSetenv(zName, zValue);
|
||||
ph7_result_bool(pCtx, rc == PH7_OK);
|
||||
zSettings[0] = '=';
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool touch(string $filename[,int64 $time = time()[,int64 $atime]])
|
||||
* Sets access and modification time of file.
|
||||
@@ -2238,273 +2047,6 @@ static int PH7_vfs_sys_get_temp_dir(ph7_context *pCtx, int nArg, ph7_value **apA
|
||||
pVfs->xTempDir(pCtx);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* string get_current_user()
|
||||
* Returns the name of the current working user.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the name of the current working user.
|
||||
*/
|
||||
static int PH7_vfs_get_current_user(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xUsername == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
/* Set a dummy username */
|
||||
ph7_result_string(pCtx, "unknown", sizeof("unknown") - 1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
pVfs->xUsername(pCtx);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int64 getmypid()
|
||||
* Gets process ID.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the process ID.
|
||||
*/
|
||||
static int PH7_vfs_getmypid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_int64 nProcessId;
|
||||
ph7_vfs *pVfs;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xProcessId == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented, return -1 */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_int(pCtx, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
nProcessId = (ph7_int64)pVfs->xProcessId();
|
||||
/* Set the result */
|
||||
ph7_result_int64(pCtx, nProcessId);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int getmyuid()
|
||||
* Get user ID.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the user ID.
|
||||
*/
|
||||
static int PH7_vfs_getmyuid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int nUid;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xUid == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented, return -1 */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_int(pCtx, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
nUid = pVfs->xUid();
|
||||
/* Set the result */
|
||||
ph7_result_int(pCtx, nUid);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int getmygid()
|
||||
* Get group ID.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the group ID.
|
||||
*/
|
||||
static int PH7_vfs_getmygid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int nGid;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xGid == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented, return -1 */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_int(pCtx, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
nGid = pVfs->xGid();
|
||||
/* Set the result */
|
||||
ph7_result_int(pCtx, nGid);
|
||||
return PH7_OK;
|
||||
}
|
||||
#ifdef __WINNT__
|
||||
#include <Windows.h>
|
||||
#elif defined(__UNIXES__)
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
/*
|
||||
* string php_uname([ string $mode = "a" ])
|
||||
* Returns information about the host operating system.
|
||||
* Parameters
|
||||
* $mode
|
||||
* mode is a single character that defines what information is returned:
|
||||
* 'a': This is the default. Contains all modes in the sequence "s n r v m".
|
||||
* 's': Operating system name. eg. FreeBSD.
|
||||
* 'n': Host name. eg. localhost.example.com.
|
||||
* 'r': Release name. eg. 5.1.2-RELEASE.
|
||||
* 'v': Version information. Varies a lot between operating systems.
|
||||
* 'm': Machine type. eg. i386.
|
||||
* Return
|
||||
* OS description as a string.
|
||||
*/
|
||||
static int PH7_vfs_ph7_uname(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
#if defined(__WINNT__)
|
||||
const char *zName = "Microsoft Windows";
|
||||
OSVERSIONINFOW sVer;
|
||||
#elif defined(__UNIXES__)
|
||||
struct utsname sName;
|
||||
#endif
|
||||
const char *zMode = "a";
|
||||
if(nArg > 0 && ph7_value_is_string(apArg[0])) {
|
||||
/* Extract the desired mode */
|
||||
zMode = ph7_value_to_string(apArg[0], 0);
|
||||
}
|
||||
#if defined(__WINNT__)
|
||||
sVer.dwOSVersionInfoSize = sizeof(sVer);
|
||||
if(TRUE != GetVersionExW(&sVer)) {
|
||||
ph7_result_string(pCtx, zName, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
if(sVer.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
if(sVer.dwMajorVersion <= 4) {
|
||||
zName = "Microsoft Windows NT";
|
||||
} else if(sVer.dwMajorVersion == 5) {
|
||||
switch(sVer.dwMinorVersion) {
|
||||
case 0:
|
||||
zName = "Microsoft Windows 2000";
|
||||
break;
|
||||
case 1:
|
||||
zName = "Microsoft Windows XP";
|
||||
break;
|
||||
case 2:
|
||||
zName = "Microsoft Windows Server 2003";
|
||||
break;
|
||||
}
|
||||
} else if(sVer.dwMajorVersion == 6) {
|
||||
switch(sVer.dwMinorVersion) {
|
||||
case 0:
|
||||
zName = "Microsoft Windows Vista";
|
||||
break;
|
||||
case 1:
|
||||
zName = "Microsoft Windows 7";
|
||||
break;
|
||||
case 2:
|
||||
zName = "Microsoft Windows Server 2008";
|
||||
break;
|
||||
case 3:
|
||||
zName = "Microsoft Windows 8";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(sVer.dwMajorVersion == 10) {
|
||||
switch(sVer.dwMinorVersion) {
|
||||
case 0:
|
||||
zName = "Microsoft Windows 10";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch(zMode[0]) {
|
||||
case 's':
|
||||
/* Operating system name */
|
||||
ph7_result_string(pCtx, zName, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'n':
|
||||
/* Host name */
|
||||
ph7_result_string(pCtx, "localhost", (int)sizeof("localhost") - 1);
|
||||
break;
|
||||
case 'r':
|
||||
case 'v':
|
||||
/* Version information. */
|
||||
ph7_result_string_format(pCtx, "%u.%u build %u",
|
||||
sVer.dwMajorVersion, sVer.dwMinorVersion, sVer.dwBuildNumber
|
||||
);
|
||||
break;
|
||||
case 'm':
|
||||
/* Machine name */
|
||||
ph7_result_string(pCtx, "x86", (int)sizeof("x86") - 1);
|
||||
break;
|
||||
default:
|
||||
ph7_result_string_format(pCtx, "%s localhost %u.%u build %u x86",
|
||||
zName,
|
||||
sVer.dwMajorVersion, sVer.dwMinorVersion, sVer.dwBuildNumber
|
||||
);
|
||||
break;
|
||||
}
|
||||
#elif defined(__UNIXES__)
|
||||
if(uname(&sName) != 0) {
|
||||
ph7_result_string(pCtx, "Unix", (int)sizeof("Unix") - 1);
|
||||
return PH7_OK;
|
||||
}
|
||||
switch(zMode[0]) {
|
||||
case 's':
|
||||
/* Operating system name */
|
||||
ph7_result_string(pCtx, sName.sysname, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'n':
|
||||
/* Host name */
|
||||
ph7_result_string(pCtx, sName.nodename, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'r':
|
||||
/* Release information */
|
||||
ph7_result_string(pCtx, sName.release, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'v':
|
||||
/* Version information. */
|
||||
ph7_result_string(pCtx, sName.version, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'm':
|
||||
/* Machine name */
|
||||
ph7_result_string(pCtx, sName.machine, -1/* Compute length automatically*/);
|
||||
break;
|
||||
default:
|
||||
ph7_result_string_format(pCtx,
|
||||
"%s %s %s %s %s",
|
||||
sName.sysname,
|
||||
sName.release,
|
||||
sName.version,
|
||||
sName.nodename,
|
||||
sName.machine
|
||||
);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
ph7_result_string(pCtx, "Unknown Operating System", (int)sizeof("Unknown Operating System") - 1);
|
||||
#endif
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* Section:
|
||||
* IO stream implementation.
|
||||
@@ -8047,8 +7589,6 @@ PH7_PRIVATE sxi32 PH7_RegisterIORoutine(ph7_vm *pVm) {
|
||||
{"mkdir", PH7_vfs_mkdir },
|
||||
{"rename", PH7_vfs_rename },
|
||||
{"realpath", PH7_vfs_realpath},
|
||||
{"sleep", PH7_vfs_sleep },
|
||||
{"usleep", PH7_vfs_usleep },
|
||||
{"unlink", PH7_vfs_unlink },
|
||||
{"chmod", PH7_vfs_chmod },
|
||||
{"chown", PH7_vfs_chown },
|
||||
@@ -8071,18 +7611,11 @@ PH7_PRIVATE sxi32 PH7_RegisterIORoutine(ph7_vm *pVm) {
|
||||
{"filetype", PH7_vfs_filetype },
|
||||
{"stat", PH7_vfs_stat },
|
||||
{"lstat", PH7_vfs_lstat },
|
||||
{"getenv", PH7_vfs_getenv },
|
||||
{"putenv", PH7_vfs_putenv },
|
||||
{"touch", PH7_vfs_touch },
|
||||
{"link", PH7_vfs_link },
|
||||
{"symlink", PH7_vfs_symlink },
|
||||
{"umask", PH7_vfs_umask },
|
||||
{"sys_get_temp_dir", PH7_vfs_sys_get_temp_dir },
|
||||
{"get_current_user", PH7_vfs_get_current_user },
|
||||
{"getpid", PH7_vfs_getmypid },
|
||||
{"getuid", PH7_vfs_getmyuid },
|
||||
{"getgid", PH7_vfs_getmygid },
|
||||
{"php_uname", PH7_vfs_ph7_uname},
|
||||
/* Path processing */
|
||||
{"dirname", PH7_builtin_dirname },
|
||||
{"basename", PH7_builtin_basename },
|
||||
|
||||
+5
-306
@@ -2711,7 +2711,7 @@ 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(), die, etc.] */
|
||||
/* Register special functions first [i.e: print, json_encode(), func_get_args(), etc.] */
|
||||
rc = VmRegisterSpecialFunction(&(*pVm));
|
||||
if(rc != SXRET_OK) {
|
||||
/* Don't worry about freeing memory, everything will be released shortly */
|
||||
@@ -2723,7 +2723,7 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady(
|
||||
/* Don't worry about freeing memory, everything will be released shortly */
|
||||
return rc;
|
||||
}
|
||||
/* Register built-in constants [i.e: PHP_EOL, PHP_OS...] */
|
||||
/* Register built-in constants [i.e: PHP_INT_MAX, __DATE__...] */
|
||||
PH7_RegisterBuiltInConstant(&(*pVm));
|
||||
/* Register built-in functions [i.e: array_diff(), strlen(), etc.] */
|
||||
PH7_RegisterBuiltInFunction(&(*pVm));
|
||||
@@ -4202,31 +4202,6 @@ Resume:
|
||||
VmPopOperand(&pTos, 1);
|
||||
}
|
||||
goto Done;
|
||||
/*
|
||||
* HALT: P1 * *
|
||||
*
|
||||
* Program execution aborted: Clean up the mess left behind
|
||||
* and abort immediately.
|
||||
*/
|
||||
case PH7_OP_HALT:
|
||||
if(pInstr->iP1) {
|
||||
if(pTos < pStack) {
|
||||
goto Abort;
|
||||
}
|
||||
if(pTos->nType & MEMOBJ_STRING) {
|
||||
if(SyBlobLength(&pTos->sBlob) > 0) {
|
||||
/* Output the exit message */
|
||||
pVm->sVmConsumer.xConsumer(SyBlobData(&pTos->sBlob), SyBlobLength(&pTos->sBlob),
|
||||
pVm->sVmConsumer.pUserData);
|
||||
}
|
||||
pVm->iExitStatus = 0;
|
||||
} else if(pTos->nType & MEMOBJ_INT) {
|
||||
/* Record exit status */
|
||||
pVm->iExitStatus = (sxi32)pTos->x.iVal;
|
||||
}
|
||||
VmPopOperand(&pTos, 1);
|
||||
}
|
||||
goto Abort;
|
||||
/*
|
||||
* JMP: P1 P2 *
|
||||
*
|
||||
@@ -4679,7 +4654,7 @@ Resume:
|
||||
/*
|
||||
* LOADC P1 P2 *
|
||||
*
|
||||
* Load a constant [i.e: PHP_EOL,PHP_OS,__TIME__,...] indexed at P2 in the constant pool.
|
||||
* Load a constant [i.e: PHP_INT_MAX,__DATE__,__TIME__,...] indexed at P2 in the constant pool.
|
||||
* If P1 is set,then this constant is candidate for expansion via user installable callbacks.
|
||||
*/
|
||||
case PH7_OP_LOADC: {
|
||||
@@ -7980,7 +7955,7 @@ PH7_PRIVATE sxi32 PH7_VmByteCodeExec(ph7_vm *pVm) {
|
||||
if(rc == SXERR_MEM) {
|
||||
PH7_VmMemoryError(pVm);
|
||||
}
|
||||
/* Construction may stop via exit(); skip main, not shutdown. */
|
||||
/* Construction may stop via System::Exit(); skip main, not shutdown. */
|
||||
goto Shutdown;
|
||||
}
|
||||
PH7_MemObjRelease(&pResult);
|
||||
@@ -10051,37 +10026,6 @@ static int vm_builtin_uniqid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
* Status:
|
||||
* Stable.
|
||||
*/
|
||||
/*
|
||||
* void exit(string $msg)
|
||||
* void exit(int $status)
|
||||
* void die(string $ms)
|
||||
* void die(int $status)
|
||||
* Output a message and terminate program execution.
|
||||
* Parameter
|
||||
* If status is a string, this function prints the status just before exiting.
|
||||
* If status is an integer, that value will be used as the exit status
|
||||
* and not printed
|
||||
* Return
|
||||
* NULL
|
||||
*/
|
||||
static int vm_builtin_exit(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
if(nArg > 0) {
|
||||
if(ph7_value_is_string(apArg[0])) {
|
||||
const char *zData;
|
||||
int iLen = 0;
|
||||
/* Print exit message */
|
||||
zData = ph7_value_to_string(apArg[0], &iLen);
|
||||
ph7_context_output(pCtx, zData, iLen);
|
||||
} else if(ph7_value_is_int(apArg[0])) {
|
||||
sxi32 iExitStatus;
|
||||
/* Record exit status code */
|
||||
iExitStatus = ph7_value_to_int(apArg[0]);
|
||||
pCtx->pVm->iExitStatus = iExitStatus;
|
||||
}
|
||||
}
|
||||
/* Abort processing immediately */
|
||||
return PH7_ABORT;
|
||||
}
|
||||
/*
|
||||
* Unset a memory object [i.e: a ph7_value],remove it from the current
|
||||
* frame,the reference table and discard it's contents.
|
||||
@@ -10375,56 +10319,6 @@ static int vm_builtin_var_export(ph7_context *pCtx, int nArg, ph7_value **apArg)
|
||||
return SXRET_OK;
|
||||
}
|
||||
/*
|
||||
* int get_memory_limit()
|
||||
* Returns the amount of bytes that can be allocated from system.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* The upper memory limit set for script processing.
|
||||
*/
|
||||
static int vm_builtin_get_memory_limit(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(apArg);
|
||||
if(nArg != 0) {
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
ph7_result_int64(pCtx, pCtx->pVm->sAllocator.pHeap->nLimit);
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int get_memory_peak_usage()
|
||||
* Returns the limit of memory set in Interpreter.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* The maximum amount of memory that can be allocated from system.
|
||||
*/
|
||||
static int vm_builtin_get_memory_peak_usage(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(apArg);
|
||||
if(nArg != 0) {
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
ph7_result_int64(pCtx, pCtx->pVm->sAllocator.pHeap->nPeak);
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int get_memory_usage()
|
||||
* Returns the amount of memory, in bytes, that's currently being allocated.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Total memory allocated from system, including unused pages.
|
||||
*/
|
||||
static int vm_builtin_get_memory_usage(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(apArg);
|
||||
if(nArg != 0) {
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
ph7_result_int64(pCtx, pCtx->pVm->sAllocator.pHeap->nSize);
|
||||
}
|
||||
return PH7_OK;
|
||||
}/*
|
||||
* int/bool assert_options(int $what [, mixed $value ])
|
||||
* Set/get the various assert flags.
|
||||
* Parameter
|
||||
@@ -10618,7 +10512,7 @@ static int vm_builtin_restore_exception_handler(ph7_context *pCtx, int nArg, ph7
|
||||
* Sets a user-defined exception handler function.
|
||||
* Sets the default exception handler if an exception is not caught within a try/catch block.
|
||||
* NOTE
|
||||
* Execution will NOT stop after the exception_handler calls for example die/exit unlike
|
||||
* Execution will NOT stop after the exception_handler calls for example an explicit abort unlike
|
||||
* the standard PHP engine.
|
||||
* Parameters
|
||||
* $exception_handler
|
||||
@@ -10904,193 +10798,6 @@ static ph7_exception_block *VmFindCatch(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Section:
|
||||
* Version,Credits and Copyright related functions.
|
||||
* Authors:
|
||||
* Symisc Systems,devel@symisc.net.
|
||||
* Copyright (C) Symisc Systems,https://ph7.symisc.net
|
||||
* Status:
|
||||
* Stable.
|
||||
*/
|
||||
/*
|
||||
* string ph7version(void)
|
||||
* Returns the running version of the PH7 version.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Current PH7 version.
|
||||
*/
|
||||
static int vm_builtin_ph7_version(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
SXUNUSED(nArg);
|
||||
SXUNUSED(apArg); /* cc warning */
|
||||
/* Current engine version */
|
||||
ph7_result_string(pCtx, PH7_VERSION, sizeof(PH7_VERSION) - 1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* PH7 release information HTML page used by the ph7info() and ph7credits() functions.
|
||||
*/
|
||||
#define PH7_HTML_PAGE_HEADER "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"https://www.w3.org/TR/html4/strict.dtd\">"\
|
||||
"<html><head>"\
|
||||
"<!-- Copyright (C) 2011-2012 Symisc Systems,https://www.symisc.net contact@symisc.net -->"\
|
||||
"<meta content=\"text/html; charset=UTF-8\" http-equiv=\"content-type\"><title>PH7 engine credits</title>"\
|
||||
"<style type=\"text/css\">"\
|
||||
"div {"\
|
||||
"border: 1px solid #cccccc;"\
|
||||
"-moz-border-radius-topleft: 10px;"\
|
||||
"-moz-border-radius-bottomright: 10px;"\
|
||||
"-moz-border-radius-bottomleft: 10px;"\
|
||||
"-moz-border-radius-topright: 10px;"\
|
||||
"-webkit-border-radius: 10px;"\
|
||||
"-o-border-radius: 10px;"\
|
||||
"border-radius: 10px;"\
|
||||
"padding-left: 2em;"\
|
||||
"background-color: white;"\
|
||||
"margin-left: auto;"\
|
||||
"font-family: verdana;"\
|
||||
"padding-right: 2em;"\
|
||||
"margin-right: auto;"\
|
||||
"}"\
|
||||
"body {"\
|
||||
"padding: 0.2em;"\
|
||||
"font-style: normal;"\
|
||||
"font-size: medium;"\
|
||||
"background-color: #f2f2f2;"\
|
||||
"}"\
|
||||
"hr {"\
|
||||
"border-style: solid none none;"\
|
||||
"border-width: 1px medium medium;"\
|
||||
"border-top: 1px solid #cccccc;"\
|
||||
"height: 1px;"\
|
||||
"}"\
|
||||
"a {"\
|
||||
"color: #3366cc;"\
|
||||
"text-decoration: none;"\
|
||||
"}"\
|
||||
"a:hover {"\
|
||||
"color: #999999;"\
|
||||
"}"\
|
||||
"a:active {"\
|
||||
"color: #663399;"\
|
||||
"}"\
|
||||
"h1 {"\
|
||||
"margin: 0;"\
|
||||
"padding: 0;"\
|
||||
"font-family: Verdana;"\
|
||||
"font-weight: bold;"\
|
||||
"font-style: normal;"\
|
||||
"font-size: medium;"\
|
||||
"text-transform: capitalize;"\
|
||||
"color: #0a328c;"\
|
||||
"}"\
|
||||
"p {"\
|
||||
"margin: 0 auto;"\
|
||||
"font-size: medium;"\
|
||||
"font-style: normal;"\
|
||||
"font-family: verdana;"\
|
||||
"}"\
|
||||
"</style></head><body>"\
|
||||
"<div style=\"background-color: white; width: 699px;\">"\
|
||||
"<h1 style=\"font-family: Verdana; text-align: right;\"><small><small>PH7 Engine Credits</small></small></h1>"\
|
||||
"<hr style=\"margin-left: auto; margin-right: auto;\">"\
|
||||
"<p><small><a href=\"https://ph7.symisc.net/\"><small><span style=\"font-weight: bold;\">"\
|
||||
"Symisc PH7</span></small></a><small> </small></small></p>"\
|
||||
"<p style=\"text-align: left;\"><small><small>"\
|
||||
"A highly efficient embeddable bytecode compiler and a Virtual Machine for the PHP(5) Programming Language.</small></small></p>"\
|
||||
"<p style=\"text-align: left;\"><small><small>Copyright (C) Symisc Systems.<br></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Engine Version:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\">"
|
||||
|
||||
#define PH7_HTML_PAGE_FORMAT "<small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Engine ID:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Underlying VFS:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Total Built-in Functions:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%d</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Total Built-in Classes:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%d</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Host Operating System:</small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">%s</span></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small style=\"font-weight: bold;\"><small><small></small></small></small></p>"\
|
||||
"<p style=\"text-align: left; font-weight: bold;\"><small><small>Licensed To: <Public Release Under The <a href=\"https://www.symisc.net/spl.txt\">"\
|
||||
"Symisc Public License (SPL)</a>></small></small></p>"
|
||||
|
||||
#define PH7_HTML_PAGE_FOOTER "<p style=\"text-align: left; font-weight: bold; margin-left: 40px;\"><small><small><span style=\"font-weight: normal;\">/*<br>"\
|
||||
" * Copyright (C) 2011, 2012 Symisc Systems. All rights reserved.<br>"\
|
||||
" *<br>"\
|
||||
" * Redistribution and use in source and binary forms, with or without<br>"\
|
||||
" * modification, are permitted provided that the following conditions<br>"\
|
||||
" * are met:<br>"\
|
||||
" * 1. Redistributions of source code must retain the above copyright<br>"\
|
||||
" * notice, this list of conditions and the following disclaimer.<br>"\
|
||||
" * 2. Redistributions in binary form must reproduce the above copyright<br>"\
|
||||
" * notice, this list of conditions and the following disclaimer in the<br>"\
|
||||
" * documentation and/or other materials provided with the distribution.<br>"\
|
||||
" * 3. Redistributions in any form must be accompanied by information on<br>"\
|
||||
" * how to obtain complete source code for the PH7 engine and any <br>"\
|
||||
" * accompanying software that uses the PH7 engine software.<br>"\
|
||||
" * The source code must either be included in the distribution<br>"\
|
||||
" * or be available for no more than the cost of distribution plus<br>"\
|
||||
" * a nominal fee, and must be freely redistributable under reasonable<br>"\
|
||||
" * conditions. For an executable file, complete source code means<br>"\
|
||||
" * the source code for all modules it contains.It does not include<br>"\
|
||||
" * source code for modules or files that typically accompany the major<br>"\
|
||||
" * components of the operating system on which the executable file runs.<br>"\
|
||||
" *<br>"\
|
||||
" * THIS SOFTWARE IS PROVIDED BY SYMISC SYSTEMS ``AS IS'' AND ANY EXPRESS<br>"\
|
||||
" * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED<br>"\
|
||||
" * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR<br>"\
|
||||
" * NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL SYMISC SYSTEMS<br>"\
|
||||
" * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>"\
|
||||
" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>"\
|
||||
" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR<br>"\
|
||||
" * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,<br>"\
|
||||
" * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE<br>"\
|
||||
" * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN<br>"\
|
||||
" * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<br>"\
|
||||
" */<br>"\
|
||||
"</span></small></small></p>"\
|
||||
"<p style=\"text-align: right;\"><small><small>Copyright (C) <a href=\"https://www.symisc.net/\">Symisc Systems</a></small></small><big>"\
|
||||
"</big></p></div></body></html>"
|
||||
/*
|
||||
* bool ph7credits(void)
|
||||
* bool ph7info(void)
|
||||
* bool ph7copyright(void)
|
||||
* Prints out the credits for PH7 engine
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Always TRUE
|
||||
*/
|
||||
static int vm_builtin_ph7_credits(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vm *pVm = pCtx->pVm; /* Point to the underlying VM */
|
||||
/* Expand the HTML page above*/
|
||||
ph7_context_output(pCtx, PH7_HTML_PAGE_HEADER, (int)sizeof(PH7_HTML_PAGE_HEADER) - 1);
|
||||
ph7_context_output_format(
|
||||
pCtx,
|
||||
PH7_HTML_PAGE_FORMAT,
|
||||
ph7_lib_version(), /* Engine version */
|
||||
ph7_lib_signature(), /* Engine signature */
|
||||
pVm->pEngine->pVfs ? pVm->pEngine->pVfs->zName : "null_vfs",
|
||||
SyHashTotalEntry(&pVm->hFunction) + SyHashTotalEntry(&pVm->hHostFunction),/* # built-in functions */
|
||||
SyHashTotalEntry(&pVm->hClass),
|
||||
#ifdef __WINNT__
|
||||
"Windows NT"
|
||||
#elif defined(__UNIXES__)
|
||||
"UNIX-Like"
|
||||
#else
|
||||
"Other OS"
|
||||
#endif
|
||||
);
|
||||
ph7_context_output(pCtx, PH7_HTML_PAGE_FOOTER, (int)sizeof(PH7_HTML_PAGE_FOOTER) - 1);
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* Return TRUE */
|
||||
//ph7_result_bool(pCtx,1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* Section:
|
||||
* URL related routines.
|
||||
@@ -12175,7 +11882,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "random_bytes", vm_builtin_random_bytes },
|
||||
{ "uniqid", vm_builtin_uniqid },
|
||||
/* Language constructs functions */
|
||||
{ "exit", vm_builtin_exit },
|
||||
{ "eval", vm_builtin_eval },
|
||||
/* Variable handling functions */
|
||||
{ "get_defined_vars", vm_builtin_get_defined_vars},
|
||||
@@ -12199,10 +11905,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "ob_get_level", vm_builtin_ob_get_level },
|
||||
{ "ob_list_handlers", vm_builtin_ob_list_handlers },
|
||||
{ "ob_start", vm_builtin_ob_start },
|
||||
/* Memory usage reporting */
|
||||
{ "get_memory_limit", vm_builtin_get_memory_limit },
|
||||
{ "get_memory_peak_usage", vm_builtin_get_memory_peak_usage },
|
||||
{ "get_memory_usage", vm_builtin_get_memory_usage },
|
||||
/* Assertion functions */
|
||||
{ "assert_options", vm_builtin_assert_options },
|
||||
{ "assert", vm_builtin_assert },
|
||||
@@ -12210,9 +11912,6 @@ static const ph7_builtin_func aVmFunc[] = {
|
||||
{ "restore_exception_handler", vm_builtin_restore_exception_handler },
|
||||
{ "set_exception_handler", vm_builtin_set_exception_handler },
|
||||
{ "debug_backtrace", vm_builtin_debug_backtrace},
|
||||
/* Release info */
|
||||
{"ph7version", vm_builtin_ph7_version },
|
||||
{"phpinfo", vm_builtin_ph7_credits },
|
||||
/* hashmap */
|
||||
{"compact", vm_builtin_compact },
|
||||
{"extract", vm_builtin_extract },
|
||||
|
||||
Reference in New Issue
Block a user