Skip to content

Commit b9d2a03

Browse files
committed
Macro hygiene.
Most of these changes are just paranoia (or "belt and braces" if you want to be more charitable) but it makes sense to be a bit careful.
1 parent 15341b1 commit b9d2a03

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

src/clj_libssh2/error.clj

+3-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@
167167
(but not equal to LIBSSH2_ERROR_EAGAIN). In those cases an exception will be
168168
thrown using maybe-throw-error."
169169
[session & body]
170-
`(let [res# (do ~@body)]
171-
(maybe-throw-error (:session ~session) res#)
170+
`(let [session# ~session
171+
res# (do ~@body)]
172+
(maybe-throw-error (:session session#) res#)
172173
res#))
173174

174175
(defn get-timeout

src/clj_libssh2/session.clj

+5-4
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@
166166
default-opts) plus :hostname, :port and :credentials which
167167
will be passed as the first three arguments to open."
168168
[session session-params & body]
169-
`(let [~session (open (:hostname ~session-params)
170-
(:port ~session-params)
171-
(:credentials ~session-params)
172-
(dissoc ~session-params :hostname :port :credentials))]
169+
`(let [session-params# ~session-params
170+
~session (open (:hostname session-params#)
171+
(:port session-params#)
172+
(:credentials session-params#)
173+
(dissoc session-params# :hostname :port :credentials))]
173174
(try
174175
(do ~@body)
175176
(finally

src/clj_libssh2/socket.clj

+9-7
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,22 @@
9898
(defmacro block
9999
"Turn a non-blocking call that returns EAGAIN into a blocking one."
100100
[session & body]
101-
`(let [start-time# (System/currentTimeMillis)]
101+
`(let [session# ~session
102+
start-time# (System/currentTimeMillis)]
102103
(while (= libssh2/ERROR_EAGAIN (do ~@body))
103-
(handle-errors ~session
104-
(wait ~session start-time#)))))
104+
(handle-errors session#
105+
(wait session# start-time#)))))
105106

106107
(defmacro block-return
107108
"Similar to block, but for functions that return a pointer"
108109
[session & body]
109-
`(let [start-time# (System/currentTimeMillis)]
110+
`(let [session# ~session
111+
start-time# (System/currentTimeMillis)]
110112
(loop [result# (do ~@body)]
111113
(if (nil? result#)
112-
(let [errno# (libssh2-session/last-errno (:session ~session))]
113-
(handle-errors ~session errno#)
114+
(let [errno# (libssh2-session/last-errno (:session session#))]
115+
(handle-errors session# errno#)
114116
(when (= libssh2/ERROR_EAGAIN errno#)
115-
(wait ~session start-time#))
117+
(wait session# start-time#))
116118
(recur (do ~@body)))
117119
result#))))

src/clj_libssh2/ssh.clj

+9-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
describing a potential session (in which case this calls
2626
clj-libssh2.session/with-session to create the session)."
2727
[session session-or-host & body]
28-
`(if (instance? Session ~session-or-host)
29-
(let [~session ~session-or-host]
30-
(do ~@body))
31-
(let [defaults# {:hostname "127.0.0.1"
32-
:port 22
33-
:credentials {:username (System/getProperty "user.name")}}]
34-
(session/with-session ~session (merge defaults# ~session-or-host)
35-
(do ~@body)))))
28+
`(let [session-or-host# ~session-or-host]
29+
(if (instance? Session session-or-host#)
30+
(let [~session session-or-host#]
31+
(do ~@body))
32+
(let [defaults# {:hostname "127.0.0.1"
33+
:port 22
34+
:credentials {:username (System/getProperty "user.name")}}]
35+
(session/with-session ~session (merge defaults# session-or-host#)
36+
(do ~@body))))))
3637

3738
(defn exec
3839
"Execute a command and get the results.

0 commit comments

Comments
 (0)