From 895fb2f53ed26c71c8944e1f68a45a3f70ce63ae Mon Sep 17 00:00:00 2001 From: Jaskirat Rajasansir Date: Tue, 31 Oct 2023 17:27:20 +0000 Subject: [PATCH] require: Ensure 'libForce' behaves the same as 'lib' if library not loaded / inited - Change dictionary param from 'force' to 'reinit' - .require.i.init: Add validation of 'reinit' parameter vs init state --- src/require.q | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/require.q b/src/require.q index b6e0a96..7e48763 100644 --- a/src/require.q +++ b/src/require.q @@ -91,13 +91,15 @@ / @see .require.i.load / @see .require.i.init .require.libForce:{[lib] - if[lib in key .require.loadedLibs; - libInfo:.require.loadedLibs lib; + libInfo:.require.loadedLibs lib; + + operations:lib,/:libInfo`loaded`inited; + if[libInfo`loaded; .log.if.info ("Force reloading library [ Library: {} ] [ Already Loaded: {} ] [ Already Initialised: {} ]"; lib; `no`yes libInfo`loaded; `no`yes libInfo`inited); ]; - .require.i[`load`init] .\: (lib; 1b); + .require.i[`load`init] .' operations; }; .require.rescanRoot:{ @@ -164,14 +166,19 @@ / .*lib*.*stack*.init[] and executes if exists (if not present, ignored). / @throws UnknownLibraryException If the library is not loaded / @throws LibraryInitFailedException If the init function throws an exception -.require.i.init:{[lib; force] +/ @throws RequireReinitialiseAssertionError If 'reinit' is set to false, but the library is already initialised - this should not happen +.require.i.init:{[lib; reinit] if[not lib in key .require.loadedLibs; '"UnknownLibraryException"; ]; + if[not[reinit] & .require.loadedLibs[lib]`inited; + '"RequireReinitialiseAssertionError"; + ]; + initFname:` sv `,lib,`init; initF:@[get;initFname;`NO_INIT_FUNC]; - initArgs:enlist[`force]!enlist force; + initArgs:enlist[`reinit]!enlist reinit; if[not `NO_INIT_FUNC~initF; .log.if.info "Library initialisation function detected [ Func: ",string[initFname]," ]"; @@ -188,7 +195,7 @@ '"LibraryInitFailedException (",string[initFname],")"; ]; - .require.markLibAsInited[lib; force]; + .require.markLibAsInited[lib; reinit]; .log.if.info "Initialised library: ",string lib; ];