fixing in the vm context instead, making the feature available in case realpath could be implemented as well
This commit is contained in:
parent
3ae20a1ca6
commit
dba8e5098f
|
@ -648,7 +648,7 @@ static sxi32 ProcessScript(
|
||||||
}
|
}
|
||||||
if(zFilePath) {
|
if(zFilePath) {
|
||||||
/* Push processed file path */
|
/* Push processed file path */
|
||||||
PH7_VmPushFilePath(pVm, zFilePath, -1, TRUE, 0);
|
PH7_VmPushFilePath(pVm, zFilePath, TRUE, 0);
|
||||||
}
|
}
|
||||||
/* Reset the error message consumer */
|
/* Reset the error message consumer */
|
||||||
SyBlobReset(&pEngine->xConf.sErrConsumer);
|
SyBlobReset(&pEngine->xConf.sErrConsumer);
|
||||||
|
|
|
@ -339,4 +339,4 @@ sxi32 SyAsciiToHex(sxi32 c) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -628,4 +628,15 @@ PH7_PRIVATE sxi32 SyStrToReal(const char *zSrc, sxu32 nLen, void *pOutVal, const
|
||||||
*(sxreal *)pOutVal = Val;
|
*(sxreal *)pOutVal = Val;
|
||||||
}
|
}
|
||||||
return zSrc >= zEnd ? SXRET_OK : SXERR_SYNTAX;
|
return zSrc >= zEnd ? SXRET_OK : SXERR_SYNTAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PH7_PRIVATE sxi32 SyRealpath(const char *zPath, char **fPath) {
|
||||||
|
#ifdef __UNIXES__
|
||||||
|
if(realpath(zPath, fPath) == NULL) {
|
||||||
|
#else
|
||||||
|
if(GetFullPathName(zPath, PATH_MAX, fPath, NULL) != 0) {
|
||||||
|
#endif
|
||||||
|
return PH7_IO_ERR;
|
||||||
|
}
|
||||||
|
return PH7_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -2907,7 +2907,7 @@ PH7_PRIVATE void *PH7_StreamOpenHandle(ph7_vm *pVm, const ph7_io_stream *pStream
|
||||||
if(rc == PH7_OK) {
|
if(rc == PH7_OK) {
|
||||||
if(bPushInclude) {
|
if(bPushInclude) {
|
||||||
/* Mark as included */
|
/* Mark as included */
|
||||||
PH7_VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), SyBlobLength(&sWorker), FALSE, pNew);
|
PH7_VmPushFilePath(pVm, (const char *)SyBlobData(&sWorker), FALSE, pNew);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2920,7 +2920,7 @@ PH7_PRIVATE void *PH7_StreamOpenHandle(ph7_vm *pVm, const ph7_io_stream *pStream
|
||||||
if(rc == PH7_OK) {
|
if(rc == PH7_OK) {
|
||||||
if(bPushInclude) {
|
if(bPushInclude) {
|
||||||
/* Mark as included */
|
/* Mark as included */
|
||||||
PH7_VmPushFilePath(pVm, sFile.zString, sFile.nByte, FALSE, pNew);
|
PH7_VmPushFilePath(pVm, sFile.zString, FALSE, pNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
11
engine/vm.c
11
engine/vm.c
|
@ -10653,18 +10653,21 @@ static int VmIsIncludedFile(ph7_vm *pVm, SyString *pFile) {
|
||||||
/*
|
/*
|
||||||
* Push a file path in the appropriate VM container.
|
* Push a file path in the appropriate VM container.
|
||||||
*/
|
*/
|
||||||
PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, int nLen, sxu8 bMain, sxi32 *pNew) {
|
PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, sxu8 bMain, sxi32 *pNew) {
|
||||||
SyString sPath;
|
SyString sPath;
|
||||||
|
char *fPath[PATH_MAX + 1];
|
||||||
char *zDup;
|
char *zDup;
|
||||||
#ifdef __WINNT__
|
#ifdef __WINNT__
|
||||||
char *zCur;
|
char *zCur;
|
||||||
#endif
|
#endif
|
||||||
|
sxi32 nLen;
|
||||||
sxi32 rc;
|
sxi32 rc;
|
||||||
if(nLen < 0) {
|
if(SyRealpath(zPath, fPath) != PH7_OK) {
|
||||||
nLen = SyStrlen(zPath);
|
return SXERR_IO;
|
||||||
}
|
}
|
||||||
|
nLen = SyStrlen(fPath);
|
||||||
/* Duplicate the file path first */
|
/* Duplicate the file path first */
|
||||||
zDup = SyMemBackendStrDup(&pVm->sAllocator, zPath, nLen);
|
zDup = SyMemBackendStrDup(&pVm->sAllocator, fPath, nLen);
|
||||||
if(zDup == 0) {
|
if(zDup == 0) {
|
||||||
return SXERR_MEM;
|
return SXERR_MEM;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,11 @@
|
||||||
/* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */
|
/* $SymiscID: ph7.h v2.1 UNIX|WIN32/64 2012-09-15 09:43 stable <chm@symisc.net> $ */
|
||||||
#include <stdarg.h> /* needed for the definition of va_list */
|
#include <stdarg.h> /* needed for the definition of va_list */
|
||||||
#include <stdio.h> /* needed for the definition of snprintf */
|
#include <stdio.h> /* needed for the definition of snprintf */
|
||||||
|
#include <limits.h> /* needed for PATH_MAX */
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifndef PATH_MAX
|
||||||
|
#define PATH_MAX MAX_PATH
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* Compile time engine version, signature, identification in the symisc source tree
|
* Compile time engine version, signature, identification in the symisc source tree
|
||||||
* and copyright notice.
|
* and copyright notice.
|
||||||
|
|
|
@ -1589,7 +1589,7 @@ PH7_PRIVATE sxi32 PH7_VmInstallUserFunction(ph7_vm *pVm, ph7_vm_func *pFunc, SyS
|
||||||
PH7_PRIVATE sxi32 PH7_VmCreateClassInstanceFrame(ph7_vm *pVm, ph7_class_instance *pObj);
|
PH7_PRIVATE sxi32 PH7_VmCreateClassInstanceFrame(ph7_vm *pVm, ph7_class_instance *pObj);
|
||||||
PH7_PRIVATE sxi32 PH7_VmRefObjRemove(ph7_vm *pVm, sxu32 nIdx, SyHashEntry *pEntry, ph7_hashmap_node *pMapEntry);
|
PH7_PRIVATE sxi32 PH7_VmRefObjRemove(ph7_vm *pVm, sxu32 nIdx, SyHashEntry *pEntry, ph7_hashmap_node *pMapEntry);
|
||||||
PH7_PRIVATE sxi32 PH7_VmRefObjInstall(ph7_vm *pVm, sxu32 nIdx, SyHashEntry *pEntry, ph7_hashmap_node *pMapEntry, sxi32 iFlags);
|
PH7_PRIVATE sxi32 PH7_VmRefObjInstall(ph7_vm *pVm, sxu32 nIdx, SyHashEntry *pEntry, ph7_hashmap_node *pMapEntry, sxi32 iFlags);
|
||||||
PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, int nLen, sxu8 bMain, sxi32 *pNew);
|
PH7_PRIVATE sxi32 PH7_VmPushFilePath(ph7_vm *pVm, const char *zPath, sxu8 bMain, sxi32 *pNew);
|
||||||
PH7_PRIVATE ph7_class *PH7_VmExtractClass(ph7_vm *pVm, const char *zName, sxu32 nByte, sxi32 iLoadable, sxi32 iNest);
|
PH7_PRIVATE ph7_class *PH7_VmExtractClass(ph7_vm *pVm, const char *zName, sxu32 nByte, sxi32 iLoadable, sxi32 iNest);
|
||||||
PH7_PRIVATE sxi32 PH7_VmRegisterConstant(ph7_vm *pVm, const SyString *pName, ProcConstant xExpand, void *pUserData);
|
PH7_PRIVATE sxi32 PH7_VmRegisterConstant(ph7_vm *pVm, const SyString *pName, ProcConstant xExpand, void *pUserData);
|
||||||
PH7_PRIVATE sxi32 PH7_VmInstallForeignFunction(ph7_vm *pVm, const SyString *pName, ProchHostFunction xFunc, void *pUserData);
|
PH7_PRIVATE sxi32 PH7_VmInstallForeignFunction(ph7_vm *pVm, const SyString *pName, ProchHostFunction xFunc, void *pUserData);
|
||||||
|
@ -1854,4 +1854,5 @@ PH7_PRIVATE sxu32 SyStrlen(const char *zSrc);
|
||||||
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
|
PH7_PRIVATE sxi32 SyMemBackendMakeThreadSafe(SyMemBackend *pBackend, const SyMutexMethods *pMethods);
|
||||||
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
|
PH7_PRIVATE sxi32 SyMemBackendDisbaleMutexing(SyMemBackend *pBackend);
|
||||||
#endif
|
#endif
|
||||||
|
PH7_PRIVATE sxi32 SyRealpath(const char *zPath, char **fPath);
|
||||||
#endif /* __PH7INT_H__ */
|
#endif /* __PH7INT_H__ */
|
||||||
|
|
|
@ -29,10 +29,6 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
|
||||||
#ifndef PATH_MAX
|
|
||||||
#define PATH_MAX MAX_PATH
|
|
||||||
#endif
|
|
||||||
/* Make sure this header file is available.*/
|
/* Make sure this header file is available.*/
|
||||||
#include "ph7.h"
|
#include "ph7.h"
|
||||||
/*
|
/*
|
||||||
|
@ -113,7 +109,6 @@ static int Output_Consumer(const void *pOutput, unsigned int nOutputLen, void *p
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
ph7 *pEngine; /* PH7 engine */
|
ph7 *pEngine; /* PH7 engine */
|
||||||
ph7_vm *pVm; /* Compiled PHP program */
|
ph7_vm *pVm; /* Compiled PHP program */
|
||||||
char pScriptPath[PATH_MAX]; /* Full path of the script */
|
|
||||||
int dump_vm = 0; /* Dump VM instructions if TRUE */
|
int dump_vm = 0; /* Dump VM instructions if TRUE */
|
||||||
int err_report = 0; /* Report run-time errors if TRUE */
|
int err_report = 0; /* Report run-time errors if TRUE */
|
||||||
int n; /* Script arguments */
|
int n; /* Script arguments */
|
||||||
|
@ -158,16 +153,9 @@ int main(int argc, char **argv) {
|
||||||
0 /* NULL: Callback Private data */
|
0 /* NULL: Callback Private data */
|
||||||
);
|
);
|
||||||
/* Now,it's time to compile our PHP file */
|
/* Now,it's time to compile our PHP file */
|
||||||
#ifdef __UNIXES__
|
|
||||||
if(realpath(argv[n], pScriptPath) == NULL) {
|
|
||||||
#else
|
|
||||||
if(GetFullPathName(argv[n], PATH_MAX, pScriptPath, NULL) != 0) {
|
|
||||||
#endif
|
|
||||||
Fatal("Error cannot retrieve full path of the script");
|
|
||||||
}
|
|
||||||
rc = ph7_compile_file(
|
rc = ph7_compile_file(
|
||||||
pEngine, /* PH7 Engine */
|
pEngine, /* PH7 Engine */
|
||||||
pScriptPath, /* Path to the PHP file to compile */
|
argv[n], /* Path to the PHP file to compile */
|
||||||
&pVm, /* OUT: Compiled PHP program */
|
&pVm, /* OUT: Compiled PHP program */
|
||||||
0 /* IN: Compile flags */
|
0 /* IN: Compile flags */
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue