You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2026/02/05 11:41:54 UTC
(sis) 03/03: Fix GDAL support on MacOS by using `System.mapLibraryName(String)`. Opportunistic documentation fixes and simplification.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 8d49b3b4458f2036232586727c33962c43865303
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Thu Feb 5 12:05:43 2026 +0100
Fix GDAL support on MacOS by using `System.mapLibraryName(String)`.
Opportunistic documentation fixes and simplification.
---
.../main/org/apache/sis/storage/gsf/panama/LibraryLoader.java | 3 +--
.../main/org/apache/sis/storage/gdal/GDAL.java | 2 +-
.../main/org/apache/sis/storage/panama/LibraryLoader.java | 3 +--
.../main/org/apache/sis/storage/panama/NativeFunctions.java | 10 ++++++----
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/incubator/src/org.apache.sis.storage.gsf/main/org/apache/sis/storage/gsf/panama/LibraryLoader.java b/incubator/src/org.apache.sis.storage.gsf/main/org/apache/sis/storage/gsf/panama/LibraryLoader.java
index 1ed6263ae5..118cc8dc67 100644
--- a/incubator/src/org.apache.sis.storage.gsf/main/org/apache/sis/storage/gsf/panama/LibraryLoader.java
+++ b/incubator/src/org.apache.sis.storage.gsf/main/org/apache/sis/storage/gsf/panama/LibraryLoader.java
@@ -16,7 +16,6 @@
*/
package org.apache.sis.storage.gsf.panama;
-import java.io.File;
import java.nio.file.Path;
import java.util.Optional;
import java.util.logging.Level;
@@ -87,7 +86,7 @@ public final class LibraryLoader {
@SuppressWarnings("restricted")
public GSF global() {
status = LibraryStatus.CANNOT_LOAD_LIBRARY;
- String filename = (File.separatorChar == '\\') ? "gsf.dll" : "libgsf.so";
+ String filename = System.mapLibraryName("gsf");
try {
symbols = SymbolLookup.libraryLookup(filename, Arena.global());
GSF instance = new GSF(this);
diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java
index b75ad43237..7a29722ce4 100644
--- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java
+++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java
@@ -284,7 +284,7 @@ final class GDAL extends NativeFunctions {
/**
* Pointers to native methods for the <abbr>OGR</abbr> part of <abbr>GDAL</abbr>.
- * Stores in a separated object for avoiding to load those symbols before needed.
+ * Stored in a separated object for avoiding to load those symbols before needed.
*
* @see #ogr()
*/
diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/LibraryLoader.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/LibraryLoader.java
index bac359f3f1..423e1b93d4 100644
--- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/LibraryLoader.java
+++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/LibraryLoader.java
@@ -16,7 +16,6 @@
*/
package org.apache.sis.storage.panama;
-import java.io.File;
import java.nio.file.Path;
import java.util.Optional;
import java.util.NoSuchElementException;
@@ -132,7 +131,7 @@ public final class LibraryLoader<F extends NativeFunctions> {
public F global(final String library) {
final var c = creator;
creator = null;
- filename = (File.separatorChar == '\\') ? (library + ".dll") : ("lib" + library + ".so");
+ filename = System.mapLibraryName(library);
status = LibraryStatus.LIBRARY_NOT_FOUND; // Default value if an exception occurs below.
F instance = null;
create: try {
diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/NativeFunctions.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/NativeFunctions.java
index 27d5a72dd8..35bd86ab54 100644
--- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/NativeFunctions.java
+++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/panama/NativeFunctions.java
@@ -91,11 +91,11 @@ public abstract class NativeFunctions implements Runnable, Callable<Object> {
* @param function name of the C/C++ <abbr>GDAL</abbr> function to invoke.
* @param signature type of arguments and return type.
* @return method handler for the <abbr>GDAL</abbr> function.
- * @throws IllegalArgumentException if the given function has not been found.
+ * @throws NoSuchElementException if the given function has not been found.
*/
@SuppressWarnings("restricted")
public final MethodHandle lookup(final String function, final FunctionDescriptor signature) {
- return symbols.find(function).map((method) -> linker.downcallHandle(method, signature)).orElseThrow();
+ return linker.downcallHandle(symbols.find(function).orElseThrow(), signature);
}
/**
@@ -107,9 +107,11 @@ public abstract class NativeFunctions implements Runnable, Callable<Object> {
* @param arg the argument.
* @return whether the return value, or empty if the method was not found or returned {@code null}.
*/
+ @SuppressWarnings("restricted")
protected final Optional<String> invokeGetString(final String function, final String arg) {
return symbols.find(function).map((method) -> {
- MethodHandle handle = lookup(function, FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS));
+ var acceptPointerReturnPointer = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
+ MethodHandle handle = linker.downcallHandle(method, acceptPointerReturnPointer);
MemorySegment result;
try (Arena local = Arena.ofConfined()) {
result = (MemorySegment) handle.invokeExact(local.allocateFrom(arg));
@@ -217,7 +219,7 @@ public abstract class NativeFunctions implements Runnable, Callable<Object> {
* because it assumes that no checked exception should be thrown.
*
* @param exception the exception thrown by {@code MethodHandler.invokeExact(…)}.
- * @return the exception to throw by the caller.
+ * @return the exception to be thrown by the caller.
*/
public static RuntimeException propagate(final Throwable exception) {
switch (exception) {