summaryrefslogtreecommitdiff
blob: 0124003bc1fc9c412a868b9dc6ac78379f84c2b9 (plain)
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
--- uuid/php/uuid.c	2016-12-18 01:23:26.000000000 -0500
+++ uuid/php/uuid.c	2016-12-18 01:23:43.564329483 -0500
@@ -41,7 +41,13 @@
 } ctx_t;
 
 /* context implicit destruction */
+#if PHP_VERSION_ID >= 70000
+static void ctx_destructor(zend_resource *rsrc)
+#else
+typedef long zend_long;
+
 static void ctx_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+#endif
 {
     ctx_t *ctx = (ctx_t *)rsrc->ptr;
 
@@ -120,16 +126,23 @@
     zval *z_ctx;
     ctx_t *ctx;
     uuid_rc_t rc;
+#if PHP_VERSION_ID >= 70000
+    char *param_types = "z/";
+#else
+    char *param_types = "z";
+#endif

     /* parse parameters */
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_ctx) == FAILURE)
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, param_types, &z_ctx) == FAILURE)
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID < 70000
     if (!PZVAL_IS_REF(z_ctx)) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_create: parameter wasn't passed by reference");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#endif
 
     /* perform operation */
     if ((ctx = (ctx_t *)malloc(sizeof(ctx_t))) == NULL)
@@ -138,7 +151,12 @@
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_create: %s", uuid_error(rc));
         RETURN_LONG((long)rc);
     }
+#if PHP_VERSION_ID >= 70000
+    zval_dtor(z_ctx);
+    ZVAL_RES(z_ctx, zend_register_resource(ctx, ctx_id));
+#else
     ZEND_REGISTER_RESOURCE(z_ctx, ctx, ctx_id);
+#endif
 
     RETURN_LONG((long)rc);
 }
@@ -158,7 +177,11 @@
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_destroy: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
@@ -185,21 +208,32 @@
     zval *z_clone;
     ctx_t *clone;
     uuid_rc_t rc;
+#if PHP_VERSION_ID >= 70000
+    char *param_types = "rz/";
+#else
+    char *param_types = "rz";
+#endif
 
     /* parse parameters */
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", &z_ctx, &z_clone) == FAILURE)
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, param_types, &z_ctx, &z_clone) == FAILURE)
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_clone: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#if PHP_VERSION_ID < 70000
     if (!PZVAL_IS_REF(z_clone)) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_clone: clone parameter wasn't passed by reference");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#endif
 
     /* perform operation */
     if ((clone = (ctx_t *)malloc(sizeof(ctx_t))) == NULL)
@@ -208,7 +243,12 @@
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_clone: %s", uuid_error(rc));
         RETURN_LONG((long)rc);
     }
+#if PHP_VERSION_ID >= 70000
+    zval_dtor(z_clone);
+    ZVAL_RES(z_clone, zend_register_resource(clone, ctx_id));
+#else
     ZEND_REGISTER_RESOURCE(z_clone, clone, ctx_id);
+#endif
 
     RETURN_LONG((long)rc);
 }
@@ -230,7 +271,11 @@
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_load: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
@@ -254,7 +299,7 @@
     zval *z_ctx;
     ctx_t *ctx;
     uuid_rc_t rc;
-    long z_mode;
+    zend_long z_mode;
     unsigned long mode;
     zval *z_ctx_ns;
     ctx_t *ctx_ns;
@@ -266,7 +311,11 @@
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_make: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
@@ -281,7 +330,11 @@
         }
     }
     else if (ZEND_NUM_ARGS() == 4 && ((mode & UUID_MAKE_V3) || (mode & UUID_MAKE_V5))) {
+#if PHP_VERSION_ID >= 70000
+        ctx_ns = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx_ns), ctx_name, ctx_id);
+#else
         ZEND_FETCH_RESOURCE(ctx_ns, ctx_t *, &z_ctx_ns, -1, ctx_name, ctx_id);
+#endif
         if (ctx_ns == NULL) {
             php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_make: invalid namespace context");
             RETURN_LONG((long)UUID_RC_ARG);
@@ -314,21 +367,33 @@
     uuid_rc_t rc;
     zval *z_result;
     int result;
+#if PHP_VERSION_ID >= 70000
+    char *param_types = "rz/";
+#else
+    char *param_types = "rz";
+#endif
 
     /* parse parameters */
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz", &z_ctx, &z_result) == FAILURE)
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, param_types, &z_ctx, &z_result) == FAILURE)
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    zval_dtor(z_result);
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_isnil: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#if PHP_VERSION_ID < 70000
     if (!PZVAL_IS_REF(z_result)) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_isnil: result parameter wasn't passed by reference");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#endif
 
     /* perform operation */
     if ((rc = uuid_isnil(ctx->uuid, &result)) != UUID_RC_OK) {
@@ -353,26 +418,42 @@
     uuid_rc_t rc;
     zval *z_result;
     int result;
+#if PHP_VERSION_ID >= 70000
+    char *param_types = "rrz/";
+#else
+    char *param_types = "rrz";
+#endif
 
     /* parse parameters */
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrz", &z_ctx, &z_ctx2, &z_result) == FAILURE)
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, param_types, &z_ctx, &z_ctx2, &z_result) == FAILURE)
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    zval_dtor(z_result);
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
-        php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_compare: invalid context");
+        php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_compare: invalid context from first parameter");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#if PHP_VERSION_ID >= 70000
+    ctx2 = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx2), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx2, ctx_t *, &z_ctx2, -1, ctx_name, ctx_id);
+#endif
-    if (ctx2 == NULL || ctx2->uuid) {
-        php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_compare: invalid context");
+    if (ctx2 == NULL || ctx2->uuid == NULL) {
+        php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_compare: invalid context from second parameter");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#if PHP_VERSION_ID < 70000
     if (!PZVAL_IS_REF(z_result)) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_compare: result parameter wasn't passed by reference");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#endif
 
     /* perform operation */
     if ((rc = uuid_compare(ctx->uuid, ctx2->uuid, &result)) != UUID_RC_OK) {
@@ -392,7 +473,7 @@
 {
     zval *z_ctx;
     ctx_t *ctx;
-    long z_fmt;
+    zend_long z_fmt;
     unsigned long fmt;
     zval *z_data;
     uuid_rc_t rc;
@@ -404,7 +485,11 @@
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_import: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
@@ -428,28 +513,40 @@
 {
     zval *z_ctx;
     ctx_t *ctx;
-    long z_fmt;
+    zend_long z_fmt;
     unsigned long fmt;
     zval *z_data;
     uuid_rc_t rc;
     void *data_ptr;
     size_t data_len;
+#if PHP_VERSION_ID >= 70000
+    char *param_types = "rlz/";
+#else
+    char *param_types = "rlz";
+#endif
 
     /* parse parameters */
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlz", &z_ctx, &z_fmt, &z_data) == FAILURE)
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, param_types, &z_ctx, &z_fmt, &z_data) == FAILURE)
         RETURN_LONG((long)UUID_RC_ARG);
 
     /* post-process and sanity check parameters */
+#if PHP_VERSION_ID >= 70000
+    zval_dtor(z_data);
+    ctx = (ctx_t *)zend_fetch_resource(Z_RES_P(z_ctx), ctx_name, ctx_id);
+#else
     ZEND_FETCH_RESOURCE(ctx, ctx_t *, &z_ctx, -1, ctx_name, ctx_id);
+#endif
     if (ctx == NULL || ctx->uuid == NULL) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_export: invalid context");
         RETURN_LONG((long)UUID_RC_ARG);
     }
     fmt = (unsigned long)z_fmt;
+#if PHP_VERSION_ID < 70000
     if (!PZVAL_IS_REF(z_data)) {
         php_error_docref(NULL TSRMLS_CC, E_WARNING, "uuid_export: data parameter wasn't passed by reference");
         RETURN_LONG((long)UUID_RC_ARG);
     }
+#endif
 
     /* perform operation */
     data_ptr = NULL;
@@ -462,7 +559,11 @@
         data_len = strlen((char *)data_ptr);
     else if (fmt == UUID_FMT_STR || fmt == UUID_FMT_TXT)
         data_len--; /* PHP doesn't wish NUL-termination on strings */
+#if PHP_VERSION_ID >= 70000
+    ZVAL_STRINGL(z_data, data_ptr, data_len);
+#else
     ZVAL_STRINGL(z_data, data_ptr, data_len, 1);
+#endif
     free(data_ptr);
 
     RETURN_LONG((long)rc);
@@ -474,7 +575,7 @@
    return error string corresponding to error return code */
 ZEND_FUNCTION(uuid_error)
 {
-    int z_rc;
+    zend_long z_rc;
     uuid_rc_t rc;
     char *error;
 
@@ -483,7 +584,11 @@
     rc = (uuid_rc_t)z_rc;
     if ((error = uuid_error(rc)) == NULL)
         RETURN_NULL();
+#if PHP_VERSION_ID >= 70000
+    RETURN_STRING(error);
+#else
     RETURN_STRING(error, 1);
+#endif
 }
 
 /* API FUNCTION: