|
20 | 20 | #include <unicode/ucnv.h> |
21 | 21 | #include <unicode/ustring.h> |
22 | 22 |
|
23 | | -#include "../intl_icu_compat.h" |
| 23 | +#include "converter_class.h" |
24 | 24 |
|
25 | 25 | extern "C" { |
26 | 26 | #include "converter.h" |
27 | 27 | #include "php_intl.h" |
28 | 28 | #include "../intl_error.h" |
29 | 29 | #include "../intl_common.h" |
30 | 30 | } |
31 | | -#include "converter_arginfo.h" |
32 | | - |
33 | | -typedef struct _php_converter_object { |
34 | | - UConverter *src, *dest; |
35 | | - zend_fcall_info_cache to_cache, from_cache; |
36 | | - intl_error error; |
37 | | - zend_object obj; |
38 | | -} php_converter_object; |
39 | | - |
40 | | - |
41 | | -static inline php_converter_object *php_converter_fetch_object(zend_object *obj) { |
42 | | - return (php_converter_object *)((char*)(obj) - offsetof(php_converter_object, obj)); |
43 | | -} |
44 | | -#define Z_INTL_CONVERTER_P(zv) php_converter_fetch_object(Z_OBJ_P(zv)) |
45 | | - |
46 | | -static zend_class_entry *php_converter_ce; |
47 | | -static zend_object_handlers php_converter_object_handlers; |
48 | 31 |
|
49 | 32 | #define CONV_GET(pzv) (Z_INTL_CONVERTER_P((pzv))) |
50 | 33 | #define THROW_UFAILURE(obj, error) php_converter_throw_failure(obj, error, \ |
@@ -332,7 +315,7 @@ static void php_converter_from_u_callback(const void *context, |
332 | 315 | /* }}} */ |
333 | 316 |
|
334 | 317 | /* {{{ php_converter_set_callbacks */ |
335 | | -static inline bool php_converter_set_callbacks(php_converter_object *objval, UConverter *cnv) { |
| 318 | +bool php_converter_set_callbacks(php_converter_object *objval, UConverter *cnv) { |
336 | 319 | bool ret = true; |
337 | 320 | UErrorCode error = U_ZERO_ERROR; |
338 | 321 |
|
@@ -504,21 +487,6 @@ PHP_METHOD(UConverter, getDestinationType) { |
504 | 487 | } |
505 | 488 | /* }}} */ |
506 | 489 |
|
507 | | -static void php_converter_resolve_callback( |
508 | | - zend_fcall_info_cache *fcc, |
509 | | - zend_object *this_ptr, |
510 | | - const char *callback_name, |
511 | | - size_t callback_name_len |
512 | | -) { |
513 | | - zend_function *fn = reinterpret_cast<zend_function *>(zend_hash_str_find_ptr_lc(&this_ptr->ce->function_table, callback_name, callback_name_len)); |
514 | | - ZEND_ASSERT(fn != nullptr); |
515 | | - |
516 | | - fcc->function_handler = fn; |
517 | | - fcc->object = this_ptr; |
518 | | - fcc->called_scope = this_ptr->ce; |
519 | | - fcc->closure = nullptr; |
520 | | -} |
521 | | - |
522 | 490 | /* {{{ */ |
523 | 491 | PHP_METHOD(UConverter, __construct) { |
524 | 492 | php_converter_object *objval = CONV_GET(ZEND_THIS); |
@@ -900,87 +868,3 @@ PHP_METHOD(UConverter, getStandards) { |
900 | 868 | } |
901 | 869 | } |
902 | 870 | /* }}} */ |
903 | | - |
904 | | -/* {{{ Converter create/clone/destroy */ |
905 | | -static void php_converter_free_object(zend_object *obj) { |
906 | | - php_converter_object *objval = php_converter_fetch_object(obj); |
907 | | - |
908 | | - if (objval->src) { |
909 | | - ucnv_close(objval->src); |
910 | | - } |
911 | | - |
912 | | - if (objval->dest) { |
913 | | - ucnv_close(objval->dest); |
914 | | - } |
915 | | - |
916 | | - intl_error_reset(&objval->error); |
917 | | - zend_object_std_dtor(obj); |
918 | | -} |
919 | | - |
920 | | -static zend_object *php_converter_object_ctor(zend_class_entry *ce, php_converter_object **pobjval) { |
921 | | - php_converter_object *objval; |
922 | | - |
923 | | - objval = reinterpret_cast<php_converter_object *>(zend_object_alloc(sizeof(php_converter_object), ce)); |
924 | | - |
925 | | - zend_object_std_init(&objval->obj, ce); |
926 | | - object_properties_init(&objval->obj, ce); |
927 | | - intl_error_init(&(objval->error)); |
928 | | - php_converter_resolve_callback(&objval->to_cache, &objval->obj, ZEND_STRL("toUCallback")); |
929 | | - php_converter_resolve_callback(&objval->from_cache, &objval->obj, ZEND_STRL("fromUCallback")); |
930 | | - |
931 | | - *pobjval = objval; |
932 | | - |
933 | | - return &objval->obj; |
934 | | -} |
935 | | - |
936 | | -static zend_object *php_converter_create_object(zend_class_entry *ce) { |
937 | | - php_converter_object *objval = nullptr; |
938 | | - zend_object *retval = php_converter_object_ctor(ce, &objval); |
939 | | - |
940 | | - object_properties_init(&(objval->obj), ce); |
941 | | - |
942 | | - return retval; |
943 | | -} |
944 | | - |
945 | | -static zend_object *php_converter_clone_object(zend_object *object) { |
946 | | - const php_converter_object *oldobj = php_converter_fetch_object(object); |
947 | | - php_converter_object *objval; |
948 | | - zend_object *retval = php_converter_object_ctor(object->ce, &objval); |
949 | | - UErrorCode error = U_ZERO_ERROR; |
950 | | - |
951 | | - objval->src = intl_icu_compat_ucnv_clone(oldobj->src, &error); |
952 | | - if (U_SUCCESS(error)) { |
953 | | - error = U_ZERO_ERROR; |
954 | | - objval->dest = intl_icu_compat_ucnv_clone(oldobj->dest, &error); |
955 | | - } |
956 | | - |
957 | | - if (U_FAILURE(error)) { |
958 | | - zend_throw_error(NULL, "Failed to clone UConverter"); |
959 | | - return retval; |
960 | | - } |
961 | | - |
962 | | - /* Update contexts for converter error handlers */ |
963 | | - php_converter_set_callbacks(objval, objval->src ); |
964 | | - php_converter_set_callbacks(objval, objval->dest); |
965 | | - |
966 | | - zend_objects_clone_members(&(objval->obj), &(oldobj->obj)); |
967 | | - |
968 | | - /* Newly cloned object deliberately does not inherit error state from original object */ |
969 | | - |
970 | | - return retval; |
971 | | -} |
972 | | -/* }}} */ |
973 | | - |
974 | | -/* {{{ php_converter_minit */ |
975 | | -U_CFUNC int php_converter_minit(INIT_FUNC_ARGS) { |
976 | | - php_converter_ce = register_class_UConverter(); |
977 | | - php_converter_ce->create_object = php_converter_create_object; |
978 | | - php_converter_ce->default_object_handlers = &php_converter_object_handlers; |
979 | | - memcpy(&php_converter_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); |
980 | | - php_converter_object_handlers.offset = offsetof(php_converter_object, obj); |
981 | | - php_converter_object_handlers.clone_obj = php_converter_clone_object; |
982 | | - php_converter_object_handlers.free_obj = php_converter_free_object; |
983 | | - |
984 | | - return SUCCESS; |
985 | | -} |
986 | | -/* }}} */ |
0 commit comments