Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fcitx
Browse files Browse the repository at this point in the history
  • Loading branch information
Fcitx Bot committed Aug 13, 2024
2 parents 5f1b9eb + aefa8a9 commit 039bd7b
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 77 deletions.
14 changes: 6 additions & 8 deletions src/base/crash_report_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ google_breakpad::ExceptionHandler *g_handler = nullptr;

// Returns the name of the build mode.
std::wstring GetBuildMode() {
#if defined(MOZC_NO_LOGGING)
#if defined(NDEBUG)
return L"rel";
#elif defined(DEBUG)
#else // NDEBUG
return L"dbg";
#else // Other than MOZC_NO_LOGGING or DEBUG
return L"opt";
#endif // MOZC_NO_LOGGING, DEBUG
#endif // NDEBUG
}

// Reduces the size of the string |str| to a max of 64 chars (Extra 1 char is
Expand Down Expand Up @@ -231,11 +229,11 @@ bool FilterHandler(void *context, EXCEPTION_POINTERS *exinfo,
MDRawAssertionInfo *assertion) {
if (exinfo == nullptr) {
// We do not catch CRT error in release build.
#ifdef MOZC_NO_LOGGING
#ifdef NDEBUG
return false;
#else // MOZC_NO_LOGGING
#else // NDEBUG
return true;
#endif // MOZC_NO_LOGGING
#endif // NDEBUG
}

// Make sure it's our module which cause the crash.
Expand Down
4 changes: 2 additions & 2 deletions src/base/log_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class LogFileSink : public absl::LogSink {
} // namespace

void RegisterLogFileSink(const std::string &path) {
#if !defined(MOZC_NO_LOGGING) && !defined(__ANDROID__)
#if !defined(NDEBUG) && !defined(__ANDROID__)
absl::InitializeLog();
absl::AddLogSink(new LogFileSink(path));
#endif // !MOZC_NO_LOGGING && !__ANDROID__
#endif // !NDEBUG && !__ANDROID__
}

} // namespace mozc
2 changes: 1 addition & 1 deletion src/base/log_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace mozc {

// Registers an `absl::LogSink` tied to a file at `path`.
//
// This function becomes no-op when MOZC_NO_LOGGING or __ANDROID__ is defined.
// This function becomes no-op when NDEBUG or __ANDROID__ is defined.
void RegisterLogFileSink(const std::string &path);

} // namespace mozc
Expand Down
1 change: 1 addition & 0 deletions src/base/win32/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ mozc_cc_library(
"//base:util",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/types:span",
],
)

Expand Down
14 changes: 8 additions & 6 deletions src/base/win32/win_api_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@
#include <windows.h>
#include <winnt.h>

#include <cstddef>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <type_traits>
#include <vector>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/types/span.h"
#include "base/util.h"

namespace mozc {
Expand Down Expand Up @@ -98,7 +101,7 @@ class ThunkRewriter {
class HookTargetInfo {
public:
explicit HookTargetInfo(
const std::vector<WinAPITestHelper::HookRequest> &requests) {
absl::Span<const WinAPITestHelper::HookRequest> requests) {
for (size_t i = 0; i < requests.size(); ++i) {
const auto &request = requests[i];
HMODULE module_handle = nullptr;
Expand All @@ -123,14 +126,14 @@ class HookTargetInfo {
}
}

const bool IsTargetModule(const std::string &module_name) const {
bool IsTargetModule(const std::string &module_name) const {
std::string lower_module_name(module_name);
Util::LowerString(&lower_module_name);
return info_.find(lower_module_name) != info_.end();
}

const FunctionPointer GetNewProc(const std::string &module_name,
FunctionPointer original_proc) const {
FunctionPointer GetNewProc(const std::string &module_name,
FunctionPointer original_proc) const {
std::string lower_module_name(module_name);
Util::LowerString(&lower_module_name);
const auto module_iterator = info_.find(lower_module_name);
Expand Down Expand Up @@ -285,8 +288,7 @@ WinAPITestHelper::HookRequest::HookRequest(const std::string &src_module,

// static
WinAPITestHelper::RestoreInfoHandle WinAPITestHelper::DoHook(
HMODULE target_module,
const std::vector<WinAPITestHelper::HookRequest> &requests) {
HMODULE target_module, absl::Span<const HookRequest> requests) {
const HookTargetInfo target_info(requests);

// Following code skips some data validations as this code is only used in
Expand Down
8 changes: 4 additions & 4 deletions src/base/win32/win_api_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include <windows.h>

#include <string>
#include <vector>

#include "absl/types/span.h"

namespace mozc {

Expand Down Expand Up @@ -102,12 +102,12 @@ class WinAPITestHelper {
// Since this code is designed to be used in unit test, this method
// causes critical failure and stops execution when something fails.
static RestoreInfoHandle DoHook(HMODULE target_module,
const std::vector<HookRequest> &requests);
absl::Span<const HookRequest> requests);

// Restores the API hooks. |backup_info| cannot be used after this method
// Restores the API hooks. |restore_info| cannot be used after this method
// is called.
// Note: This method is not thread-safe.
static void RestoreHook(RestoreInfoHandle backup_info);
static void RestoreHook(RestoreInfoHandle restore_info);
};

#define DEFINE_HOOK(module_name, original_proc, new_proc) \
Expand Down
4 changes: 2 additions & 2 deletions src/base/win32/winmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int WinMainToMain(int argc, char *argv[]);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
{
// Load debug_sleep_time from registry.
// With this parameter, developer can inject a debugger
Expand All @@ -119,7 +119,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
::RegCloseKey(hKey);
}
}
#endif // !MOZC_NO_LOGGING
#endif // !NDEBUG

mozc::WinCommandLine cmd;
int argc = cmd.argc();
Expand Down
4 changes: 2 additions & 2 deletions src/config/config_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ const Config &ConfigHandlerImpl::DefaultConfig() const {
void ConfigHandlerImpl::SetConfigInternal(Config config) {
config_ = std::move(config);

#ifdef MOZC_NO_LOGGING
#ifdef NDEBUG
// Delete the optional field from the config.
config_.clear_verbose_level();
// Fall back if the default value is not the expected value.
if (config_.verbose_level() != 0) {
config_.set_verbose_level(0);
}
#endif // MOZC_NO_LOGGING
#endif // NDEBUG

mozc::internal::SetConfigVLogLevel(config_.verbose_level());

Expand Down
12 changes: 6 additions & 6 deletions src/config/config_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ TEST_F(ConfigHandlerTest, SetConfig) {

ConfigHandler::GetDefaultConfig(&input);
input.set_incognito_mode(true);
#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
input.set_verbose_level(2);
#endif // MOZC_NO_LOGGING
#endif // NDEBUG
ConfigHandler::SetMetaData(&input);
ConfigHandler::SetConfig(input);
output.Clear();
Expand All @@ -99,9 +99,9 @@ TEST_F(ConfigHandlerTest, SetConfig) {

ConfigHandler::GetDefaultConfig(&input);
input.set_incognito_mode(false);
#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
input.set_verbose_level(0);
#endif // MOZC_NO_LOGGING
#endif // NDEBUG
ConfigHandler::SetMetaData(&input);
ConfigHandler::SetConfig(input);
output.Clear();
Expand Down Expand Up @@ -172,9 +172,9 @@ TEST_F(ConfigHandlerTest, SetConfig_IdentityCheck) {

ConfigHandler::GetDefaultConfig(&input);
input.set_incognito_mode(true);
#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
input.set_verbose_level(2);
#endif // MOZC_NO_LOGGING
#endif // NDEBUG

ClockMock clock1(absl::FromUnixSeconds(1000));

Expand Down
13 changes: 7 additions & 6 deletions src/dictionary/gen_aux_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import sys


class Entry():
class Entry:
"""Class for an entry in the dictionary."""

def __init__(self, key: str, value: str, lid: str, rid: str, cost: int):
Expand All @@ -64,7 +64,7 @@ def Parse(cls, line: str) -> 'Entry':
return Entry(key, value, lid, rid, int(cost))


class EntryList():
class EntryList:
"""Class for a list of entries."""

def __init__(self):
Expand All @@ -88,7 +88,7 @@ def AtRatio(self, ratio: float) -> Entry:
return self.entries[index]


class PosIds():
class PosIds:
"""Class for pos ids."""

def __init__(self):
Expand Down Expand Up @@ -128,7 +128,7 @@ def GetId(self, pos_name: str) -> str:
return self.ids.get(pos_name, '')


class Dictionary():
class Dictionary:
"""Class for dictionary0*.txt."""

def __init__(self):
Expand Down Expand Up @@ -171,7 +171,7 @@ def GetCost(self, pos_id: str, ratio: float) -> int:
return self.pos_entry_map[pos_key].AtRatio(ratio).cost


class AuxDictionary():
class AuxDictionary:
"""Class for aux_dictionary.tsv."""

def __init__(self, dictionary):
Expand Down Expand Up @@ -213,7 +213,7 @@ def WriteFile(self, output):
file.write('\t'.join(aux_entry) + '\n')


class WordsDictionary():
class WordsDictionary:
"""Class for words.tsv."""

def __init__(self, dictionary, aux):
Expand Down Expand Up @@ -278,5 +278,6 @@ def main():
words.Parse(words_tsv, args.id_def)
words.WriteFile(args.output)


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions src/gui/config_dialog/config_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ ConfigDialog::ConfigDialog()
miscStartupWidget->setVisible(false);
#endif // __linux__

#ifdef MOZC_NO_LOGGING
#ifdef NDEBUG
// disable logging options
miscLoggingWidget->setVisible(false);

Expand All @@ -119,7 +119,7 @@ ConfigDialog::ConfigDialog()
constexpr int kMiscTabIndex = 6;
configDialogTabWidget->removeTab(kMiscTabIndex);
#endif // __linux__
#endif // MOZC_NO_LOGGING
#endif // NDEBUG

suggestionsSizeSpinBox->setRange(1, 9);

Expand Down
4 changes: 2 additions & 2 deletions src/gui/config_dialog/keybinding_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ KeyBindingFilter::KeyState KeyBindingFilter::Encode(QString *result) const {
}

// in release binary, unknown_key_ is hidden
#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
if (!unknown_key_.isEmpty()) {
results << unknown_key_;
}
#endif // MOZC_NO_LOGGING
#endif // NDEBUG

KeyBindingFilter::KeyState result_state = KeyBindingFilter::ACCEPT_KEY;

Expand Down
4 changes: 2 additions & 2 deletions src/gui/config_dialog/keymap_editor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ class KeyMapValidator {
return false;
}

#ifdef MOZC_NO_LOGGING
#ifdef NDEBUG
if (fields[2] == kReportBugCommand) {
return false;
}
#endif // MOZC_NO_LOGGING
#endif // NDEBUG
return true;
}

Expand Down
1 change: 0 additions & 1 deletion src/gyp/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
'defines': [
'NDEBUG',
'QT_NO_DEBUG',
'MOZC_NO_LOGGING',
'ABSL_MIN_LOG_LEVEL=100',
'IGNORE_HELP_FLAG',
'IGNORE_INVALID_FLAG'
Expand Down
1 change: 0 additions & 1 deletion src/gyp/common_win.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
'defines': [
'NDEBUG',
'QT_NO_DEBUG',
'MOZC_NO_LOGGING',
'ABSL_MIN_LOG_LEVEL=100',
'IGNORE_HELP_FLAG',
'IGNORE_INVALID_FLAG'
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/qt/qt_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ QtServer::QtServer() : timeout_(0) {
timeout_ = 1000 * std::clamp(absl::GetFlag(FLAGS_timeout), 3, 24 * 60 * 60);
MOZC_VLOG(2) << "timeout is set to be : " << timeout_;

#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
config::Config config;
config::ConfigHandler::GetConfig(&config);
mozc::internal::SetConfigVLogLevel(config.verbose_level());
#endif // MOZC_NO_LOGGING
#endif // NDEBUG
}

QtServer::~QtServer() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/renderer_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ RendererServer::RendererServer()
timeout_ = 1000 * std::clamp(absl::GetFlag(FLAGS_timeout), 3, 24 * 60 * 60);
MOZC_VLOG(2) << "timeout is set to be : " << timeout_;

#ifndef MOZC_NO_LOGGING
#ifndef NDEBUG
config::Config config;
config::ConfigHandler::GetConfig(&config);
mozc::internal::SetConfigVLogLevel(config.verbose_level());
#endif // MOZC_NO_LOGGING
#endif // NDEBUG
}

RendererServer::~RendererServer() = default;
Expand Down
Loading

0 comments on commit 039bd7b

Please sign in to comment.