Skip to content

Commit

Permalink
refactor(developer): km_core_keyboard_load_from_blob in debugger
Browse files Browse the repository at this point in the history
Replaces `km_core_keyboard_load` with `km_core_keyboard_load_from_blob`.

Fixes: #12690
  • Loading branch information
mcdurdin committed Nov 27, 2024
1 parent 63b83bd commit b5b1747
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 22 additions & 1 deletion developer/src/tike/debug/Keyman.System.Debug.DebugCore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ TDebugCore = class
implementation

uses
System.Classes,

KeymanPaths;

{ TDebugCore }

constructor TDebugCore.Create(const Filename: string; EnableDebug: Boolean);
var
status: km_core_status;
fs: TFileStream;
Buffer: Pointer;
BufferSize: NativeInt;
begin
inherited Create;

Expand All @@ -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)]);

Expand Down
6 changes: 4 additions & 2 deletions developer/src/tike/main/Keyman.System.KeymanCore.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b5b1747

Please sign in to comment.