@@ -128,7 +128,7 @@ static zend_internal_function zend_ffi_cast_fn;
128
128
static zend_internal_function zend_ffi_type_fn ;
129
129
130
130
/* forward declarations */
131
- static void _zend_ffi_type_dtor (zend_ffi_type * type );
131
+ //??? static void _zend_ffi_type_dtor(zend_ffi_type *type);
132
132
static void zend_ffi_finalize_type (zend_ffi_dcl * dcl );
133
133
static bool zend_ffi_is_same_type (zend_ffi_type * type1 , zend_ffi_type * type2 );
134
134
static zend_ffi_type * zend_ffi_remember_type (zend_ffi_type * type );
@@ -2205,7 +2205,7 @@ static zend_object *zend_ffi_new(zend_class_entry *class_type) /* {{{ */
2205
2205
}
2206
2206
/* }}} */
2207
2207
2208
- static void _zend_ffi_type_dtor (zend_ffi_type * type ) /* {{{ */
2208
+ ZEND_API void _zend_ffi_type_dtor (zend_ffi_type * type ) /* {{{ */
2209
2209
{
2210
2210
type = ZEND_FFI_TYPE (type );
2211
2211
@@ -2922,6 +2922,13 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
2922
2922
FFI_G (tags ) = NULL ;
2923
2923
2924
2924
if (code && ZSTR_LEN (code )) {
2925
+ if (zend_ffi_cache_cdef_get ) {
2926
+ ffi = zend_ffi_cache_cdef_get (code );
2927
+ if (ffi ) {
2928
+ RETURN_OBJ (& ffi -> std );
2929
+ }
2930
+ }
2931
+
2925
2932
/* Parse C definitions */
2926
2933
FFI_G (default_type_attr ) = ZEND_FFI_ATTR_STORED ;
2927
2934
@@ -2971,6 +2978,10 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
2971
2978
ffi -> symbols = FFI_G (symbols );
2972
2979
ffi -> tags = FFI_G (tags );
2973
2980
2981
+ if (zend_ffi_cache_cdef_add ) {
2982
+ ffi = zend_ffi_cache_cdef_add (code , ffi );
2983
+ }
2984
+
2974
2985
FFI_G (symbols ) = NULL ;
2975
2986
FFI_G (tags ) = NULL ;
2976
2987
@@ -3714,7 +3725,10 @@ ZEND_METHOD(FFI, new) /* {{{ */
3714
3725
3715
3726
FFI_G (default_type_attr ) = 0 ;
3716
3727
3717
- if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
3728
+ if (zend_ffi_cache_type_get
3729
+ && zend_ffi_cache_type_get (type_def , & dcl ) == SUCCESS ) {
3730
+ /* pass */
3731
+ } else if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
3718
3732
zend_ffi_type_dtor (dcl .type );
3719
3733
if (clean_tags && FFI_G (tags )) {
3720
3734
zend_hash_destroy (FFI_G (tags ));
@@ -3727,24 +3741,28 @@ ZEND_METHOD(FFI, new) /* {{{ */
3727
3741
FFI_G (symbols ) = NULL ;
3728
3742
}
3729
3743
return ;
3744
+ } else {
3745
+ if (clean_tags && FFI_G (tags )) {
3746
+ zend_ffi_tags_cleanup (& dcl );
3747
+ }
3748
+ if (clean_symbols && FFI_G (symbols )) {
3749
+ zend_hash_destroy (FFI_G (symbols ));
3750
+ efree (FFI_G (symbols ));
3751
+ FFI_G (symbols ) = NULL ;
3752
+ }
3753
+ FFI_G (symbols ) = NULL ;
3754
+ FFI_G (tags ) = NULL ;
3755
+
3756
+ if (zend_ffi_cache_type_add ) {
3757
+ zend_ffi_cache_type_add (type_def , & dcl );
3758
+ }
3730
3759
}
3731
3760
3732
3761
type = ZEND_FFI_TYPE (dcl .type );
3733
3762
if (dcl .attr & ZEND_FFI_ATTR_CONST ) {
3734
3763
is_const = 1 ;
3735
3764
}
3736
3765
3737
- if (clean_tags && FFI_G (tags )) {
3738
- zend_ffi_tags_cleanup (& dcl );
3739
- }
3740
- if (clean_symbols && FFI_G (symbols )) {
3741
- zend_hash_destroy (FFI_G (symbols ));
3742
- efree (FFI_G (symbols ));
3743
- FFI_G (symbols ) = NULL ;
3744
- }
3745
- FFI_G (symbols ) = NULL ;
3746
- FFI_G (tags ) = NULL ;
3747
-
3748
3766
type_ptr = dcl .type ;
3749
3767
} else {
3750
3768
zend_ffi_ctype * ctype = (zend_ffi_ctype * ) type_obj ;
@@ -3864,7 +3882,10 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3864
3882
3865
3883
FFI_G (default_type_attr ) = 0 ;
3866
3884
3867
- if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
3885
+ if (zend_ffi_cache_type_get
3886
+ && zend_ffi_cache_type_get (type_def , & dcl ) == SUCCESS ) {
3887
+ /* pass */
3888
+ } else if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
3868
3889
zend_ffi_type_dtor (dcl .type );
3869
3890
if (clean_tags && FFI_G (tags )) {
3870
3891
zend_hash_destroy (FFI_G (tags ));
@@ -3877,24 +3898,28 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3877
3898
FFI_G (symbols ) = NULL ;
3878
3899
}
3879
3900
return ;
3901
+ } else {
3902
+ if (clean_tags && FFI_G (tags )) {
3903
+ zend_ffi_tags_cleanup (& dcl );
3904
+ }
3905
+ if (clean_symbols && FFI_G (symbols )) {
3906
+ zend_hash_destroy (FFI_G (symbols ));
3907
+ efree (FFI_G (symbols ));
3908
+ FFI_G (symbols ) = NULL ;
3909
+ }
3910
+ FFI_G (symbols ) = NULL ;
3911
+ FFI_G (tags ) = NULL ;
3912
+
3913
+ if (zend_ffi_cache_type_add ) {
3914
+ zend_ffi_cache_type_add (type_def , & dcl );
3915
+ }
3880
3916
}
3881
3917
3882
3918
type = ZEND_FFI_TYPE (dcl .type );
3883
3919
if (dcl .attr & ZEND_FFI_ATTR_CONST ) {
3884
3920
is_const = 1 ;
3885
3921
}
3886
3922
3887
- if (clean_tags && FFI_G (tags )) {
3888
- zend_ffi_tags_cleanup (& dcl );
3889
- }
3890
- if (clean_symbols && FFI_G (symbols )) {
3891
- zend_hash_destroy (FFI_G (symbols ));
3892
- efree (FFI_G (symbols ));
3893
- FFI_G (symbols ) = NULL ;
3894
- }
3895
- FFI_G (symbols ) = NULL ;
3896
- FFI_G (tags ) = NULL ;
3897
-
3898
3923
type_ptr = dcl .type ;
3899
3924
} else {
3900
3925
zend_ffi_ctype * ctype = (zend_ffi_ctype * ) ztype ;
@@ -4036,7 +4061,10 @@ ZEND_METHOD(FFI, type) /* {{{ */
4036
4061
4037
4062
FFI_G (default_type_attr ) = 0 ;
4038
4063
4039
- if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
4064
+ if (zend_ffi_cache_type_get
4065
+ && zend_ffi_cache_type_get (type_def , & dcl ) == SUCCESS ) {
4066
+ /* pass */
4067
+ } else if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
4040
4068
zend_ffi_type_dtor (dcl .type );
4041
4069
if (clean_tags && FFI_G (tags )) {
4042
4070
zend_hash_destroy (FFI_G (tags ));
@@ -4049,18 +4077,21 @@ ZEND_METHOD(FFI, type) /* {{{ */
4049
4077
FFI_G (symbols ) = NULL ;
4050
4078
}
4051
4079
return ;
4052
- }
4053
-
4054
- if (clean_tags && FFI_G (tags )) {
4055
- zend_ffi_tags_cleanup (& dcl );
4056
- }
4057
- if (clean_symbols && FFI_G (symbols )) {
4058
- zend_hash_destroy (FFI_G (symbols ));
4059
- efree (FFI_G (symbols ));
4080
+ } else {
4081
+ if (clean_tags && FFI_G (tags )) {
4082
+ zend_ffi_tags_cleanup (& dcl );
4083
+ }
4084
+ if (clean_symbols && FFI_G (symbols )) {
4085
+ zend_hash_destroy (FFI_G (symbols ));
4086
+ efree (FFI_G (symbols ));
4087
+ FFI_G (symbols ) = NULL ;
4088
+ }
4060
4089
FFI_G (symbols ) = NULL ;
4090
+ FFI_G (tags ) = NULL ;
4091
+ if (zend_ffi_cache_type_add ) {
4092
+ zend_ffi_cache_type_add (type_def , & dcl );
4093
+ }
4061
4094
}
4062
- FFI_G (symbols ) = NULL ;
4063
- FFI_G (tags ) = NULL ;
4064
4095
4065
4096
ctype = (zend_ffi_ctype * )zend_ffi_ctype_new (zend_ffi_ctype_ce );
4066
4097
ctype -> type = dcl .type ;
0 commit comments