12 #include "ext/standard/info.h"
13 #include "php_scandir.h"
18 #include "validator.h"
21 ZEND_DECLARE_MODULE_GLOBALS(psi
);
24 STD_PHP_INI_ENTRY("psi.directory", "psis", PHP_INI_ALL
, OnUpdateString
, directory
, zend_psi_globals
, psi_globals
)
27 static int psi_select_dirent(const struct dirent
*entry
)
29 return 0 == fnmatch("*.psi", entry
->d_name
, FNM_CASEFOLD
);
32 PHP_MINIT_FUNCTION(psi
)
36 struct dirent
**entries
= NULL
;
38 REGISTER_INI_ENTRIES();
42 if (!(ctx
= jit_context_create())) {
43 zend_error(E_WARNING
, "Could not initialize libjit!");
49 n
= php_scandir(PSI_G(directory
), &entries
, psi_select_dirent
, alphasort
);
51 php_error(E_WARNING
, "Failed to scan PSI directory '%s'", PSI_G(directory
));
52 } else for (i
= 0; i
< n
; ++i
) {
57 if (MAXPATHLEN
<= slprintf(psi
, MAXPATHLEN
, "%s/%s", PSI_G(directory
), entries
[i
]->d_name
)) {
58 php_error(E_WARNING
, "Path to PSI file too long: %s/%s",
59 PSI_G(directory
), entries
[i
]->d_name
);
61 if (!PSI_ParserInit(&P
, psi
, 0)) {
62 php_error(E_WARNING
, "Failed to init PSI parser (%s): %s",
63 psi
, strerror(errno
));
67 while (-1 != PSI_ParserScan(&P
)) {
68 PSI_ParserParse(&P
, PSI_TokenAlloc(&P
));
70 PSI_ParserParse(&P
, NULL
);
72 if (!PSI_ValidatorInit(&V
, &P
)) {
73 php_error(E_WARNING
, "Failed to init PSI validator");
78 if (PSI_ValidatorValidate(&V
)) {
81 jit_context_build_start(ctx
);
82 if (PSI_CompilerInit(&C
, &V
, ctx
)) {
83 zend_function_entry
*closures
= PSI_CompilerCompile(&C
);
86 zend_register_functions(NULL
, closures
, NULL
, MODULE_PERSISTENT
);
90 jit_context_build_end(ctx
);
92 PSI_ValidatorDtor(&V
);
95 for (i
= 0; i
< n
; ++i
) {
102 PHP_MSHUTDOWN_FUNCTION(psi
)
104 jit_context_t ctx
= PSI_G(context
);
105 jit_context_destroy(ctx
);
107 UNREGISTER_INI_ENTRIES();
112 /* Remove if there's nothing to do at request start */
113 /* {{{ PHP_RINIT_FUNCTION
115 PHP_RINIT_FUNCTION(psi
)
117 #if defined(COMPILE_DL_PSI) && defined(ZTS)
118 ZEND_TSRMLS_CACHE_UPDATE();
124 /* Remove if there's nothing to do at request end */
125 /* {{{ PHP_RSHUTDOWN_FUNCTION
127 PHP_RSHUTDOWN_FUNCTION(psi
)
133 PHP_MINFO_FUNCTION(psi
)
135 php_info_print_table_start();
136 php_info_print_table_header(2, "psi support", "enabled");
137 php_info_print_table_end();
139 DISPLAY_INI_ENTRIES();
141 const zend_function_entry psi_functions
[] = {
145 zend_module_entry psi_module_entry
= {
146 STANDARD_MODULE_HEADER
,
151 PHP_RINIT(psi
), /* Replace with NULL if there's nothing to do at request start */
152 PHP_RSHUTDOWN(psi
), /* Replace with NULL if there's nothing to do at request end */
155 STANDARD_MODULE_PROPERTIES
158 #ifdef COMPILE_DL_PSI
160 ZEND_TSRMLS_CACHE_DEFINE();
170 * vim600: noet sw=4 ts=4 fdm=marker
171 * vim<600: noet sw=4 ts=4