diff options
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/zend_compile.c | 3 | ||||
-rw-r--r-- | Zend/zend_globals.h | 5 | ||||
-rw-r--r-- | Zend/zend_multibyte.c | 56 | ||||
-rw-r--r-- | Zend/zend_multibyte.h | 14 |
4 files changed, 56 insertions, 22 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5656b2dedc..ac31da4157 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -200,9 +200,6 @@ void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */ CG(script_encoding_list) = NULL; CG(script_encoding_list_size) = 0; CG(internal_encoding) = NULL; - CG(encoding_detector) = NULL; - CG(encoding_converter) = NULL; - CG(encoding_oddlen) = NULL; CG(encoding_declared) = 0; } /* }}} */ diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h index 1f6b8d4f1f..8ec2a88c04 100644 --- a/Zend/zend_globals.h +++ b/Zend/zend_globals.h @@ -155,11 +155,6 @@ struct _zend_compiler_globals { zend_encoding *internal_encoding; - /* multibyte utility functions */ - zend_encoding_detector encoding_detector; - zend_encoding_converter encoding_converter; - zend_encoding_oddlen encoding_oddlen; - #ifdef ZTS zval ***static_members_table; int last_static_member; diff --git a/Zend/zend_multibyte.c b/Zend/zend_multibyte.c index 33d8688b37..0843413d05 100644 --- a/Zend/zend_multibyte.c +++ b/Zend/zend_multibyte.c @@ -513,7 +513,36 @@ static zend_encoding *zend_encoding_table[] = { NULL }; +static char* dummy_encoding_detector(const unsigned char *string, size_t length, char *list TSRMLS_DC) +{ + return NULL; +} + +static int dummy_encoding_converter(unsigned char **to, size_t *to_length, const unsigned char *from, size_t from_length, const char *encoding_to, const char *encoding_from TSRMLS_DC) +{ + return -1; +} +static size_t dummy_encoding_oddlen(const unsigned char *string, size_t length, const char *encoding TSRMLS_DC) +{ + return 0; +} + +static int dummy_encoding_list_checker(const char *encoding_list TSRMLS_DC) +{ + return 0; +} + +static const char* dummy_get_internal_encoding(TSRMLS_D) +{ + return NULL; +} + +ZEND_API zend_encoding_detector zend_multibyte_encoding_detector = dummy_encoding_detector; +ZEND_API zend_encoding_converter zend_multibyte_encoding_converter = dummy_encoding_converter; +ZEND_API zend_encoding_oddlen zend_multibyte_encoding_oddlen = dummy_encoding_oddlen; +ZEND_API zend_encoding_list_checker zend_multibyte_check_encoding_list = dummy_encoding_list_checker; +ZEND_API zend_encoding_name_getter zend_multibyte_get_internal_encoding = dummy_get_internal_encoding; ZEND_API int zend_multibyte_set_script_encoding(const char *encoding_list, size_t encoding_list_size TSRMLS_DC) @@ -540,11 +569,13 @@ ZEND_API int zend_multibyte_set_internal_encoding(const char *encoding_name TSRM return 0; } -ZEND_API int zend_multibyte_set_functions(zend_encoding_detector encoding_detector, zend_encoding_converter encoding_converter, zend_encoding_oddlen encoding_oddlen TSRMLS_DC) +ZEND_API int zend_multibyte_set_functions(zend_encoding_detector encoding_detector, zend_encoding_converter encoding_converter, zend_encoding_oddlen encoding_oddlen, zend_encoding_list_checker encoding_list_checker, zend_encoding_name_getter get_internal_encoding TSRMLS_DC) { - CG(encoding_detector) = encoding_detector; - CG(encoding_converter) = encoding_converter; - CG(encoding_oddlen) = encoding_oddlen; + zend_multibyte_encoding_detector = encoding_detector; + zend_multibyte_encoding_converter = encoding_converter; + zend_multibyte_encoding_oddlen = encoding_oddlen; + zend_multibyte_check_encoding_list = encoding_list_checker; + zend_multibyte_get_internal_encoding = get_internal_encoding; return 0; } @@ -659,18 +690,16 @@ static size_t zend_multibyte_encoding_filter(unsigned char **to, size_t *to_leng { size_t oddlen; - if (!CG(encoding_converter)) { + if (zend_multibyte_encoding_converter == dummy_encoding_converter) { return 0; } - if (CG(encoding_oddlen)) { - oddlen = CG(encoding_oddlen)(from, from_length, from_encoding TSRMLS_CC); - if (oddlen > 0) { - from_length -= oddlen; - } + oddlen = zend_multibyte_encoding_oddlen(from, from_length, from_encoding TSRMLS_CC); + if (oddlen > 0) { + from_length -= oddlen; } - if (CG(encoding_converter)(to, to_length, from, from_length, to_encoding, from_encoding TSRMLS_CC) != 0) { + if (zend_multibyte_encoding_converter(to, to_length, from, from_length, to_encoding, from_encoding TSRMLS_CC) != 0) { return 0; } @@ -1053,10 +1082,11 @@ static zend_encoding* zend_multibyte_find_script_encoding(zend_encoding *onetime } /* if multiple encodings specified, detect automagically */ - if (CG(script_encoding_list_size) > 1 && CG(encoding_detector)) { + if (CG(script_encoding_list_size) > 1 && + zend_multibyte_encoding_detector != dummy_encoding_detector) { list = zend_multibyte_assemble_encoding_list(CG(script_encoding_list), CG(script_encoding_list_size)); - name = CG(encoding_detector)(LANG_SCNG(script_org), + name = zend_multibyte_encoding_detector(LANG_SCNG(script_org), LANG_SCNG(script_org_size), list TSRMLS_CC); if (list) { efree(list); diff --git a/Zend/zend_multibyte.h b/Zend/zend_multibyte.h index 02421a8ab5..94d8417b80 100644 --- a/Zend/zend_multibyte.h +++ b/Zend/zend_multibyte.h @@ -36,6 +36,10 @@ typedef int (*zend_encoding_converter)(unsigned char **to, size_t *to_length, co typedef size_t (*zend_encoding_oddlen)(const unsigned char *string, size_t length, const char *encoding TSRMLS_DC); +typedef int (*zend_encoding_list_checker)(const char *encoding_list TSRMLS_DC); + +typedef const char* (*zend_encoding_name_getter)(TSRMLS_D); + typedef struct _zend_encoding { zend_encoding_filter input_filter; /* escape input filter */ zend_encoding_filter output_filter; /* escape output filter */ @@ -49,10 +53,18 @@ typedef struct _zend_encoding { * zend multibyte APIs */ BEGIN_EXTERN_C() + +/* multibyte utility functions */ +ZEND_API extern zend_encoding_detector zend_multibyte_encoding_detector; +ZEND_API extern zend_encoding_converter zend_multibyte_encoding_converter; +ZEND_API extern zend_encoding_oddlen zend_multibyte_encoding_oddlen; +ZEND_API extern zend_encoding_list_checker zend_multibyte_check_encoding_list; +ZEND_API extern zend_encoding_name_getter zend_multibyte_get_internal_encoding; + ZEND_API int zend_multibyte_set_script_encoding(const char *encoding_list, size_t encoding_list_size TSRMLS_DC); ZEND_API int zend_multibyte_set_internal_encoding(const char *encoding_name TSRMLS_DC); -ZEND_API int zend_multibyte_set_functions(zend_encoding_detector encoding_detector, zend_encoding_converter encoding_converter, zend_encoding_oddlen encoding_oddlen TSRMLS_DC); +ZEND_API int zend_multibyte_set_functions(zend_encoding_detector encoding_detector, zend_encoding_converter encoding_converter, zend_encoding_oddlen encoding_oddlen, zend_encoding_list_checker encoding_list_checker, zend_encoding_name_getter get_internal_encoding TSRMLS_DC); ZEND_API int zend_multibyte_set_filter(zend_encoding *onetime_encoding TSRMLS_DC); ZEND_API zend_encoding* zend_multibyte_fetch_encoding(const char *encoding_name); ZEND_API size_t zend_multibyte_script_encoding_filter(unsigned char **to, size_t |