@@ -459,7 +459,7 @@ static zend_never_inline zend_ffi_cdata *zend_ffi_cdata_to_zval_slow_ret(void *p
459
459
}
460
460
/* }}} */
461
461
462
- static zend_always_inline void zend_ffi_cdata_to_zval (zend_ffi_cdata * cdata , void * ptr , zend_ffi_type * type , int read_type , zval * rv , zend_ffi_flags flags , zend_bool is_ret ) /* {{{ */
462
+ static zend_always_inline void zend_ffi_cdata_to_zval (zend_ffi_cdata * cdata , void * ptr , zend_ffi_type * type , int read_type , zval * rv , zend_ffi_flags flags , zend_bool is_ret , zend_bool debug_union ) /* {{{ */
463
463
{
464
464
if (read_type == BP_VAR_R ) {
465
465
zend_ffi_type_kind kind = type -> kind ;
@@ -514,6 +514,9 @@ static zend_always_inline void zend_ffi_cdata_to_zval(zend_ffi_cdata *cdata, voi
514
514
if (* (void * * )ptr == NULL ) {
515
515
ZVAL_NULL (rv );
516
516
return ;
517
+ } else if (debug_union ) {
518
+ ZVAL_STR (rv , zend_strpprintf (0 , "%p" , * (void * * )ptr ));
519
+ return ;
517
520
} else if ((type -> attr & ZEND_FFI_ATTR_CONST ) && ZEND_FFI_TYPE (type -> pointer .type )-> kind == ZEND_FFI_TYPE_CHAR ) {
518
521
ZVAL_STRING (rv , * (char * * )ptr );
519
522
return ;
@@ -864,7 +867,7 @@ static void zend_ffi_callback_trampoline(ffi_cif* cif, void* ret, void** args, v
864
867
865
868
ZEND_HASH_FOREACH_PTR (callback_data -> type -> func .args , arg_type ) {
866
869
arg_type = ZEND_FFI_TYPE (arg_type );
867
- zend_ffi_cdata_to_zval (NULL , args [n ], arg_type , BP_VAR_R , & fci .params [n ], (zend_ffi_flags )(arg_type -> attr & ZEND_FFI_ATTR_CONST ), 0 );
870
+ zend_ffi_cdata_to_zval (NULL , args [n ], arg_type , BP_VAR_R , & fci .params [n ], (zend_ffi_flags )(arg_type -> attr & ZEND_FFI_ATTR_CONST ), 0 , 0 );
868
871
n ++ ;
869
872
} ZEND_HASH_FOREACH_END ();
870
873
}
@@ -999,7 +1002,7 @@ static zval *zend_ffi_cdata_get(zval *object, zval *member, int read_type, void
999
1002
return & EG (uninitialized_zval );;
1000
1003
}
1001
1004
1002
- zend_ffi_cdata_to_zval (cdata , cdata -> ptr , type , BP_VAR_R , rv , 0 , 0 );
1005
+ zend_ffi_cdata_to_zval (cdata , cdata -> ptr , type , BP_VAR_R , rv , 0 , 0 , 0 );
1003
1006
return rv ;
1004
1007
}
1005
1008
/* }}} */
@@ -1171,7 +1174,7 @@ static zval *zend_ffi_cdata_read_field(zval *object, zval *member, int read_type
1171
1174
}
1172
1175
}
1173
1176
ptr = (void * )(((char * )ptr ) + field -> offset );
1174
- zend_ffi_cdata_to_zval (NULL , ptr , field_type , read_type , rv , (cdata -> flags & ZEND_FFI_FLAG_CONST ) | (zend_ffi_flags )field -> is_const , 0 );
1177
+ zend_ffi_cdata_to_zval (NULL , ptr , field_type , read_type , rv , (cdata -> flags & ZEND_FFI_FLAG_CONST ) | (zend_ffi_flags )field -> is_const , 0 , 0 );
1175
1178
} else {
1176
1179
zend_ffi_bit_field_to_zval (ptr , field , rv );
1177
1180
}
@@ -1312,7 +1315,7 @@ static zval *zend_ffi_cdata_read_dim(zval *object, zval *offset, int read_type,
1312
1315
return & EG (uninitialized_zval );
1313
1316
}
1314
1317
1315
- zend_ffi_cdata_to_zval (NULL , ptr , dim_type , read_type , rv , is_const , 0 );
1318
+ zend_ffi_cdata_to_zval (NULL , ptr , dim_type , read_type , rv , is_const , 0 , 0 );
1316
1319
return rv ;
1317
1320
}
1318
1321
/* }}} */
@@ -1863,7 +1866,7 @@ static zval *zend_ffi_cdata_it_get_current_data(zend_object_iterator *it) /* {{{
1863
1866
ptr = (void * )((char * )cdata -> ptr + dim_type -> size * iter -> it .index );
1864
1867
1865
1868
zval_ptr_dtor (& iter -> value );
1866
- zend_ffi_cdata_to_zval (NULL , ptr , dim_type , iter -> by_ref ? BP_VAR_RW : BP_VAR_R , & iter -> value , (cdata -> flags & ZEND_FFI_FLAG_CONST ) | (zend_ffi_flags )(type -> attr & ZEND_FFI_ATTR_CONST ), 0 );
1869
+ zend_ffi_cdata_to_zval (NULL , ptr , dim_type , iter -> by_ref ? BP_VAR_RW : BP_VAR_R , & iter -> value , (cdata -> flags & ZEND_FFI_FLAG_CONST ) | (zend_ffi_flags )(type -> attr & ZEND_FFI_ATTR_CONST ), 0 , 0 );
1867
1870
return & iter -> value ;
1868
1871
}
1869
1872
/* }}} */
@@ -1958,7 +1961,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zval *object, int *is_temp) /* {
1958
1961
case ZEND_FFI_TYPE_SINT32 :
1959
1962
case ZEND_FFI_TYPE_UINT64 :
1960
1963
case ZEND_FFI_TYPE_SINT64 :
1961
- zend_ffi_cdata_to_zval (cdata , ptr , type , BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 );
1964
+ zend_ffi_cdata_to_zval (cdata , ptr , type , BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 , 0 );
1962
1965
ht = zend_new_array (1 );
1963
1966
zend_hash_str_add (ht , "cdata" , sizeof ("cdata" )- 1 , & tmp );
1964
1967
* is_temp = 1 ;
@@ -1978,7 +1981,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zval *object, int *is_temp) /* {
1978
1981
* is_temp = 1 ;
1979
1982
return ht ;
1980
1983
} else {
1981
- zend_ffi_cdata_to_zval (NULL , * (void * * )ptr , ZEND_FFI_TYPE (type -> pointer .type ), BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 );
1984
+ zend_ffi_cdata_to_zval (NULL , * (void * * )ptr , ZEND_FFI_TYPE (type -> pointer .type ), BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 , 0 );
1982
1985
ht = zend_new_array (1 );
1983
1986
zend_hash_index_add_new (ht , 0 , & tmp );
1984
1987
* is_temp = 1 ;
@@ -1991,7 +1994,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zval *object, int *is_temp) /* {
1991
1994
if (key ) {
1992
1995
if (!f -> bits ) {
1993
1996
void * f_ptr = (void * )(((char * )ptr ) + f -> offset );
1994
- zend_ffi_cdata_to_zval (NULL , f_ptr , ZEND_FFI_TYPE (f -> type ), BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 );
1997
+ zend_ffi_cdata_to_zval (NULL , f_ptr , ZEND_FFI_TYPE (f -> type ), BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 , type -> attr & ZEND_FFI_ATTR_UNION );
1995
1998
zend_hash_add (ht , key , & tmp );
1996
1999
} else {
1997
2000
zend_ffi_bit_field_to_zval (ptr , f , & tmp );
@@ -2004,7 +2007,7 @@ static HashTable *zend_ffi_cdata_get_debug_info(zval *object, int *is_temp) /* {
2004
2007
case ZEND_FFI_TYPE_ARRAY :
2005
2008
ht = zend_new_array (type -> array .length );
2006
2009
for (n = 0 ; n < type -> array .length ; n ++ ) {
2007
- zend_ffi_cdata_to_zval (NULL , ptr , ZEND_FFI_TYPE (type -> array .type ), BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 );
2010
+ zend_ffi_cdata_to_zval (NULL , ptr , ZEND_FFI_TYPE (type -> array .type ), BP_VAR_R , & tmp , ZEND_FFI_FLAG_CONST , 0 , 0 );
2008
2011
zend_hash_index_add (ht , n , & tmp );
2009
2012
ptr = (void * )(((char * )ptr ) + ZEND_FFI_TYPE (type -> array .type )-> size );
2010
2013
}
@@ -2373,7 +2376,7 @@ static zval *zend_ffi_read_var(zval *object, zval *member, int read_type, void *
2373
2376
zend_tmp_string_release (tmp_var_name );
2374
2377
2375
2378
if (sym -> kind == ZEND_FFI_SYM_VAR ) {
2376
- zend_ffi_cdata_to_zval (NULL , sym -> addr , ZEND_FFI_TYPE (sym -> type ), read_type , rv , (zend_ffi_flags )sym -> is_const , 0 );
2379
+ zend_ffi_cdata_to_zval (NULL , sym -> addr , ZEND_FFI_TYPE (sym -> type ), read_type , rv , (zend_ffi_flags )sym -> is_const , 0 , 0 );
2377
2380
} else if (sym -> kind == ZEND_FFI_SYM_FUNC ) {
2378
2381
zend_ffi_cdata * cdata ;
2379
2382
zend_ffi_type * new_type = emalloc (sizeof (zend_ffi_type ));
@@ -2746,7 +2749,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
2746
2749
free_alloca (arg_values , arg_values_use_heap );
2747
2750
}
2748
2751
2749
- zend_ffi_cdata_to_zval (NULL , ret , ZEND_FFI_TYPE (type -> func .ret_type ), BP_VAR_R , return_value , 0 , 1 );
2752
+ zend_ffi_cdata_to_zval (NULL , ret , ZEND_FFI_TYPE (type -> func .ret_type ), BP_VAR_R , return_value , 0 , 1 , 0 );
2750
2753
free_alloca (ret , ret_use_heap );
2751
2754
2752
2755
exit :
0 commit comments