Allow to set memory limit from SAPI.
The build was successful. Details

This commit is contained in:
Rafal Kupiec 2018-09-04 11:52:55 +02:00
parent c00c91599f
commit 8ca6deca4e
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
1 changed files with 8 additions and 0 deletions

View File

@ -58,6 +58,7 @@ static void Help(void) {
puts("ph7 [-h|-r|-d] path/to/php_file [script args]"); puts("ph7 [-h|-r|-d] path/to/php_file [script args]");
puts("\t-d: Dump PH7 byte-code instructions"); puts("\t-d: Dump PH7 byte-code instructions");
puts("\t-r: Report run-time errors"); puts("\t-r: Report run-time errors");
puts("\t-m: Set memory limit");
puts("\t-h: Display this message an exit"); puts("\t-h: Display this message an exit");
/* Exit immediately */ /* Exit immediately */
exit(0); exit(0);
@ -109,6 +110,7 @@ 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 *sLimitArg = NULL; /* Memory limit */
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 */
@ -128,6 +130,8 @@ int main(int argc, char **argv) {
} else if(c == 'r' || c == 'R') { } else if(c == 'r' || c == 'R') {
/* Report run-time errors */ /* Report run-time errors */
err_report = 1; err_report = 1;
} else if(c == 'm' || c == 'M' && SyStrlen(argv[n]) > 2) {
sLimitArg = argv[n] + 2;
} else { } else {
/* Display a help message and exit */ /* Display a help message and exit */
Help(); Help();
@ -146,6 +150,10 @@ int main(int argc, char **argv) {
*/ */
Fatal("Error while allocating a new PH7 engine instance"); Fatal("Error while allocating a new PH7 engine instance");
} }
rc = ph7_config(pEngine, PH7_CONFIG_MEM_LIMIT, sLimitArg, 0);
if(rc != PH7_OK) {
Fatal("Error while setting memory limit");
}
/* Set an error log consumer callback. This callback [Output_Consumer()] will /* Set an error log consumer callback. This callback [Output_Consumer()] will
* redirect all compile-time error messages to STDOUT. * redirect all compile-time error messages to STDOUT.
*/ */