flush
[m6w6/ext-psi] / src / module.c
1
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5
6 #include "php.h"
7 #include "php_ini.h"
8 #include "ext/standard/info.h"
9
10 #include "php_psi.h"
11
12 #include "libjit.h"
13
14 ZEND_DECLARE_MODULE_GLOBALS(psi);
15
16 PHP_INI_BEGIN()
17 STD_PHP_INI_ENTRY("psi.directory", "psis", PHP_INI_ALL, OnUpdateString, directory, zend_psi_globals, psi_globals)
18 PHP_INI_END();
19
20 void psi_error(int type, const char *msg, ...)
21 {
22 char buf[0x1000];
23 va_list argv;
24
25 va_start(argv, msg);
26 vslprintf(buf, 0x1000, msg, argv);
27 va_end(argv);
28
29 php_error(type, buf);
30 }
31
32 PHP_MINIT_FUNCTION(psi)
33 {
34 REGISTER_INI_ENTRIES();
35
36 PSI_ContextInit(&PSI_G(context), PSI_Libjit(), psi_error);
37 PSI_ContextBuild(&PSI_G(context), PSI_G(directory));
38
39 return SUCCESS;
40 }
41 PHP_MSHUTDOWN_FUNCTION(psi)
42 {
43 PSI_ContextDtor(&PSI_G(context));
44
45 UNREGISTER_INI_ENTRIES();
46
47 return SUCCESS;
48 }
49
50 /* Remove if there's nothing to do at request start */
51 /* {{{ PHP_RINIT_FUNCTION
52 */
53 PHP_RINIT_FUNCTION(psi)
54 {
55 #if defined(COMPILE_DL_PSI) && defined(ZTS)
56 ZEND_TSRMLS_CACHE_UPDATE();
57 #endif
58 return SUCCESS;
59 }
60 /* }}} */
61
62 /* Remove if there's nothing to do at request end */
63 /* {{{ PHP_RSHUTDOWN_FUNCTION
64 */
65 PHP_RSHUTDOWN_FUNCTION(psi)
66 {
67 return SUCCESS;
68 }
69 /* }}} */
70
71 PHP_MINFO_FUNCTION(psi)
72 {
73 php_info_print_table_start();
74 php_info_print_table_header(2, "psi support", "enabled");
75 php_info_print_table_end();
76
77 DISPLAY_INI_ENTRIES();
78 }
79 const zend_function_entry psi_functions[] = {
80 PHP_FE_END
81 };
82
83 zend_module_entry psi_module_entry = {
84 STANDARD_MODULE_HEADER,
85 "psi",
86 psi_functions,
87 PHP_MINIT(psi),
88 PHP_MSHUTDOWN(psi),
89 PHP_RINIT(psi), /* Replace with NULL if there's nothing to do at request start */
90 PHP_RSHUTDOWN(psi), /* Replace with NULL if there's nothing to do at request end */
91 PHP_MINFO(psi),
92 PHP_PSI_VERSION,
93 STANDARD_MODULE_PROPERTIES
94 };
95
96 #ifdef COMPILE_DL_PSI
97 #ifdef ZTS
98 ZEND_TSRMLS_CACHE_DEFINE();
99 #endif
100 ZEND_GET_MODULE(psi)
101 #endif
102
103 /*
104 * Local variables:
105 * tab-width: 4
106 * c-basic-offset: 4
107 * End:
108 * vim600: noet sw=4 ts=4 fdm=marker
109 * vim<600: noet sw=4 ts=4
110 */