@@ -67,8 +67,12 @@ static const char *zend_ffi_tag_kind_name[3] = {"enum", "struct", "union"};
6767#define ZEND_FFI_SIZEOF_ARG \
6868 MAX(FFI_SIZEOF_ARG, sizeof(double))
6969
70+ static struct _zend_ffi_api ffi_api ;
71+
7072static zend_class_entry * zend_ffi_exception_ce ;
7173static zend_class_entry * zend_ffi_parser_exception_ce ;
74+ static zend_class_entry * zend_ffi_ce ;
75+ static zend_class_entry * zend_ffi_cdata_ce ;
7276static zend_class_entry * zend_ffi_ctype_ce ;
7377
7478static zend_object_handlers zend_ffi_handlers ;
@@ -91,7 +95,7 @@ static ZEND_FUNCTION(ffi_trampoline);
9195static ZEND_COLD void zend_ffi_return_unsupported (zend_ffi_type * type );
9296static ZEND_COLD void zend_ffi_pass_unsupported (zend_ffi_type * type );
9397static ZEND_COLD void zend_ffi_assign_incompatible (zval * arg , zend_ffi_type * type );
94- //??? static bool zend_ffi_is_compatible_type(zend_ffi_type *dst_type, zend_ffi_type *src_type);
98+ static bool zend_ffi_is_compatible_type (zend_ffi_type * dst_type , zend_ffi_type * src_type );
9599
96100#if FFI_CLOSURES
97101static void * zend_ffi_create_callback (zend_ffi_type * type , zval * value );
@@ -177,7 +181,7 @@ static bool zend_ffi_func_ptr_are_compatible(zend_ffi_type *dst_type, zend_ffi_t
177181}
178182/* }}} */
179183
180- PHP_FFI_API bool zend_ffi_is_compatible_type (zend_ffi_type * dst_type , zend_ffi_type * src_type ) /* {{{ */
184+ static bool zend_ffi_is_compatible_type (zend_ffi_type * dst_type , zend_ffi_type * src_type ) /* {{{ */
181185{
182186 while (1 ) {
183187 if (dst_type == src_type ) {
@@ -352,7 +356,7 @@ static ffi_type *zend_ffi_get_type(zend_ffi_type *type) /* {{{ */
352356}
353357/* }}} */
354358
355- static zend_ffi_cdata * _zend_ffi_cdata_create (void * ptr , zend_ffi_type * type ) /* {{{ */
359+ static zend_ffi_cdata * zend_ffi_cdata_create (void * ptr , zend_ffi_type * type ) /* {{{ */
356360{
357361 zend_ffi_cdata * cdata = emalloc (sizeof (zend_ffi_cdata ));
358362
@@ -2935,8 +2939,8 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
29352939 FFI_G (tags ) = NULL ;
29362940
29372941 if (code && ZSTR_LEN (code )) {
2938- if (zend_ffi_cache_scope_get ) {
2939- zend_ffi_scope * scope = zend_ffi_cache_scope_get (code );
2942+ if (ffi_api . cache_scope_get ) {
2943+ zend_ffi_scope * scope = ffi_api . cache_scope_get (code );
29402944 if (scope ) {
29412945 ffi = (zend_ffi * )zend_ffi_new (zend_ffi_ce );
29422946 ffi -> lib = handle ;
@@ -2990,12 +2994,12 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
29902994 } ZEND_HASH_FOREACH_END ();
29912995 }
29922996
2993- if (zend_ffi_cache_scope_add ) {
2997+ if (ffi_api . cache_scope_add ) {
29942998 zend_ffi_scope scope , * cached_scope ;
29952999
29963000 scope .symbols = FFI_G (symbols );
29973001 scope .tags = FFI_G (tags );
2998- cached_scope = zend_ffi_cache_scope_add (code , & scope );
3002+ cached_scope = ffi_api . cache_scope_add (code , & scope );
29993003 if (cached_scope ) {
30003004 if (FFI_G (symbols )) {
30013005 zend_hash_destroy (FFI_G (symbols ));
@@ -3262,8 +3266,8 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
32623266 close (fd );
32633267 ZSTR_VAL (code )[code_size ] = 0 ;
32643268
3265- if (!preload && zend_ffi_cache_scope_get ) {
3266- zend_ffi_scope * scope = zend_ffi_cache_scope_get (code );
3269+ if (!preload && ffi_api . cache_scope_get ) {
3270+ zend_ffi_scope * scope = ffi_api . cache_scope_get (code );
32673271 if (scope ) {
32683272 ffi = (zend_ffi * )zend_ffi_new (zend_ffi_ce );
32693273 ffi -> lib = handle ;
@@ -3473,12 +3477,12 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
34733477 ffi -> tags = scope -> tags ;
34743478 ffi -> persistent = 1 ;
34753479 } else {
3476- if (zend_ffi_cache_scope_add ) {
3480+ if (ffi_api . cache_scope_add ) {
34773481 zend_ffi_scope scope , * cached_scope ;
34783482
34793483 scope .symbols = FFI_G (symbols );
34803484 scope .tags = FFI_G (tags );
3481- cached_scope = zend_ffi_cache_scope_add (code , & scope );
3485+ cached_scope = ffi_api . cache_scope_add (code , & scope );
34823486 if (cached_scope ) {
34833487 if (FFI_G (symbols )) {
34843488 zend_hash_destroy (FFI_G (symbols ));
@@ -3802,8 +3806,8 @@ ZEND_METHOD(FFI, new) /* {{{ */
38023806
38033807 FFI_G (default_type_attr ) = 0 ;
38043808
3805- if (zend_ffi_cache_type_get
3806- && (cached_dcl = zend_ffi_cache_type_get (type_def , FFI_G (symbols )))) {
3809+ if (ffi_api . cache_type_get
3810+ && (cached_dcl = ffi_api . cache_type_get (type_def , FFI_G (symbols )))) {
38073811 memcpy (& dcl , cached_dcl , sizeof (zend_ffi_dcl ));
38083812 } else if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
38093813 zend_ffi_type_dtor (dcl .type );
@@ -3823,8 +3827,8 @@ ZEND_METHOD(FFI, new) /* {{{ */
38233827 zend_ffi_tags_cleanup (& dcl );
38243828 }
38253829
3826- if (zend_ffi_cache_type_add ) {
3827- cached_dcl = zend_ffi_cache_type_add (type_def , & dcl , FFI_G (symbols ));
3830+ if (zend_ffi_api -> cache_type_add ) {
3831+ cached_dcl = zend_ffi_api -> cache_type_add (type_def , & dcl , FFI_G (symbols ));
38283832 if (cached_dcl ) {
38293833 if (ZEND_FFI_TYPE_IS_OWNED (dcl .type )) {
38303834 _zend_ffi_type_dtor (dcl .type );
@@ -3967,8 +3971,8 @@ ZEND_METHOD(FFI, cast) /* {{{ */
39673971
39683972 FFI_G (default_type_attr ) = 0 ;
39693973
3970- if (zend_ffi_cache_type_get
3971- && (cached_dcl = zend_ffi_cache_type_get (type_def , FFI_G (symbols )))) {
3974+ if (ffi_api . cache_type_get
3975+ && (cached_dcl = ffi_api . cache_type_get (type_def , FFI_G (symbols )))) {
39723976 memcpy (& dcl , cached_dcl , sizeof (zend_ffi_dcl ));
39733977 } else if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
39743978 zend_ffi_type_dtor (dcl .type );
@@ -3988,8 +3992,8 @@ ZEND_METHOD(FFI, cast) /* {{{ */
39883992 zend_ffi_tags_cleanup (& dcl );
39893993 }
39903994
3991- if (zend_ffi_cache_type_add ) {
3992- cached_dcl = zend_ffi_cache_type_add (type_def , & dcl , FFI_G (symbols ));
3995+ if (ffi_api . cache_type_add ) {
3996+ cached_dcl = ffi_api . cache_type_add (type_def , & dcl , FFI_G (symbols ));
39933997 if (cached_dcl ) {
39943998 if (ZEND_FFI_TYPE_IS_OWNED (dcl .type )) {
39953999 _zend_ffi_type_dtor (dcl .type );
@@ -4154,8 +4158,8 @@ ZEND_METHOD(FFI, type) /* {{{ */
41544158
41554159 FFI_G (default_type_attr ) = 0 ;
41564160
4157- if (zend_ffi_cache_type_get
4158- && (cached_dcl = zend_ffi_cache_type_get (type_def , FFI_G (symbols )))) {
4161+ if (ffi_api . cache_type_get
4162+ && (cached_dcl = ffi_api . cache_type_get (type_def , FFI_G (symbols )))) {
41594163 memcpy (& dcl , cached_dcl , sizeof (zend_ffi_dcl ));
41604164 } else if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
41614165 zend_ffi_type_dtor (dcl .type );
@@ -4175,8 +4179,8 @@ ZEND_METHOD(FFI, type) /* {{{ */
41754179 zend_ffi_tags_cleanup (& dcl );
41764180 }
41774181
4178- if (zend_ffi_cache_type_add ) {
4179- cached_dcl = zend_ffi_cache_type_add (type_def , & dcl , FFI_G (symbols ));
4182+ if (ffi_api . cache_type_add ) {
4183+ cached_dcl = ffi_api . cache_type_add (type_def , & dcl , FFI_G (symbols ));
41804184 if (cached_dcl ) {
41814185 if (ZEND_FFI_TYPE_IS_OWNED (dcl .type )) {
41824186 _zend_ffi_type_dtor (dcl .type );
@@ -5311,7 +5315,7 @@ static ZEND_INI_DISP(zend_ffi_enable_displayer_cb) /* {{{ */
53115315}
53125316/* }}} */
53135317
5314- static void _zend_ffi_type_print (FILE * f , const zend_ffi_type * type ) /* {{{ */
5318+ static void zend_ffi_type_print (FILE * f , const zend_ffi_type * type ) /* {{{ */
53155319{
53165320 zend_ffi_ctype_name_buf buf ;
53175321
@@ -5604,8 +5608,16 @@ ZEND_MINIT_FUNCTION(ffi)
56045608 zend_ffi_ctype_handlers .get_properties = zend_fake_get_properties ;
56055609 zend_ffi_ctype_handlers .get_gc = zend_fake_get_gc ;
56065610
5607- zend_ffi_cdata_create = _zend_ffi_cdata_create ;
5608- zend_ffi_type_print = _zend_ffi_type_print ;
5611+ memset (& ffi_api , 0 , sizeof (ffi_api ));
5612+
5613+ ffi_api .scope_ce = zend_ffi_ce ;
5614+ ffi_api .cdata_ce = zend_ffi_cdata_ce ;
5615+
5616+ ffi_api .cdata_create = zend_ffi_cdata_create ;
5617+ ffi_api .type_print = zend_ffi_type_print ;
5618+ ffi_api .is_compatible_type = zend_ffi_is_compatible_type ;
5619+
5620+ zend_ffi_api = & ffi_api ;
56095621
56105622 if (FFI_G (preload )) {
56115623 return zend_ffi_preload (FFI_G (preload ));
0 commit comments