Skip to content

Commit bbf3d43

Browse files
author
Moriyoshi Koizumi
committed
* Refactor zend_multibyte facility.
Now mbstring.script_encoding is superseded by zend.script_encoding.
1 parent c28cac4 commit bbf3d43

33 files changed

+1696
-2317
lines changed

Zend/zend.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,25 @@ static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
8989
}
9090
/* }}} */
9191

92+
static ZEND_INI_MH(OnUpdateScriptEncoding) /* {{{ */
93+
{
94+
if (!CG(multibyte)) {
95+
return FAILURE;
96+
}
97+
if (!zend_multibyte_get_functions(TSRMLS_C)) {
98+
return SUCCESS;
99+
}
100+
return zend_multibyte_set_script_encoding_by_string(new_value, new_value_length TSRMLS_CC);
101+
}
102+
/* }}} */
103+
104+
92105
ZEND_INI_BEGIN()
93106
ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting)
94107
STD_ZEND_INI_BOOLEAN("zend.enable_gc", "1", ZEND_INI_ALL, OnUpdateGCEnabled, gc_enabled, zend_gc_globals, gc_globals)
95108
STD_ZEND_INI_BOOLEAN("zend.multibyte", "0", ZEND_INI_PERDIR, OnUpdateBool, multibyte, zend_compiler_globals, compiler_globals)
96-
STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
109+
ZEND_INI_ENTRY("zend.script_encoding", NULL, ZEND_INI_ALL, OnUpdateScriptEncoding)
110+
STD_ZEND_INI_BOOLEAN("zend.detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
97111
ZEND_INI_END()
98112

99113

@@ -528,6 +542,9 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals TSRMLS
528542
if (compiler_globals->static_members_table) {
529543
free(compiler_globals->static_members_table);
530544
}
545+
if (compiler_globals->script_encoding_list) {
546+
pefree(compiler_globals->script_encoding_list, 1);
547+
}
531548
compiler_globals->last_static_member = 0;
532549
}
533550
/* }}} */

Zend/zend_compile.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,6 @@ void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */
197197
init_compiler_declarables(TSRMLS_C);
198198
zend_stack_init(&CG(context_stack));
199199

200-
CG(script_encoding_list) = NULL;
201-
CG(script_encoding_list_size) = 0;
202-
CG(internal_encoding) = NULL;
203200
CG(encoding_declared) = 0;
204201
}
205202
/* }}} */
@@ -238,10 +235,6 @@ void shutdown_compiler(TSRMLS_D) /* {{{ */
238235
zend_hash_destroy(&CG(filenames_table));
239236
zend_llist_destroy(&CG(open_files));
240237
zend_stack_destroy(&CG(context_stack));
241-
242-
if (CG(script_encoding_list)) {
243-
efree(CG(script_encoding_list));
244-
}
245238
}
246239
/* }}} */
247240

@@ -5864,7 +5857,7 @@ void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */
58645857
CG(encoding_declared) = 1;
58655858

58665859
convert_to_string(&val->u.constant);
5867-
new_encoding = zend_multibyte_fetch_encoding(val->u.constant.value.str.val);
5860+
new_encoding = zend_multibyte_fetch_encoding(val->u.constant.value.str.val TSRMLS_CC);
58685861
if (!new_encoding) {
58695862
zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", val->u.constant.value.str.val);
58705863
} else {
@@ -5879,6 +5872,8 @@ void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC) /* {{{ */
58795872
zend_multibyte_yyinput_again(old_input_filter, old_encoding TSRMLS_CC);
58805873
}
58815874
}
5875+
} else {
5876+
zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because Zend multibyte feature is turned off by settings");
58825877
}
58835878
zval_dtor(&val->u.constant);
58845879
} else {

Zend/zend_globals.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,12 @@ struct _zend_compiler_globals {
147147

148148
HashTable interned_strings;
149149

150-
zend_encoding **script_encoding_list;
150+
const zend_encoding **script_encoding_list;
151151
size_t script_encoding_list_size;
152152
zend_bool multibyte;
153153
zend_bool detect_unicode;
154154
zend_bool encoding_declared;
155155

156-
zend_encoding *internal_encoding;
157-
158156
#ifdef ZTS
159157
zval ***static_members_table;
160158
int last_static_member;
@@ -310,8 +308,7 @@ struct _zend_php_scanner_globals {
310308
/* input/ouput filters */
311309
zend_encoding_filter input_filter;
312310
zend_encoding_filter output_filter;
313-
zend_encoding *script_encoding;
314-
zend_encoding *internal_encoding;
311+
const zend_encoding *script_encoding;
315312
};
316313

317314
#endif /* ZEND_GLOBALS_H */

0 commit comments

Comments
 (0)