1 --- geos-3.5.0/php/geos.c.orig 2015-08-14 20:23:15.000000000 +0200
2 +++ geos-3.5.0/php/geos.c 2016-03-18 22:08:27.255515276 +0100
4 #define zend_function_entry function_entry
7 +#if PHP_MAJOR_VERSION >= 7
8 +#define zend_uint zend_ulong
9 +#define PHP_RETURN_STRING(x, n) RETURN_STRING(x)
10 +#define PHP_RETURN_STRINGL(x, l, n) RETURN_STRINGL(x, l)
11 +#define php_zend_hash_get_current_key(s, k, i, n) zend_hash_get_current_key(s, k, i)
12 +#define php_add_assoc_string(rv, res, resv, n) add_assoc_string(rv, res, resv)
13 +#define PHP_KEY_VAL(key) ZSTR_VAL(key)
15 +#define PHP_RETURN_STRING(x, n) RETURN_STRING(x, n)
16 +#define PHP_RETURN_STRINGL(x, l, n) RETURN_STRINGL(x, l, n)
17 +#define php_zend_hash_get_current_key(s, k, i, n) zend_hash_get_current_key(s, k, i, n)
18 +#define php_add_assoc_string(rv, res, resv, n) add_assoc_string(rv, res, resv, n)
19 +#define PHP_KEY_VAL(key) (key)
22 static zend_function_entry geos_functions[] = {
23 PHP_FE(GEOSVersion, NULL)
24 PHP_FE(GEOSPolygonize, NULL)
28 typedef struct Proxy_t {
29 +#if PHP_MAJOR_VERSION >= 7
39 setRelay(zval* val, void* obj) {
41 +#if PHP_MAJOR_VERSION >= 7
42 + Proxy* proxy = (Proxy*)((char*)(Z_OBJ_P(val)) - XtOffsetOf(Proxy, std));
44 Proxy* proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
50 getRelay(zval* val, zend_class_entry* ce) {
52 - Proxy *proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
53 +#if PHP_MAJOR_VERSION >= 7
54 + Proxy* proxy = (Proxy*)((char*)(Z_OBJ_P(val)) - XtOffsetOf(Proxy, std));
56 + Proxy* proxy = (Proxy*)zend_object_store_get_object(val TSRMLS_CC);
58 if ( proxy->std.ce != ce ) {
59 php_error_docref(NULL TSRMLS_CC, E_ERROR,
60 "Relay object is not an %s", ce->name);
65 +#if PHP_MAJOR_VERSION >= 7
68 static zend_object_value
70 Gen_create_obj (zend_class_entry *type,
71 - zend_objects_free_object_storage_t st, zend_object_handlers* handlers)
72 +#if PHP_MAJOR_VERSION < 7
73 + zend_objects_free_object_storage_t st,
75 + zend_object_handlers* handlers)
78 +#if PHP_MAJOR_VERSION < 7
79 zend_object_value retval;
82 - Proxy *obj = (Proxy *)emalloc(sizeof(Proxy));
83 - memset(obj, 0, sizeof(Proxy));
84 +#if PHP_MAJOR_VERSION >= 7
85 + Proxy *obj = (Proxy *)ecalloc(1, sizeof(Proxy) + zend_object_properties_size(type));
86 + zend_object_std_init(&obj->std, type);
88 + Proxy *obj = (Proxy *)ecalloc(1, sizeof(Proxy));
92 ALLOC_HASHTABLE(obj->std.properties);
93 zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
95 object_properties_init(&(obj->std), type);
98 +#if PHP_MAJOR_VERSION >= 7
101 retval.handle = zend_objects_store_put(obj, NULL, st, NULL TSRMLS_CC);
102 retval.handlers = handlers;
111 /* Serializer function for GEOSGeometry */
113 +#if PHP_MAJOR_VERSION >= 7
115 +Geometry_serialize(zval *object, unsigned char **buffer, size_t *buf_len,
116 + zend_serialize_data *data TSRMLS_DC)
119 Geometry_serialize(zval *object, unsigned char **buffer, zend_uint *buf_len,
120 zend_serialize_data *data TSRMLS_DC)
123 GEOSWKBWriter *serializer;
129 +#if PHP_MAJOR_VERSION >= 7
131 +Geometry_deserialize(zval *object, zend_class_entry *ce, const unsigned char *buf,
132 + size_t buf_len, zend_unserialize_data *data TSRMLS_DC)
135 Geometry_deserialize(zval **object, zend_class_entry *ce, const unsigned char *buf,
136 zend_uint buf_len, zend_unserialize_data *data TSRMLS_DC)
139 GEOSWKBReader* deserializer;
142 "Geometry_deserialize called with unexpected zend_class_entry");
145 +#if PHP_MAJOR_VERSION >= 7
146 + object_init_ex(object, ce);
147 + setRelay(object, geom);
149 object_init_ex(*object, ce);
150 setRelay(*object, geom);
156 ngeoms = GEOSGetNumGeometries(g);
157 for (i=0; i<ngeoms; ++i)
159 +#if PHP_MAJOR_VERSION >= 7
165 const GEOSGeometry* c = GEOSGetGeometryN(g, i);
166 if ( ! c ) continue; /* should get an exception */
167 @@ -440,14 +506,30 @@
168 cc = GEOSGeom_clone(c);
169 if ( ! cc ) continue; /* should get an exception */
171 +#if PHP_MAJOR_VERSION >= 7
172 + object_init_ex(&tmp, Geometry_ce_ptr);
173 + setRelay(&tmp, cc);
174 + add_next_index_zval(array, &tmp);
177 object_init_ex(tmp, Geometry_ce_ptr);
179 add_next_index_zval(array, tmp);
185 +#if PHP_MAJOR_VERSION >= 7
187 +Geometry_dtor (zend_object *object TSRMLS_DC)
189 + Proxy *obj = (Proxy *)((char*)object - XtOffsetOf(Proxy, std));
190 + GEOSGeom_destroy((GEOSGeometry*)obj->relay);
192 + zend_object_std_dtor(object);
196 Geometry_dtor (void *object TSRMLS_DC)
198 @@ -459,13 +541,21 @@
204 +#if PHP_MAJOR_VERSION >= 7
205 +static zend_object *
206 +Geometry_create_obj (zend_class_entry *type TSRMLS_DC)
208 + return Gen_create_obj(type, &Geometry_object_handlers);
211 static zend_object_value
212 Geometry_create_obj (zend_class_entry *type TSRMLS_DC)
214 return Gen_create_obj(type, Geometry_dtor, &Geometry_object_handlers);
219 PHP_METHOD(Geometry, __construct)
225 - RETURN_STRING(ret, 0);
226 + PHP_RETURN_STRING(ret, 0);
229 PHP_METHOD(Geometry, project)
230 @@ -595,10 +685,16 @@
231 double mitreLimit = default_mitreLimit;
232 long singleSided = 0;
233 zval *style_val = NULL;
234 +#if PHP_MAJOR_VERSION >= 7
246 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
248 @@ -612,37 +708,62 @@
251 style = HASH_OF(style_val);
252 - while(zend_hash_get_current_key(style, &key, &index, 0)
253 + while(php_zend_hash_get_current_key(style, &key, &index, 0)
254 == HASH_KEY_IS_STRING)
256 - if(!strcmp(key, "quad_segs"))
257 + if(!strcmp(PHP_KEY_VAL(key), "quad_segs"))
259 +#if PHP_MAJOR_VERSION >= 7
260 + data = zend_hash_get_current_data(style);
261 + quadSegs = getZvalAsLong(data);
263 zend_hash_get_current_data(style, (void**)&data);
264 quadSegs = getZvalAsLong(*data);
266 GEOSBufferParams_setQuadrantSegments(params, quadSegs);
268 - else if(!strcmp(key, "endcap"))
269 + else if(!strcmp(PHP_KEY_VAL(key), "endcap"))
271 +#if PHP_MAJOR_VERSION >= 7
272 + data = zend_hash_get_current_data(style);
273 + endCapStyle = getZvalAsLong(data);
275 zend_hash_get_current_data(style, (void**)&data);
276 endCapStyle = getZvalAsLong(*data);
278 GEOSBufferParams_setEndCapStyle(params, endCapStyle);
280 - else if(!strcmp(key, "join"))
281 + else if(!strcmp(PHP_KEY_VAL(key), "join"))
283 +#if PHP_MAJOR_VERSION >= 7
284 + data = zend_hash_get_current_data(style);
285 + joinStyle = getZvalAsLong(data);
287 zend_hash_get_current_data(style, (void**)&data);
288 joinStyle = getZvalAsLong(*data);
290 GEOSBufferParams_setJoinStyle(params, joinStyle);
292 - else if(!strcmp(key, "mitre_limit"))
293 + else if(!strcmp(PHP_KEY_VAL(key), "mitre_limit"))
295 +#if PHP_MAJOR_VERSION >= 7
296 + data = zend_hash_get_current_data(style);
297 + mitreLimit = getZvalAsDouble(data);
299 zend_hash_get_current_data(style, (void**)&data);
300 mitreLimit = getZvalAsDouble(*data);
302 GEOSBufferParams_setMitreLimit(params, mitreLimit);
304 - else if(!strcmp(key, "single_sided"))
305 + else if(!strcmp(PHP_KEY_VAL(key), "single_sided"))
307 +#if PHP_MAJOR_VERSION >= 7
308 + data = zend_hash_get_current_data(style);
309 + singleSided = getZvalAsLong(data);
311 zend_hash_get_current_data(style, (void**)&data);
312 singleSided = getZvalAsLong(*data);
314 GEOSBufferParams_setSingleSided(params, singleSided);
317 @@ -687,10 +808,16 @@
318 long int joinStyle = default_joinStyle;
319 double mitreLimit = default_mitreLimit;
320 zval *style_val = NULL;
321 +#if PHP_MAJOR_VERSION >= 7
333 this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
335 @@ -702,23 +829,38 @@
338 style = HASH_OF(style_val);
339 - while(zend_hash_get_current_key(style, &key, &index, 0)
340 + while(php_zend_hash_get_current_key(style, &key, &index, 0)
341 == HASH_KEY_IS_STRING)
343 - if(!strcmp(key, "quad_segs"))
344 + if(!strcmp(PHP_KEY_VAL(key), "quad_segs"))
346 +#if PHP_MAJOR_VERSION >= 7
347 + data = zend_hash_get_current_data(style);
348 + quadSegs = getZvalAsLong(data);
350 zend_hash_get_current_data(style, (void**)&data);
351 quadSegs = getZvalAsLong(*data);
354 - else if(!strcmp(key, "join"))
355 + else if(!strcmp(PHP_KEY_VAL(key), "join"))
357 +#if PHP_MAJOR_VERSION >= 7
358 + data = zend_hash_get_current_data(style);
359 + joinStyle = getZvalAsLong(data);
361 zend_hash_get_current_data(style, (void**)&data);
362 joinStyle = getZvalAsLong(*data);
365 - else if(!strcmp(key, "mitre_limit"))
366 + else if(!strcmp(PHP_KEY_VAL(key), "mitre_limit"))
368 +#if PHP_MAJOR_VERSION >= 7
369 + data = zend_hash_get_current_data(style);
370 + mitreLimit = getZvalAsDouble(data);
372 zend_hash_get_current_data(style, (void**)&data);
373 mitreLimit = getZvalAsDouble(*data);
377 zend_hash_move_forward(style);
379 if ( ! pat ) RETURN_NULL(); /* should get an exception first */
380 retStr = estrdup(pat);
382 - RETURN_STRING(retStr, 0);
383 + PHP_RETURN_STRING(retStr, 0);
385 retInt = GEOSRelatePattern(this, other, pat);
386 if ( retInt == 2 ) RETURN_NULL(); /* should get an exception first */
387 @@ -1007,7 +1149,7 @@
388 if ( ! pat ) RETURN_NULL(); /* should get an exception first */
389 retStr = estrdup(pat);
391 - RETURN_STRING(retStr, 0);
392 + PHP_RETURN_STRING(retStr, 0);
396 @@ -1409,6 +1551,9 @@
399 char *reasonVal = NULL;
400 +#if PHP_MAJOR_VERSION >= 7
403 zval *locationVal = NULL;
406 @@ -1428,7 +1573,11 @@
410 +#if PHP_MAJOR_VERSION >= 7
411 + locationVal = &locationValS;
413 MAKE_STD_ZVAL(locationVal);
415 object_init_ex(locationVal, Geometry_ce_ptr);
416 setRelay(locationVal, location);
418 @@ -1438,7 +1587,7 @@
419 /* return value is an array */
420 array_init(return_value);
421 add_assoc_bool(return_value, "valid", retBool);
422 - if ( reasonVal ) add_assoc_string(return_value, "reason", reasonVal, 0);
423 + if ( reasonVal ) php_add_assoc_string(return_value, "reason", reasonVal, 0);
424 if ( locationVal ) add_assoc_zval(return_value, "location", locationVal);
427 @@ -1538,7 +1687,7 @@
428 typVal = estrdup(typ);
431 - RETURN_STRING(typVal, 0);
432 + PHP_RETURN_STRING(typVal, 0);
436 @@ -1999,6 +2148,16 @@
438 static zend_object_handlers WKTReader_object_handlers;
440 +#if PHP_MAJOR_VERSION >= 7
442 +WKTReader_dtor (zend_object *object TSRMLS_DC)
444 + Proxy *obj = (Proxy *)((char*)object - XtOffsetOf(Proxy, std));
445 + GEOSWKTReader_destroy((GEOSWKTReader*)obj->relay);
447 + zend_object_std_dtor(object);
451 WKTReader_dtor (void *object TSRMLS_DC)
453 @@ -2010,12 +2169,21 @@
459 +#if PHP_MAJOR_VERSION >= 7
460 +static zend_object *
461 +WKTReader_create_obj (zend_class_entry *type TSRMLS_DC)
463 + return Gen_create_obj(type, &WKTReader_object_handlers);
466 static zend_object_value
467 WKTReader_create_obj (zend_class_entry *type TSRMLS_DC)
469 return Gen_create_obj(type, WKTReader_dtor, &WKTReader_object_handlers);
474 PHP_METHOD(WKTReader, __construct)
475 @@ -2082,6 +2250,16 @@
477 static zend_object_handlers WKTWriter_object_handlers;
479 +#if PHP_MAJOR_VERSION >= 7
481 +WKTWriter_dtor (zend_object *object TSRMLS_DC)
483 + Proxy *obj = (Proxy *)((char*)object - XtOffsetOf(Proxy, std));
484 + GEOSWKTWriter_destroy((GEOSWKTWriter*)obj->relay);
486 + zend_object_std_dtor(object);
490 WKTWriter_dtor (void *object TSRMLS_DC)
492 @@ -2093,12 +2271,21 @@
498 +#if PHP_MAJOR_VERSION >= 7
499 +static zend_object *
500 +WKTWriter_create_obj (zend_class_entry *type TSRMLS_DC)
502 + return Gen_create_obj(type, &WKTWriter_object_handlers);
505 static zend_object_value
506 WKTWriter_create_obj (zend_class_entry *type TSRMLS_DC)
508 return Gen_create_obj(type, WKTWriter_dtor, &WKTWriter_object_handlers);
512 PHP_METHOD(WKTWriter, __construct)
514 @@ -2139,7 +2326,7 @@
515 retstr = estrdup(wkt);
518 - RETURN_STRING(retstr, 0);
519 + PHP_RETURN_STRING(retstr, 0);
522 PHP_METHOD(WKTWriter, setTrim)
523 @@ -2257,6 +2444,16 @@
525 static zend_object_handlers WKBWriter_object_handlers;
527 +#if PHP_MAJOR_VERSION >= 7
529 +WKBWriter_dtor (zend_object *object TSRMLS_DC)
531 + Proxy *obj = (Proxy *)((char*)object - XtOffsetOf(Proxy, std));
532 + GEOSWKBWriter_destroy((GEOSWKBWriter*)obj->relay);
534 + zend_object_std_dtor(object);
538 WKBWriter_dtor (void *object TSRMLS_DC)
540 @@ -2268,12 +2465,21 @@
546 +#if PHP_MAJOR_VERSION >= 7
547 +static zend_object *
548 +WKBWriter_create_obj (zend_class_entry *type TSRMLS_DC)
550 + return Gen_create_obj(type, &WKBWriter_object_handlers);
553 static zend_object_value
554 WKBWriter_create_obj (zend_class_entry *type TSRMLS_DC)
556 return Gen_create_obj(type, WKBWriter_dtor, &WKBWriter_object_handlers);
561 * GEOSWKBWriter w = new GEOSWKBWriter()
562 @@ -2356,7 +2562,7 @@
563 retstr = estrndup(ret, retsize);
566 - RETURN_STRINGL(retstr, retsize, 0);
567 + PHP_RETURN_STRINGL(retstr, retsize, 0);
571 @@ -2388,7 +2594,7 @@
572 retstr = estrndup(ret, retsize);
575 - RETURN_STRING(retstr, 0);
576 + PHP_RETURN_STRING(retstr, 0);
580 @@ -2481,6 +2687,16 @@
582 static zend_object_handlers WKBReader_object_handlers;
584 +#if PHP_MAJOR_VERSION >= 7
586 +WKBReader_dtor (zend_object *object TSRMLS_DC)
588 + Proxy *obj = (Proxy *)((char*)object - XtOffsetOf(Proxy, std));
589 + GEOSWKBReader_destroy((GEOSWKBReader*)obj->relay);
591 + zend_object_std_dtor(object);
595 WKBReader_dtor (void *object TSRMLS_DC)
597 @@ -2492,12 +2708,21 @@
603 +#if PHP_MAJOR_VERSION >= 7
604 +static zend_object *
605 +WKBReader_create_obj (zend_class_entry *type TSRMLS_DC)
607 + return Gen_create_obj(type, &WKBReader_object_handlers);
610 static zend_object_value
611 WKBReader_create_obj (zend_class_entry *type TSRMLS_DC)
613 return Gen_create_obj(type, WKBReader_dtor, &WKBReader_object_handlers);
618 PHP_METHOD(WKBReader, __construct)
619 @@ -2575,7 +2800,7 @@
622 str = estrdup(GEOSversion());
623 - RETURN_STRING(str, 0);
624 + PHP_RETURN_STRING(str, 0);
628 @@ -2608,7 +2833,11 @@
629 GEOSGeometry *cut_edges;
630 GEOSGeometry *dangles;
631 GEOSGeometry *invalid_rings;
632 +#if PHP_MAJOR_VERSION >= 7
639 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
640 @@ -2624,11 +2853,36 @@
641 /* return value should be an array */
642 array_init(return_value);
644 +#if PHP_MAJOR_VERSION >= 7
645 + ZVAL_NEW_ARR(&array_elem);
646 + array_init(&array_elem);
647 + dumpGeometry(rings, &array_elem);
648 + GEOSGeom_destroy(rings);
649 + add_assoc_zval(return_value, "rings", &array_elem);
651 + ZVAL_NEW_ARR(&array_elem);
652 + array_init(&array_elem);
653 + dumpGeometry(cut_edges, &array_elem);
654 + GEOSGeom_destroy(cut_edges);
655 + add_assoc_zval(return_value, "cut_edges", &array_elem);
657 + ZVAL_NEW_ARR(&array_elem);
658 + array_init(&array_elem);
659 + dumpGeometry(dangles, &array_elem);
660 + GEOSGeom_destroy(dangles);
661 + add_assoc_zval(return_value, "dangles", &array_elem);
663 + ZVAL_NEW_ARR(&array_elem);
664 + array_init(&array_elem);
665 + dumpGeometry(invalid_rings, &array_elem);
666 + GEOSGeom_destroy(invalid_rings);
667 + add_assoc_zval(return_value, "invalid_rings", &array_elem);
669 MAKE_STD_ZVAL(array_elem);
670 array_init(array_elem);
671 dumpGeometry(rings, array_elem);
672 GEOSGeom_destroy(rings);
673 - add_assoc_zval(return_value, "rings", array_elem);
674 + add_assoc_zval(return_value, "rings", array_elem);
676 MAKE_STD_ZVAL(array_elem);
677 array_init(array_elem);
678 @@ -2647,7 +2901,7 @@
679 dumpGeometry(invalid_rings, array_elem);
680 GEOSGeom_destroy(invalid_rings);
681 add_assoc_zval(return_value, "invalid_rings", array_elem);
687 @@ -2813,6 +3067,9 @@
688 memcpy(&WKTReader_object_handlers,
689 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
690 WKTReader_object_handlers.clone_obj = NULL;
691 +#if PHP_MAJOR_VERSION >= 7
692 + WKTReader_object_handlers.free_obj = &WKTReader_dtor;
696 INIT_CLASS_ENTRY(ce, "GEOSWKTWriter", WKTWriter_methods);
697 @@ -2821,6 +3078,9 @@
698 memcpy(&WKTWriter_object_handlers,
699 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
700 WKTWriter_object_handlers.clone_obj = NULL;
701 +#if PHP_MAJOR_VERSION >= 7
702 + WKTWriter_object_handlers.free_obj = &WKTWriter_dtor;
706 INIT_CLASS_ENTRY(ce, "GEOSGeometry", Geometry_methods);
707 @@ -2829,6 +3089,9 @@
708 memcpy(&Geometry_object_handlers,
709 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
710 Geometry_object_handlers.clone_obj = NULL;
711 +#if PHP_MAJOR_VERSION >= 7
712 + Geometry_object_handlers.free_obj = &Geometry_dtor;
714 /* Geometry serialization */
715 Geometry_ce_ptr->serialize = Geometry_serialize;
716 Geometry_ce_ptr->unserialize = Geometry_deserialize;
717 @@ -2840,6 +3103,9 @@
718 memcpy(&WKBWriter_object_handlers,
719 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
720 WKBWriter_object_handlers.clone_obj = NULL;
721 +#if PHP_MAJOR_VERSION >= 7
722 + WKBWriter_object_handlers.free_obj = &WKBWriter_dtor;
726 INIT_CLASS_ENTRY(ce, "GEOSWKBReader", WKBReader_methods);
727 @@ -2848,6 +3114,9 @@
728 memcpy(&WKBReader_object_handlers,
729 zend_get_std_object_handlers(), sizeof(zend_object_handlers));
730 WKBReader_object_handlers.clone_obj = NULL;
731 +#if PHP_MAJOR_VERSION >= 7
732 + WKBReader_object_handlers.free_obj = &WKBReader_dtor;