@@ -204,19 +204,17 @@ typedef struct _zend_ffi_ctype {
204
204
static zend_class_entry * zend_ffi_exception_ce ;
205
205
static zend_class_entry * zend_ffi_parser_exception_ce ;
206
206
static zend_class_entry * zend_ffi_ce ;
207
+ static zend_class_entry * zend_ffi_scope_ce ;
207
208
static zend_class_entry * zend_ffi_cdata_ce ;
208
209
static zend_class_entry * zend_ffi_ctype_ce ;
209
210
210
211
static zend_object_handlers zend_ffi_handlers ;
212
+ static zend_object_handlers zend_ffi_scope_handlers ;
211
213
static zend_object_handlers zend_ffi_cdata_handlers ;
212
214
static zend_object_handlers zend_ffi_cdata_value_handlers ;
213
215
static zend_object_handlers zend_ffi_cdata_free_handlers ;
214
216
static zend_object_handlers zend_ffi_ctype_handlers ;
215
217
216
- static zend_internal_function zend_ffi_new_fn ;
217
- static zend_internal_function zend_ffi_cast_fn ;
218
- static zend_internal_function zend_ffi_type_fn ;
219
-
220
218
/* forward declarations */
221
219
static void _zend_ffi_type_dtor (zend_ffi_type * type );
222
220
static void zend_ffi_finalize_type (zend_ffi_dcl * dcl );
@@ -2279,7 +2277,7 @@ static HashTable *zend_ffi_ctype_get_debug_info(zend_object *obj, int *is_temp)
2279
2277
}
2280
2278
/* }}} */
2281
2279
2282
- static zend_object * zend_ffi_new (zend_class_entry * class_type ) /* {{{ */
2280
+ static zend_object * zend_ffi_scope_new (zend_class_entry * class_type ) /* {{{ */
2283
2281
{
2284
2282
zend_ffi * ffi ;
2285
2283
@@ -2415,7 +2413,7 @@ static void zend_ffi_scope_hash_dtor(zval *zv) /* {{{ */
2415
2413
}
2416
2414
/* }}} */
2417
2415
2418
- static void zend_ffi_free_obj (zend_object * object ) /* {{{ */
2416
+ static void zend_ffi_scope_free_obj (zend_object * object ) /* {{{ */
2419
2417
{
2420
2418
zend_ffi * ffi = (zend_ffi * )object ;
2421
2419
@@ -2475,7 +2473,7 @@ static zend_object *zend_ffi_cdata_clone_obj(zend_object *obj) /* {{{ */
2475
2473
}
2476
2474
/* }}} */
2477
2475
2478
- static zval * zend_ffi_read_var (zend_object * obj , zend_string * var_name , int read_type , void * * cache_slot , zval * rv ) /* {{{ */
2476
+ static zval * zend_ffi_scope_read_var (zend_object * obj , zend_string * var_name , int read_type , void * * cache_slot , zval * rv ) /* {{{ */
2479
2477
{
2480
2478
zend_ffi * ffi = (zend_ffi * )obj ;
2481
2479
zend_ffi_symbol * sym = NULL ;
@@ -2518,7 +2516,7 @@ static zval *zend_ffi_read_var(zend_object *obj, zend_string *var_name, int read
2518
2516
}
2519
2517
/* }}} */
2520
2518
2521
- static zval * zend_ffi_write_var (zend_object * obj , zend_string * var_name , zval * value , void * * cache_slot ) /* {{{ */
2519
+ static zval * zend_ffi_scope_write_var (zend_object * obj , zend_string * var_name , zval * value , void * * cache_slot ) /* {{{ */
2522
2520
{
2523
2521
zend_ffi * ffi = (zend_ffi * )obj ;
2524
2522
zend_ffi_symbol * sym = NULL ;
@@ -2870,30 +2868,17 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
2870
2868
}
2871
2869
/* }}} */
2872
2870
2873
- static zend_function * zend_ffi_get_func (zend_object * * obj , zend_string * name , const zval * key ) /* {{{ */
2871
+ static zend_function * zend_ffi_scope_get_func (zend_object * * obj , zend_string * name , const zval * key ) /* {{{ */
2874
2872
{
2875
2873
zend_ffi * ffi = (zend_ffi * )* obj ;
2876
2874
zend_ffi_symbol * sym = NULL ;
2877
2875
zend_function * func ;
2878
2876
zend_ffi_type * type ;
2877
+ zval * zv ;
2879
2878
2880
- if (ZSTR_LEN (name ) == sizeof ("new" ) - 1
2881
- && (ZSTR_VAL (name )[0 ] == 'n' || ZSTR_VAL (name )[0 ] == 'N' )
2882
- && (ZSTR_VAL (name )[1 ] == 'e' || ZSTR_VAL (name )[1 ] == 'E' )
2883
- && (ZSTR_VAL (name )[2 ] == 'w' || ZSTR_VAL (name )[2 ] == 'W' )) {
2884
- return (zend_function * )& zend_ffi_new_fn ;
2885
- } else if (ZSTR_LEN (name ) == sizeof ("cast" ) - 1
2886
- && (ZSTR_VAL (name )[0 ] == 'c' || ZSTR_VAL (name )[0 ] == 'C' )
2887
- && (ZSTR_VAL (name )[1 ] == 'a' || ZSTR_VAL (name )[1 ] == 'A' )
2888
- && (ZSTR_VAL (name )[2 ] == 's' || ZSTR_VAL (name )[2 ] == 'S' )
2889
- && (ZSTR_VAL (name )[3 ] == 't' || ZSTR_VAL (name )[3 ] == 'T' )) {
2890
- return (zend_function * )& zend_ffi_cast_fn ;
2891
- } else if (ZSTR_LEN (name ) == sizeof ("type" ) - 1
2892
- && (ZSTR_VAL (name )[0 ] == 't' || ZSTR_VAL (name )[0 ] == 'T' )
2893
- && (ZSTR_VAL (name )[1 ] == 'y' || ZSTR_VAL (name )[1 ] == 'Y' )
2894
- && (ZSTR_VAL (name )[2 ] == 'p' || ZSTR_VAL (name )[2 ] == 'P' )
2895
- && (ZSTR_VAL (name )[3 ] == 'e' || ZSTR_VAL (name )[3 ] == 'E' )) {
2896
- return (zend_function * )& zend_ffi_type_fn ;
2879
+ zv = zend_hash_find (& zend_ffi_scope_ce -> function_table , name );
2880
+ if (zv ) {
2881
+ return (zend_function * )Z_PTR_P (zv );
2897
2882
}
2898
2883
2899
2884
if (ffi -> symbols ) {
@@ -3063,7 +3048,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
3063
3048
}
3064
3049
}
3065
3050
3066
- ffi = (zend_ffi * )zend_ffi_new ( zend_ffi_ce );
3051
+ ffi = (zend_ffi * )zend_ffi_scope_new ( zend_ffi_scope_ce );
3067
3052
ffi -> lib = handle ;
3068
3053
ffi -> symbols = FFI_G (symbols );
3069
3054
ffi -> tags = FFI_G (tags );
@@ -3499,15 +3484,15 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
3499
3484
}
3500
3485
3501
3486
if (EG (objects_store ).object_buckets ) {
3502
- ffi = (zend_ffi * )zend_ffi_new ( zend_ffi_ce );
3487
+ ffi = (zend_ffi * )zend_ffi_scope_new ( zend_ffi_scope_ce );
3503
3488
} else {
3504
3489
ffi = ecalloc (1 , sizeof (zend_ffi ));
3505
3490
}
3506
3491
ffi -> symbols = scope -> symbols ;
3507
3492
ffi -> tags = scope -> tags ;
3508
3493
ffi -> persistent = 1 ;
3509
3494
} else {
3510
- ffi = (zend_ffi * )zend_ffi_new ( zend_ffi_ce );
3495
+ ffi = (zend_ffi * )zend_ffi_scope_new ( zend_ffi_scope_ce );
3511
3496
ffi -> lib = handle ;
3512
3497
ffi -> symbols = FFI_G (symbols );
3513
3498
ffi -> tags = FFI_G (tags );
@@ -3580,7 +3565,7 @@ ZEND_METHOD(FFI, scope) /* {{{ */
3580
3565
RETURN_THROWS ();
3581
3566
}
3582
3567
3583
- ffi = (zend_ffi * )zend_ffi_new ( zend_ffi_ce );
3568
+ ffi = (zend_ffi * )zend_ffi_scope_new ( zend_ffi_scope_ce );
3584
3569
3585
3570
ffi -> symbols = scope -> symbols ;
3586
3571
ffi -> tags = scope -> tags ;
@@ -3759,7 +3744,7 @@ static void zend_ffi_tags_cleanup(zend_ffi_dcl *dcl) /* {{{ */
3759
3744
}
3760
3745
/* }}} */
3761
3746
3762
- ZEND_METHOD ( FFI , new ) /* {{{ */
3747
+ static void _zend_ffi_new ( INTERNAL_FUNCTION_PARAMETERS , bool is_static_call ) /* {{{ */
3763
3748
{
3764
3749
zend_string * type_def = NULL ;
3765
3750
zend_object * type_obj = NULL ;
@@ -3769,7 +3754,6 @@ ZEND_METHOD(FFI, new) /* {{{ */
3769
3754
bool owned = 1 ;
3770
3755
bool persistent = 0 ;
3771
3756
bool is_const = 0 ;
3772
- bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
3773
3757
zend_ffi_flags flags = ZEND_FFI_FLAG_OWNED ;
3774
3758
3775
3759
ZEND_FFI_VALIDATE_API_RESTRICTION ();
@@ -3780,13 +3764,6 @@ ZEND_METHOD(FFI, new) /* {{{ */
3780
3764
Z_PARAM_BOOL (persistent )
3781
3765
ZEND_PARSE_PARAMETERS_END ();
3782
3766
3783
- if (is_static_call ) {
3784
- zend_error (E_DEPRECATED , "Calling FFI::new() statically is deprecated" );
3785
- if (EG (exception )) {
3786
- RETURN_THROWS ();
3787
- }
3788
- }
3789
-
3790
3767
if (!owned ) {
3791
3768
flags &= ~ZEND_FFI_FLAG_OWNED ;
3792
3769
}
@@ -3884,6 +3861,18 @@ ZEND_METHOD(FFI, new) /* {{{ */
3884
3861
}
3885
3862
/* }}} */
3886
3863
3864
+ ZEND_METHOD (FFI , new ) /* {{{ */
3865
+ {
3866
+ _zend_ffi_new (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
3867
+ }
3868
+ /* }}} */
3869
+
3870
+ ZEND_METHOD (FFI_Scope , new ) /* {{{ */
3871
+ {
3872
+ _zend_ffi_new (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
3873
+ }
3874
+ /* }}} */
3875
+
3887
3876
ZEND_METHOD (FFI , free ) /* {{{ */
3888
3877
{
3889
3878
zval * zv ;
@@ -3918,14 +3907,13 @@ ZEND_METHOD(FFI, free) /* {{{ */
3918
3907
}
3919
3908
/* }}} */
3920
3909
3921
- ZEND_METHOD ( FFI , cast ) /* {{{ */
3910
+ static void _zend_ffi_cast ( INTERNAL_FUNCTION_PARAMETERS , bool is_static_call ) /* {{{ */
3922
3911
{
3923
3912
zend_string * type_def = NULL ;
3924
3913
zend_object * ztype = NULL ;
3925
3914
zend_ffi_type * old_type , * type , * type_ptr ;
3926
3915
zend_ffi_cdata * old_cdata , * cdata ;
3927
3916
bool is_const = 0 ;
3928
- bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
3929
3917
zval * zv , * arg ;
3930
3918
void * ptr ;
3931
3919
@@ -3935,13 +3923,6 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3935
3923
Z_PARAM_ZVAL (zv )
3936
3924
ZEND_PARSE_PARAMETERS_END ();
3937
3925
3938
- if (is_static_call ) {
3939
- zend_error (E_DEPRECATED , "Calling FFI::cast() statically is deprecated" );
3940
- if (EG (exception )) {
3941
- RETURN_THROWS ();
3942
- }
3943
- }
3944
-
3945
3926
arg = zv ;
3946
3927
ZVAL_DEREF (zv );
3947
3928
@@ -4101,25 +4082,29 @@ ZEND_METHOD(FFI, cast) /* {{{ */
4101
4082
}
4102
4083
/* }}} */
4103
4084
4104
- ZEND_METHOD (FFI , type ) /* {{{ */
4085
+ ZEND_METHOD (FFI , cast ) /* {{{ */
4086
+ {
4087
+ _zend_ffi_cast (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
4088
+ }
4089
+ /* }}} */
4090
+
4091
+ ZEND_METHOD (FFI_Scope , cast ) /* {{{ */
4092
+ {
4093
+ _zend_ffi_cast (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
4094
+ }
4095
+ /* }}} */
4096
+
4097
+ static void _zend_ffi_type (INTERNAL_FUNCTION_PARAMETERS , bool is_static_call ) /* {{{ */
4105
4098
{
4106
4099
zend_ffi_ctype * ctype ;
4107
4100
zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
4108
4101
zend_string * type_def ;
4109
- bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
4110
4102
4111
4103
ZEND_FFI_VALIDATE_API_RESTRICTION ();
4112
4104
ZEND_PARSE_PARAMETERS_START (1 , 1 )
4113
4105
Z_PARAM_STR (type_def );
4114
4106
ZEND_PARSE_PARAMETERS_END ();
4115
4107
4116
- if (is_static_call ) {
4117
- zend_error (E_DEPRECATED , "Calling FFI::type() statically is deprecated" );
4118
- if (EG (exception )) {
4119
- RETURN_THROWS ();
4120
- }
4121
- }
4122
-
4123
4108
if (!is_static_call ) {
4124
4109
zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
4125
4110
FFI_G (symbols ) = ffi -> symbols ;
@@ -4166,6 +4151,18 @@ ZEND_METHOD(FFI, type) /* {{{ */
4166
4151
}
4167
4152
/* }}} */
4168
4153
4154
+ ZEND_METHOD (FFI , type ) /* {{{ */
4155
+ {
4156
+ _zend_ffi_type (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
4157
+ }
4158
+ /* }}} */
4159
+
4160
+ ZEND_METHOD (FFI_Scope , type ) /* {{{ */
4161
+ {
4162
+ _zend_ffi_type (INTERNAL_FUNCTION_PARAM_PASSTHRU , 0 );
4163
+ }
4164
+ /* }}} */
4165
+
4169
4166
ZEND_METHOD (FFI , typeof ) /* {{{ */
4170
4167
{
4171
4168
zval * zv , * arg ;
@@ -5386,30 +5383,6 @@ static zend_result zend_ffi_preload(char *preload) /* {{{ */
5386
5383
}
5387
5384
/* }}} */
5388
5385
5389
- /* The startup code for observers adds a temporary to each function for internal use.
5390
- * The "new", "cast", and "type" functions in FFI are both static and non-static.
5391
- * Only the static versions are in the function table and the non-static versions are not.
5392
- * This means the non-static versions will be skipped by the observers startup code.
5393
- * This function fixes that by incrementing the temporary count for the non-static versions.
5394
- */
5395
- static zend_result (* prev_zend_post_startup_cb )(void );
5396
- static zend_result ffi_fixup_temporaries (void ) {
5397
- if (ZEND_OBSERVER_ENABLED ) {
5398
- ++ zend_ffi_new_fn .T ;
5399
- ++ zend_ffi_cast_fn .T ;
5400
- ++ zend_ffi_type_fn .T ;
5401
- }
5402
- #ifndef ZTS
5403
- ZEND_MAP_PTR (zend_ffi_new_fn .run_time_cache ) = ZEND_MAP_PTR (((zend_internal_function * )zend_hash_str_find_ptr (& zend_ffi_ce -> function_table , "new" , sizeof ("new" )- 1 ))-> run_time_cache );
5404
- ZEND_MAP_PTR (zend_ffi_cast_fn .run_time_cache ) = ZEND_MAP_PTR (((zend_internal_function * )zend_hash_str_find_ptr (& zend_ffi_ce -> function_table , "cast" , sizeof ("cast" )- 1 ))-> run_time_cache );
5405
- ZEND_MAP_PTR (zend_ffi_type_fn .run_time_cache ) = ZEND_MAP_PTR (((zend_internal_function * )zend_hash_str_find_ptr (& zend_ffi_ce -> function_table , "type" , sizeof ("type" )- 1 ))-> run_time_cache );
5406
- #endif
5407
- if (prev_zend_post_startup_cb ) {
5408
- return prev_zend_post_startup_cb ();
5409
- }
5410
- return SUCCESS ;
5411
- }
5412
-
5413
5386
/* {{{ ZEND_MINIT_FUNCTION */
5414
5387
ZEND_MINIT_FUNCTION (ffi )
5415
5388
{
@@ -5422,39 +5395,35 @@ ZEND_MINIT_FUNCTION(ffi)
5422
5395
zend_ffi_parser_exception_ce = register_class_FFI_ParserException (zend_ffi_exception_ce );
5423
5396
5424
5397
zend_ffi_ce = register_class_FFI ();
5425
- zend_ffi_ce -> create_object = zend_ffi_new ;
5426
5398
zend_ffi_ce -> default_object_handlers = & zend_ffi_handlers ;
5427
5399
5428
- memcpy (& zend_ffi_new_fn , zend_hash_str_find_ptr (& zend_ffi_ce -> function_table , "new" , sizeof ("new" )- 1 ), sizeof (zend_internal_function ));
5429
- zend_ffi_new_fn .fn_flags &= ~ZEND_ACC_STATIC ;
5430
- memcpy (& zend_ffi_cast_fn , zend_hash_str_find_ptr (& zend_ffi_ce -> function_table , "cast" , sizeof ("cast" )- 1 ), sizeof (zend_internal_function ));
5431
- zend_ffi_cast_fn .fn_flags &= ~ZEND_ACC_STATIC ;
5432
- memcpy (& zend_ffi_type_fn , zend_hash_str_find_ptr (& zend_ffi_ce -> function_table , "type" , sizeof ("type" )- 1 ), sizeof (zend_internal_function ));
5433
- zend_ffi_type_fn .fn_flags &= ~ZEND_ACC_STATIC ;
5434
-
5435
- prev_zend_post_startup_cb = zend_post_startup_cb ;
5436
- zend_post_startup_cb = ffi_fixup_temporaries ;
5400
+ zend_ffi_scope_ce = register_class_FFI_Scope ();
5401
+ zend_ffi_scope_ce -> create_object = zend_ffi_scope_new ;
5402
+ zend_ffi_scope_ce -> default_object_handlers = & zend_ffi_scope_handlers ;
5437
5403
5438
5404
memcpy (& zend_ffi_handlers , zend_get_std_object_handlers (), sizeof (zend_object_handlers ));
5439
5405
zend_ffi_handlers .get_constructor = zend_fake_get_constructor ;
5440
- zend_ffi_handlers .free_obj = zend_ffi_free_obj ;
5441
- zend_ffi_handlers .clone_obj = NULL ;
5442
- zend_ffi_handlers .read_property = zend_ffi_read_var ;
5443
- zend_ffi_handlers .write_property = zend_ffi_write_var ;
5444
- zend_ffi_handlers .read_dimension = zend_fake_read_dimension ;
5445
- zend_ffi_handlers .write_dimension = zend_fake_write_dimension ;
5446
- zend_ffi_handlers .get_property_ptr_ptr = zend_fake_get_property_ptr_ptr ;
5447
- zend_ffi_handlers .has_property = zend_fake_has_property ;
5448
- zend_ffi_handlers .unset_property = zend_fake_unset_property ;
5449
- zend_ffi_handlers .has_dimension = zend_fake_has_dimension ;
5450
- zend_ffi_handlers .unset_dimension = zend_fake_unset_dimension ;
5451
- zend_ffi_handlers .get_method = zend_ffi_get_func ;
5452
- zend_ffi_handlers .compare = zend_fake_compare_objects ;
5453
- zend_ffi_handlers .cast_object = zend_fake_cast_object ;
5454
- zend_ffi_handlers .get_debug_info = NULL ;
5455
- zend_ffi_handlers .get_closure = NULL ;
5456
- zend_ffi_handlers .get_properties = zend_fake_get_properties ;
5457
- zend_ffi_handlers .get_gc = zend_fake_get_gc ;
5406
+
5407
+ memcpy (& zend_ffi_scope_handlers , zend_get_std_object_handlers (), sizeof (zend_object_handlers ));
5408
+ zend_ffi_scope_handlers .get_constructor = zend_fake_get_constructor ;
5409
+ zend_ffi_scope_handlers .free_obj = zend_ffi_scope_free_obj ;
5410
+ zend_ffi_scope_handlers .clone_obj = NULL ;
5411
+ zend_ffi_scope_handlers .read_property = zend_ffi_scope_read_var ;
5412
+ zend_ffi_scope_handlers .write_property = zend_ffi_scope_write_var ;
5413
+ zend_ffi_scope_handlers .read_dimension = zend_fake_read_dimension ;
5414
+ zend_ffi_scope_handlers .write_dimension = zend_fake_write_dimension ;
5415
+ zend_ffi_scope_handlers .get_property_ptr_ptr = zend_fake_get_property_ptr_ptr ;
5416
+ zend_ffi_scope_handlers .has_property = zend_fake_has_property ;
5417
+ zend_ffi_scope_handlers .unset_property = zend_fake_unset_property ;
5418
+ zend_ffi_scope_handlers .has_dimension = zend_fake_has_dimension ;
5419
+ zend_ffi_scope_handlers .unset_dimension = zend_fake_unset_dimension ;
5420
+ zend_ffi_scope_handlers .get_method = zend_ffi_scope_get_func ;
5421
+ zend_ffi_scope_handlers .compare = zend_fake_compare_objects ;
5422
+ zend_ffi_scope_handlers .cast_object = zend_fake_cast_object ;
5423
+ zend_ffi_scope_handlers .get_debug_info = NULL ;
5424
+ zend_ffi_scope_handlers .get_closure = NULL ;
5425
+ zend_ffi_scope_handlers .get_properties = zend_fake_get_properties ;
5426
+ zend_ffi_scope_handlers .get_gc = zend_fake_get_gc ;
5458
5427
5459
5428
zend_ffi_cdata_ce = register_class_FFI_CData ();
5460
5429
zend_ffi_cdata_ce -> create_object = zend_ffi_cdata_new ;
0 commit comments