From 20956f2549dc6cf11de04f3494af491ced65ec6d Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 7 Jul 2022 13:05:39 -0500 Subject: [PATCH] Add function to get the segment from a static variable --- CHANGELOG.md | 2 ++ src/clj/coffi/ffi.clj | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 733d9e4..55813bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). ## [Unreleased] +### Added +- New function to allow getting the backing memory segment of a `coffi.ffi.StaticVariable`, to replace the `Addressable` implementation lost in the migration to JDK 18 ## [0.5.357] - 2022-07-07 ### Removed diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index 5057346..b68e8b0 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -19,6 +19,7 @@ FunctionDescriptor MemoryAddress MemoryLayout + MemorySegment NativeSymbol SegmentAllocator))) @@ -594,6 +595,14 @@ [static-var f & args] (freset! static-var (apply f @static-var args))) +(defn static-variable-segment + "Gets the backing [[MemorySegment]] from `static-var`. + + This is primarily useful when you need to pass the static variable's address + to a native function which takes an [[Addressable]]." + ^MemorySegment [static-var] + (.-seg ^StaticVariable static-var)) + (defn static-variable "Constructs a reference to a mutable value stored in `symbol-or-addr`.