Skip to content

Commit

Permalink
changed the output of the encodings for mb_functions to the correct…
Browse files Browse the repository at this point in the history
… function (#1204)
  • Loading branch information
Danil42Russia authored Jan 28, 2025
1 parent c9d8417 commit 7d80b66
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 41 deletions.
2 changes: 0 additions & 2 deletions builtin-functions/kphp-full/kphp_toggles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

function set_migration_php8_warning ($mask ::: int) ::: void;

function set_detect_incorrect_encoding_names_warning(bool $show) ::: void;

function set_json_log_on_timeout_mode(bool $enabled) ::: void;

function set_json_log_demangle_stacktrace(bool $enable) ::: void;
Expand Down
2 changes: 0 additions & 2 deletions builtin-functions/kphp-light/kphp-toggles.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

function set_detect_incorrect_encoding_names_warning(bool $show) ::: void;

/** @kphp-extern-func-info generate-stub */
function kphp_turn_on_host_tag_in_inner_statshouse_metrics_toggle() ::: void;

Expand Down
26 changes: 1 addition & 25 deletions runtime-common/stdlib/string/mbstring-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@

#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"

int mb_detect_encoding_new(const string &encoding) noexcept {
int mb_detect_encoding(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")) {
Expand All @@ -23,29 +22,6 @@ int mb_detect_encoding_new(const string &encoding) noexcept {
return -1;
}

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 (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 (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 (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;
}

int64_t mb_UTF8_strlen(const char *s) {
int64_t res = 0;
for (int64_t i = 0; s[i]; i++) {
Expand Down
8 changes: 0 additions & 8 deletions runtime-common/stdlib/string/mbstring-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,3 @@ Optional<int64_t> f$mb_stripos(const string &haystack, const string &needle, int

string f$mb_substr(const string &str, int64_t start, const mixed &length = std::numeric_limits<int64_t>::max(),
const string &encoding = StringLibConstants::get().CP1251_STR) noexcept;

inline void f$set_detect_incorrect_encoding_names_warning(bool show) noexcept {
StringLibContext::get().detect_incorrect_encoding_names = show;
}

inline void free_detect_incorrect_encoding_names() noexcept {
StringLibContext::get().detect_incorrect_encoding_names = false;
}
3 changes: 0 additions & 3 deletions runtime-common/stdlib/string/string-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ 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;
};

Expand Down
1 change: 0 additions & 1 deletion runtime/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,6 @@ static void free_runtime_libs() {
free_kphp_backtrace();

free_use_updated_gmmktime();
free_detect_incorrect_encoding_names();

vk::singleton<JsonLogger>::get().reset_buffers();
#ifdef PDO_DRIVER_MYSQL
Expand Down

0 comments on commit 7d80b66

Please sign in to comment.