Extend native class API to support full AerScript declarations
Build / AerScript (push) Successful in 18s
Build / AerScript (push) Successful in 18s
This commit is contained in:
+76
-1
@@ -280,6 +280,9 @@ static int PH7_vfs_mkdir(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
rc = pVfs->xMkdir(zPath, iMode, iRecursive);
|
||||
/* IO return value */
|
||||
ph7_result_bool(pCtx, rc == PH7_OK);
|
||||
@@ -518,6 +521,9 @@ static int PH7_vfs_chmod(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
zPath = ph7_value_to_string(apArg[0], 0);
|
||||
/* Extract the mode */
|
||||
iMode = ph7_value_to_int(apArg[1]);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
rc = pVfs->xChmod(zPath, iMode);
|
||||
/* IO return value */
|
||||
@@ -559,6 +565,9 @@ static int PH7_vfs_chown(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
zPath = ph7_value_to_string(apArg[0], 0);
|
||||
/* Extract the user */
|
||||
zUser = ph7_value_to_string(apArg[1], 0);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
rc = pVfs->xChown(zPath, zUser);
|
||||
/* IO return value */
|
||||
@@ -600,6 +609,9 @@ static int PH7_vfs_chgrp(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
zPath = ph7_value_to_string(apArg[0], 0);
|
||||
/* Extract the user */
|
||||
zGroup = ph7_value_to_string(apArg[1], 0);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
rc = pVfs->xChgrp(zPath, zGroup);
|
||||
/* IO return value */
|
||||
@@ -1488,6 +1500,9 @@ static int PH7_vfs_touch(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
nAccess = nTime;
|
||||
}
|
||||
}
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
rc = pVfs->xTouch(zFile, nTime, nAccess);
|
||||
/* IO result */
|
||||
ph7_result_bool(pCtx, rc == PH7_OK);
|
||||
@@ -2186,6 +2201,9 @@ static int PH7_vfs_umask(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
if(nArg > 0) {
|
||||
iNew = ph7_value_to_int(apArg[0]);
|
||||
}
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
iOld = pVfs->xUmask(iNew);
|
||||
/* Old mask */
|
||||
@@ -2527,6 +2545,7 @@ static int PH7_builtin_ftruncate(ph7_context *pCtx, int nArg, ph7_value **apArg)
|
||||
const ph7_io_stream *pStream;
|
||||
io_private *pDev;
|
||||
int rc;
|
||||
ph7_int64 nSize;
|
||||
if(nArg < 2 || !ph7_value_is_resource(apArg[0])) {
|
||||
/* Missing/Invalid arguments, return FALSE */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING, "Expecting an IO handle");
|
||||
@@ -2553,7 +2572,11 @@ static int PH7_builtin_ftruncate(ph7_context *pCtx, int nArg, ph7_value **apArg)
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
rc = pStream->xTrunc(pDev->pHandle, ph7_value_to_int64(apArg[1]));
|
||||
nSize = ph7_value_to_int64(apArg[1]);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
rc = pStream->xTrunc(pDev->pHandle, nSize);
|
||||
if(rc == PH7_OK) {
|
||||
/* Discard buffered data */
|
||||
ResetIOPrivate(pDev);
|
||||
@@ -2618,6 +2641,9 @@ static int PH7_builtin_fseek(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
whence = ph7_value_to_int(apArg[2]);
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
rc = pStream->xSeek(pDev->pHandle, iOfft, whence);
|
||||
if(rc == PH7_OK) {
|
||||
/* Ignore buffered data */
|
||||
@@ -2973,6 +2999,11 @@ PH7_PRIVATE void *PH7_StreamOpenHandle(ph7_vm *pVm, const ph7_io_stream *pStream
|
||||
SyString sFile;
|
||||
char sFilePath[PATH_MAX + 1];
|
||||
int rc;
|
||||
/* Open callers may have just converted flags/mode through a magic hook.
|
||||
* A failed conversion must never open (and possibly truncate) the URI. */
|
||||
if(pVm->iPendingTransfer) {
|
||||
return 0;
|
||||
}
|
||||
if(pStream == 0) {
|
||||
/* No such stream device */
|
||||
return 0;
|
||||
@@ -3179,6 +3210,9 @@ static int PH7_builtin_fgets(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
nLen = ph7_value_to_int64(apArg[1]);
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
n = StreamReadLine(pDev, &zLine, nLen);
|
||||
if(n < 1) {
|
||||
/* EOF or IO error, return FALSE */
|
||||
@@ -3240,6 +3274,9 @@ static int PH7_builtin_fread(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
}
|
||||
/* Allocate enough buffer */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
pBuf = ph7_context_alloc_chunk(pCtx, (unsigned int)nLen, FALSE, FALSE);
|
||||
if(pBuf == 0) {
|
||||
PH7_VmMemoryError(pCtx->pVm);
|
||||
@@ -3316,6 +3353,9 @@ static int PH7_builtin_fgetcsv(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
nLen = ph7_value_to_int64(apArg[1]);
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
n = StreamReadLine(pDev, &zLine, nLen);
|
||||
if(n < 1) {
|
||||
/* EOF or IO error, return FALSE */
|
||||
@@ -3419,6 +3459,9 @@ static int PH7_builtin_fgetss(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
nLen = ph7_value_to_int64(apArg[1]);
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
n = StreamReadLine(pDev, &zLine, nLen);
|
||||
if(n < 1) {
|
||||
/* EOF or IO error, return FALSE */
|
||||
@@ -3756,6 +3799,10 @@ static int PH7_builtin_file_get_contents(ph7_context *pCtx, int nArg, ph7_value
|
||||
if(nArg > 3) {
|
||||
/* Extract the offset */
|
||||
n = ph7_value_to_int64(apArg[3]);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
PH7_StreamCloseHandle(pStream, pHandle);
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
if(n > 0) {
|
||||
if(pStream->xSeek) {
|
||||
/* Seek to the desired offset */
|
||||
@@ -3768,6 +3815,10 @@ static int PH7_builtin_file_get_contents(ph7_context *pCtx, int nArg, ph7_value
|
||||
}
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
PH7_StreamCloseHandle(pStream, pHandle);
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
nRead = 0;
|
||||
for(;;) {
|
||||
n = pStream->xRead(pHandle, zBuf,
|
||||
@@ -3839,6 +3890,9 @@ static int PH7_builtin_file_put_contents(ph7_context *pCtx, int nArg, ph7_value
|
||||
}
|
||||
/* Data to write */
|
||||
zData = ph7_value_to_string(apArg[1], &nLen);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
if(nLen < 1) {
|
||||
/* Nothing to write, return immediately */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
@@ -3862,6 +3916,9 @@ static int PH7_builtin_file_put_contents(ph7_context *pCtx, int nArg, ph7_value
|
||||
iOpenFlags |= PH7_IO_OPEN_APPEND;
|
||||
}
|
||||
}
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
pHandle = PH7_StreamOpenHandle(pCtx->pVm, pStream, zFile, iOpenFlags, use_include,
|
||||
nArg > 3 ? apArg[3] : 0, FALSE, FALSE);
|
||||
if(pHandle == 0) {
|
||||
@@ -4207,6 +4264,9 @@ static int PH7_builtin_fwrite(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
/* Extract the data to write */
|
||||
zString = ph7_value_to_string(apArg[1], &nLen);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
if(nArg > 2) {
|
||||
/* Maximum data length to write */
|
||||
n = ph7_value_to_int(apArg[2]);
|
||||
@@ -4214,6 +4274,9 @@ static int PH7_builtin_fwrite(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
nLen = n;
|
||||
}
|
||||
}
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
if(nLen < 1) {
|
||||
/* Nothing to write */
|
||||
ph7_result_int(pCtx, 0);
|
||||
@@ -4276,6 +4339,9 @@ static int PH7_builtin_flock(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
/* Requested lock operation */
|
||||
nLock = ph7_value_to_int(apArg[1]);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
/* Lock operation */
|
||||
rc = pStream->xLock(pDev->pHandle, nLock);
|
||||
/* IO result */
|
||||
@@ -4363,6 +4429,9 @@ static int csv_write_callback(ph7_value *pKey, ph7_value *pValue, void *pUserDat
|
||||
sxu32 n;
|
||||
/* Point to the raw data */
|
||||
zData = ph7_value_to_string(pValue, &nLen);
|
||||
if(pValue->pVm->iPendingTransfer) {
|
||||
return pValue->pVm->iPendingTransfer;
|
||||
}
|
||||
if(nLen < 1) {
|
||||
/* Nothing to write */
|
||||
return PH7_OK;
|
||||
@@ -4465,7 +4534,13 @@ static int PH7_builtin_fputcsv(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
}
|
||||
/* Iterate throw array entries and write csv data */
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
ph7_array_walk(apArg[1], csv_write_callback, &sCsv);
|
||||
if(pCtx->pVm->iPendingTransfer) {
|
||||
return pCtx->pVm->iPendingTransfer;
|
||||
}
|
||||
/* Write a line ending */
|
||||
#ifdef __WINNT__
|
||||
zEol = "\r\n";
|
||||
|
||||
Reference in New Issue
Block a user