Skip to content

Commit 7addb08

Browse files
committed
PHPC-1332: PHP array API fixes for 64-bit Windows
1 parent cdc8be3 commit 7addb08

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/contrib/php_array_api.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* +----------------------------------------------------------------------+
2-
| PHP Version 5 |
2+
| PHP Version 7 |
33
+----------------------------------------------------------------------+
4-
| Copyright (c) 1997-2013 The PHP Group |
4+
| Copyright (c) 1997-2018 The PHP Group |
55
+----------------------------------------------------------------------+
66
| This source file is subject to version 3.01 of the PHP license, |
77
| that is bundled with this package in the file LICENSE, and is |
@@ -29,10 +29,14 @@
2929
# define PAA_LENGTH_ADJ(l) (l)
3030
# define PAA_SYM_EXISTS zend_symtable_str_exists
3131
# define PAA_SYM_DEL zend_symtable_str_del
32+
# define PAA_LONG zend_long
33+
# define PAA_ULONG zend_ulong
3234
#else
3335
# define PAA_LENGTH_ADJ(l) (l+1)
3436
# define PAA_SYM_EXISTS zend_symtable_exists
3537
# define PAA_SYM_DEL zend_symtable_del
38+
# define PAA_LONG long
39+
# define PAA_ULONG ulong
3640
#endif
3741

3842
/**
@@ -72,7 +76,7 @@
7276
* zend_bool php_array_existsc(zval *zarr, const char *litstr)
7377
* zend_bool php_array_existsl(zval *zarr, const char *key, int key_len)
7478
* zend_bool php_array_existsl_safe(zval *zarr, const char *key, int key_len)
75-
* zend_bool php_array_existsn(zval *zarr, long idx)
79+
* zend_bool php_array_existsn(zval *zarr, unsigned long idx)
7680
* zend_bool php_array_existsz(zval *zarr, zval *key)
7781
*/
7882
static inline
@@ -153,7 +157,7 @@ zend_bool php_array_existsz(zval *zarr, zval *key) {
153157
* NULL terminated string key of known length
154158
* php_array_fetchl_safe_T(zval *zarr, const char *key, int key_len, ...)
155159
* String key of known length, may not be NULL terminated
156-
* php_array_fetchn_T(zval *zarr, long idx, ...)
160+
* php_array_fetchn_T(zval *zarr, unsigned long idx, ...)
157161
* Numeric key
158162
* php_array_fetchz_T(zval *zarr, zval *key, ...)
159163
* zval* key
@@ -164,7 +168,7 @@ zend_bool php_array_existsz(zval *zarr, zval *key) {
164168
* zval *php_array_fetch(zval *zarr, const char *key)
165169
* zval *php_array_fetchl(zval *zarr, const char *key, int key_len)
166170
* zval *php_array_fetchl_safe(zval *zarr, const char *key, int key_len)
167-
* zval *php_array_fetchn(zval *zarr, long idx)
171+
* zval *php_array_fetchn(zval *zarr, unsigned long idx)
168172
* zval *php_array_fetchc(zval *zarr, const char *litstr)
169173
* zval *php_array_fetchz(zval *zarr, zval *key)
170174
*/
@@ -201,7 +205,7 @@ zval *php_array_fetchl_safe(zval *zarr, const char *key, int key_len) {
201205
return ret;
202206
}
203207
static inline
204-
zval *php_array_fetchn(zval *zarr, long idx) {
208+
zval *php_array_fetchn(zval *zarr, PAA_ULONG idx) {
205209
#ifdef ZEND_ENGINE_3
206210
return zend_hash_index_find(Z_ARRVAL_P(zarr), idx);
207211
#else
@@ -244,7 +248,7 @@ static inline ctype php_array_fetchl_##ztype(zval *zarr, const char *key, int ke
244248
{ return php_array_zval_to_##ztype(php_array_fetchl(zarr, key, key_len)); } \
245249
static inline ctype php_array_fetchl_safe_##ztype(zval *zarr, const char *key, int key_len) \
246250
{ return php_array_zval_to_##ztype(php_array_fetchl_safe(zarr, key, key_len)); } \
247-
static inline ctype php_array_fetchn_##ztype(zval *zarr, long idx) \
251+
static inline ctype php_array_fetchn_##ztype(zval *zarr, PAA_ULONG idx) \
248252
{ return php_array_zval_to_##ztype(php_array_fetchn(zarr, idx)); } \
249253
static inline ctype php_array_fetchz_##ztype(zval *zarr, zval *key) \
250254
{ return php_array_zval_to_##ztype(php_array_fetchz(zarr, key)); }
@@ -254,7 +258,7 @@ static inline ctype php_array_fetchz_##ztype(zval *zarr, zval *key) \
254258
* zend_bool php_array_fetch_bool(zval *zarr, const char *key)
255259
* zend_bool php_array_fetchl_bool(zval *zarr, const char *key, int key_len)
256260
* zend_bool php_array_fetchl_safe_bool(zval *zarr, const char *key, int key_len)
257-
* zend_bool php_array_fetchn_bool(zval *zarr, long idx)
261+
* zend_bool php_array_fetchn_bool(zval *zarr, unsigned long idx)
258262
* zend_bool php_array_fetchc_bool(zval *zarr, const char *litstr)
259263
* zend_bool php_array_fetchz_bool(zval *zarr, zval *key)
260264
*/
@@ -271,12 +275,12 @@ PHP_ARRAY_FETCH_TYPE_MAP(zend_bool, bool)
271275
* long php_array_fetch_long(zval *zarr, const char *key)
272276
* long php_array_fetchl_long(zval *zarr, const char *key, int key_len)
273277
* long php_array_fetchl_safe_long(zval *zarr, const char *key, int key_len)
274-
* long php_array_fetchn_long(zval *zarr, long idx)
278+
* long php_array_fetchn_long(zval *zarr, unsigned long idx)
275279
* long php_array_fetchc_long(zval *zarr, const char *litstr)
276280
* long php_array_fetchz_long(zval *zarr, zval *key)
277281
*/
278282
static inline
279-
long php_array_zval_to_long(zval *z) {
283+
PAA_LONG php_array_zval_to_long(zval *z) {
280284
if (!z) { return 0; }
281285
switch(Z_TYPE_P(z)) {
282286
case IS_NULL: return 0;
@@ -287,7 +291,6 @@ long php_array_zval_to_long(zval *z) {
287291
case IS_BOOL: return Z_BVAL_P(z);
288292
#endif
289293
case IS_LONG: return Z_LVAL_P(z);
290-
case IS_DOUBLE: return (long)Z_DVAL_P(z);
291294
default:
292295
{
293296
zval c = *z;
@@ -297,7 +300,7 @@ long php_array_zval_to_long(zval *z) {
297300
}
298301
}
299302
}
300-
PHP_ARRAY_FETCH_TYPE_MAP(long, long)
303+
PHP_ARRAY_FETCH_TYPE_MAP(PAA_LONG, long)
301304
#define php_array_fetchc_long(zarr, litstr) \
302305
php_array_zval_to_long(php_array_fetchc(zarr, litstr))
303306

@@ -306,7 +309,7 @@ PHP_ARRAY_FETCH_TYPE_MAP(long, long)
306309
* double php_array_fetch_double(zval *zarr, const char *key)
307310
* double php_array_fetchl_double(zval *zarr, const char *key, int key_len)
308311
* double php_array_fetchl_safe_double(zval *zarr, const char *key, int key_len)
309-
* double php_array_fetchn_double(zval *zarr, long idx)
312+
* double php_array_fetchn_double(zval *zarr, unsigned long idx)
310313
* double php_array_fetchc_double(zval *zarr, const char *litstr)
311314
* double php_array_fetchz_double(zval *zarr, zval *key)
312315
*/
@@ -346,7 +349,7 @@ PHP_ARRAY_FETCH_TYPE_MAP(double, double)
346349
* char *php_array_fetch_string(zval *zarr, const char *key, int *plen, zend_bool *pfree)
347350
* char *php_array_fetchl_string(zval *zarr, const char *key, int key_len, int *plen, zend_bool *pfree)
348351
* char *php_array_fetchl_safe_string(zval *zarr, const char *key, int key_len, int *plen, zend_bool *pfree)
349-
* char *php_array_fetchn_string(zval *zarr, long idx, int *plen, zend_bool *pfree)
352+
* char *php_array_fetchn_string(zval *zarr, unsigned long idx, int *plen, zend_bool *pfree)
350353
* char *php_array_fetchc_string(zval *zarr, const char *litstr, int *plen, zend_bool *pfree)
351354
* char *php_array_fetchz_string(zval *zarr, zval *key, int *plen, zend_bool *pfree)
352355
*/
@@ -400,7 +403,7 @@ char *php_array_zval_to_string(zval *z, int *plen, zend_bool *pfree) {
400403
* zval *php_array_fetch_array(zval *zarr, const char *key)
401404
* zval *php_array_fetchl_array(zval *zarr, const char *key, int key_len)
402405
* zval *php_array_fetchl_safe_array(zval *zarr, const char *key, int key_len)
403-
* zval *php_array_fetchn_array(zval *zarr, long idx)
406+
* zval *php_array_fetchn_array(zval *zarr, unsigned long idx)
404407
* zval *php_array_fetchc_array(zval *zarr, const char *litstr)
405408
* zval *php_array_fetchz_array(zval *zarr, zval *key)
406409
*/
@@ -431,7 +434,7 @@ PHP_ARRAY_FETCH_TYPE_MAP(zval*, array)
431434
* zval *php_array_fetch_resource(zval *zarr, const char *key, int le)
432435
* zval *php_array_fetchl_resource(zval *zarr, const char *key, int key_len, int le)
433436
* zval *php_array_fetchl_safe_resource(zval *zarr, const char *key, int key_len, int le)
434-
* zval *php_array_fetchn_resource(zval *zarr, long idx, int le)
437+
* zval *php_array_fetchn_resource(zval *zarr, unsigned long idx, int le)
435438
* zval *php_array_fetchc_resource(zval *zarr, const char *litstr, int le)
436439
* zval *php_array_fetchz_resource(zval *zarr, zval *key, int le)
437440
*/
@@ -472,7 +475,7 @@ void *php_array_zval_to_resource(zval *z, int le TSRMLS_DC) {
472475
* zval *php_array_fetch_object(zval *zarr, const char *key, zend_class_entry *ce)
473476
* zval *php_array_fetchl_object(zval *zarr, const char *key, int key_len, zend_class_entry *ce)
474477
* zval *php_array_fetchl_safe_object(zval *zarr, const char *key, int key_len, zend_class_entry *ce)
475-
* zval *php_array_fetchn_object(zval *zarr, long idx, zend_class_entry *ce)
478+
* zval *php_array_fetchn_object(zval *zarr, unsigned long idx, zend_class_entry *ce)
476479
* zval *php_array_fetchc_object(zval *zarr, const char *litstr, zend_class_entry *ce)
477480
* zval *php_array_fetchz_object(zval *zarr, zval *key, zend_class_entry *ce)
478481
*/
@@ -517,13 +520,8 @@ void php_array_unsetl_safe(zval *zarr, const char *key, int key_len) {
517520
}
518521
#define php_array_unsetn(zarr, idx) \
519522
zend_symtable_index_del(Z_ARRVAL_P(zarr), idx)
520-
#ifdef ZEND_ENGINE_3
521-
# define php_array_unsetc(zarr, litstr) \
522-
zend_symtable_str_del(Z_ARRVAL_P(zarr), litstr, PAA_LENGTH_ADJ(sizeof(litstr) - 1))
523-
#else
524-
# define php_array_unsetc(zarr, litstr) \
525-
zend_symtable_del(Z_ARRVAL_P(zarr), litstr, PAA_LENGTH_ADJ(sizeof(litstr) - 1))
526-
#endif
523+
#define php_array_unsetc(zarr, litstr) \
524+
PAA_SYM_DEL(Z_ARRVAL_P(zarr), litstr, PAA_LENGTH_ADJ(sizeof(litstr) - 1))
527525
static inline void php_array_unsetz(zval *zarr, zval *key) {
528526
switch (Z_TYPE_P(key)) {
529527
case IS_NULL:

0 commit comments

Comments
 (0)