Skip to content

Commit 895fb2f

Browse files
committed
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
1 parent 6f56708 commit 895fb2f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/require.q

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@
9191
/ @see .require.i.load
9292
/ @see .require.i.init
9393
.require.libForce:{[lib]
94-
if[lib in key .require.loadedLibs;
95-
libInfo:.require.loadedLibs lib;
94+
libInfo:.require.loadedLibs lib;
95+
96+
operations:lib,/:libInfo`loaded`inited;
9697

98+
if[libInfo`loaded;
9799
.log.if.info ("Force reloading library [ Library: {} ] [ Already Loaded: {} ] [ Already Initialised: {} ]"; lib; `no`yes libInfo`loaded; `no`yes libInfo`inited);
98100
];
99101

100-
.require.i[`load`init] .\: (lib; 1b);
102+
.require.i[`load`init] .' operations;
101103
};
102104

103105
.require.rescanRoot:{
@@ -164,14 +166,19 @@
164166
/ .*lib*.*stack*.init[] and executes if exists (if not present, ignored).
165167
/ @throws UnknownLibraryException If the library is not loaded
166168
/ @throws LibraryInitFailedException If the init function throws an exception
167-
.require.i.init:{[lib; force]
169+
/ @throws RequireReinitialiseAssertionError If 'reinit' is set to false, but the library is already initialised - this should not happen
170+
.require.i.init:{[lib; reinit]
168171
if[not lib in key .require.loadedLibs;
169172
'"UnknownLibraryException";
170173
];
171174

175+
if[not[reinit] & .require.loadedLibs[lib]`inited;
176+
'"RequireReinitialiseAssertionError";
177+
];
178+
172179
initFname:` sv `,lib,`init;
173180
initF:@[get;initFname;`NO_INIT_FUNC];
174-
initArgs:enlist[`force]!enlist force;
181+
initArgs:enlist[`reinit]!enlist reinit;
175182

176183
if[not `NO_INIT_FUNC~initF;
177184
.log.if.info "Library initialisation function detected [ Func: ",string[initFname]," ]";
@@ -188,7 +195,7 @@
188195
'"LibraryInitFailedException (",string[initFname],")";
189196
];
190197

191-
.require.markLibAsInited[lib; force];
198+
.require.markLibAsInited[lib; reinit];
192199

193200
.log.if.info "Initialised library: ",string lib;
194201
];

0 commit comments

Comments
 (0)