Skip to content

Commit b7e7a89

Browse files
committed
several fixes -
- param parsing Z_PARAM_STR vs Z_PARAM_STRING - some functions for new params - etc
1 parent cb25136 commit b7e7a89

23 files changed

+306
-320
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
932932
case 'f': case 'A':
933933
case 'H': case 'p':
934934
case 'S': case 'P':
935+
case 'i':
935936
max_num_args++;
936937
break;
937938

Zend/zend_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ static zend_always_inline int _z_param_str(zval *arg, zend_string **dest, int ch
11721172
return 1;
11731173
}
11741174

1175-
static zend_always_inline int _z_param_string(zval *arg, char **dest, zend_size_t *dest_len, int check_null TSRMLS_DC)
1175+
static zend_always_inline int _z_param_string(zval *arg, char **dest, int *dest_len, int check_null TSRMLS_DC)
11761176
{
11771177
zend_string *str;
11781178

ext/pcre/php_pcre.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,22 +541,21 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ *
541541
{
542542
/* parameters */
543543
zend_string *regex; /* Regular expression */
544-
char *subject; /* String to match against */
545-
int subject_len;
544+
zend_string *subject; /* String to match against */
546545
pcre_cache_entry *pce; /* Compiled regular expression */
547546
zval *subpats = NULL; /* Array for subpatterns */
548547
long flags = 0; /* Match control flags */
549548
long start_offset = 0; /* Where the new search starts */
550549

551550
#ifndef FAST_ZPP
552-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ss|z/ll", &regex,
553-
&subject, &subject_len, &subpats, &flags, &start_offset) == FAILURE) {
551+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|z/ll", &regex,
552+
&subject, &subpats, &flags, &start_offset) == FAILURE) {
554553
RETURN_FALSE;
555554
}
556555
#else
557556
ZEND_PARSE_PARAMETERS_START(2, 5)
558557
Z_PARAM_STR(regex)
559-
Z_PARAM_STRING(subject, subject_len)
558+
Z_PARAM_STR(subject)
560559
Z_PARAM_OPTIONAL
561560
Z_PARAM_ZVAL_EX(subpats, 0, 1)
562561
Z_PARAM_LONG(flags)
@@ -569,7 +568,7 @@ static void php_do_pcre_match(INTERNAL_FUNCTION_PARAMETERS, int global) /* {{{ *
569568
RETURN_FALSE;
570569
}
571570

572-
php_pcre_match_impl(pce, subject, subject_len, return_value, subpats,
571+
php_pcre_match_impl(pce, subject->val, subject->len, return_value, subpats,
573572
global, ZEND_NUM_ARGS() >= 4, flags, start_offset TSRMLS_CC);
574573
}
575574
/* }}} */
@@ -1554,22 +1553,21 @@ static PHP_FUNCTION(preg_filter)
15541553
static PHP_FUNCTION(preg_split)
15551554
{
15561555
zend_string *regex; /* Regular expression */
1557-
char *subject; /* String to match against */
1558-
int subject_len;
1556+
zend_string *subject; /* String to match against */
15591557
long limit_val = -1;/* Integer value of limit */
15601558
long flags = 0; /* Match control flags */
15611559
pcre_cache_entry *pce; /* Compiled regular expression */
15621560

15631561
/* Get function parameters and do error checking */
15641562
#ifndef FAST_ZPP
1565-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ss|ll", &regex,
1563+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ll", &regex,
15661564
&subject, &subject_len, &limit_val, &flags) == FAILURE) {
15671565
RETURN_FALSE;
15681566
}
15691567
#else
15701568
ZEND_PARSE_PARAMETERS_START(2, 4)
15711569
Z_PARAM_STR(regex)
1572-
Z_PARAM_STRING(subject, subject_len)
1570+
Z_PARAM_STR(subject)
15731571
Z_PARAM_OPTIONAL
15741572
Z_PARAM_LONG(limit_val)
15751573
Z_PARAM_LONG(flags)
@@ -1581,7 +1579,7 @@ static PHP_FUNCTION(preg_split)
15811579
RETURN_FALSE;
15821580
}
15831581

1584-
php_pcre_split_impl(pce, subject, subject_len, return_value, limit_val, flags TSRMLS_CC);
1582+
php_pcre_split_impl(pce, subject->val, subject->len, return_value, limit_val, flags TSRMLS_CC);
15851583
}
15861584
/* }}} */
15871585

ext/standard/array.c

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ PHP_FUNCTION(ksort)
255255

256256
PHPAPI int php_count_recursive(zval *array, long mode TSRMLS_DC) /* {{{ */
257257
{
258-
long cnt = 0;
258+
php_int_t cnt = 0;
259259
zval *element;
260260

261261
if (Z_TYPE_P(array) == IS_ARRAY) {
@@ -289,7 +289,7 @@ PHP_FUNCTION(count)
289289
{
290290
zval *array;
291291
long mode = COUNT_NORMAL;
292-
long cnt;
292+
php_int_t cnt;
293293
zval *element;
294294

295295
#ifndef FAST_ZPP
@@ -1230,7 +1230,7 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{
12301230
*array, /* array to check in */
12311231
*entry, /* pointer to array entry */
12321232
res; /* comparison result */
1233-
ulong num_idx;
1233+
php_uint_t num_idx;
12341234
zend_string *str_idx;
12351235
zend_bool strict = 0; /* strict comparison or not */
12361236

@@ -1360,7 +1360,7 @@ PHP_FUNCTION(extract)
13601360
long extract_type = EXTR_OVERWRITE;
13611361
zval *entry;
13621362
zend_string *var_name;
1363-
ulong num_key;
1363+
php_uint_t num_key;
13641364
int var_exists, count = 0;
13651365
int extract_refs = 0;
13661366
zend_array *symbol_table;
@@ -1554,9 +1554,9 @@ PHP_FUNCTION(compact)
15541554
PHP_FUNCTION(array_fill)
15551555
{
15561556
zval *val;
1557-
long start_key, num;
1557+
php_int_t start_key, num;
15581558

1559-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz", &start_key, &num, &val) == FAILURE) {
1559+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "iiz", &start_key, &num, &val) == FAILURE) {
15601560
return;
15611561
}
15621562

@@ -1652,7 +1652,7 @@ PHP_FUNCTION(range)
16521652
if (Z_TYPE_P(zlow) == IS_STRING && Z_TYPE_P(zhigh) == IS_STRING && Z_STRSIZE_P(zlow) >= 1 && Z_STRSIZE_P(zhigh) >= 1) {
16531653
int type1, type2;
16541654
unsigned char low, high;
1655-
long lstep = (long) step;
1655+
php_int_t lstep = (php_int_t) step;
16561656

16571657
type1 = is_numeric_string(Z_STRVAL_P(zlow), Z_STRSIZE_P(zlow), NULL, NULL, 0);
16581658
type2 = is_numeric_string(Z_STRVAL_P(zhigh), Z_STRSIZE_P(zhigh), NULL, NULL, 0);
@@ -1709,7 +1709,7 @@ PHP_FUNCTION(range)
17091709

17101710
} else if (Z_TYPE_P(zlow) == IS_DOUBLE || Z_TYPE_P(zhigh) == IS_DOUBLE || is_step_double) {
17111711
double low, high, value;
1712-
long i;
1712+
php_int_t i;
17131713
double_str:
17141714
low = zval_get_double(zlow);
17151715
high = zval_get_double(zhigh);
@@ -1742,11 +1742,11 @@ PHP_FUNCTION(range)
17421742
}
17431743
} else {
17441744
double low, high;
1745-
long lstep;
1745+
php_int_t lstep;
17461746
long_str:
17471747
low = zval_get_double(zlow);
17481748
high = zval_get_double(zhigh);
1749-
lstep = (long) step;
1749+
lstep = (php_int_t) step;
17501750

17511751
Z_TYPE_INFO(tmp) = IS_INT;
17521752
if (low > high) { /* Negative steps */
@@ -1755,7 +1755,7 @@ PHP_FUNCTION(range)
17551755
goto err;
17561756
}
17571757
for (; low >= high; low -= lstep) {
1758-
Z_IVAL(tmp) = (long)low;
1758+
Z_IVAL(tmp) = (php_int_t)low;
17591759
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp);
17601760
}
17611761
} else if (high > low) { /* Positive steps */
@@ -1764,11 +1764,11 @@ PHP_FUNCTION(range)
17641764
goto err;
17651765
}
17661766
for (; low <= high; low += lstep) {
1767-
Z_IVAL(tmp) = (long)low;
1767+
Z_IVAL(tmp) = (php_int_t)low;
17681768
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp);
17691769
}
17701770
} else {
1771-
Z_IVAL(tmp) = (long)low;
1771+
Z_IVAL(tmp) = (php_int_t)low;
17721772
zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &tmp);
17731773
}
17741774
}
@@ -1995,7 +1995,7 @@ static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
19951995
zval *stack, /* Input stack */
19961996
*val; /* Value to be popped */
19971997
zend_string *key = NULL;
1998-
ulong index;
1998+
php_uint_t index;
19991999

20002000
#ifndef FAST_ZPP
20012001
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &stack) == FAILURE) {
@@ -2145,13 +2145,13 @@ PHP_FUNCTION(array_splice)
21452145
HashTable old_hash;
21462146
uint idx;
21472147
Bucket *p; /* Bucket used for traversing hash */
2148-
long i,
2148+
php_int_t i,
21492149
offset,
21502150
length = 0,
21512151
repl_num = 0; /* Number of replacement elements */
21522152
int num_in; /* Number of elements in the input array */
21532153

2154-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/l|lz/", &array, &offset, &length, &repl_array) == FAILURE) {
2154+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/i|iz/", &array, &offset, &length, &repl_array) == FAILURE) {
21552155
return;
21562156
}
21572157

@@ -2190,7 +2190,7 @@ PHP_FUNCTION(array_splice)
21902190
/* ..and the length */
21912191
if (length < 0) {
21922192
size = num_in - offset + length;
2193-
} else if (((unsigned long) offset + (unsigned long) length) > (unsigned) num_in) {
2193+
} else if (((php_uint_t) offset + (php_uint_t) length) > (unsigned) num_in) {
21942194
size = num_in - offset;
21952195
}
21962196

@@ -2222,16 +2222,16 @@ PHP_FUNCTION(array_slice)
22222222
zval *input, /* Input array */
22232223
*z_length = NULL, /* How many elements to get */
22242224
*entry; /* An array entry */
2225-
long offset, /* Offset to get elements from */
2225+
php_int_t offset, /* Offset to get elements from */
22262226
length = 0;
22272227
zend_bool preserve_keys = 0; /* Whether to preserve keys while copying to the new array or not */
22282228
int num_in, /* Number of elements in the input array */
22292229
pos; /* Current position in the array */
22302230
zend_string *string_key;
2231-
ulong num_key;
2231+
php_uint_t num_key;
22322232

22332233
#ifndef FAST_ZPP
2234-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "al|zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) {
2234+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ai|zb", &input, &offset, &z_length, &preserve_keys) == FAILURE) {
22352235
return;
22362236
}
22372237
#else
@@ -2265,7 +2265,7 @@ PHP_FUNCTION(array_slice)
22652265
/* ..and the length */
22662266
if (length < 0) {
22672267
length = num_in - offset + length;
2268-
} else if (((unsigned long) offset + (unsigned long) length) > (unsigned) num_in) {
2268+
} else if (((php_uint_t) offset + (php_uint_t) length) > (unsigned) num_in) {
22692269
length = num_in - offset;
22702270
}
22712271

@@ -2404,7 +2404,7 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src TSRMLS_DC
24042404
{
24052405
zval *src_entry, *dest_entry, *src_zval, *dest_zval;
24062406
zend_string *string_key;
2407-
ulong num_key;
2407+
php_uint_t num_key;
24082408
int ret;
24092409

24102410
ZEND_HASH_FOREACH_KEY_VAL(src, num_key, string_key, src_entry) {
@@ -2564,7 +2564,7 @@ PHP_FUNCTION(array_keys)
25642564
new_val; /* New value */
25652565
int add_key; /* Flag to indicate whether a key should be added */
25662566
zend_bool strict = 0; /* do strict comparison */
2567-
ulong num_idx;
2567+
php_uint_t num_idx;
25682568
zend_string *str_idx;
25692569
int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
25702570

@@ -2775,7 +2775,7 @@ PHP_FUNCTION(array_reverse)
27752775
zval *input, /* Input array */
27762776
*entry; /* An entry in the input array */
27772777
zend_string *string_key;
2778-
ulong num_key;
2778+
php_uint_t num_key;
27792779
zend_bool preserve_keys = 0; /* whether to preserve keys */
27802780

27812781
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &input, &preserve_keys) == FAILURE) {
@@ -2810,20 +2810,20 @@ PHP_FUNCTION(array_pad)
28102810
zval *pads; /* Array to pass to splice */
28112811
HashTable *new_hash;/* Return value from splice */
28122812
HashTable old_hash;
2813-
long pad_size; /* Size to pad to */
2814-
long pad_size_abs; /* Absolute value of pad_size */
2813+
php_int_t pad_size; /* Size to pad to */
2814+
php_int_t pad_size_abs; /* Absolute value of pad_size */
28152815
int input_size; /* Size of the input array */
28162816
int num_pads; /* How many pads do we need */
28172817
int do_pad; /* Whether we should do padding at all */
28182818
int i;
28192819

2820-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "alz", &input, &pad_size, &pad_value) == FAILURE) {
2820+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aiz", &input, &pad_size, &pad_value) == FAILURE) {
28212821
return;
28222822
}
28232823

28242824
/* Do some initial calculations */
28252825
input_size = zend_hash_num_elements(Z_ARRVAL_P(input));
2826-
pad_size_abs = abs(pad_size);
2826+
pad_size_abs = ZEND_ABS(pad_size);
28272827
if (pad_size_abs < 0) {
28282828
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may only pad up to 1048576 elements at a time");
28292829
zval_dtor(return_value);
@@ -2874,7 +2874,7 @@ PHP_FUNCTION(array_pad)
28742874
PHP_FUNCTION(array_flip)
28752875
{
28762876
zval *array, *entry, data;
2877-
ulong num_idx;
2877+
php_uint_t num_idx;
28782878
zend_string *str_idx;
28792879

28802880
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
@@ -2912,10 +2912,10 @@ PHP_FUNCTION(array_change_key_case)
29122912
zval *array, *entry;
29132913
zend_string *string_key;
29142914
zend_string *new_key;
2915-
ulong num_key;
2916-
long change_to_upper=0;
2915+
php_uint_t num_key;
2916+
php_int_t change_to_upper=0;
29172917

2918-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &change_to_upper) == FAILURE) {
2918+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|i", &array, &change_to_upper) == FAILURE) {
29192919
return;
29202920
}
29212921

@@ -4141,12 +4141,12 @@ PHP_FUNCTION(array_multisort)
41414141
PHP_FUNCTION(array_rand)
41424142
{
41434143
zval *input;
4144-
long randval, num_req = 1;
4144+
php_int_t randval, num_req = 1;
41454145
int num_avail;
41464146
zend_string *string_key;
4147-
ulong num_key;
4147+
php_uint_t num_key;
41484148

4149-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &input, &num_req) == FAILURE) {
4149+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|i", &input, &num_req) == FAILURE) {
41504150
return;
41514151
}
41524152

@@ -4247,7 +4247,7 @@ PHP_FUNCTION(array_product)
42474247

42484248
if (Z_TYPE(entry_n) == IS_INT && Z_TYPE_P(return_value) == IS_INT) {
42494249
dval = (double)Z_IVAL_P(return_value) * (double)Z_IVAL(entry_n);
4250-
if ( (double)LONG_MIN <= dval && dval <= (double)LONG_MAX ) {
4250+
if ( (double)PHP_INT_MIN <= dval && dval <= (double)PHP_INT_MAX ) {
42514251
Z_IVAL_P(return_value) *= Z_IVAL(entry_n);
42524252
continue;
42534253
}
@@ -4328,7 +4328,7 @@ PHP_FUNCTION(array_filter)
43284328
zend_string *string_key;
43294329
zend_fcall_info fci = empty_fcall_info;
43304330
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
4331-
ulong num_key;
4331+
php_uint_t num_key;
43324332

43334333
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|fl", &array, &fci, &fci_cache, &use_type) == FAILURE) {
43344334
return;
@@ -4620,15 +4620,15 @@ PHP_FUNCTION(array_key_exists)
46204620
PHP_FUNCTION(array_chunk)
46214621
{
46224622
int argc = ZEND_NUM_ARGS(), num_in;
4623-
long size, current = 0;
4623+
php_int_t size, current = 0;
46244624
zend_string *str_key;
4625-
ulong num_key;
4625+
php_uint_t num_key;
46264626
zend_bool preserve_keys = 0;
46274627
zval *input = NULL;
46284628
zval chunk;
46294629
zval *entry;
46304630

4631-
if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, &preserve_keys) == FAILURE) {
4631+
if (zend_parse_parameters(argc TSRMLS_CC, "ai|b", &input, &size, &preserve_keys) == FAILURE) {
46324632
return;
46334633
}
46344634
/* Do bounds checking for size parameter. */

0 commit comments

Comments
 (0)