@@ -411,6 +411,15 @@ static int php_array_natural_general_compare(const void *a, const void *b, int f
411
411
412
412
fval = & f -> val ;
413
413
sval = & s -> val ;
414
+
415
+ if (Z_ISREF_P (fval )) {
416
+ fval = Z_REFVAL_P (fval );
417
+ }
418
+
419
+ if (Z_ISREF_P (sval )) {
420
+ sval = Z_REFVAL_P (sval );
421
+ }
422
+
414
423
ZVAL_COPY_VALUE (& first , fval );
415
424
ZVAL_COPY_VALUE (& second , sval );
416
425
@@ -1392,7 +1401,7 @@ PHP_FUNCTION(extract)
1392
1401
}
1393
1402
} else {
1394
1403
ZVAL_DUP (& data , entry );
1395
- ZEND_SET_SYMBOL_WITH_LENGTH (EG (active_symbol_table ), Z_STRVAL (final_name ), Z_STRLEN (final_name ) + 1 , & data , 1 , 0 );
1404
+ ZEND_SET_SYMBOL_WITH_LENGTH (EG (active_symbol_table ), Z_STRVAL (final_name ), Z_STRLEN (final_name ), & data , 1 , 0 );
1396
1405
}
1397
1406
count ++ ;
1398
1407
}
@@ -1525,6 +1534,10 @@ PHP_FUNCTION(array_fill_keys)
1525
1534
zend_hash_internal_pointer_reset_ex (Z_ARRVAL_P (keys ), & pos );
1526
1535
while ((entry = zend_hash_get_current_data_ex (Z_ARRVAL_P (keys ), & pos )) != NULL ) {
1527
1536
1537
+ if (UNEXPECTED (Z_ISREF_P (entry ))) {
1538
+ entry = Z_REFVAL_P (entry );
1539
+ }
1540
+
1528
1541
if (Z_TYPE_P (entry ) == IS_LONG ) {
1529
1542
zval_add_ref (val );
1530
1543
zend_hash_index_update (Z_ARRVAL_P (return_value ), Z_LVAL_P (entry ), val );
@@ -1816,7 +1829,9 @@ PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval *l
1816
1829
pos ++ ;
1817
1830
/* Get entry and increase reference count */
1818
1831
entry = & p -> val ;
1819
- Z_ADDREF_P (entry );
1832
+ if (Z_REFCOUNTED_P (entry )) {
1833
+ Z_ADDREF_P (entry );
1834
+ }
1820
1835
1821
1836
/* Update output hash depending on key type */
1822
1837
if (p -> key == NULL ) {
@@ -1833,7 +1848,9 @@ PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval *l
1833
1848
if (Z_TYPE (p -> val ) == IS_UNDEF ) continue ;
1834
1849
pos ++ ;
1835
1850
entry = & p -> val ;
1836
- Z_ADDREF_P (entry );
1851
+ if (Z_REFCOUNTED_P (entry )) {
1852
+ Z_ADDREF_P (entry );
1853
+ }
1837
1854
if (p -> key == NULL ) {
1838
1855
zend_hash_next_index_insert (removed , entry );
1839
1856
} else {
@@ -1859,7 +1876,9 @@ PHPAPI HashTable* php_splice(HashTable *in_hash, int offset, int length, zval *l
1859
1876
p = in_hash -> arData + idx ;
1860
1877
if (Z_TYPE (p -> val ) == IS_UNDEF ) continue ;
1861
1878
entry = & p -> val ;
1862
- if (Z_REFCOUNTED_P (entry )) Z_ADDREF_P (entry );
1879
+ if (Z_REFCOUNTED_P (entry )) {
1880
+ Z_ADDREF_P (entry );
1881
+ }
1863
1882
if (p -> key == NULL ) {
1864
1883
zend_hash_next_index_insert (out_hash , entry );
1865
1884
} else {
@@ -2284,7 +2303,9 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC
2284
2303
(dest_entry = zend_hash_find (dest , string_key )) == NULL ||
2285
2304
Z_TYPE_P (dest_entry ) != IS_ARRAY ) {
2286
2305
2287
- Z_ADDREF_P (src_entry );
2306
+ if (Z_REFCOUNTED_P (src_entry )) {
2307
+ Z_ADDREF_P (src_entry );
2308
+ }
2288
2309
zend_hash_update (dest , string_key , src_entry );
2289
2310
2290
2311
continue ;
@@ -2296,7 +2317,9 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC
2296
2317
(dest_entry = zend_hash_index_find (dest , num_key )) == NULL ||
2297
2318
Z_TYPE_P (dest_entry ) != IS_ARRAY ) {
2298
2319
2299
- Z_ADDREF_P (src_entry );
2320
+ if (Z_REFCOUNTED_P (src_entry )) {
2321
+ Z_ADDREF_P (src_entry );
2322
+ }
2300
2323
zend_hash_index_update (dest , num_key , src_entry );
2301
2324
2302
2325
continue ;
@@ -2591,16 +2614,16 @@ PHP_FUNCTION(array_column)
2591
2614
zkeyval = zend_hash_index_find (ht , Z_LVAL_P (zkey ));
2592
2615
}
2593
2616
2594
- Z_ADDREF_P (zcolval );
2617
+ if (Z_REFCOUNTED_P (zcolval )) {
2618
+ Z_ADDREF_P (zcolval );
2619
+ }
2595
2620
if (zkeyval && Z_TYPE_P (zkeyval ) == IS_STRING ) {
2596
- //???
2597
2621
add_assoc_zval (return_value , Z_STRVAL_P (zkeyval ), zcolval );
2598
2622
} else if (zkeyval && Z_TYPE_P (zkeyval ) == IS_LONG ) {
2599
2623
add_index_zval (return_value , Z_LVAL_P (zkeyval ), zcolval );
2600
2624
} else if (zkeyval && Z_TYPE_P (zkeyval ) == IS_OBJECT ) {
2601
2625
SEPARATE_ZVAL (zkeyval );
2602
2626
convert_to_string (zkeyval );
2603
- //???
2604
2627
add_assoc_zval (return_value , Z_STRVAL_P (zkeyval ), zcolval );
2605
2628
} else {
2606
2629
add_next_index_zval (return_value , zcolval );
@@ -2785,7 +2808,7 @@ PHP_FUNCTION(array_change_key_case)
2785
2808
php_strtolower (new_key -> val , new_key -> len );
2786
2809
}
2787
2810
zend_hash_update (Z_ARRVAL_P (return_value ), new_key , entry );
2788
- STR_FREE (new_key );
2811
+ STR_RELEASE (new_key );
2789
2812
break ;
2790
2813
}
2791
2814
@@ -2968,8 +2991,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
2968
2991
for (i = 0 ; i < argc ; i ++ ) {
2969
2992
if (Z_TYPE (args [i ]) != IS_ARRAY ) {
2970
2993
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Argument #%d is not an array" , i + 1 );
2971
- RETVAL_NULL ();
2972
- goto out ;
2994
+ RETURN_NULL ();
2973
2995
}
2974
2996
}
2975
2997
@@ -2990,7 +3012,9 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
2990
3012
}
2991
3013
}
2992
3014
if (ok ) {
2993
- Z_ADDREF (p -> val );
3015
+ if (Z_REFCOUNTED (p -> val )) {
3016
+ Z_ADDREF (p -> val );
3017
+ }
2994
3018
zend_hash_index_update (Z_ARRVAL_P (return_value ), p -> h , & p -> val );
2995
3019
}
2996
3020
} else {
@@ -3005,13 +3029,13 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa
3005
3029
}
3006
3030
}
3007
3031
if (ok ) {
3008
- Z_ADDREF (p -> val );
3032
+ if (Z_REFCOUNTED (p -> val )) {
3033
+ Z_ADDREF (p -> val );
3034
+ }
3009
3035
zend_hash_update (Z_ARRVAL_P (return_value ), p -> key , & p -> val );
3010
3036
}
3011
3037
}
3012
3038
}
3013
- out :
3014
- efree (args );
3015
3039
}
3016
3040
/* }}} */
3017
3041
@@ -3409,7 +3433,9 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
3409
3433
}
3410
3434
}
3411
3435
if (ok ) {
3412
- Z_ADDREF (p -> val );
3436
+ if (Z_REFCOUNTED (p -> val )) {
3437
+ Z_ADDREF (p -> val );
3438
+ }
3413
3439
zend_hash_index_update (Z_ARRVAL_P (return_value ), p -> h , & p -> val );
3414
3440
}
3415
3441
} else {
@@ -3424,7 +3450,9 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty
3424
3450
}
3425
3451
}
3426
3452
if (ok ) {
3427
- Z_ADDREF (p -> val );
3453
+ if (Z_REFCOUNTED (p -> val )) {
3454
+ Z_ADDREF (p -> val );
3455
+ }
3428
3456
zend_hash_update (Z_ARRVAL_P (return_value ), p -> key , & p -> val );
3429
3457
}
3430
3458
}
@@ -3795,7 +3823,6 @@ PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC) /* {{{
3795
3823
for (k = 0; k < MULTISORT_LAST; k++) \
3796
3824
efree(ARRAYG(multisort_flags)[k]); \
3797
3825
efree(arrays); \
3798
- efree(args); \
3799
3826
RETURN_FALSE;
3800
3827
3801
3828
/* {{{ proto bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...])
@@ -4168,7 +4195,6 @@ PHP_FUNCTION(array_filter)
4168
4195
zval * operand ;
4169
4196
zval args [2 ];
4170
4197
zval retval ;
4171
- //??? zval *key = NULL;
4172
4198
zend_bool have_callback = 0 ;
4173
4199
long use_type = 0 ;
4174
4200
zend_string * string_key ;
@@ -4190,16 +4216,7 @@ PHP_FUNCTION(array_filter)
4190
4216
have_callback = 1 ;
4191
4217
fci .no_separation = 0 ;
4192
4218
fci .retval = & retval ;
4193
-
4194
- if (use_type == ARRAY_FILTER_USE_BOTH ) {
4195
- fci .param_count = 2 ;
4196
- //??? args[1] = &key;
4197
- } else {
4198
- fci .param_count = 1 ;
4199
- if (use_type == ARRAY_FILTER_USE_KEY ) {
4200
- //??? args[0] = &key;
4201
- }
4202
- }
4219
+ fci .param_count = 1 ;
4203
4220
}
4204
4221
4205
4222
for (zend_hash_internal_pointer_reset_ex (Z_ARRVAL_P (array ), & pos );
@@ -4213,28 +4230,40 @@ PHP_FUNCTION(array_filter)
4213
4230
/* Set up the key */
4214
4231
switch (key_type ) {
4215
4232
case HASH_KEY_IS_LONG :
4216
- ZVAL_LONG (& args [0 ], num_key );
4233
+ if (use_type == ARRAY_FILTER_USE_BOTH ) {
4234
+ fci .param_count = 2 ;
4235
+ ZVAL_LONG (& args [1 ], num_key );
4236
+ } else if (use_type == ARRAY_FILTER_USE_KEY ) {
4237
+ ZVAL_LONG (& args [0 ], num_key );
4238
+ }
4217
4239
break ;
4218
4240
4219
4241
case HASH_KEY_IS_STRING :
4220
- ZVAL_STR (& args [0 ], STR_COPY (string_key ));
4242
+ if (use_type == ARRAY_FILTER_USE_BOTH ) {
4243
+ ZVAL_STR (& args [1 ], STR_COPY (string_key ));
4244
+ } else if (use_type == ARRAY_FILTER_USE_KEY ) {
4245
+ ZVAL_STR (& args [0 ], STR_COPY (string_key ));
4246
+ }
4221
4247
break ;
4222
4248
}
4223
4249
}
4224
-
4225
4250
if (use_type != ARRAY_FILTER_USE_KEY ) {
4226
4251
ZVAL_COPY_VALUE (& args [0 ], operand );
4227
4252
}
4228
4253
fci .params = args ;
4229
4254
4230
- if (zend_call_function (& fci , & fci_cache TSRMLS_CC ) == SUCCESS && Z_TYPE (retval ) != IS_UNDEF ) {
4231
- int retval_true = zend_is_true (& retval TSRMLS_CC );
4255
+ if (zend_call_function (& fci , & fci_cache TSRMLS_CC ) == SUCCESS ) {
4256
+ if (!ZVAL_IS_UNDEF (& retval )) {
4257
+ int retval_true = zend_is_true (& retval TSRMLS_CC );
4232
4258
4233
- zval_ptr_dtor (& retval );
4234
- if (use_type ) {
4235
- zval_ptr_dtor (& args [0 ]);
4236
- }
4237
- if (!retval_true ) {
4259
+ zval_ptr_dtor (& retval );
4260
+ if (use_type ) {
4261
+ zval_ptr_dtor (& args [0 ]);
4262
+ }
4263
+ if (!retval_true ) {
4264
+ continue ;
4265
+ }
4266
+ } else {
4238
4267
continue ;
4239
4268
}
4240
4269
} else {
@@ -4287,7 +4316,6 @@ PHP_FUNCTION(array_map)
4287
4316
for (i = 0 ; i < n_arrays ; i ++ ) {
4288
4317
if (Z_TYPE (arrays [i ]) != IS_ARRAY ) {
4289
4318
php_error_docref (NULL TSRMLS_CC , E_WARNING , "Argument #%d should be an array" , i + 2 );
4290
- efree (args );
4291
4319
efree (array_len );
4292
4320
efree (array_pos );
4293
4321
return ;
@@ -4307,7 +4335,6 @@ PHP_FUNCTION(array_map)
4307
4335
RETVAL_ZVAL (args [0 ], 1 , 0 );
4308
4336
efree (array_len );
4309
4337
efree (array_pos );
4310
- efree (args );
4311
4338
return ;
4312
4339
}
4313
4340
@@ -4359,7 +4386,6 @@ PHP_FUNCTION(array_map)
4359
4386
if (zend_call_function (& fci , & fci_cache TSRMLS_CC ) != SUCCESS || Z_TYPE (result ) == IS_UNDEF ) {
4360
4387
php_error_docref (NULL TSRMLS_CC , E_WARNING , "An error occurred while invoking the map callback" );
4361
4388
efree (array_len );
4362
- efree (args );
4363
4389
efree (array_pos );
4364
4390
zval_dtor (return_value );
4365
4391
efree (params );
@@ -4382,7 +4408,6 @@ PHP_FUNCTION(array_map)
4382
4408
efree (params );
4383
4409
efree (array_len );
4384
4410
efree (array_pos );
4385
- efree (args );
4386
4411
}
4387
4412
/* }}} */
4388
4413
0 commit comments