From 4c3b2132eefd0e3d5cde444802d31d97c2a22baa Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 4 Dec 2024 13:38:07 +0700 Subject: [PATCH] chore(core): remove `km_core_keyboard_load` API Fixes: #12497 --- core/docs/api/background.md | 2 +- core/docs/api/index.md | 2 +- core/docs/api/keyboards.md | 27 +++--- core/docs/api/options.md | 2 +- core/docs/api/processor.md | 2 +- core/docs/api/state.md | 2 +- core/include/keyman/keyman_core_api.h | 54 +---------- core/src/km_core_keyboard_api.cpp | 90 ++----------------- .../tests/unit/km_core_keyboard_api.tests.cpp | 40 +++------ core/tests/unit/ldml/core_ldml_min.tests.cpp | 2 +- linux/debian/libkeymancore2.symbols | 1 - linux/debian/tests/test-build | 4 +- windows/src/engine/keyman32/K32_load.cpp | 2 +- .../keyboardoptionstests.cpp | 2 +- 14 files changed, 44 insertions(+), 188 deletions(-) diff --git a/core/docs/api/background.md b/core/docs/api/background.md index b0d09da10f7..d4c638f0ce7 100644 --- a/core/docs/api/background.md +++ b/core/docs/api/background.md @@ -396,7 +396,7 @@ typedef enum { KM_CORE_FALSE = 0, KM_CORE_TRUE = 1 } km_core_bool; [km_core_keyboard_attrs]: keyboards#km_core_keyboard_attrs "km_core_keyboard_attrs struct" [km_core_keyboard_key]: keyboards#km_core_keyboard_key "km_core_keyboard_key struct" [km_core_keyboard_imx]: keyboards#km_core_keyboard_imx "km_core_keyboard_imx struct" -[km_core_keyboard_load]: keyboards#km_core_keyboard_load "km_core_keyboard_load function" +[km_core_keyboard_load_from_blob]: keyboards#km_core_keyboard_load_from_blob "km_core_keyboard_load_from_blob function" [km_core_keyboard_dispose]: keyboards#km_core_keyboard_dispose "km_core_keyboard_dispose function" [km_core_keyboard_get_attrs]: keyboards#km_core_keyboard_get_attrs "km_core_keyboard_get_attrs function" [km_core_keyboard_get_key_list]: keyboards#km_core_keyboard_get_key_list "km_core_keyboard_get_key_list function" diff --git a/core/docs/api/index.md b/core/docs/api/index.md index 8112d9c8793..f005ad3981d 100644 --- a/core/docs/api/index.md +++ b/core/docs/api/index.md @@ -103,7 +103,7 @@ Caps Lock. [km_core_keyboard_attrs]: keyboards#km_core_keyboard_attrs "km_core_keyboard_attrs struct" [km_core_keyboard_key]: keyboards#km_core_keyboard_key "km_core_keyboard_key struct" [km_core_keyboard_imx]: keyboards#km_core_keyboard_imx "km_core_keyboard_imx struct" -[km_core_keyboard_load]: keyboards#km_core_keyboard_load "km_core_keyboard_load function" +[km_core_keyboard_load_from_blob]: keyboards#km_core_keyboard_load_from_blob "km_core_keyboard_load_from_blob function" [km_core_keyboard_dispose]: keyboards#km_core_keyboard_dispose "km_core_keyboard_dispose function" [km_core_keyboard_get_attrs]: keyboards#km_core_keyboard_get_attrs "km_core_keyboard_get_attrs function" [km_core_keyboard_get_key_list]: keyboards#km_core_keyboard_get_key_list "km_core_keyboard_get_key_list function" diff --git a/core/docs/api/keyboards.md b/core/docs/api/keyboards.md index b9312a78d94..6f02b428898 100644 --- a/core/docs/api/keyboards.md +++ b/core/docs/api/keyboards.md @@ -102,28 +102,35 @@ typedef struct { ------------------------------------------------------------------------------- -# km_core_keyboard_load() {#km_core_keyboard_load} +# km_core_keyboard_load_from_blob() {#km_core_keyboard_load_from_blob} ## Description -Parse and load keyboard from the supplied path and a pointer to the loaded keyboard -into the out paramter. +Parse and load keyboard from the supplied blob and size and a pointer to the +loaded keyboard into the out paramter. ## Specification ```c KMN_API km_core_status -km_core_keyboard_load(km_core_path_name kb_path, - km_core_keyboard **keyboard); +km_core_keyboard_load_from_blob(const km_core_path_name kb_name, + const void* blob, + const size_t blob_size, + km_core_keyboard** keyboard); ``` ## Parameters -`kb_path` -: On Windows, a UTF-16 string; on other platforms, a C string: - contains a valid path to the keyboard file. +`kb_name` +: a string with the name of the keyboard. + +`blob` +: a byte array containing the content of a KMX/KMX+ file. + +`blob_size` +: a size_t variable with the size of the blob in bytes. `keyboard` : A pointer to result variable: A pointer to the opaque keyboard @@ -154,7 +161,7 @@ km_core_keyboard_load(km_core_path_name kb_path, ## Description Free the allocated memory belonging to an opaque keyboard object previously -returned by [km_core_keyboard_load]. +returned by [km_core_keyboard_load_from_blob]. ## Specification @@ -637,7 +644,7 @@ km_core_state_to_json(km_core_state const *state, [km_core_keyboard_attrs]: keyboards#km_core_keyboard_attrs "km_core_keyboard_attrs struct" [km_core_keyboard_key]: keyboards#km_core_keyboard_key "km_core_keyboard_key struct" [km_core_keyboard_imx]: keyboards#km_core_keyboard_imx "km_core_keyboard_imx struct" -[km_core_keyboard_load]: keyboards#km_core_keyboard_load "km_core_keyboard_load function" +[km_core_keyboard_load_from_blob]: keyboards#km_core_keyboard_load_from_blob "km_core_keyboard_load_from_blob function" [km_core_keyboard_dispose]: keyboards#km_core_keyboard_dispose "km_core_keyboard_dispose function" [km_core_keyboard_get_attrs]: keyboards#km_core_keyboard_get_attrs "km_core_keyboard_get_attrs function" [km_core_keyboard_get_key_list]: keyboards#km_core_keyboard_get_key_list "km_core_keyboard_get_key_list function" diff --git a/core/docs/api/options.md b/core/docs/api/options.md index e5a171d6fea..41d5fe28c9a 100644 --- a/core/docs/api/options.md +++ b/core/docs/api/options.md @@ -263,7 +263,7 @@ km_core_state_options_to_json(km_core_state const *state, [km_core_keyboard_attrs]: keyboards#km_core_keyboard_attrs "km_core_keyboard_attrs struct" [km_core_keyboard_key]: keyboards#km_core_keyboard_key "km_core_keyboard_key struct" [km_core_keyboard_imx]: keyboards#km_core_keyboard_imx "km_core_keyboard_imx struct" -[km_core_keyboard_load]: keyboards#km_core_keyboard_load "km_core_keyboard_load function" +[km_core_keyboard_load_from_blob]: keyboards#km_core_keyboard_load_from_blob "km_core_keyboard_load_from_blob function" [km_core_keyboard_dispose]: keyboards#km_core_keyboard_dispose "km_core_keyboard_dispose function" [km_core_keyboard_get_attrs]: keyboards#km_core_keyboard_get_attrs "km_core_keyboard_get_attrs function" [km_core_keyboard_get_key_list]: keyboards#km_core_keyboard_get_key_list "km_core_keyboard_get_key_list function" diff --git a/core/docs/api/processor.md b/core/docs/api/processor.md index 0cd491ba81a..c72d743bb9c 100644 --- a/core/docs/api/processor.md +++ b/core/docs/api/processor.md @@ -177,7 +177,7 @@ enum km_core_event_code { [km_core_keyboard_attrs]: keyboards#km_core_keyboard_attrs "km_core_keyboard_attrs struct" [km_core_keyboard_key]: keyboards#km_core_keyboard_key "km_core_keyboard_key struct" [km_core_keyboard_imx]: keyboards#km_core_keyboard_imx "km_core_keyboard_imx struct" -[km_core_keyboard_load]: keyboards#km_core_keyboard_load "km_core_keyboard_load function" +[km_core_keyboard_load_from_blob]: keyboards#km_core_keyboard_load_from_blob "km_core_keyboard_load_from_blob function" [km_core_keyboard_dispose]: keyboards#km_core_keyboard_dispose "km_core_keyboard_dispose function" [km_core_keyboard_get_attrs]: keyboards#km_core_keyboard_get_attrs "km_core_keyboard_get_attrs function" [km_core_keyboard_get_key_list]: keyboards#km_core_keyboard_get_key_list "km_core_keyboard_get_key_list function" diff --git a/core/docs/api/state.md b/core/docs/api/state.md index 3c0c57a6aa5..0292d9f8a59 100644 --- a/core/docs/api/state.md +++ b/core/docs/api/state.md @@ -264,7 +264,7 @@ An opaque pointer to a state object. [km_core_keyboard_attrs]: keyboards#km_core_keyboard_attrs "km_core_keyboard_attrs struct" [km_core_keyboard_key]: keyboards#km_core_keyboard_key "km_core_keyboard_key struct" [km_core_keyboard_imx]: keyboards#km_core_keyboard_imx "km_core_keyboard_imx struct" -[km_core_keyboard_load]: keyboards#km_core_keyboard_load "km_core_keyboard_load function" +[km_core_keyboard_load_from_blob]: keyboards#km_core_keyboard_load_from_blob "km_core_keyboard_load_from_blob function" [km_core_keyboard_dispose]: keyboards#km_core_keyboard_dispose "km_core_keyboard_dispose function" [km_core_keyboard_get_attrs]: keyboards#km_core_keyboard_get_attrs "km_core_keyboard_get_attrs function" [km_core_keyboard_get_key_list]: keyboards#km_core_keyboard_get_key_list "km_core_keyboard_get_key_list function" diff --git a/core/include/keyman/keyman_core_api.h b/core/include/keyman/keyman_core_api.h index 3c41182bab2..7863689296d 100644 --- a/core/include/keyman/keyman_core_api.h +++ b/core/include/keyman/keyman_core_api.h @@ -1096,58 +1096,6 @@ typedef struct { ------------------------------------------------------------------------------- -# km_core_keyboard_load() - -## Description - -DEPRECATED: use [km_core_keyboard_load_from_blob] instead. - -Parse and load keyboard from the supplied path and a pointer to the loaded keyboard -into the out parameter. - -## Specification - -```c */ -// TODO-web-core: Deprecate this function (#12497) -// KMN_DEPRECATED_API -KMN_API -km_core_status -km_core_keyboard_load(km_core_path_name kb_path, - km_core_keyboard **keyboard); - -/* -``` - -## Parameters - -`kb_path` -: On Windows, a UTF-16 string; on other platforms, a C string: - contains a valid path to the keyboard file. - -`keyboard` -: A pointer to result variable: A pointer to the opaque keyboard - object returned by the Processor. This memory must be freed with a - call to [km_core_keyboard_dispose]. - -## Returns - -`KM_CORE_STATUS_OK` -: On success. - -`KM_CORE_STATUS_NO_MEM` -: In the event an internal memory allocation fails. - -`KM_CORE_STATUS_IO_ERROR` -: In the event the keyboard file is unparseable for any reason - -`KM_CORE_STATUS_INVALID_ARGUMENT` -: In the event the file doesn't exist or is inaccesible or `keyboard` is null. - -`KM_CORE_STATUS_OS_ERROR` -: Bit 31 (high bit) set, bits 0-30 are an OS-specific error code. - -------------------------------------------------------------------------------- - # km_core_keyboard_load_from_blob() ## Description @@ -1207,7 +1155,7 @@ km_core_status km_core_keyboard_load_from_blob(const km_core_path_name kb_name, ## Description Free the allocated memory belonging to an opaque keyboard object previously -returned by [km_core_keyboard_load]. +returned by [km_core_keyboard_load_from_blob]. ## Specification diff --git a/core/src/km_core_keyboard_api.cpp b/core/src/km_core_keyboard_api.cpp index abaf3bfaa08..70d37fa63b0 100644 --- a/core/src/km_core_keyboard_api.cpp +++ b/core/src/km_core_keyboard_api.cpp @@ -40,16 +40,18 @@ namespace } // namespace km_core_status -keyboard_load_from_blob_internal( +km_core_keyboard_load_from_blob( const km_core_path_name kb_name, - const std::vector & buf, + const void* blob, + const size_t blob_size, km_core_keyboard** keyboard ) { assert(keyboard); - if (!keyboard) { + if (!keyboard || !blob) { return KM_CORE_STATUS_INVALID_ARGUMENT; } + std::vector buf((uint8_t*)blob, (uint8_t*)blob + blob_size); *keyboard = nullptr; try { abstract_processor* kp = processor_factory(kb_name, buf); @@ -65,88 +67,6 @@ keyboard_load_from_blob_internal( return KM_CORE_STATUS_OK; } -km_core_status -km_core_keyboard_load_from_blob( - const km_core_path_name kb_name, - const void* blob, - const size_t blob_size, - km_core_keyboard** keyboard -) { - assert(keyboard); - if (!keyboard || !blob) { - return KM_CORE_STATUS_INVALID_ARGUMENT; - } - - std::vector buf((uint8_t*)blob, (uint8_t*)blob + blob_size); - return keyboard_load_from_blob_internal(kb_name, buf, keyboard); -} - -// TODO-web-core: Remove this code when we remove the deprecated km_core_keyboard_load method -// BEGIN DEPRECATED -#include -std::vector load_kmx_file(path const& kb_path) { - std::vector data; - std::ifstream file(static_cast(kb_path), std::ios::binary | std::ios::ate); - if (!file.good()) { - return std::vector(); - } - const std::streamsize size = file.tellg(); - if (size >= KMX_MAX_ALLOWED_FILE_SIZE) { - return std::vector(); - } - - file.seekg(0, std::ios::beg); - - data.resize((size_t)size); - if (!file.read((char*)data.data(), size)) { - return std::vector(); - } - - file.close(); - return data; -} - -KMN_DEPRECATED_API -km_core_status -km_core_keyboard_load(km_core_path_name kb, km_core_keyboard **keyboard) -{ - assert(keyboard); - if (!keyboard || !kb) { - return KM_CORE_STATUS_INVALID_ARGUMENT; - } - - path const kb_path(kb); - try - { - abstract_processor* kp = nullptr; - km_core_status status = KM_CORE_STATUS_OK; - // Some legacy packages may include upper-case file extensions - if (kb_path.suffix() == ".kmx" || kb_path.suffix() == ".KMX") { - std::vector buf = load_kmx_file(kb_path); - status = keyboard_load_from_blob_internal(kb_path.stem().c_str(), buf, (km_core_keyboard**)&kp); - if (status != KM_CORE_STATUS_OK) { - return status; - } - } else if (kb_path.suffix() == ".mock") { - kp = new mock_processor(kb_path); - } else { - kp = new null_processor(); - } - status = kp->validate(); - if (status != KM_CORE_STATUS_OK) { - delete kp; - return status; - } - *keyboard = static_cast(kp); - } - catch (std::bad_alloc &) - { - return KM_CORE_STATUS_NO_MEM; - } - return KM_CORE_STATUS_OK; -} -// END DEPRECATED - void km_core_keyboard_dispose(km_core_keyboard *keyboard) { diff --git a/core/tests/unit/km_core_keyboard_api.tests.cpp b/core/tests/unit/km_core_keyboard_api.tests.cpp index 184ec130c42..fb9ea32818d 100644 --- a/core/tests/unit/km_core_keyboard_api.tests.cpp +++ b/core/tests/unit/km_core_keyboard_api.tests.cpp @@ -10,19 +10,17 @@ km::core::path test_dir; -// TODO-web-core: Remove this code when we remove the deprecated km_core_keyboard_load method -// BEGIN DEPRECATED -#if defined(__GNUC__) || defined(__clang__) -#define PRAGMA(X) _Pragma(#X) -#define DISABLE_WARNING_PUSH PRAGMA(GCC diagnostic push) -#define DISABLE_WARNING_POP PRAGMA(GCC diagnostic pop) -#define DISABLE_WARNING(W) PRAGMA(GCC diagnostic ignored #W) -#define DISABLE_WARNING_DEPRECATED_DECLARATIONS DISABLE_WARNING(-Wdeprecated-declarations) -#else -#define DISABLE_WARNING_PUSH -#define DISABLE_WARNING_POP -#define DISABLE_WARNING_DEPRECATED_DECLARATIONS -#endif +// #if defined(__GNUC__) || defined(__clang__) +// #define PRAGMA(X) _Pragma(#X) +// #define DISABLE_WARNING_PUSH PRAGMA(GCC diagnostic push) +// #define DISABLE_WARNING_POP PRAGMA(GCC diagnostic pop) +// #define DISABLE_WARNING(W) PRAGMA(GCC diagnostic ignored #W) +// #define DISABLE_WARNING_DEPRECATED_DECLARATIONS DISABLE_WARNING(-Wdeprecated-declarations) +// #else +// #define DISABLE_WARNING_PUSH +// #define DISABLE_WARNING_POP +// #define DISABLE_WARNING_DEPRECATED_DECLARATIONS +// #endif class KmCoreKeyboardApiTests : public testing::Test { protected: @@ -35,22 +33,6 @@ class KmCoreKeyboardApiTests : public testing::Test { } }; -TEST_F(KmCoreKeyboardApiTests, LoadFromFile) { - // Setup - km::core::path kmxfile = km::core::path(test_dir / "kmx/k_020___deadkeys_and_backspace.kmx"); - - // Execute - DISABLE_WARNING_PUSH - DISABLE_WARNING_DEPRECATED_DECLARATIONS - auto status = km_core_keyboard_load(kmxfile.c_str(), &this->keyboard); - DISABLE_WARNING_POP - - // Verify - EXPECT_EQ(status, KM_CORE_STATUS_OK); - EXPECT_TRUE(this->keyboard != nullptr); -} -// END DEPRECATED - TEST_F(KmCoreKeyboardApiTests, LoadFromBlob) { // Setup km::core::path kmxfile = km::core::path(test_dir / "kmx/k_020___deadkeys_and_backspace.kmx"); diff --git a/core/tests/unit/ldml/core_ldml_min.tests.cpp b/core/tests/unit/ldml/core_ldml_min.tests.cpp index fadd62a2a45..9657b104b51 100644 --- a/core/tests/unit/ldml/core_ldml_min.tests.cpp +++ b/core/tests/unit/ldml/core_ldml_min.tests.cpp @@ -26,7 +26,7 @@ int main(int argc, const char *argv[]) { auto blob = km::tests::load_kmx_file(nowhere); status = km_core_keyboard_load_from_blob(nowhere, blob.data(), blob.size(), &test_kb); - std::cerr << "null km_core_keyboard_load = " << status << std::endl; + std::cerr << "null km_core_keyboard_load_from_blob = " << status << std::endl; test_assert(status == KM_CORE_STATUS_INVALID_ARGUMENT); test_assert(test_kb == nullptr); km_core_keyboard_dispose(test_kb); diff --git a/linux/debian/libkeymancore2.symbols b/linux/debian/libkeymancore2.symbols index 968f155551b..5ecfeb58a28 100644 --- a/linux/debian/libkeymancore2.symbols +++ b/linux/debian/libkeymancore2.symbols @@ -18,7 +18,6 @@ libkeymancore.so.2 libkeymancore2 #MINVER# km_core_keyboard_get_key_list@Base 17.0.195 km_core_keyboard_imx_list_dispose@Base 17.0.195 km_core_keyboard_key_list_dispose@Base 17.0.195 - km_core_keyboard_load@Base 17.0.195 km_core_keyboard_load_from_blob@Base 18.0.101 km_core_options_list_size@Base 17.0.195 km_core_process_event@Base 17.0.195 diff --git a/linux/debian/tests/test-build b/linux/debian/tests/test-build index 9a48325793c..45186784abe 100755 --- a/linux/debian/tests/test-build +++ b/linux/debian/tests/test-build @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { km_core_option_item opts[] = {KM_CORE_OPTIONS_END}; km_core_keyboard *kb = NULL; km_core_state *state = NULL; - km_core_keyboard_load(NULL, &kb); + km_core_keyboard_load_from_blob(NULL, NULL, 0, &kb); km_core_state_create(kb, opts, &state); km_core_actions const *a = km_core_state_get_actions(state); } @@ -62,7 +62,7 @@ echo "build 3: OK" # km_core_option_item opts[] = {KM_CORE_OPTIONS_END}; # km_core_keyboard *kb = NULL; # km_core_state *state = NULL; -# km_core_keyboard_load(NULL, &kb); +# km_core_keyboard_load_from_blob(NULL, NULL, 0, &kb); # km_core_state_create(kb, opts, &state); # km_core_actions const *a = km_core_state_get_actions(state); # } diff --git a/windows/src/engine/keyman32/K32_load.cpp b/windows/src/engine/keyman32/K32_load.cpp index 6ad3fc90b2a..a1a927ab6fa 100644 --- a/windows/src/engine/keyman32/K32_load.cpp +++ b/windows/src/engine/keyman32/K32_load.cpp @@ -127,7 +127,7 @@ BOOL LoadlpKeyboard(int i) free(buffer); if (err_status != KM_CORE_STATUS_OK) { - SendDebugMessageFormat("km_core_keyboard_load failed for %ls with error status [%d]", keyboardPath, err_status); + SendDebugMessageFormat("km_core_keyboard_load_from_blob failed for %ls with error status [%d]", keyboardPath, err_status); goto ExitError; } delete[] keyboardPath; diff --git a/windows/src/engine/keyman32/tests/keyman-engine-tests/keyboardoptionstests.cpp b/windows/src/engine/keyman32/tests/keyman-engine-tests/keyboardoptionstests.cpp index 282ee48ac63..ad9799724a0 100644 --- a/windows/src/engine/keyman32/tests/keyman-engine-tests/keyboardoptionstests.cpp +++ b/windows/src/engine/keyman32/tests/keyman-engine-tests/keyboardoptionstests.cpp @@ -16,7 +16,7 @@ TEST(KEYBOARDOPTIONS, SetupCoreEnvironment) { km_core_path_name dummyPath = L"dummyActions.mock"; EXPECT_EQ(SetupCoreEnvironment(&core_env_opts), TRUE); - EXPECT_EQ(km_core_keyboard_load(dummyPath, &kp->lpCoreKeyboard), KM_CORE_STATUS_OK); + EXPECT_EQ(km_core_keyboard_load_from_blob(dummyPath, (void *)"MOCK", 4, &kp->lpCoreKeyboard), KM_CORE_STATUS_OK); EXPECT_EQ(km_core_state_create(kp->lpCoreKeyboard, core_env_opts, &kp->lpCoreKeyboardState), KM_CORE_STATUS_OK); km_core_option_item *expected_items = new km_core_option_item[5];