Select the types of activity you want to include in your feed.
chore(bindings/clojure): bump to 0.1.2; fix stale require in README
Bump the default VERSION to 0.1.2. Also correct the usage example's requires to the rockbox.ffi.* namespaces (they were still showing the pre-rename rockbox.metadata/dsp/player).
···7777 "rockbox-ffi`. Tried:\n " (str/join "\n " tried))
7878 {:tried (vec tried)})))))
79798080-(def ^:private linker (Linker/nativeLinker))
8080+;; Lazy: even Linker/nativeLinker is a Foreign-API call, kept out of ns load so
8181+;; requiring this namespace does no FFM work (cljdoc analysis, older JDKs).
8282+(def ^:private linker (delay (Linker/nativeLinker)))
81838284;; The library outlives every call, so it lives in the global arena (never
8383-;; unloaded). The lookup is created once, process-wide.
8484-(def ^:private lookup (SymbolLookup/libraryLookup (locate-lib) (Arena/global)))
8585+;; unloaded). Loaded lazily on first FFI use — merely `require`-ing this
8686+;; namespace (e.g. for cljdoc doc analysis) must NOT touch native code.
8787+(def ^:private lookup (delay (SymbolLookup/libraryLookup (locate-lib) (Arena/global))))
85888689(defn- fd-of ^FunctionDescriptor [ret args]
8790 (FunctionDescriptor/of ret (into-array MemoryLayout args)))
···9093 (FunctionDescriptor/ofVoid (into-array MemoryLayout args)))
91949295(defn- dc ^MethodHandle [^String name ^FunctionDescriptor fd]
9393- (let [sym (-> lookup (.find name)
9696+ (let [sym (-> @lookup (.find name)
9497 (.orElseThrow (reify java.util.function.Supplier
9598 (get [_] (ex-info (str "symbol " name " not found in librockbox_ffi") {})))))]
9696- (.downcallHandle linker sym fd (make-array Linker$Option 0))))
9999+ (.downcallHandle @linker sym fd (make-array Linker$Option 0))))
97100101101+;; Bound lazily (a delay): the downcall handles are built on first FFI call,
102102+;; not at namespace load, so requiring this ns never dlopens the library.
98103(def ^:private handles
9999- {;; ---- deallocators / version ----
104104+ (delay
105105+ {;; ---- deallocators / version ----
100106 :abi-version (dc "rb_ffi_abi_version" (fd-of I32 []))
101107 :string-free (dc "rb_string_free" (fd-void [PTR]))
102108 :buffer-free (dc "rb_buffer_free" (fd-void [PTR I64]))
···141147 :player-set-replaygain (dc "rb_player_set_replaygain" (fd-void [PTR I32 F32 BOOL]))
142148 :player-volume (dc "rb_player_volume" (fd-of F32 [PTR]))
143149 :player-sample-rate (dc "rb_player_sample_rate" (fd-of I32 [PTR]))
144144- :player-status-json (dc "rb_player_status_json" (fd-of PTR [PTR]))})
150150+ :player-status-json (dc "rb_player_status_json" (fd-of PTR [PTR]))}))
145151146152(defn call
147153 "Invoke the C function bound to `k`. Args must already be the right JVM type
148154 (use int/long/float/boolean/MemorySegment at the call site — the ABI does no
149155 narrowing). Returns the boxed result, or nil for void functions."
150156 [k & args]
151151- (.invokeWithArguments ^MethodHandle (get handles k) (to-array args)))
157157+ (.invokeWithArguments ^MethodHandle (get @handles k) (to-array args)))
152158153159(defn take-string
154160 "Copy a heap C string returned by the ABI into a String, then free it.