Commit graph

87 commits

Author SHA1 Message Date
Marc Durdin
0cc6901085
Merge branch 'fix/core/10605-app-context-copy-strip-markers' into fix/core/10615-10616-10617-core-surrogates-and-app-context-markers-and-memory-leak 2024-02-07 12:33:33 +11:00
Marc Durdin
c807415563
chore: Apply suggestions from code review
Co-authored-by: Steven R. Loomis <srl295@gmail.com>
2024-02-07 12:20:56 +11:00
Marc Durdin
9ba919c2a9 fix(core): surrogate handling, markers in app context, and memory leak
Fixes #10615 (surrogate handling, km_core_state_context_set_if_needed).
Fixes #10616 (markers in app context, in unit tests)
Fixes #10617 (memory leak in replace_context).

The surrogate handling and markers in app context bugs were quite
tangled, so opted to fix those both together in one commit. The memory
leak was spotted while verifying the changes for surrogate handling.

Surrogates were not handled in is_context_unchanged, and opted to
refactor to work directly with km_core_context_item arrays rather than
continue with the string-based comparison, for simplicity.

While writing the corresponding unit tests, realised that the
app_context checks were incorrect in a number of existing tests, and so
fixed up the existing tests at the same time as writing up the new
tests. The only changes to core for this were to add assertions for the
app_context to ensure that markers are not inadvertently added.
2024-02-03 09:16:16 +07:00
Marc Durdin
9e50f50687 fix(core): strip markers in actions_update_app_context_nfu()
Fixes #10605.
2024-02-02 15:10:05 +07:00
Marc Durdin
aad7c0a42b chore(core): fixup typos 2024-02-01 15:05:24 +07:00
Marc Durdin
1b88ab99be fix(core): make km_core_state_get_actions() idempotent
Fixes #10582.

Returned struct from the `km_core_state_get_actions()` API is now owned
by the state object. This is a change in API contract. The corresponding
`km_core_actions_dispose()` API has been made private, because there is
never any need for API consumers to call it. As this change is happening
in alpha, we won't bump the ABI version.

`state->app_context` is now guaranteed to be in sync with
`state->context` after `km_core_process_event()`, with the actions
struct populated at that point.

The next and final step in this refactor is to remove the actions queue
altogether from the Core and make that a kmn-only concept, but that will
wait until 18.0. The only consumers of the actions queue are the
kmn-specific interactive debugger in Keyman Developer, and kmn-specific
Input Method eXtensions in Keyman Engine for Windows.
2024-02-01 11:28:08 +07:00
Marc Durdin
4c95fef55a
Merge pull request #10533 from keymanapp/feat/core/10530-actions-deleted-context
feat(core): add `deleted_context` to `km_core_actions` struct 🌱
2024-01-30 11:46:10 +11:00
Eberhard Beilharz
2ebca107e0
chore(core): Fix build failures 2024-01-29 12:17:27 +01:00
Eberhard Beilharz
5404c02315
chore(core): Merge remote-tracking branch 'origin/epic/core/9999-normalization' into fix/core/10100-ContextNuances
# Conflicts:
#	core/tests/unit/kmnkbd/state_context_api.cpp
2024-01-29 12:05:17 +01:00
Marc Durdin
8501f2aa6d feat(core): add deleted_context to km_core_actions struct
Fixes #10530.

Adds the deleted_context member to the km_core_actions struct, and
associated unit tests. Simplifies integration by providing the consumer
with all the data they need in order to execute the transform,
specifically around number of delete operations required, without
needing to query the target application context again. The number of
delete operations will vary according to application compliance and
selected encoding; for example a UTF-16 string may require 2
delete-backs for surrogate pairs in the text buffer for a compliant app,
whereas there will be a single delete-back key event for a non-compliant
app.

The deleted_context member should also be used for debug assertions.
2024-01-29 13:21:25 +07:00
Marc Durdin
41cc2f4d1e feat(developer): make context_get and context_length public again
Rolls back the privatisation of the km_core_context_get and
km_core_context_length APIs because the debugger uses them.
2024-01-26 06:37:09 +07:00
Marc Durdin
c5e9a8ce35
Merge branch 'refactor/developer/10214-debugger-app-context' into feat/developer/10416-10458-ldml-debugger-markers 2024-01-26 09:50:06 +11:00
Marc Durdin
4906545e31
Merge branch 'epic/core/9999-normalization' into refactor/core/10431-remove-unused-core-context-apis 2024-01-24 12:14:11 +11:00
Marc Durdin
fa39ae0b22 chore(core): fixup types on unit test 2024-01-23 13:12:47 +07:00
Marc Durdin
39b64be67a refactor(developer): use km_core_state_get_actions for LDML keyboard debugger
Relates to #10416.

Moves from using action queue to action struct for the LDML keyboard
debugger. Does not do the same for the KMX keyboard debugger, because
that relies on action items to do single-step debugging.
2024-01-23 12:42:27 +07:00
Steven R. Loomis
aecf4e4552
Update core/tests/unit/kmnkbd/test_actions_normalize.cpp
Co-authored-by: Marc Durdin <marc@durdin.net>
2024-01-22 16:47:28 -06:00
Steven R. Loomis
ac315661ed feat(core): ldml actions: include what you use 🌱
- missed an include

For: #10410
2024-01-19 13:45:12 -06:00
Steven R. Loomis
04a6e164d7 feat(core): ldml actions: updates per code review 🌱
- fix backspace processing
- fix k_102 - we can no longer test for context invalidation here
- fix a test that assumed non-const km_core_actions.output

For: #10410
2024-01-19 11:24:41 -06:00
Eberhard Beilharz
a4c940418f
fix(core): Fix nuances when updating context
Fixes #10100.
2024-01-19 15:56:40 +01:00
Marc Durdin
a26e21aba7 chore(core): address review comments 2024-01-19 08:01:45 +07:00
Marc Durdin
83f80c061a refactor(core): remove unused context APIs
Fixes #10431.

The `km_core_` prefix has been removed from internal-only functions, and
these function declarations moved to context.hpp.

The functions have not been moved from km_core_context_api.cpp at this
stage.

Rewrote the function documentation in Javadoc style comments for the
internal use functions.
2024-01-18 12:18:07 +07:00
Marc Durdin
8b3c247520 chore(core): add surrogate pair tests to test_actions_normalize
Fixes #10424.
2024-01-18 09:48:29 +07:00
Marc Durdin
b3261b8dc4 refactor(core): move context helpers to a new module
Fixes #10423.
2024-01-18 09:26:58 +07:00
Marc Durdin
823120b0c4 chore(core): simplify input assumptions for actions_normalize
Per discussion in #10422, we can assume that input cached_context is
always NFD. However input actions->output may not start at a
normalization boundary, so we still need to backtrack to a normalization
boundary in order to get our NFC output. But cached_context never need
change.

This makes no change to the algorithm, but tweaks some of the unit tests
to adhere to this input assumption.

Note: we could consider adding a debug assertion that cached_context is
NFD.
2024-01-18 08:25:15 +07:00
Marc Durdin
39f081391e chore(core): dedup set_context_from_string 2024-01-17 13:05:11 +07:00
Marc Durdin
7218f93ca9 chore(core): test typos 2024-01-17 12:07:38 +07:00
Marc Durdin
e6096a267c feat(core): action output normalization
Fixes #9999.

Note TODO items:
- [ ] Renormalize cached_context across action boundary. Blocked by #10369.
- [ ] Add extra tests for surrogate pairs
- [ ] Move set_context_from_string into helper module
- [ ] if we don't apply normalization, we still need to fixup the
      app_context, to keep it coherent with cached_context (or at least
      we need to verify that app_context is never used in this
      situation)
2024-01-17 10:41:00 +07:00
Marc Durdin
e39affe93b feat(core): infrastructure for normalization of output
Relates to #9999.

Establishes functions, unit test sources, normalization entry point and
an effectively no-op unit test for normalization support.
2024-01-16 13:46:46 +07:00
Marc Durdin
e5c2525241 refactor(core): split context API from Core primary API
Relates to #9999.
Fixes #10384.

The context API endpoints should no longer be considered as part of the
standard Core API. The only consumers that have a need to access these
APIs are the IMX integration in Engine for Windows, and the Keyman
Developer Debugger.

These symbols are currently used by Developer:
* `km_core_context` struct
* `km_core_context_type` enum
* `km_core_context_item` struct
* `KM_CORE_CONTEXT_ITEM_END` macro
* `km_core_state_context()`
* `km_core_context_set()`
* `km_core_context_clear()`

These symbols are currently used by Windows IMX:
* `km_core_context` struct
* `km_core_context_type` enum
* `km_core_context_item` struct
* `KM_CORE_CONTEXT_ITEM_END` macro
* `km_core_context_items_dispose()`
* `km_core_context_item_list_size()`
* `km_core_state_get_intermediate_context()`

The following functions and symbols are moving to
keyman_core_api_context.h:
* `km_core_context` struct
* `km_core_context_type` enum
* `km_core_context_item` struct
* `KM_CORE_CONTEXT_ITEM_END` macro
* `km_core_state_context()` function
* `km_core_state_get_intermediate_context()` function
* `km_core_context_set()` function
* `km_core_context_clear()` function
* `km_core_context_get()` function
* `km_core_context_items_from_utf16()` function
* `km_core_context_items_from_utf8()` function
* `km_core_context_items_to_utf8()` function
* `km_core_context_items_to_utf16()` function
* `km_core_context_items_to_utf32()` function
* `km_core_context_items_dispose()` function
* `km_core_context_length()` function
* `km_core_context_append()` function
* `km_core_context_shrink()` function
* `km_core_context_item_list_size()` function
2024-01-16 12:04:41 +07:00
Marc Durdin
8abab53988 chore(core): Merge branch 'feat/core/10365-context-debug' into feat/core/9999-normalization-of-context
Note: shifted minor changes from action_api.cpp to new
state_context_api.cpp.
2024-01-16 06:16:45 +07:00
Marc Durdin
ba3290de75 chore(core): Merge branch 'master' into feat/core/10365-context-debug
Note: resolved merge conflict with action_api.cpp by shifting new code
into state_context_api.cpp.
2024-01-16 05:46:36 +07:00
Marc Durdin
bd46fb271b feat(core): unit tests need to set both app context and cached context 2024-01-15 12:34:00 +07:00
Marc Durdin
bfb26eaf64 feat(core): adds km_core_state_context_debug
Fixes #10365.

Adds a `km_core_state_context_debug` function that returns a km_core_cp
string containing the current cached or intermediate context. The
function must be used only for debug logging purposes -- the string is
not intended to parsed for other purposes and the format may change in
the future.

This commit adds the function and corresponding unit tests. Subsequent
commits will update existing context debug functions in various engines
to use this API endpoint instead.
2024-01-15 07:19:31 +07:00
Eberhard Beilharz
141b85814e
refactor(core): Move km_core_state_context_* tests to separate file
It was fairly surprising to have the unit tests for
`km_core_state_context_*` methods in `action_api.cpp`, so this change
moves them to a separate file.
2024-01-12 15:34:32 +01:00
Marc Durdin
802f22578a chore(core): address review comments 2023-12-04 13:37:59 +07:00
Marc Durdin
b6daac0bdb feat(core): action struct to action items conversion
Adds state->set_actions(). This sets the Core's action list to match the
contents of the action struct. Note that markers are not supported and
backspace expected_values will be empty, as this information is not
available. As the intended consumer of the action struct does not need
to know this information, this should be adequate.
2023-12-01 12:27:49 +07:00
rc-swag
6820f36f7d fix(core): set_if_needed updates a empty cached context
In the case when the cached context had been cleared the
km_core_state_context_set_if_needed call would just compare
the null terminations of both strings and not set the cached
context to the application context.
2023-11-30 13:09:22 +10:00
Marc Durdin
7ec4832edc fix(core): memory management of options in action struct
Fixes #10067.

Management of memory for persisted options was wrong in the action
struct, as the members key and value would be freed immediately after
being added to the temporary vector (because the vector was of the
struct rather than of the class).

Given the struct is a C struct, we need the memory management to be
explicit, so we now release() each option into the vector as we create
it, which means that its member values will not be freed when the option
is then immediately deleted. (This allows us to use the initial copy of
the members of option that option() constructor does.)

Added the release() function as that was a relatively clear way of
indicating that the contents of the structure are now owned by the
caller, following the pattern from std::unique_ptr.

Finally, the unit test for persisted options was in the action_api.cpp
test module, but it was never called, so this was not being tested. Now
it is.
2023-11-24 07:52:31 +10:00
Marc Durdin
8475b68248 feat(core): make persist_options always point to a valid array 2023-10-25 05:46:43 +07:00
Marc Durdin
8223792404 chore(core): rename kbp to core 2023-10-25 05:30:22 +07:00
Marc Durdin
82177013e9 chore(core): Merge branch 'master' into feat/core/9720-actions-apis 2023-10-24 20:55:10 +07:00
Marc Durdin
40ca1d1ed8 chore(core): address review comments 2023-10-24 20:53:44 +07:00
Marc Durdin
69e92f312a chore(core): rename to code_points_to_delete 2023-10-24 13:46:52 +07:00
Marc Durdin
cd428ae412 feat(core): address review comments
* Renamed various functions and types
* Clarified return values
* Updated doc comments
2023-10-24 12:22:34 +07:00
Marc Durdin
0aa86501c6 chore(core): fix types and compile errors
Fixes #9832. Addresses a couple of other cross-platform compile issues.
2023-10-24 09:25:08 +07:00
Marc Durdin
61330ba06d feat(core): new actions APIs
Fixes #9720.

Note: this will deprecate a number of Keyman Core APIs -- pretty much
all existing action and context APIs. Deprecation marks will come in a
follow-up commit.
2023-10-23 15:01:55 +07:00
Eberhard Beilharz
604fbc1a75
chore(linux): Rename namespace kbp to core 2023-10-19 10:39:55 +02:00
Eberhard Beilharz
52bb859817
chore(linux): Rename (lib)kmnkbp to (lib)keymancore 2023-10-19 10:35:09 +02:00
Eberhard Beilharz
2f073f7778
chore(linux): Rename KMN_CORE to KM_CORE_LIBRARY 2023-10-19 08:51:29 +02:00
Eberhard Beilharz
b5c6f31b05
chore(linux): Rename KBP to CORE 2023-10-18 15:48:21 +02:00