X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fcontext.c;h=49391305879892bfc33399d34ab0a4c0be77f4ec;hp=2b91f43adfe294c5bb5c7ff82f30b619feef59a1;hb=6e8b5c090b44299f82f4e748d8bf6b8bc5b66414;hpb=4a49fe2f8eb21cdeabb06acec7a0395b6708d911 diff --git a/src/context.c b/src/context.c index 2b91f43..4939130 100644 --- a/src/context.c +++ b/src/context.c @@ -6,6 +6,8 @@ #include "php.h" #include "php_scandir.h" #include "context.h" +#include "parser.h" +#include "validator.h" PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErrorFunc error) { @@ -38,7 +40,7 @@ void PSI_ContextBuild(PSI_Context *C, const char *path) n = php_scandir(path, &entries, psi_select_dirent, alphasort); if (n < 0) { - C->error(PSI_WARNING, "Failed to scan PSI directory '%s'", path); + return; } else for (i = 0; i < n; ++i) { char psi[MAXPATHLEN]; PSI_Parser P; @@ -48,7 +50,7 @@ void PSI_ContextBuild(PSI_Context *C, const char *path) C->error(PSI_WARNING, "Path to PSI file too long: %s/%s", path, entries[i]->d_name); } - if (!PSI_ParserInit(&P, psi, psi_error, 0)) { + if (!PSI_ParserInit(&P, psi, C->error, 0)) { C->error(PSI_WARNING, "Failed to init PSI parser (%s): %s", psi, strerror(errno)); continue; @@ -66,12 +68,12 @@ void PSI_ContextBuild(PSI_Context *C, const char *path) PSI_ParserDtor(&P); if (PSI_ValidatorValidate(&V)) { - zend_function_entry *closures = PSI_ContextCompile(C, (PSI_Data *) &V); + zend_function_entry *closures; + closures = PSI_ContextCompile(C, (PSI_Data *) &V); if (closures && SUCCESS != zend_register_functions(NULL, closures, NULL, MODULE_PERSISTENT)) { C->error(PSI_WARNING, "Failed to register functions!"); } - } PSI_ValidatorDtor(&V); } @@ -86,9 +88,36 @@ void PSI_ContextBuild(PSI_Context *C, const char *path) zend_function_entry *PSI_ContextCompile(PSI_Context *C, PSI_Data *D) { - size_t count = C->count++; + size_t i, count = C->count++; zend_function_entry *zfe; + if (D->consts) { + zend_constant zc; + + zc.flags = CONST_PERSISTENT|CONST_CS; + zc.module_number = EG(current_module)->module_number; + + for (i = 0; i < D->consts->count; ++i) { + constant *c = D->consts->list[i]; + + zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1); + ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1)); + + switch (c->type->type) { + case PSI_T_BOOL: + convert_to_boolean(&zc.value); + break; + case PSI_T_INT: + convert_to_long(&zc.value); + break; + case PSI_T_FLOAT: + convert_to_double(&zc.value); + break; + } + zend_register_constant(&zc); + } + } + C->data = realloc(C->data, C->count * sizeof(*C->data)); PSI_DataExchange(&C->data[count], D); @@ -108,8 +137,12 @@ void PSI_ContextDtor(PSI_Context *C) for (i = 0; i < C->count; ++i) { PSI_DataDtor(&C->data[i]); + if (C->closures[i]){ + free(C->closures[i]); + } } free(C->data); + free(C->closures); memset(C, 0, sizeof(*C)); }