From a731de398ffb8cf7daf7568c485f0a1fad674afd Mon Sep 17 00:00:00 2001 From: Alexander Polyakov Date: Tue, 29 Oct 2024 17:56:25 +0300 Subject: [PATCH] Move mbstring functions into runtime-common --- common/unicode/unicode.cmake | 21 ++- compiler/compiler-core.cpp | 20 ++- compiler/compiler-core.h | 3 + compiler/compiler.cmake | 1 + compiler/make/make.cpp | 10 +- compiler/runtime_build_info.h | 1 + compiler/unicode_sources.h.in | 3 + runtime-common/stdlib/stdlib.cmake | 3 +- .../stdlib/string/mbstring-functions.cpp | 129 +++++++++--------- .../stdlib/string/mbstring-functions.h | 21 +-- runtime-common/stdlib/string/string-context.h | 3 + runtime-light/runtime-light.cmake | 8 +- runtime/regexp.h | 2 +- runtime/runtime.cmake | 1 - 14 files changed, 133 insertions(+), 93 deletions(-) create mode 100644 compiler/unicode_sources.h.in rename runtime/mbstring.cpp => runtime-common/stdlib/string/mbstring-functions.cpp (69%) rename runtime/mbstring.h => runtime-common/stdlib/string/mbstring-functions.h (66%) diff --git a/common/unicode/unicode.cmake b/common/unicode/unicode.cmake index ab78694101..65fcc2b0a0 100644 --- a/common/unicode/unicode.cmake +++ b/common/unicode/unicode.cmake @@ -31,8 +31,21 @@ add_custom_command( DEPENDS ${UNICODE_DATA_LIST} COMMENT "unicode-utils-auto.h generation") -vk_add_library(unicode OBJECT - ${UNICODE_DIR}/unicode-utils.cpp - ${UNICODE_DIR}/utf8-utils.cpp - ${AUTO_DIR}/common/unicode-utils-auto.h) +set(UNICODE_SOURCES unicode-utils.cpp utf8-utils.cpp) +if (COMPILE_RUNTIME_LIGHT) + set(UNICODE_SOURCES_FOR_COMP "${UNICODE_SOURCES}") + configure_file(${BASE_DIR}/compiler/unicode_sources.h.in ${AUTO_DIR}/compiler/unicode_sources.h) +endif() + +prepend(UNICODE_SOURCES ${UNICODE_DIR}/ ${UNICODE_SOURCES}) + +if (COMPILE_RUNTIME_LIGHT) + vk_add_library(light_unicode OBJECT ${UNICODE_SOURCES} ${AUTO_DIR}/common/unicode-utils-auto.h) + set_property(TARGET light_unicode PROPERTY POSITION_INDEPENDENT_CODE ON) + + target_compile_options(light_unicode PUBLIC -stdlib=libc++) + target_link_options(light_unicode PUBLIC -stdlib=libc++ -static-libstdc++) +endif() + +vk_add_library(unicode OBJECT ${UNICODE_SOURCES} ${AUTO_DIR}/common/unicode-utils-auto.h) diff --git a/compiler/compiler-core.cpp b/compiler/compiler-core.cpp index 9b2c88bfaf..3e3bf03b6d 100644 --- a/compiler/compiler-core.cpp +++ b/compiler/compiler-core.cpp @@ -12,13 +12,14 @@ #include "compiler/const-manipulations.h" #include "compiler/data/composer-json-data.h" -#include "compiler/data/ffi-data.h" #include "compiler/data/define-data.h" +#include "compiler/data/ffi-data.h" #include "compiler/data/function-data.h" #include "compiler/data/lib-data.h" #include "compiler/data/modulite-data.h" #include "compiler/data/src-dir.h" #include "compiler/data/src-file.h" +#include "compiler/index.h" #include "compiler/name-gen.h" #include "compiler/runtime_build_info.h" @@ -654,6 +655,10 @@ const Index &CompilerCore::get_common_index() { return common_sources_index; } +const Index &CompilerCore::get_unicode_index() { + return unicode_sources_index; +} + File *CompilerCore::get_file_info(std::string &&file_name) { return cpp_index.insert_file(std::move(file_name)); } @@ -692,6 +697,14 @@ static std::vector get_common_sources() { #endif } +static std::vector get_unicode_sources() { +#ifdef RUNTIME_LIGHT + return split(UNICODE_SOURCES, ';'); +#else + return {}; +#endif +} + void CompilerCore::init_runtime_and_common_srcs_dir() { runtime_common_sources_dir = settings().runtime_and_common_src.get() + "runtime-common/"; runtime_common_sources_index.sync_with_dir(runtime_common_sources_dir); @@ -707,6 +720,11 @@ void CompilerCore::init_runtime_and_common_srcs_dir() { common_sources_index.sync_with_dir(common_sources_dir); common_sources_dir = common_sources_index.get_dir(); // As in init_dest_dir, IDK what is it for common_sources_index.filter_with_whitelist(get_common_sources()); + + unicode_sources_dir = settings().runtime_and_common_src.get() + "common/unicode/"; + unicode_sources_index.sync_with_dir(unicode_sources_dir); + unicode_sources_dir = unicode_sources_index.get_dir(); // As in init_dest_dir, IDK what is it for + unicode_sources_index.filter_with_whitelist(get_unicode_sources()); } bool CompilerCore::try_require_file(SrcFilePtr file) { diff --git a/compiler/compiler-core.h b/compiler/compiler-core.h index 238b4de484..da05de4c8f 100644 --- a/compiler/compiler-core.h +++ b/compiler/compiler-core.h @@ -40,6 +40,7 @@ class CompilerCore { Index runtime_common_sources_index; Index runtime_sources_index; Index common_sources_index; + Index unicode_sources_index; TSHashTable file_ht; TSHashTable dirs_ht; TSHashTable functions_ht; @@ -71,6 +72,7 @@ class CompilerCore { std::string runtime_common_sources_dir; std::string runtime_sources_dir; std::string common_sources_dir; + std::string unicode_sources_dir; CompilerCore(); void start(); @@ -144,6 +146,7 @@ class CompilerCore { const Index &get_runtime_core_index(); const Index &get_runtime_index(); const Index &get_common_index(); + const Index &get_unicode_index(); File *get_file_info(std::string &&file_name); void del_extra_files(); void init_dest_dir(); diff --git a/compiler/compiler.cmake b/compiler/compiler.cmake index 24f0efa2d4..8d6244313e 100644 --- a/compiler/compiler.cmake +++ b/compiler/compiler.cmake @@ -6,6 +6,7 @@ set(KEYWORDS_GPERF ${KPHP_COMPILER_DIR}/keywords.gperf) if (COMPILE_RUNTIME_LIGHT) prepend(RUNTIME_BUILD_INFO ${KPHP_COMPILER_AUTO_DIR}/ common_sources.h + unicode_sources.h runtime_sources.h runtime_common_sources.h runtime_compile_flags.h) diff --git a/compiler/make/make.cpp b/compiler/make/make.cpp index 52a334070a..b9ccc6ba6f 100644 --- a/compiler/make/make.cpp +++ b/compiler/make/make.cpp @@ -16,18 +16,19 @@ #include "common/wrappers/pathname.h" #include "compiler/compiler-core.h" -#include "compiler/data/lib-data.h" #include "compiler/data/ffi-data.h" +#include "compiler/data/lib-data.h" +#include "compiler/index.h" #include "compiler/make/cpp-to-obj-target.h" -#include "compiler/make/runtime-src-to-obj-target.h" #include "compiler/make/file-target.h" #include "compiler/make/h-to-pch-target.h" #include "compiler/make/hardlink-or-copy.h" #include "compiler/make/make-runner.h" #include "compiler/make/objs-to-bin-target.h" -#include "compiler/make/objs-to-obj-target.h" #include "compiler/make/objs-to-k2-component-target.h" +#include "compiler/make/objs-to-obj-target.h" #include "compiler/make/objs-to-static-lib-target.h" +#include "compiler/make/runtime-src-to-obj-target.h" #include "compiler/runtime_build_info.h" #include "compiler/stage.h" #include "compiler/threading/profiler.h" @@ -459,11 +460,12 @@ static std::vector build_runtime_and_common_from_sources(const std::stri const Index &runtime_core_dir = G->get_runtime_core_index(); const Index &runtime_dir = G->get_runtime_index(); const Index &common_dir = G->get_common_index(); + const Index &unicode_index = G->get_unicode_index(); std::vector objs; objs.reserve(runtime_dir.get_files_count() + common_dir.get_files_count()); - for (const auto *dir : std::vector{&runtime_core_dir, &runtime_dir, &common_dir}) { + for (const auto *dir : std::vector{&runtime_core_dir, &runtime_dir, &common_dir, &unicode_index}) { for (File *cpp_file : dir->get_files()) { File *obj_file = obj_dir.insert_file(static_cast(cpp_file->name_without_ext) + ".o"); make.create_cpp_target(cpp_file); diff --git a/compiler/runtime_build_info.h b/compiler/runtime_build_info.h index 0cc05a8cd9..0f07847a22 100644 --- a/compiler/runtime_build_info.h +++ b/compiler/runtime_build_info.h @@ -3,6 +3,7 @@ #ifdef RUNTIME_LIGHT #include "auto/compiler/common_sources.h" +#include "auto/compiler/unicode_sources.h" #include "auto/compiler/runtime_compile_flags.h" #include "auto/compiler/runtime_common_sources.h" #include "auto/compiler/runtime_sources.h" diff --git a/compiler/unicode_sources.h.in b/compiler/unicode_sources.h.in new file mode 100644 index 0000000000..d41ec31383 --- /dev/null +++ b/compiler/unicode_sources.h.in @@ -0,0 +1,3 @@ +#pragma once + +#define UNICODE_SOURCES "${UNICODE_SOURCES_FOR_COMP}" diff --git a/runtime-common/stdlib/stdlib.cmake b/runtime-common/stdlib/stdlib.cmake index aaa11259a1..7b4e259f9c 100644 --- a/runtime-common/stdlib/stdlib.cmake +++ b/runtime-common/stdlib/stdlib.cmake @@ -1,3 +1,4 @@ -prepend(STDLIB_STRING stdlib/string/ string-functions.cpp) +prepend(STDLIB_STRING stdlib/string/ string-functions.cpp + mbstring-functions.cpp) set(STDLIB_SRC "${STDLIB_STRING}") diff --git a/runtime/mbstring.cpp b/runtime-common/stdlib/string/mbstring-functions.cpp similarity index 69% rename from runtime/mbstring.cpp rename to runtime-common/stdlib/string/mbstring-functions.cpp index 53f9e462ff..cbe8887beb 100644 --- a/runtime/mbstring.cpp +++ b/runtime-common/stdlib/string/mbstring-functions.cpp @@ -2,23 +2,14 @@ // Copyright (c) 2024 LLC «V Kontakte» // Distributed under the GPL v3 License, see LICENSE.notice.txt -#include "runtime/mbstring.h" +#include "runtime-common/stdlib/string/mbstring-functions.h" #include "common/unicode/unicode-utils.h" #include "common/unicode/utf8-utils.h" +#include "runtime-common/stdlib/string/string-context.h" #include "runtime-common/stdlib/string/string-functions.h" -static bool is_detect_incorrect_encoding_names_warning{false}; - -void f$set_detect_incorrect_encoding_names_warning(bool show) { - is_detect_incorrect_encoding_names_warning = show; -} - -void free_detect_incorrect_encoding_names() { - is_detect_incorrect_encoding_names_warning = false; -} - -static int mb_detect_encoding_new(const string &encoding) { +int mb_detect_encoding_new(const string &encoding) noexcept { const auto *encoding_name = f$strtolower(encoding).c_str(); if (!strcmp(encoding_name, "cp1251") || !strcmp(encoding_name, "cp-1251") || !strcmp(encoding_name, "windows-1251")) { @@ -32,43 +23,44 @@ static int mb_detect_encoding_new(const string &encoding) { return -1; } -static int mb_detect_encoding(const string &encoding) { +int mb_detect_encoding(const string &encoding) noexcept { const int result_new = mb_detect_encoding_new(encoding); + const auto detect_incorrect_encoding_names = StringLibContext::get().detect_incorrect_encoding_names; if (strstr(encoding.c_str(), "1251")) { - if (is_detect_incorrect_encoding_names_warning && 1251 != result_new) { + if (detect_incorrect_encoding_names && 1251 != result_new) { php_warning("mb_detect_encoding returns 1251, but new will return %d, encoding %s", result_new, encoding.c_str()); } return 1251; } if (strstr(encoding.c_str(), "-8")) { - if (is_detect_incorrect_encoding_names_warning && 8 != result_new) { + if (detect_incorrect_encoding_names && 8 != result_new) { php_warning("mb_detect_encoding returns 8, but new will return %d, encoding %s", result_new, encoding.c_str()); } return 8; } - if (is_detect_incorrect_encoding_names_warning && -1 != result_new) { + if (detect_incorrect_encoding_names && -1 != result_new) { php_warning("mb_detect_encoding returns -1, but new will return %d, encoding %s", result_new, encoding.c_str()); } return -1; } -static int64_t mb_UTF8_strlen(const char *s) { +int64_t mb_UTF8_strlen(const char *s) { int64_t res = 0; for (int64_t i = 0; s[i]; i++) { - if ((((unsigned char)s[i]) & 0xc0) != 0x80) { + if (((static_cast(s[i])) & 0xc0) != 0x80) { res++; } } return res; } -static int64_t mb_UTF8_advance(const char *s, int64_t cnt) { - php_assert (cnt >= 0); - int64_t i; +int64_t mb_UTF8_advance(const char *s, int64_t cnt) { + php_assert(cnt >= 0); + int64_t i = 0; for (i = 0; s[i] && cnt >= 0; i++) { - if ((((unsigned char)s[i]) & 0xc0) != 0x80) { + if (((static_cast(s[i])) & 0xc0) != 0x80) { cnt--; } } @@ -78,20 +70,23 @@ static int64_t mb_UTF8_advance(const char *s, int64_t cnt) { return i; } -static int64_t mb_UTF8_get_offset(const char *s, int64_t pos) { +int64_t mb_UTF8_get_offset(const char *s, int64_t pos) { int64_t res = 0; for (int64_t i = 0; i < pos && s[i]; i++) { - if ((((unsigned char)s[i]) & 0xc0) != 0x80) { + if (((static_cast(s[i])) & 0xc0) != 0x80) { res++; } } return res; } -bool mb_UTF8_check(const char *s) { +bool mb_UTF8_check(const char *s) noexcept { do { -#define CHECK(condition) if (!(condition)) {return false;} - unsigned int a = (unsigned char)(*s++); +#define CHECK(condition) \ + if (!(condition)) { \ + return false; \ + } + unsigned int a = static_cast(*s++); if ((a & 0x80) == 0) { if (a == 0) { return true; @@ -99,28 +94,28 @@ bool mb_UTF8_check(const char *s) { continue; } - CHECK ((a & 0x40) != 0); + CHECK((a & 0x40) != 0); - unsigned int b = (unsigned char)(*s++); + unsigned int b = static_cast(*s++); CHECK((b & 0xc0) == 0x80); if ((a & 0x20) == 0) { CHECK((a & 0x1e) > 0); continue; } - unsigned int c = (unsigned char)(*s++); + unsigned int c = static_cast(*s++); CHECK((c & 0xc0) == 0x80); if ((a & 0x10) == 0) { int x = (((a & 0x0f) << 6) | (b & 0x20)); - CHECK(x != 0 && x != 0x360);//surrogates + CHECK(x != 0 && x != 0x360); // surrogates continue; } - unsigned int d = (unsigned char)(*s++); + unsigned int d = static_cast(*s++); CHECK((d & 0xc0) == 0x80); if ((a & 0x08) == 0) { int t = (((a & 0x07) << 6) | (b & 0x30)); - CHECK(0 < t && t < 0x110);//end of unicode + CHECK(0 < t && t < 0x110); // end of unicode continue; } @@ -128,13 +123,13 @@ bool mb_UTF8_check(const char *s) { #undef CHECK } while (true); - php_assert (0); + php_assert(0); } -bool f$mb_check_encoding(const string &str, const string &encoding) { +bool f$mb_check_encoding(const string &str, const string &encoding) noexcept { int encoding_num = mb_detect_encoding(encoding); if (encoding_num < 0) { - php_critical_error ("encoding \"%s\" doesn't supported in mb_check_encoding", encoding.c_str()); + php_critical_error("encoding \"%s\" doesn't supported in mb_check_encoding", encoding.c_str()); return !str.empty(); } @@ -145,11 +140,10 @@ bool f$mb_check_encoding(const string &str, const string &encoding) { return mb_UTF8_check(str.c_str()); } - -int64_t f$mb_strlen(const string &str, const string &encoding) { +int64_t f$mb_strlen(const string &str, const string &encoding) noexcept { int encoding_num = mb_detect_encoding(encoding); if (encoding_num < 0) { - php_critical_error ("encoding \"%s\" doesn't supported in mb_strlen", encoding.c_str()); + php_critical_error("encoding \"%s\" doesn't supported in mb_strlen", encoding.c_str()); return str.size(); } @@ -160,11 +154,10 @@ int64_t f$mb_strlen(const string &str, const string &encoding) { return mb_UTF8_strlen(str.c_str()); } - -string f$mb_strtolower(const string &str, const string &encoding) { +string f$mb_strtolower(const string &str, const string &encoding) noexcept { int encoding_num = mb_detect_encoding(encoding); if (encoding_num < 0) { - php_critical_error ("encoding \"%s\" doesn't supported in mb_strtolower", encoding.c_str()); + php_critical_error("encoding \"%s\" doesn't supported in mb_strtolower", encoding.c_str()); return str; } @@ -172,26 +165,26 @@ string f$mb_strtolower(const string &str, const string &encoding) { if (encoding_num == 1251) { string res(len, false); for (int i = 0; i < len; i++) { - switch ((unsigned char)str[i]) { + switch (static_cast(str[i])) { case 'A' ... 'Z': - res[i] = (char)(str[i] + 'a' - 'A'); + res[i] = static_cast(str[i] + 'a' - 'A'); break; case 0xC0 ... 0xDF: - res[i] = (char)(str[i] + 32); + res[i] = static_cast(str[i] + 32); break; case 0x81: - res[i] = (char)0x83; + res[i] = static_cast(0x83); break; case 0xA3: - res[i] = (char)0xBC; + res[i] = static_cast(0xBC); break; case 0xA5: - res[i] = (char)0xB4; + res[i] = static_cast(0xB4); break; case 0xA1: case 0xB2: case 0xBD: - res[i] = (char)(str[i] + 1); + res[i] = static_cast(str[i] + 1); break; case 0x80: case 0x8A: @@ -199,7 +192,7 @@ string f$mb_strtolower(const string &str, const string &encoding) { case 0xA8: case 0xAA: case 0xAF: - res[i] = (char)(str[i] + 16); + res[i] = static_cast(str[i] + 16); break; default: res[i] = str[i]; @@ -211,8 +204,8 @@ string f$mb_strtolower(const string &str, const string &encoding) { string res(len * 3, false); const char *s = str.c_str(); int res_len = 0; - int p; - int ch; + int p = 0; + int ch = 0; while ((p = get_char_utf8(&ch, s)) > 0) { s += p; res_len += put_char_utf8(unicode_tolower(ch), &res[res_len]); @@ -226,10 +219,10 @@ string f$mb_strtolower(const string &str, const string &encoding) { } } -string f$mb_strtoupper(const string &str, const string &encoding) { +string f$mb_strtoupper(const string &str, const string &encoding) noexcept { int encoding_num = mb_detect_encoding(encoding); if (encoding_num < 0) { - php_critical_error ("encoding \"%s\" doesn't supported in mb_strtoupper", encoding.c_str()); + php_critical_error("encoding \"%s\" doesn't supported in mb_strtoupper", encoding.c_str()); return str; } @@ -237,26 +230,26 @@ string f$mb_strtoupper(const string &str, const string &encoding) { if (encoding_num == 1251) { string res(len, false); for (int i = 0; i < len; i++) { - switch ((unsigned char)str[i]) { + switch (static_cast(str[i])) { case 'a' ... 'z': - res[i] = (char)(str[i] + 'A' - 'a'); + res[i] = static_cast(str[i] + 'A' - 'a'); break; case 0xE0 ... 0xFF: - res[i] = (char)(str[i] - 32); + res[i] = static_cast(str[i] - 32); break; case 0x83: - res[i] = (char)(0x81); + res[i] = static_cast(0x81); break; case 0xBC: - res[i] = (char)(0xA3); + res[i] = static_cast(0xA3); break; case 0xB4: - res[i] = (char)(0xA5); + res[i] = static_cast(0xA5); break; case 0xA2: case 0xB3: case 0xBE: - res[i] = (char)(str[i] - 1); + res[i] = static_cast(str[i] - 1); break; case 0x98: case 0xA0: @@ -269,7 +262,7 @@ string f$mb_strtoupper(const string &str, const string &encoding) { case 0xB8: case 0xBA: case 0xBF: - res[i] = (char)(str[i] - 16); + res[i] = static_cast(str[i] - 16); break; default: res[i] = str[i]; @@ -281,8 +274,8 @@ string f$mb_strtoupper(const string &str, const string &encoding) { string res(len * 3, false); const char *s = str.c_str(); int res_len = 0; - int p; - int ch; + int p = 0; + int ch = 0; while ((p = get_char_utf8(&ch, s)) > 0) { s += p; res_len += put_char_utf8(unicode_toupper(ch), &res[res_len]); @@ -310,7 +303,7 @@ int check_strpos_agrs(const char *func_name, const string &needle, int64_t offse const int encoding_num = mb_detect_encoding(encoding); if (unlikely(encoding_num < 0)) { - php_critical_error ("encoding \"%s\" doesn't supported in %s()", encoding.c_str(), func_name); + php_critical_error("encoding \"%s\" doesn't supported in %s()", encoding.c_str(), func_name); return 0; } return encoding_num; @@ -345,14 +338,14 @@ Optional f$mb_stripos(const string &haystack, const string &needle, int return false; } -string f$mb_substr(const string &str, int64_t start, const mixed &length_var, const string &encoding) { +string f$mb_substr(const string &str, int64_t start, const mixed &length_var, const string &encoding) noexcept { int encoding_num = mb_detect_encoding(encoding); if (encoding_num < 0) { - php_critical_error ("encoding \"%s\" doesn't supported in mb_substr", encoding.c_str()); + php_critical_error("encoding \"%s\" doesn't supported in mb_substr", encoding.c_str()); return str; } - int64_t length; + int64_t length = 0; if (length_var.is_null()) { length = std::numeric_limits::max(); } else { diff --git a/runtime/mbstring.h b/runtime-common/stdlib/string/mbstring-functions.h similarity index 66% rename from runtime/mbstring.h rename to runtime-common/stdlib/string/mbstring-functions.h index bcb101b933..374422f8f7 100644 --- a/runtime/mbstring.h +++ b/runtime-common/stdlib/string/mbstring-functions.h @@ -4,21 +4,20 @@ #pragma once -#include #include #include "runtime-common/core/runtime-core.h" #include "runtime-common/stdlib/string/string-context.h" -bool mb_UTF8_check(const char *s); +bool mb_UTF8_check(const char *s) noexcept; -bool f$mb_check_encoding(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR); +bool f$mb_check_encoding(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; -int64_t f$mb_strlen(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR); +int64_t f$mb_strlen(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; -string f$mb_strtolower(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR); +string f$mb_strtolower(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; -string f$mb_strtoupper(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR); +string f$mb_strtoupper(const string &str, const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; Optional f$mb_strpos(const string &haystack, const string &needle, int64_t offset = 0, const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; @@ -27,8 +26,12 @@ Optional f$mb_stripos(const string &haystack, const string &needle, int const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; string f$mb_substr(const string &str, int64_t start, const mixed &length = std::numeric_limits::max(), - const string &encoding = StringLibConstants::get().CP1251_STR); + const string &encoding = StringLibConstants::get().CP1251_STR) noexcept; -void f$set_detect_incorrect_encoding_names_warning(bool show); +inline void f$set_detect_incorrect_encoding_names_warning(bool show) noexcept { + StringLibContext::get().detect_incorrect_encoding_names = show; +} -void free_detect_incorrect_encoding_names(); +inline void free_detect_incorrect_encoding_names() noexcept { + StringLibContext::get().detect_incorrect_encoding_names = false; +} diff --git a/runtime-common/stdlib/string/string-context.h b/runtime-common/stdlib/string/string-context.h index e9aca0fbf3..3b0884cbed 100644 --- a/runtime-common/stdlib/string/string-context.h +++ b/runtime-common/stdlib/string/string-context.h @@ -39,6 +39,9 @@ class StringLibContext final : vk::not_copyable { int64_t str_replace_count_dummy{}; double default_similar_text_percent_stub{}; + // mb_string context + bool detect_incorrect_encoding_names{}; + static StringLibContext &get() noexcept; }; diff --git a/runtime-light/runtime-light.cmake b/runtime-light/runtime-light.cmake index 1adeb09944..6be762940d 100644 --- a/runtime-light/runtime-light.cmake +++ b/runtime-light/runtime-light.cmake @@ -33,14 +33,14 @@ vk_add_library(runtime-light OBJECT ${RUNTIME_LIGHT_SRC}) set_property(TARGET runtime-light PROPERTY POSITION_INDEPENDENT_CODE ON) set_target_properties(runtime-light PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${BASE_DIR}/objs) -target_compile_options(runtime-light PUBLIC -stdlib=libc++) +target_compile_options(runtime-light PUBLIC -stdlib=libc++ -iquote + ${GENERATED_DIR} -fPIC) target_link_options(runtime-light PUBLIC -stdlib=libc++ -static-libstdc++) -target_compile_options(runtime-light PUBLIC -fPIC) vk_add_library(kphp-light-runtime STATIC) target_link_libraries( - kphp-light-runtime PUBLIC vk::light_common vk::runtime-light - vk::runtime-common) + kphp-light-runtime PUBLIC vk::light_common vk::light_unicode + vk::runtime-light vk::runtime-common) set_target_properties(kphp-light-runtime PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${OBJS_DIR}) diff --git a/runtime/regexp.h b/runtime/regexp.h index 1dd8fe8307..50b5aa9dc6 100644 --- a/runtime/regexp.h +++ b/runtime/regexp.h @@ -11,7 +11,7 @@ #include "runtime-common/core/runtime-core.h" #include "runtime/context/runtime-context.h" #include "runtime/kphp_tracing.h" -#include "runtime/mbstring.h" +#include "runtime-common/stdlib/string/mbstring-functions.h" namespace re2 { class RE2; diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index f0acdc1f4e..da3018eedd 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -93,7 +93,6 @@ prepend(KPHP_RUNTIME_SOURCES ${BASE_DIR}/runtime/ kphp_tracing_binlog.cpp mail.cpp math_functions.cpp - mbstring.cpp memcache.cpp memory_usage.cpp misc.cpp