diff --git a/builtin-functions/kphp-light/stdlib/vkext-functions.txt b/builtin-functions/kphp-light/stdlib/vkext-functions.txt index b18580fd41..18a68e6f0c 100644 --- a/builtin-functions/kphp-light/stdlib/vkext-functions.txt +++ b/builtin-functions/kphp-light/stdlib/vkext-functions.txt @@ -1,7 +1,5 @@ ) add_dependencies(flex_data_shared-pic flex-data-src-pic) diff --git a/runtime-common/stdlib/vkext/vkext-functions.cpp b/runtime-common/stdlib/vkext/vkext-functions.cpp index f339532df3..24058f467d 100644 --- a/runtime-common/stdlib/vkext/vkext-functions.cpp +++ b/runtime-common/stdlib/vkext/vkext-functions.cpp @@ -6,6 +6,11 @@ #include #include +#include "flex/flex.h" + +#include "runtime-common/core/utils/kphp-assert-core.h" +#include "runtime-common/stdlib/string/string-context.h" + namespace { constexpr std::array utf8_to_win_convert_0x400 = { @@ -458,3 +463,19 @@ string f$vk_whitespace_pack(const string& str, bool html_opt) noexcept { } return buffered.result; } + +string f$vk_flex(const string& name, const string& case_name, int64_t sex, const string& type, int64_t lang_id) noexcept { + constexpr size_t ERROR_MSG_BUG_SIZE{1000}; + std::array error_msg_buffer{'\0'}; + + auto* static_buffer{StringLibContext::get().static_buf.get()}; + std::string_view res = flex(std::string_view{name.c_str(), name.size()}, std::string_view{case_name.c_str(), case_name.size()}, sex == 1, + std::string_view{type.c_str(), type.size()}, lang_id, static_buffer, error_msg_buffer.data(), ERROR_MSG_BUG_SIZE); + if (error_msg_buffer[0] != '\0') { + php_warning("%s", error_msg_buffer.data()); + } + if (res.data() == name.c_str()) { + return name; + } + return string{res.data(), static_cast(res.size())}; +} diff --git a/runtime-common/stdlib/vkext/vkext-functions.h b/runtime-common/stdlib/vkext/vkext-functions.h index 81265ced6e..2c39c87d3a 100644 --- a/runtime-common/stdlib/vkext/vkext-functions.h +++ b/runtime-common/stdlib/vkext/vkext-functions.h @@ -50,3 +50,5 @@ inline string f$vk_sp_to_cyrillic(const string& s) noexcept { inline string f$vk_sp_words_only(const string& s) noexcept { return vkext_impl_::sp_words_only(s); } + +string f$vk_flex(const string& name, const string& case_name, int64_t sex, const string& type, int64_t lang_id = 0) noexcept; diff --git a/runtime-light/runtime-light.cmake b/runtime-light/runtime-light.cmake index 3cc64e6e03..0ea0cfa0dc 100644 --- a/runtime-light/runtime-light.cmake +++ b/runtime-light/runtime-light.cmake @@ -64,7 +64,7 @@ set(RUNTIME_LIGHT_LINK_LIBS "${KPHP_TIMELIB_PIC_LIBRARIES} ${PCRE2_PIC_LIBRARIES vk_add_library_pic(kphp-light-runtime-pic STATIC) target_compile_options(kphp-light-runtime-pic PUBLIC ${RUNTIME_LIGHT_COMPILE_FLAGS}) target_link_options(kphp-light-runtime-pic PUBLIC ${RUNTIME_LIGHT_LINK_FLAGS}) -target_link_libraries(kphp-light-runtime-pic PUBLIC vk::pic::light-common vk::pic::unicode vk::pic::runtime-light vk::pic::runtime-common) +target_link_libraries(kphp-light-runtime-pic PUBLIC vk::pic::flex-data-src vk::pic::light-common vk::pic::unicode vk::pic::runtime-light vk::pic::runtime-common) set_target_properties(kphp-light-runtime-pic PROPERTIES LIBRARY_OUTPUT_NAME libkphp-light-runtime.a) diff --git a/runtime/misc.cpp b/runtime/misc.cpp index 11bae7501d..82f7c64510 100644 --- a/runtime/misc.cpp +++ b/runtime/misc.cpp @@ -12,6 +12,7 @@ #include #include "runtime-common/stdlib/serialization/json-functions.h" +#include "runtime-common/stdlib/vkext/vkext-functions.h" #include "runtime/context/runtime-context.h" #include "runtime/critical_section.h" #include "runtime/datetime/datetime_functions.h" @@ -20,7 +21,6 @@ #include "runtime/interface.h" #include "runtime/math_functions.h" #include "runtime/string_functions.h" -#include "runtime/vkext.h" #include "server/json-logger.h" #include "server/php-engine-vars.h" diff --git a/runtime/runtime.cmake b/runtime/runtime.cmake index 9c161d5864..1525041cc9 100644 --- a/runtime/runtime.cmake +++ b/runtime/runtime.cmake @@ -116,7 +116,6 @@ prepend(KPHP_RUNTIME_SOURCES ${BASE_DIR}/runtime/ uber-h3.cpp udp.cpp tcp.cpp - vkext.cpp ffi.cpp zlib.cpp zstd.cpp) diff --git a/runtime/vkext.cpp b/runtime/vkext.cpp deleted file mode 100644 index 9771e1edd1..0000000000 --- a/runtime/vkext.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2020 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#include "runtime/vkext.h" - -#include "common/wrappers/string_view.h" -#include "flex/flex.h" -#include "runtime/php_assert.h" - -#define BUFF_LEN (1 << 16) -static char buff[BUFF_LEN]; - -string f$vk_flex(const string& name, const string& case_name, int64_t sex, const string& type, int64_t lang_id) noexcept { - constexpr size_t ERROR_MSG_BUG_SIZE = 1000; - static char ERROR_MSG_BUF[ERROR_MSG_BUG_SIZE] = {'\0'}; - ERROR_MSG_BUF[0] = '\0'; - vk::string_view res = flex(vk::string_view{name.c_str(), name.size()}, vk::string_view{case_name.c_str(), case_name.size()}, sex == 1, - vk::string_view{type.c_str(), type.size()}, lang_id, buff, ERROR_MSG_BUF, ERROR_MSG_BUG_SIZE); - if (ERROR_MSG_BUF[0] != '\0') { - php_warning("%s", ERROR_MSG_BUF); - } - if (res.data() == name.c_str()) { - return name; - } - return string{res.data(), static_cast(res.size())}; -} diff --git a/runtime/vkext.h b/runtime/vkext.h deleted file mode 100644 index f33a9ae344..0000000000 --- a/runtime/vkext.h +++ /dev/null @@ -1,11 +0,0 @@ -// Compiler for PHP (aka KPHP) -// Copyright (c) 2020 LLC «V Kontakte» -// Distributed under the GPL v3 License, see LICENSE.notice.txt - -#pragma once - -#include "runtime-common/core/runtime-core.h" - -#include "runtime-common/stdlib/vkext/vkext-functions.h" - -string f$vk_flex(const string& name, const string& case_name, int64_t sex, const string& type, int64_t lang_id = 0) noexcept; diff --git a/tests/cpp/runtime/flex-test.cpp b/tests/cpp/runtime/flex-test.cpp index f3e88cb55a..46122b490d 100644 --- a/tests/cpp/runtime/flex-test.cpp +++ b/tests/cpp/runtime/flex-test.cpp @@ -3,7 +3,7 @@ #include #include -#include "runtime/vkext.h" +#include "runtime-common/stdlib/vkext/vkext-functions.h" using casing_table = std::array; diff --git a/tests/phpt/dl/474_flex.php b/tests/phpt/dl/474_flex.php index ce61cef0e9..e1e26791df 100644 --- a/tests/phpt/dl/474_flex.php +++ b/tests/phpt/dl/474_flex.php @@ -1,4 +1,4 @@ -@ok k2_skip benchmark +@ok benchmark