@@ -186,29 +186,60 @@ PHP_MINFO_FUNCTION(geospatial)
186
186
}
187
187
/* }}} */
188
188
189
+ /* {{{ Version compat helpers */
190
+ #if PHP_VERSION_ID >= 70000
191
+ # define ADD_STRING (zv , name , val ) add_assoc_string_ex(zv, name, sizeof(name)-1, val);
192
+ # define GEOSPAT_MAKE_STD_ZVAL (zv ) zv = ecalloc(sizeof(zval), 1);
193
+ #else
194
+ # define ADD_STRING (zv , name , val ) add_assoc_string_ex(zv, name, sizeof(name), val, 1);
195
+ # define GEOSPAT_MAKE_STD_ZVAL (zv ) MAKE_STD_ZVAL(zv)
196
+ #endif
197
+ /* }}} */
198
+
189
199
/* {{{ Helpers */
190
200
void retval_point_from_coordinates (zval * return_value , double lon , double lat )
191
201
{
192
202
zval * coordinates ;
193
203
194
204
array_init (return_value );
195
- MAKE_STD_ZVAL (coordinates );
205
+ GEOSPAT_MAKE_STD_ZVAL (coordinates );
196
206
array_init (coordinates );
197
- add_assoc_string_ex (return_value , "type" , sizeof ( "type" ), " Point", 1 );
207
+ ADD_STRING (return_value , "type" , " Point" );
198
208
add_next_index_double (coordinates , lon );
199
209
add_next_index_double (coordinates , lat );
210
+ #if PHP_VERSION_ID >= 70000
211
+ add_assoc_zval_ex (return_value , "coordinates" , sizeof ("coordinates" ) - 1 , coordinates );
212
+ efree (coordinates );
213
+ #else
200
214
add_assoc_zval_ex (return_value , "coordinates" , sizeof ("coordinates" ), coordinates );
215
+ #endif
201
216
}
202
217
203
218
static int parse_point_pair (zval * coordinates , double * lon , double * lat )
204
219
{
205
220
HashTable * coords ;
221
+ #if PHP_VERSION_ID >= 70000
222
+ zval * z_lon , * z_lat ;
223
+ #else
206
224
zval * * z_lon , * * z_lat ;
225
+ #endif
207
226
208
227
coords = HASH_OF (coordinates );
209
228
if (coords -> nNumOfElements != 2 ) {
210
229
return 0 ;
211
230
}
231
+ #if PHP_VERSION_ID >= 70000
232
+ if ((z_lon = zend_hash_index_find (coords , 0 )) == NULL ) {
233
+ return 0 ;
234
+ }
235
+ if ((z_lat = zend_hash_index_find (coords , 1 )) == NULL ) {
236
+ return 0 ;
237
+ }
238
+ convert_to_double_ex (z_lon );
239
+ convert_to_double_ex (z_lat );
240
+ * lon = Z_DVAL_P (z_lon );
241
+ * lat = Z_DVAL_P (z_lat );
242
+ #else
212
243
if (zend_hash_index_find (coords , 0 , (void * * ) & z_lon ) != SUCCESS ) {
213
244
return 0 ;
214
245
}
@@ -219,11 +250,29 @@ static int parse_point_pair(zval *coordinates, double *lon, double *lat)
219
250
convert_to_double_ex (z_lat );
220
251
* lon = Z_DVAL_PP (z_lon );
221
252
* lat = Z_DVAL_PP (z_lat );
253
+ #endif
222
254
return 1 ;
223
255
}
224
256
225
257
int geojson_point_to_lon_lat (zval * point , double * lon , double * lat )
226
258
{
259
+ #if PHP_VERSION_ID >= 70000
260
+ zval * type , * coordinates ;
261
+
262
+ if ((type = zend_hash_str_find (HASH_OF (point ), "type" , sizeof ("type" ) - 1 )) == NULL ) {
263
+ return 0 ;
264
+ }
265
+ if (Z_TYPE_P (type ) != IS_STRING || strcmp (Z_STRVAL_P (type ), "Point" ) != 0 ) {
266
+ return 0 ;
267
+ }
268
+ if ((coordinates = zend_hash_str_find (HASH_OF (point ), "coordinates" , sizeof ("coordinates" ) - 1 )) == NULL ) {
269
+ return 0 ;
270
+ }
271
+ if (Z_TYPE_P (coordinates ) != IS_ARRAY ) {
272
+ return 0 ;
273
+ }
274
+ return parse_point_pair (coordinates , lon , lat );
275
+ #else
227
276
zval * * type , * * coordinates ;
228
277
229
278
if (zend_hash_find (HASH_OF (point ), "type" , sizeof ("type" ), (void * * ) & type ) != SUCCESS ) {
@@ -238,8 +287,8 @@ int geojson_point_to_lon_lat(zval *point, double *lon, double *lat)
238
287
if (Z_TYPE_PP (coordinates ) != IS_ARRAY ) {
239
288
return 0 ;
240
289
}
241
-
242
290
return parse_point_pair (* coordinates , lon , lat );
291
+ #endif
243
292
}
244
293
245
294
/* }}} */
@@ -410,7 +459,11 @@ PHP_FUNCTION(dms_to_decimal)
410
459
double degrees , minutes , sign ;
411
460
double seconds , decimal ;
412
461
char * direction = "" ;
462
+ #if PHP_VERSION_ID >= 70000
463
+ size_t direction_len ;
464
+ #else
413
465
int direction_len ;
466
+ #endif
414
467
415
468
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ddd|s" , & degrees , & minutes , & seconds , & direction , & direction_len ) == FAILURE ) {
416
469
return ;
@@ -436,7 +489,11 @@ PHP_FUNCTION(decimal_to_dms)
436
489
int degrees , minutes ;
437
490
char * direction ;
438
491
char * coordinate ;
492
+ #if PHP_VERSION_ID >= 70000
493
+ size_t coordinate_len ;
494
+ #else
439
495
int coordinate_len ;
496
+ #endif
440
497
441
498
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "ds" , & decimal , & coordinate , & coordinate_len ) == FAILURE ) {
442
499
return ;
@@ -456,7 +513,7 @@ PHP_FUNCTION(decimal_to_dms)
456
513
add_assoc_long (return_value , "degrees" , degrees );
457
514
add_assoc_long (return_value , "minutes" , minutes );
458
515
add_assoc_double (return_value , "seconds" , seconds );
459
- add_assoc_string (return_value , "direction" , direction , 1 );
516
+ ADD_STRING (return_value , "direction" , direction );
460
517
}
461
518
/* }}} */
462
519
@@ -690,17 +747,28 @@ geo_array *geo_hashtable_to_array(zval *array)
690
747
geo_array * tmp ;
691
748
int element_count ;
692
749
HashPosition pos ;
750
+ #if PHP_VERSION_ID >= 70000
751
+ zval * entry ;
752
+ #else
693
753
zval * * entry ;
754
+ #endif
694
755
double lon , lat ;
695
756
int i = 0 ;
696
757
697
758
element_count = zend_hash_num_elements (Z_ARRVAL_P (array ));
698
759
tmp = geo_array_ctor (element_count );
699
760
761
+ #if PHP_VERSION_ID >= 70000
762
+ ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (array ), entry ) {
763
+
764
+ if (!parse_point_pair (entry , & lon , & lat )) {
765
+ #else
700
766
zend_hash_internal_pointer_reset_ex (Z_ARRVAL_P (array ), & pos );
701
767
while (zend_hash_get_current_data_ex (Z_ARRVAL_P (array ), (void * * )& entry , & pos ) == SUCCESS ) {
702
768
703
769
if (!parse_point_pair (* entry , & lon , & lat )) {
770
+ #endif
771
+
704
772
goto failure ;
705
773
}
706
774
@@ -710,7 +778,11 @@ geo_array *geo_hashtable_to_array(zval *array)
710
778
711
779
zend_hash_move_forward_ex (Z_ARRVAL_P (array ), & pos );
712
780
i ++ ;
781
+ #if PHP_VERSION_ID >= 70000
782
+ } ZEND_HASH_FOREACH_END ();
783
+ #else
713
784
}
785
+ #endif
714
786
715
787
return tmp ;
716
788
@@ -722,6 +794,28 @@ geo_array *geo_hashtable_to_array(zval *array)
722
794
int geojson_linestring_to_array (zval * line , geo_array * * array )
723
795
{
724
796
geo_array * tmp ;
797
+ #if PHP_VERSION_ID >= 70000
798
+ zval * type , * coordinates ;
799
+
800
+ if (Z_TYPE_P (line ) != IS_ARRAY ) {
801
+ return 0 ;
802
+ }
803
+
804
+ if ((type = zend_hash_str_find (HASH_OF (line ), "type" , sizeof ("type" ) - 1 )) == NULL ) {
805
+ return 0 ;
806
+ }
807
+ if (Z_TYPE_P (type ) != IS_STRING || strcmp (Z_STRVAL_P (type ), "Linestring" ) != 0 ) {
808
+ return 0 ;
809
+ }
810
+ if ((coordinates = zend_hash_str_find (HASH_OF (line ), "coordinates" , sizeof ("coordinates" ) - 1 )) == NULL ) {
811
+ return 0 ;
812
+ }
813
+ if (Z_TYPE_P (coordinates ) != IS_ARRAY ) {
814
+ return 0 ;
815
+ }
816
+
817
+ tmp = geo_hashtable_to_array (coordinates );
818
+ #else
725
819
zval * * type , * * coordinates ;
726
820
727
821
if (Z_TYPE_P (line ) != IS_ARRAY ) {
@@ -742,6 +836,7 @@ int geojson_linestring_to_array(zval *line, geo_array **array)
742
836
}
743
837
744
838
tmp = geo_hashtable_to_array (* coordinates );
839
+ #endif
745
840
if (tmp && array ) {
746
841
* array = tmp ;
747
842
return 1 ;
@@ -828,11 +923,14 @@ PHP_FUNCTION(rdp_simplify)
828
923
rdp_simplify (points , epsilon , 0 , points -> count - 1 );
829
924
for (i = 0 ; i < points -> count ; i ++ ) {
830
925
if (points -> status [i ]) {
831
- MAKE_STD_ZVAL (pair );
926
+ GEOSPAT_MAKE_STD_ZVAL (pair );
832
927
array_init (pair );
833
928
add_next_index_double (pair , points -> x [i ]);
834
929
add_next_index_double (pair , points -> y [i ]);
835
930
add_next_index_zval (return_value , pair );
931
+ #if PHP_VERSION_ID >= 70000
932
+ efree (pair );
933
+ #endif
836
934
}
837
935
}
838
936
@@ -899,11 +997,14 @@ PHP_FUNCTION(interpolate_linestring)
899
997
900
998
for (i = 0 ; i < new_array -> count ; i ++ ) {
901
999
if (new_array -> status [i ]) {
902
- MAKE_STD_ZVAL (pair );
1000
+ GEOSPAT_MAKE_STD_ZVAL (pair );
903
1001
array_init (pair );
904
1002
add_next_index_double (pair , new_array -> x [i ]);
905
1003
add_next_index_double (pair , new_array -> y [i ]);
906
1004
add_next_index_zval (return_value , pair );
1005
+ #if PHP_VERSION_ID >= 70000
1006
+ efree (pair );
1007
+ #endif
907
1008
}
908
1009
}
909
1010
@@ -940,11 +1041,14 @@ PHP_FUNCTION(interpolate_polygon)
940
1041
941
1042
for (i = 0 ; i < points -> count ; i ++ ) {
942
1043
if (points -> status [i ]) {
943
- MAKE_STD_ZVAL (pair );
1044
+ GEOSPAT_MAKE_STD_ZVAL (pair );
944
1045
array_init (pair );
945
1046
add_next_index_double (pair , points -> x [i ]);
946
1047
add_next_index_double (pair , points -> y [i ]);
947
1048
add_next_index_zval (return_value , pair );
1049
+ #if PHP_VERSION_ID >= 70000
1050
+ efree (pair );
1051
+ #endif
948
1052
}
949
1053
}
950
1054
0 commit comments