Skip to content

Commit

Permalink
require: Ensure 'libForce' behaves the same as 'lib' if library not l…
Browse files Browse the repository at this point in the history
…oaded / inited

 - Change dictionary param from 'force' to 'reinit'
 - .require.i.init: Add validation of 'reinit' parameter vs init state
  • Loading branch information
jasraj committed Oct 31, 2023
1 parent 6f56708 commit 895fb2f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/require.q
Original file line number Diff line number Diff line change
Expand Up @@ -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:{
Expand Down Expand Up @@ -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]," ]";
Expand All @@ -188,7 +195,7 @@
'"LibraryInitFailedException (",string[initFname],")";
];

.require.markLibAsInited[lib; force];
.require.markLibAsInited[lib; reinit];

.log.if.info "Initialised library: ",string lib;
];
Expand Down

0 comments on commit 895fb2f

Please sign in to comment.