Skip to content

Commit d07ef17

Browse files
puredangerstuarthalloway
authored andcommitted
CLJ-2484 Move user.clj initialization out of RT<clinit>
Signed-off-by: Stuart Halloway <[email protected]>
1 parent 578a031 commit d07ef17

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

Diff for: src/jvm/clojure/java/api/Clojure.java

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import clojure.lang.IFn;
1414
import clojure.lang.Symbol;
1515
import clojure.lang.Var;
16+
import clojure.lang.RT;
1617

1718
/**
1819
* <p>The Clojure class provides a minimal interface to bootstrap Clojure access
@@ -93,6 +94,7 @@ public static Object read(String s) {
9394
}
9495

9596
static {
97+
RT.init();
9698
Symbol edn = (Symbol) var("clojure.core", "symbol").invoke("clojure.edn");
9799
var("clojure.core", "require").invoke(edn);
98100
}

Diff for: src/jvm/clojure/lang/Compile.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Compile{
3232
private static final Var unchecked_math = RT.var("clojure.core", "*unchecked-math*");
3333

3434
public static void main(String[] args) throws IOException, ClassNotFoundException{
35-
35+
RT.init();
3636
OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref();
3737
PrintWriter err = RT.errPrintWriter();
3838
String path = System.getProperty(PATH_PROP);

Diff for: src/jvm/clojure/lang/RT.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public Object invoke(Object arg1) {
335335
v.setMeta(map(DOC_KEY, "Sequentially read and evaluate the set of forms contained in the file.",
336336
arglistskw, list(vector(namesym))));
337337
try {
338-
doInit();
338+
load("clojure/core");
339339
}
340340
catch(Exception e) {
341341
throw Util.sneakyThrow(e);
@@ -389,10 +389,6 @@ else if(failIfNotFound) {
389389
}
390390
}
391391

392-
static public void init() {
393-
RT.errPrintWriter().println("No need to call RT.init() anymore");
394-
}
395-
396392
static public long lastModified(URL url, String libfile) throws IOException{
397393
URLConnection connection = url.openConnection();
398394
try {
@@ -467,8 +463,13 @@ else if(!loaded && failIfNotFound)
467463
scriptbase.contains("_") ? " Please check that namespaces with dashes use underscores in the Clojure file name." : ""));
468464
}
469465

470-
static void doInit() throws ClassNotFoundException, IOException{
471-
load("clojure/core");
466+
static public void init() {
467+
doInit();
468+
}
469+
470+
private static boolean INIT = false; // init guard
471+
private synchronized static void doInit() {
472+
if(INIT) {return;} else {INIT=true;}
472473

473474
Var.pushThreadBindings(
474475
RT.mapUniqueKeys(CURRENT_NS, CURRENT_NS.deref(),
@@ -491,6 +492,9 @@ static void doInit() throws ClassNotFoundException, IOException{
491492
Var start_servers = var("clojure.core.server", "start-servers");
492493
start_servers.invoke(System.getProperties());
493494
}
495+
catch(Exception e) {
496+
throw Util.sneakyThrow(e);
497+
}
494498
finally {
495499
Var.popThreadBindings();
496500
}

Diff for: src/jvm/clojure/lang/Util.java

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ static private <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
245245
}
246246

247247
static public Object loadWithClass(String scriptbase, Class<?> loadFrom) throws IOException, ClassNotFoundException{
248+
RT.init();
248249
Var.pushThreadBindings(RT.map(new Object[] { Compiler.LOADER, loadFrom.getClassLoader() }));
249250
try {
250251
return RT.var("clojure.core", "load").invoke(scriptbase);

Diff for: src/jvm/clojure/main.java

+3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ public class main{
2323
final static private Var MAIN = RT.var("clojure.main", "main");
2424

2525
public static void legacy_repl(String[] args) {
26+
RT.init();
2627
REQUIRE.invoke(CLOJURE_MAIN);
2728
LEGACY_REPL.invoke(RT.seq(args));
2829
}
2930

3031
public static void legacy_script(String[] args) {
32+
RT.init();
3133
REQUIRE.invoke(CLOJURE_MAIN);
3234
LEGACY_SCRIPT.invoke(RT.seq(args));
3335
}
3436

3537
public static void main(String[] args) {
38+
RT.init();
3639
REQUIRE.invoke(CLOJURE_MAIN);
3740
MAIN.applyTo(RT.seq(args));
3841
}

0 commit comments

Comments
 (0)