-
Notifications
You must be signed in to change notification settings - Fork 10
/
php_ogr_shims.h
executable file
·185 lines (170 loc) · 7.43 KB
/
php_ogr_shims.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/******************************************************************************
* Project: PHP Interface for OGR C API
* Purpose: Shims for PHP5 and PHP7+ compatibility
* Author: Edward Nash, e.nash@dvz-mv.de
*
******************************************************************************
* Copyright (c) 2019-2021, DVZ Datenverarbeitungszentrum Mecklenburg-Vorpommern GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*/
/* Shim macros ZEND_FETCH_RESOURCE and ZEND_FETCH_RESOURCE2 for PHP7+ */
#if PHP_MAJOR_VERSION < 7
#define _ZEND_FETCH_RESOURCE(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type) \
ZEND_FETCH_RESOURCE(rsrc, rsrc_type, &passed_id, default_id, resource_type_name, resource_type)
#define _ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2) \
ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, &passed_id, default_id, resource_type_name, resource_type1, resource_type2)
#else
#define _ZEND_FETCH_RESOURCE(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type) \
rsrc = (rsrc_type) zend_fetch_resource(Z_RES_P(passed_id), resource_type_name, resource_type); \
if (rsrc == NULL) RETURN_FALSE;
#define _ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1, resource_type2) \
rsrc = (rsrc_type) zend_fetch_resource2(Z_RES_P(passed_id), resource_type_name, resource_type1, resource_type2); \
if (rsrc == NULL) RETURN_FALSE;
#endif
/* Define macro ZEND_REGISTER_RESOURCE for PHP7+ */
#if PHP_MAJOR_VERSION >= 7
#define ZEND_REGISTER_RESOURCE(zval, rsrc, resource_type) \
ZVAL_RES(zval, zend_register_resource(rsrc, resource_type));
#endif
/* Shim function zend_list_delete for PHP7+ */
#if PHP_MAJOR_VERSION < 7
#define _ZEND_FREE_RESOURCE(zv) zend_list_delete(Z_LVAL_P(zv))
#else
#define _ZEND_FREE_RESOURCE(zv) zend_list_close(Z_RES_P(zv))
#endif
/* shim ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX and ZEND_ARG_TYPE_INFO for PHP5 backwards compatibility */
#if PHP_MAJOR_VERSION < 7
#define _ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, arginfo_required_num, type, class_name, allow_null) \
ZEND_BEGIN_ARG_INFO_EX(name, return_reference, 0, arginfo_required_num)
#define _ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
ZEND_ARG_INFO(pass_by_ref, name)
#else
#define _ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null)
/* class_name argument was removed in PHP 7.2 */
#if PHP_MAJOR_VERSION < 8 && PHP_MINOR_VERSION < 2
#define _ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, arginfo_required_num, type, class_name, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, arginfo_required_num, type, class_name, allow_null)
#else
#define _ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, arginfo_required_num, type, class_name, allow_null) \
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, arginfo_required_num, type, allow_null)
#endif
#endif
/* shim zend_rsrc_list_entry (PHP5) and zend_resource (PHP7+) */
#if PHP_MAJOR_VERSION < 7
typedef zend_rsrc_list_entry zend_resource_t;
#else
typedef zend_resource zend_resource_t;
#endif
/* shim string handling functions */
#if PHP_MAJOR_VERSION < 7
#define _RETURN_DUPLICATED_STRING(str) RETURN_STRING(str, 1)
#define _ZVAL_STRING(zv, str) ZVAL_STRING(zv, str, 1)
#define _ZVAL_STRINGL(zv, str, len) ZVAL_STRINGL(zv, str, len, 1)
#define _ADD_ASSOC_STRING(zval, key, str) \
add_assoc_string(zval, key, str, 1)
#define _ADD_NEXT_INDEX_STRING(zval, str) \
add_next_index_string(zval, str, 1)
#else
#define _RETURN_DUPLICATED_STRING(str) \
RETURN_STR(zend_string_init(str, strlen(str), 0))
#define _ZVAL_STRING(zv, str) ZVAL_STRING(zv, str)
#define _ZVAL_STRINGL(zv, str, len) ZVAL_STRINGL(zv, str, len)
#define _ADD_ASSOC_STRING(zval, key, str) \
add_assoc_str(zval, key, zend_string_init(str, strlen(str), 0))
#define _ADD_NEXT_INDEX_STRING(zval, str) \
add_next_index_str(zval, zend_string_init(str, strlen(str), 0))
#endif
/* shim usage of zend_list_find */
#if PHP_MAJOR_VERSION < 7
#define _ZEND_LIST_FINDD(zv, zvType) zend_list_find(Z_RESVAL_P(zv), &zvType)
#else
#define _ZEND_LIST_FINDD(zv, zvType) zvType = Z_RES_P(zv)->type
#endif
/* define shim macros for looping over a PHP array zval */
#if PHP_MAJOR_VERSION < 7
typedef zval** zval_loop_iterator_t;
#define _ZVAL_LOOP_ITERATOR_STRVAL(zv) Z_STRVAL_PP(zv)
#define _ZVAL_LOOP_ITERATOR_LVAL(zv) Z_LVAL_PP(zv)
#define _ZVAL_LOOP_ITERATOR_DVAL(zv) Z_DVAL_PP(zv)
#define _ZVAL_SIMPLE_LOOP_START(azv, izv) \
zend_hash_internal_pointer_reset(Z_ARRVAL_P(azv)); \
while (zend_hash_get_current_data(Z_ARRVAL_P(azv), (void **) &izv) == SUCCESS) {
#define _ZVAL_SIMPLE_LOOP_END(azv) \
zend_hash_move_forward(Z_ARRVAL_P(azv)); \
}
#else
typedef zval* zval_loop_iterator_t;
#define _ZVAL_LOOP_ITERATOR_STRVAL(zv) Z_STRVAL_P(zv)
#define _ZVAL_LOOP_ITERATOR_LVAL(zv) Z_LVAL_P(zv)
#define _ZVAL_LOOP_ITERATOR_DVAL(zv) Z_DVAL_P(zv)
#define _ZVAL_SIMPLE_LOOP_START(azv, izv) \
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(azv), izv) {
#define _ZVAL_SIMPLE_LOOP_END(azv) \
} ZEND_HASH_FOREACH_END();
#endif
/* shim php_stream_from_zval */
#if PHP_MAJOR_VERSION < 7
#define _PHP_STREAM_FROM_ZVAL(stream, hfile) php_stream_from_zval(stream, &hfile)
#else
#define _PHP_STREAM_FROM_ZVAL(stream, hfile) php_stream_from_zval(stream, hfile)
#endif
/* shim zend_long for PHP 5 */
#if PHP_MAJOR_VERSION < 7
typedef long zend_long;
#endif
/* shim zval string length type */
#if PHP_MAJOR_VERSION < 7
typedef int strsize_t;
#else
typedef size_t strsize_t;
#endif
/* shim zval_ptr_dtor */
#if PHP_MAJOR_VERSION < 7
#define _ZVAL_PTR_DTOR(__zval) zval_dtor(__zval)
#else
#define _ZVAL_PTR_DTOR(__zval) zval_ptr_dtor(__zval)
#endif
/* shim all thread-safety macros deprecated in PHP7 and removed in PHP8 */
#ifndef TSRMLS_D
#define TSRMLS_D void
#endif
#ifndef TSRMLS_DC
#define TSRMLS_DC
#endif
#ifndef TSRMLS_C
#define TSRMLS_C
#endif
#ifndef TSRMLS_CC
#define TSRMLS_CC
#endif
#ifndef TSRMLS_FETCH
#define TSRMLS_FETCH()
#endif
/* shim return check on object_init (void in PHP 8) */
#if PHP_MAJOR_VERSION < 8
#define OBJECT_INIT(_zval) if (object_init(_zval)==FAILURE) { \
php_report_ogr_error(E_WARNING); \
RETURN_FALSE; \
}
#else
#define OBJECT_INIT(_zval) object_init(_zval);
#endif