X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fmodule.c;h=4df3e110a4c65c49323d2c0cae64ca22c8686999;hp=389cbc5752e123fc33cd1fab4eb8a4f7c264da80;hb=762750b4a3f4e0471993849c4bd12965f6b62356;hpb=7d79fea75fc664e54a5d5a2668a55f554296a845 diff --git a/src/module.c b/src/module.c index 389cbc5..4df3e11 100644 --- a/src/module.c +++ b/src/module.c @@ -3,20 +3,13 @@ #include "config.h" #endif -#include -#include -#include - #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" -#include "php_scandir.h" #include "php_psi.h" -#include "parser.h" -#include "validator.h" -#include "compiler.h" +#include "libjit.h" ZEND_DECLARE_MODULE_GLOBALS(psi); @@ -24,85 +17,30 @@ PHP_INI_BEGIN() STD_PHP_INI_ENTRY("psi.directory", "psis", PHP_INI_ALL, OnUpdateString, directory, zend_psi_globals, psi_globals) PHP_INI_END(); -static int psi_select_dirent(const struct dirent *entry) +void psi_error(int type, const char *msg, ...) { - return 0 == fnmatch("*.psi", entry->d_name, FNM_CASEFOLD); + char buf[0x1000]; + va_list argv; + + va_start(argv, msg); + vslprintf(buf, 0x1000, msg, argv); + va_end(argv); + + php_error(type, buf); } PHP_MINIT_FUNCTION(psi) { - jit_context_t ctx; - int i, n; - struct dirent **entries = NULL; - REGISTER_INI_ENTRIES(); - jit_init(); - - if (!(ctx = jit_context_create())) { - zend_error(E_WARNING, "Could not initialize libjit!"); - return FAILURE; - } - - PSI_G(context) = ctx; - - n = php_scandir(PSI_G(directory), &entries, psi_select_dirent, alphasort); - if (n < 0) { - php_error(E_WARNING, "Failed to scan PSI directory '%s'", PSI_G(directory)); - } else for (i = 0; i < n; ++i) { - char psi[MAXPATHLEN]; - PSI_Parser P; - PSI_Validator V; - - if (MAXPATHLEN <= slprintf(psi, MAXPATHLEN, "%s/%s", PSI_G(directory), entries[i]->d_name)) { - php_error(E_WARNING, "Path to PSI file too long: %s/%s", - PSI_G(directory), entries[i]->d_name); - } - if (!PSI_ParserInit(&P, psi, 0)) { - php_error(E_WARNING, "Failed to init PSI parser (%s): %s", - psi, strerror(errno)); - continue; - } - - while (-1 != PSI_ParserScan(&P)) { - PSI_ParserParse(&P, PSI_TokenAlloc(&P)); - }; - PSI_ParserParse(&P, NULL); - - if (!PSI_ValidatorInit(&V, &P)) { - php_error(E_WARNING, "Failed to init PSI validator"); - break; - } - PSI_ParserDtor(&P); - - if (PSI_ValidatorValidate(&V)) { - PSI_Compiler C; - - jit_context_build_start(ctx); - if (PSI_CompilerInit(&C, &V, ctx)) { - zend_function_entry *closures = PSI_CompilerCompile(&C); - - if (closures) { - zend_register_functions(NULL, closures, NULL, MODULE_PERSISTENT); - } - PSI_CompilerDtor(&C); - } - jit_context_build_end(ctx); - } - PSI_ValidatorDtor(&V); - } - if (entries) { - for (i = 0; i < n; ++i) { - free(entries[i]); - } - free(entries); - } + PSI_ContextInit(&PSI_G(context), PSI_Libjit(), psi_error); + PSI_ContextBuild(&PSI_G(context), PSI_G(directory)); + return SUCCESS; } PHP_MSHUTDOWN_FUNCTION(psi) { - jit_context_t ctx = PSI_G(context); - jit_context_destroy(ctx); + PSI_ContextDtor(&PSI_G(context)); UNREGISTER_INI_ENTRIES();