Permalink
Browse files

Removed compile time dependency from ext/mbstring

  • Loading branch information...
1 parent 088a6ad commit 755c2cd0d85b65f35abb2d54204fa7d38b820268 Dmitry Stogov committed Dec 8, 2010
Showing with 481 additions and 279 deletions.
  1. +1 −0 NEWS
  2. +0 −3 Zend/zend_compile.c
  3. +0 −5 Zend/zend_globals.h
  4. +43 −13 Zend/zend_multibyte.c
  5. +13 −1 Zend/zend_multibyte.h
  6. +40 −56 ext/exif/exif.c
  7. +108 −9 ext/mbstring/mbstring.c
  8. +3 −80 ext/standard/html.c
  9. +105 −112 main/rfc1867.c
  10. +13 −0 main/rfc1867.h
  11. +104 −0 tests/basic/028.phpt
  12. +51 −0 tests/basic/029.phpt
View
@@ -32,6 +32,7 @@ PHP NEWS
. Added multibyte suppport by default. Previosly php had to be compiled
with --enable-zend-multibyte. Now it can be enabled or disabled throug
zend.multibyte directive in php.ini (Dmitry)
+ . Removed compile time dependency from ext/mbstring (Dmitry)
. Added scalar typehints to the parser and the reflection API. (Ilia, Derick)
. Added support for Traits. (Stefan)
. Added closure $this support back. (Stas)
View
@@ -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;
}
/* }}} */
View
@@ -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;
View
@@ -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);
View
@@ -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
View
@@ -66,16 +66,6 @@
#include "ext/standard/php_image.h"
#include "ext/standard/info.h"
-#if defined(PHP_WIN32) || (HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING))
-#define EXIF_USE_MBSTRING 1
-#else
-#define EXIF_USE_MBSTRING 0
-#endif
-
-#if EXIF_USE_MBSTRING
-#include "ext/mbstring/mbstring.h"
-#endif
-
/* needed for ssize_t definition */
#include <sys/types.h>
@@ -176,23 +166,19 @@ ZEND_DECLARE_MODULE_GLOBALS(exif)
ZEND_INI_MH(OnUpdateEncode)
{
-#if EXIF_USE_MBSTRING
- if (new_value && strlen(new_value) && !php_mb_check_encoding_list(new_value TSRMLS_CC)) {
+ if (new_value && strlen(new_value) && !zend_multibyte_check_encoding_list(new_value TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value);
return FAILURE;
}
-#endif
return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
}
ZEND_INI_MH(OnUpdateDecode)
{
-#if EXIF_USE_MBSTRING
- if (!php_mb_check_encoding_list(new_value TSRMLS_CC)) {
+ if (!zend_multibyte_check_encoding_list(new_value TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value);
return FAILURE;
}
-#endif
return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
}
@@ -224,7 +210,11 @@ static PHP_GINIT_FUNCTION(exif)
PHP_MINIT_FUNCTION(exif)
{
REGISTER_INI_ENTRIES();
- REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", EXIF_USE_MBSTRING, CONST_CS | CONST_PERSISTENT);
+ if (zend_hash_exists(&module_registry, "mbstring", sizeof("mbstring"))) {
+ REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", 1, CONST_CS | CONST_PERSISTENT);
+ } else {
+ REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", 0, CONST_CS | CONST_PERSISTENT);
+ }
return SUCCESS;
}
/* }}} */
@@ -241,9 +231,7 @@ PHP_MSHUTDOWN_FUNCTION(exif)
/* {{{ exif dependencies */
static const zend_module_dep exif_module_deps[] = {
ZEND_MOD_REQUIRED("standard")
-#if EXIF_USE_MBSTRING
- ZEND_MOD_REQUIRED("mbstring")
-#endif
+ ZEND_MOD_OPTIONAL("mbstring")
{NULL, NULL, NULL}
};
/* }}} */
@@ -2588,7 +2576,6 @@ static int exif_process_undefined(char **result, char *value, size_t byte_count
/* {{{ exif_process_string_raw
* Copy a string in Exif header to a character string returns length of allocated buffer if any. */
-#if !EXIF_USE_MBSTRING
static int exif_process_string_raw(char **result, char *value, size_t byte_count) {
/* we cannot use strlcpy - here the problem is that we have to copy NUL
* chars up to byte_count, we also have to add a single NUL character to
@@ -2602,7 +2589,6 @@ static int exif_process_string_raw(char **result, char *value, size_t byte_count
}
return 0;
}
-#endif
/* }}} */
/* {{{ exif_process_string
@@ -2629,11 +2615,8 @@ static int exif_process_string(char **result, char *value, size_t byte_count TSR
static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount TSRMLS_DC)
{
int a;
-
-#if EXIF_USE_MBSTRING
char *decode;
size_t len;;
-#endif
*pszEncoding = NULL;
/* Copy the comment */
@@ -2642,7 +2625,6 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
*pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8;
ByteCount -= 8;
-#if EXIF_USE_MBSTRING
/* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16)
* since we have no encoding support for the BOM yet we skip that.
*/
@@ -2659,34 +2641,38 @@ static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoP
} else {
decode = ImageInfo->decode_unicode_le;
}
- *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, decode, &len TSRMLS_CC);
+ if (zend_multibyte_encoding_converter(
+ pszInfoPtr,
+ &len,
+ szValuePtr,
+ ByteCount,
+ ImageInfo->encode_unicode,
+ decode
+ TSRMLS_DC) != 0) {
+ len = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
+ }
return len;
-#else
- return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
-#endif
- } else
- if (!memcmp(szValuePtr, "ASCII\0\0\0", 8)) {
+ } else if (!memcmp(szValuePtr, "ASCII\0\0\0", 8)) {
*pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8;
ByteCount -= 8;
- } else
- if (!memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) {
+ } else if (!memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) {
/* JIS should be tanslated to MB or we leave it to the user - leave it to the user */
*pszEncoding = estrdup((const char*)szValuePtr);
szValuePtr = szValuePtr+8;
ByteCount -= 8;
-#if EXIF_USE_MBSTRING
- if (ImageInfo->motorola_intel) {
- *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_be, &len TSRMLS_CC);
- } else {
- *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_le, &len TSRMLS_CC);
+ if (zend_multibyte_encoding_converter(
+ pszInfoPtr,
+ &len,
+ szValuePtr,
+ ByteCount,
+ ImageInfo->encode_jis,
+ ImageInfo->motorola_intel ? ImageInfo->decode_jis_be : ImageInfo->decode_jis_le
+ TSRMLS_DC) != 0) {
+ len = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
}
return len;
-#else
- return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
-#endif
- } else
- if (!memcmp(szValuePtr, "\0\0\0\0\0\0\0\0", 8)) {
+ } else if (!memcmp(szValuePtr, "\0\0\0\0\0\0\0\0", 8)) {
/* 8 NULL means undefined and should be ASCII... */
*pszEncoding = estrdup("UNDEFINED");
szValuePtr = szValuePtr+8;
@@ -2714,19 +2700,17 @@ static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_fi
xp_field->tag = tag;
/* Copy the comment */
-#if EXIF_USE_MBSTRING
-/* What if MS supports big-endian with XP? */
-/* if (ImageInfo->motorola_intel) {
- xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_be, &xp_field->size TSRMLS_CC);
- } else {
- xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC);
- }*/
- xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC);
- return xp_field->size;
-#else
- xp_field->size = exif_process_string_raw(&xp_field->value, szValuePtr, ByteCount);
+ if (zend_multibyte_encoding_converter(
+ &xp_field->value,
+ &xp_field->size,
+ szValuePtr,
+ ByteCount,
+ ImageInfo->encode_unicode,
+ ImageInfo->motorola_intel ? ImageInfo->decode_unicode_be : ImageInfo->decode_unicode_le
+ TSRMLS_DC) != 0) {
+ xp_field->size = exif_process_string_raw(&xp_field->value, szValuePtr, ByteCount);
+ }
return xp_field->size;
-#endif
}
/* }}} */
Oops, something went wrong. Retry.

0 comments on commit 755c2cd

Please sign in to comment.