From b5b1747b0d29978144673ef43333fdb1159625b8 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 27 Nov 2024 08:56:50 +0700 Subject: [PATCH 1/2] refactor(developer): `km_core_keyboard_load_from_blob` in debugger Replaces `km_core_keyboard_load` with `km_core_keyboard_load_from_blob`. Fixes: #12690 --- .../debug/Keyman.System.Debug.DebugCore.pas | 23 ++++++++++++++++++- .../tike/main/Keyman.System.KeymanCore.pas | 6 +++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas b/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas index bcc522e28c6..8af691be941 100644 --- a/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas +++ b/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas @@ -37,6 +37,8 @@ TDebugCore = class implementation uses + System.Classes, + KeymanPaths; { TDebugCore } @@ -44,6 +46,9 @@ implementation constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean); var status: km_core_status; + fs: TFileStream; + Buffer: Pointer; + BufferSize: NativeInt; begin inherited Create; @@ -52,7 +57,23 @@ constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean); FKeyboard := nil; FState := nil; - status := km_core_keyboard_load(PChar(FileName), FKeyboard); + buffer := nil; + try + fs := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite); + try + BufferSize := fs.Size; + Buffer := AllocMem(BufferSize); + if fs.Read(Buffer^, BufferSize) <> BufferSize then + raise EDebugCore.Create('Unable to start debugger -- failed to read file from disk'); + finally + fs.Free; + end; + + status := km_core_keyboard_load_from_blob(PChar(FileName), Buffer, BufferSize, FKeyboard); + finally + FreeMem(Buffer); + end; + if status <> KM_CORE_STATUS_OK then raise EDebugCore.CreateFmt('Unable to start debugger -- keyboard load failed with error %x', [Ord(status)]); diff --git a/developer/src/tike/main/Keyman.System.KeymanCore.pas b/developer/src/tike/main/Keyman.System.KeymanCore.pas index 96f9219b379..22c4ac49430 100644 --- a/developer/src/tike/main/Keyman.System.KeymanCore.pas +++ b/developer/src/tike/main/Keyman.System.KeymanCore.pas @@ -245,8 +245,10 @@ km_core_keyboard_attrs = record pkm_core_keyboard_attrs = ^km_core_keyboard_attrs; -function km_core_keyboard_load( - kb_path: km_core_path_name; +function km_core_keyboard_load_from_blob( + kb_name: km_core_path_name; + blob: Pointer; + blob_size: NativeUint; var keyboard: pkm_core_keyboard ): km_core_status; cdecl; external keymancore delayed; From 73dc549023e795f297b4cca5cf3863ab3b907509 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 27 Nov 2024 03:58:19 +0100 Subject: [PATCH 2/2] chore: Update developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas Co-authored-by: Darcy Wong --- developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas b/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas index 8af691be941..884eea627b1 100644 --- a/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas +++ b/developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas @@ -57,7 +57,7 @@ constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean); FKeyboard := nil; FState := nil; - buffer := nil; + Buffer := nil; try fs := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite); try