summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-04-16 16:35:35 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-04-17 14:05:53 +0200
commitf73f190c3f97479f735b97c22a8e4885344edca1 (patch)
tree625e71a2a24f578560492d93291df1dbaad28869 /main
parent3ccd3aba90b4c0c95f1e0a457dbbc33c4524a4ed (diff)
downloadphp-git-f73f190c3f97479f735b97c22a8e4885344edca1.tar.gz
Fix internal_encoding fallback in mbstring
By introducing a hook that is called whenever one of internal_encoding / input_encoding / output_encoding changes, so that mbstring can adjust it's internal state. This also makes internal_encoding work with zend multibyte.
Diffstat (limited to 'main')
-rw-r--r--main/main.c41
-rw-r--r--main/php.h5
2 files changed, 46 insertions, 0 deletions
diff --git a/main/main.c b/main/main.c
index 5eb34b7fa4..f021f22af5 100644
--- a/main/main.c
+++ b/main/main.c
@@ -578,12 +578,44 @@ static PHP_INI_DISP(display_errors_mode)
}
/* }}} */
+PHPAPI const char *php_get_internal_encoding() {
+ if (PG(internal_encoding) && PG(internal_encoding)[0]) {
+ return PG(internal_encoding);
+ } else if (SG(default_charset)) {
+ return SG(default_charset);
+ }
+ return "";
+}
+
+PHPAPI const char *php_get_input_encoding() {
+ if (PG(input_encoding) && PG(input_encoding)[0]) {
+ return PG(input_encoding);
+ } else if (SG(default_charset)) {
+ return SG(default_charset);
+ }
+ return "";
+}
+
+PHPAPI const char *php_get_output_encoding() {
+ if (PG(output_encoding) && PG(output_encoding)[0]) {
+ return PG(output_encoding);
+ } else if (SG(default_charset)) {
+ return SG(default_charset);
+ }
+ return "";
+}
+
+PHPAPI void (*php_internal_encoding_changed)(void) = NULL;
+
/* {{{ PHP_INI_MH
*/
static PHP_INI_MH(OnUpdateDefaultCharset)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+ if (php_internal_encoding_changed) {
+ php_internal_encoding_changed();
+ }
#ifdef PHP_WIN32
php_win32_cp_do_update(ZSTR_VAL(new_value));
#endif
@@ -598,6 +630,9 @@ static PHP_INI_MH(OnUpdateInternalEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+ if (php_internal_encoding_changed) {
+ php_internal_encoding_changed();
+ }
#ifdef PHP_WIN32
php_win32_cp_do_update(ZSTR_VAL(new_value));
#endif
@@ -612,6 +647,9 @@ static PHP_INI_MH(OnUpdateInputEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+ if (php_internal_encoding_changed) {
+ php_internal_encoding_changed();
+ }
#ifdef PHP_WIN32
php_win32_cp_do_update(NULL);
#endif
@@ -626,6 +664,9 @@ static PHP_INI_MH(OnUpdateOutputEncoding)
{
if (new_value) {
OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
+ if (php_internal_encoding_changed) {
+ php_internal_encoding_changed();
+ }
#ifdef PHP_WIN32
php_win32_cp_do_update(NULL);
#endif
diff --git a/main/php.h b/main/php.h
index 48b4633879..be9917922a 100644
--- a/main/php.h
+++ b/main/php.h
@@ -371,6 +371,11 @@ PHPAPI int php_mergesort(void *base, size_t nmemb, size_t size, int (*cmp)(const
PHPAPI void php_register_pre_request_shutdown(void (*func)(void *), void *userdata);
PHPAPI void php_com_initialize(void);
PHPAPI char *php_get_current_user(void);
+
+PHPAPI const char *php_get_internal_encoding(void);
+PHPAPI const char *php_get_input_encoding(void);
+PHPAPI const char *php_get_output_encoding(void);
+PHPAPI extern void (*php_internal_encoding_changed)(void);
END_EXTERN_C()
/* PHP-named Zend macro wrappers */