ffi: improve support for functions returning arrays
[m6w6/ext-psi] / php_psi.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifndef PHP_PSI_H
27 #define PHP_PSI_H
28
29 #include "php.h"
30
31 extern zend_module_entry psi_module_entry;
32 #define phpext_psi_ptr &psi_module_entry
33
34 #define PHP_PSI_VERSION "0.1.0"
35
36 #ifdef PHP_WIN32
37 # define PHP_PSI_API __declspec(dllexport)
38 #elif defined(__GNUC__) && __GNUC__ >= 4
39 # define PHP_PSI_API __attribute__ ((visibility("default")))
40 #else
41 # define PHP_PSI_API
42 #endif
43
44 #ifdef ZTS
45 #include "TSRM.h"
46 #endif
47
48 static inline int psi_check_env(const char *var) {
49 char *set = getenv(var);
50 return (set && *set && '0' != *set);
51 }
52
53 typedef struct psi_object {
54 void *data;
55 void (*dtor)(void *data);
56 size_t size;
57 zend_object std;
58 } psi_object;
59
60 static inline psi_object *PSI_OBJ(zval *zv, zend_object *zo) {
61 if (zv) {
62 zo = Z_OBJ_P(zv);
63 }
64 if (!zo) {
65 return NULL;
66 }
67 return (void *) (((char *) zo) - zo->handlers->offset);
68 }
69
70 PHP_PSI_API zend_object *psi_object_init(zend_class_entry *ce);
71 PHP_PSI_API zend_object *psi_object_init_ex(zend_class_entry *ce, void *data, void (*dtor)(void *));
72 PHP_PSI_API zend_class_entry *psi_object_get_class_entry();
73
74 ZEND_BEGIN_MODULE_GLOBALS(psi)
75 char *engine;
76 char *directory;
77 char *search_path;
78 struct psi_context_ops *ops;
79 struct psi_context *context;
80 struct {
81 struct psi_plist *decls;
82 struct psi_plist *vars;
83 } blacklist;
84 ZEND_END_MODULE_GLOBALS(psi);
85
86 ZEND_EXTERN_MODULE_GLOBALS(psi);
87
88 #define PSI_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(psi, v)
89
90 #if defined(ZTS) && defined(COMPILE_DL_PSI)
91 ZEND_TSRMLS_CACHE_EXTERN();
92 #endif
93
94 #endif /* PHP_PSI_H */
95
96
97 /*
98 * Local variables:
99 * tab-width: 4
100 * c-basic-offset: 4
101 * End:
102 * vim600: noet sw=4 ts=4 fdm=marker
103 * vim<600: noet sw=4 ts=4
104 */