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
)
30 #define FNM_CASEFOLD 0
32 return 0 == fnmatch("*.psi", entry
->d_name
, FNM_CASEFOLD
);
35 PHP_MINIT_FUNCTION(psi
)
39 struct dirent
**entries
= NULL
;
41 REGISTER_INI_ENTRIES();
45 if (!(ctx
= jit_context_create())) {
46 zend_error(E_WARNING
, "Could not initialize libjit!");
52 n
= php_scandir(PSI_G(directory
), &entries
, psi_select_dirent
, alphasort
);
54 php_error(E_WARNING
, "Failed to scan PSI directory '%s'", PSI_G(directory
));
55 } else for (i
= 0; i
< n
; ++i
) {
60 if (MAXPATHLEN
<= slprintf(psi
, MAXPATHLEN
, "%s/%s", PSI_G(directory
), entries
[i
]->d_name
)) {
61 php_error(E_WARNING
, "Path to PSI file too long: %s/%s",
62 PSI_G(directory
), entries
[i
]->d_name
);
64 if (!PSI_ParserInit(&P
, psi
, 0)) {
65 php_error(E_WARNING
, "Failed to init PSI parser (%s): %s",
66 psi
, strerror(errno
));
70 while (-1 != PSI_ParserScan(&P
)) {
71 PSI_ParserParse(&P
, PSI_TokenAlloc(&P
));
73 PSI_ParserParse(&P
, NULL
);
75 if (!PSI_ValidatorInit(&V
, &P
)) {
76 php_error(E_WARNING
, "Failed to init PSI validator");
81 if (PSI_ValidatorValidate(&V
)) {
84 jit_context_build_start(ctx
);
85 if (PSI_CompilerInit(&C
, &V
, ctx
)) {
86 zend_function_entry
*closures
= PSI_CompilerCompile(&C
);
89 if (SUCCESS
!= zend_register_functions(NULL
, closures
, NULL
, MODULE_PERSISTENT
)) {
90 fprintf(stderr
, "Failed to register functions!\n");
93 //PSI_CompilerDtor(&C);
95 jit_context_build_end(ctx
);
97 PSI_ValidatorDtor(&V
);
100 for (i
= 0; i
< n
; ++i
) {
107 PHP_MSHUTDOWN_FUNCTION(psi
)
109 jit_context_t ctx
= PSI_G(context
);
110 jit_context_destroy(ctx
);
112 UNREGISTER_INI_ENTRIES();
117 /* Remove if there's nothing to do at request start */
118 /* {{{ PHP_RINIT_FUNCTION
120 PHP_RINIT_FUNCTION(psi
)
122 #if defined(COMPILE_DL_PSI) && defined(ZTS)
123 ZEND_TSRMLS_CACHE_UPDATE();
129 /* Remove if there's nothing to do at request end */
130 /* {{{ PHP_RSHUTDOWN_FUNCTION
132 PHP_RSHUTDOWN_FUNCTION(psi
)
138 PHP_MINFO_FUNCTION(psi
)
140 php_info_print_table_start();
141 php_info_print_table_header(2, "psi support", "enabled");
142 php_info_print_table_end();
144 DISPLAY_INI_ENTRIES();
146 const zend_function_entry psi_functions
[] = {
150 zend_module_entry psi_module_entry
= {
151 STANDARD_MODULE_HEADER
,
156 PHP_RINIT(psi
), /* Replace with NULL if there's nothing to do at request start */
157 PHP_RSHUTDOWN(psi
), /* Replace with NULL if there's nothing to do at request end */
160 STANDARD_MODULE_PROPERTIES
163 #ifdef COMPILE_DL_PSI
165 ZEND_TSRMLS_CACHE_DEFINE();
175 * vim600: noet sw=4 ts=4 fdm=marker
176 * vim<600: noet sw=4 ts=4