Skip to content

Commit

Permalink
Make loading of libs thread safe, fixes babashka/babashka#1482
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Feb 6, 2023
1 parent ee5211c commit f6b42a7
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ SCI is used in [babashka](https://github.com/babashka/babashka),
- Improve top level macro expansion error location
- Fix pprinting vars
- Add `reader-conditional` to core vars
- Fix [#babashka/1482](https://github.com/babashka/babashka/issues/1482): make loading of libs thread safe

## 0.6.37 (2022-12-20)

13 changes: 11 additions & 2 deletions src/sci/impl/load.cljc
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@
(defn handle-require-libspec
[ctx lib opts]
(let [env* (:env ctx)
env @env* ;; NOTE: loading namespaces is not (yet) thread-safe
env @env*
cnn (utils/current-ns-name)
lib (get (:ns-aliases env) lib lib)]
(if-let [as-alias (:as-alias opts)]
@@ -146,7 +146,7 @@
(add-loaded-lib env* lib)
nil))))

(defn load-lib [ctx prefix lib & options]
(defn load-lib* [ctx prefix lib options]
(when (and prefix (pos? (.indexOf (name lib) #?(:clj (int \.)
:cljs \.))))
(throw-error-with-location (str "Found lib name '" (name lib) "' containing period with prefix '"
@@ -156,6 +156,15 @@
opts (apply hash-map options)]
(handle-require-libspec ctx lib opts)))

#?(:clj
(let [load-lock (Object.)]
(defn load-lib [ctx prefix lib & options]
(locking load-lock
(load-lib* ctx prefix lib options))))
:cljs
(defn load-lib [ctx prefix lib & options]
(load-lib* ctx prefix lib options)))

(defn- prependss
"Prepends a symbol or a seq to coll"
[x coll]

0 comments on commit f6b42a7

Please sign in to comment.