X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fcontext.c;h=22fd915c8a73c0d81d0b49a13fdc99afee873935;hp=d1f808cb19512d076f90b4b024325d64ca25a9a8;hb=09529efcde471127419e141807b83b37077003a0;hpb=c9384515a81cb64d345b299908b2852f51bb8e6e diff --git a/src/context.c b/src/context.c index d1f808c..22fd915 100644 --- a/src/context.c +++ b/src/context.c @@ -58,6 +58,58 @@ #include "php_psi_posix.h" +PHP_MINIT_FUNCTION(psi_context) +{ + unsigned flags = 0; + struct psi_context_ops *ops = NULL; + +#ifdef HAVE_LIBJIT + if (!strcasecmp(PSI_G(engine), "jit")) { + ops = psi_libjit_ops(); + } else +#endif +#ifdef HAVE_LIBFFI + ops = psi_libffi_ops(); +#endif + + if (!ops) { + php_error(E_WARNING, "No PSI engine found"); + return FAILURE; + } + + PSI_G(ops) = ops; + if (ops->load && SUCCESS != ops->load()) { + return FAILURE; + } + + if (psi_check_env("PSI_DEBUG")) { + flags |= PSI_DEBUG; + } + if (psi_check_env("PSI_SILENT")) { + flags |= PSI_SILENT; + } + + PSI_G(context) = psi_context_init(NULL, PSI_G(ops), psi_error_wrapper, flags); + psi_context_build(PSI_G(context), PSI_G(directory)); + + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(psi_context) +{ + if (psi_check_env("PSI_DUMP")) { + psi_context_dump(PSI_G(context), STDOUT_FILENO); + } + + psi_context_free(&PSI_G(context)); + + if (PSI_G(ops)->free) { + PSI_G(ops)->free(); + } + + return SUCCESS; +} + struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_ops *ops, psi_error_cb error, unsigned flags) { if (!C) { @@ -142,7 +194,7 @@ void psi_context_build(struct psi_context *C, const char *paths) psi_parser_parse(&P, I); psi_context_add(C, &P); psi_parser_dtor(&P); - free(I); + psi_parser_input_free(&I); } } @@ -168,8 +220,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C) { zend_constant zc; - zc.flags = CONST_PERSISTENT|CONST_CS; - zc.module_number = EG(current_module)->module_number; + ZEND_CONSTANT_SET_FLAGS(&zc, CONST_CS|CONST_PERSISTENT, EG(current_module)->module_number); if (C->consts) { size_t i = 0; @@ -177,11 +228,11 @@ zend_function_entry *psi_context_compile(struct psi_context *C) while (psi_plist_get(C->consts, i++, &c)) { - if (zend_get_constant_str(c->name, strlen(c->name))) { + if (zend_get_constant(c->name)) { continue; } - zc.name = zend_string_init(c->name, strlen(c->name), 1); + zc.name = zend_string_copy(c->name); switch (c->type->type) { case PSI_T_BOOL: @@ -197,6 +248,9 @@ zend_function_entry *psi_context_compile(struct psi_context *C) case PSI_T_STRING: case PSI_T_QUOTED_STRING: ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str)); + if (ZSTR_IS_INTERNED(Z_STR(zc.value))) { + Z_TYPE_FLAGS(zc.value) = 0; + } break; default: assert(0); @@ -219,9 +273,9 @@ zend_function_entry *psi_context_compile(struct psi_context *C) zend_string *name; if (psi_decl_type_is_anon(e->name, "enum")) { - name = strpprintf(0, "psi\\%s", item->name); + name = strpprintf(0, "psi\\%s", item->name->val); } else { - name = strpprintf(0, "psi\\%s\\%s", e->name, item->name); + name = strpprintf(0, "psi\\%s\\%s", e->name->val, item->name->val); } if (zend_get_constant(name)) { @@ -324,8 +378,13 @@ void psi_context_free(struct psi_context **C) void psi_context_dump(struct psi_context *C, int fd) { - dprintf(fd, "// psi.engine=%s\n", - (char *) C->ops->query(C, PSI_CONTEXT_QUERY_SELF, NULL)); + size_t i; + + dprintf(fd, "// psi.engine=%s\n// %lu files\n", + (char *) C->ops->query(C, PSI_CONTEXT_QUERY_SELF, NULL), + C->count); - psi_data_dump(fd, PSI_DATA(C)); + for (i = 0; i < C->count; ++i) { + psi_data_dump(fd, &C->data[i]); + } }