Skip to content

Commit

Permalink
Merge pull request #84 from bgilbert/ffm
Browse files Browse the repository at this point in the history
Small FFM race fix and small cleanup
  • Loading branch information
bgilbert authored May 3, 2024
2 parents 39c3814 + df6b004 commit 8be2d71
Showing 1 changed file with 34 additions and 47 deletions.
81 changes: 34 additions & 47 deletions org/openslide/OpenSlideFFM.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ private static RuntimeException wrapException(Throwable ex) {
C_POINTER, "openslide_detect_vendor", C_POINTER);

static String openslide_detect_vendor(String filename) {
if (filename == null) {
return null;
}
MemorySegment ret;
try (Arena arena = Arena.ofConfined()) {
ret = (MemorySegment) detect_vendor.invokeExact(
Expand All @@ -254,9 +251,6 @@ static String openslide_detect_vendor(String filename) {
C_POINTER, "openslide_open", C_POINTER);

static OpenSlideRef openslide_open(String filename) {
if (filename == null) {
return null;
}
MemorySegment ret;
try (Arena arena = Arena.ofConfined()) {
ret = (MemorySegment) open.invokeExact(
Expand Down Expand Up @@ -362,14 +356,16 @@ static void openslide_read_icc_profile(OpenSlideRef osr, byte dest[]) {
static String openslide_get_error(OpenSlideRef osr) {
MemorySegment ret;
try (Ref.ScopedLock l = osr.lock()) {
ret = (MemorySegment) get_error.invokeExact(osr.getSegment());
} catch (Throwable ex) {
throw wrapException(ex);
}
if (ret.equals(MemorySegment.NULL)) {
return null;
try {
ret = (MemorySegment) get_error.invokeExact(osr.getSegment());
} catch (Throwable ex) {
throw wrapException(ex);
}
if (ret.equals(MemorySegment.NULL)) {
return null;
}
return ret.getString(0);
}
return ret.getString(0);
}

private static final MethodHandle get_property_names = function(
Expand All @@ -378,32 +374,33 @@ static String openslide_get_error(OpenSlideRef osr) {
static String[] openslide_get_property_names(OpenSlideRef osr) {
MemorySegment ret;
try (Ref.ScopedLock l = osr.lock()) {
ret = (MemorySegment) get_property_names.invokeExact(
osr.getSegment());
} catch (Throwable ex) {
throw wrapException(ex);
try {
ret = (MemorySegment) get_property_names.invokeExact(
osr.getSegment());
} catch (Throwable ex) {
throw wrapException(ex);
}
return segment_to_string_array(ret);
}
return segment_to_string_array(ret);
}

private static final MethodHandle get_property_value = function(
C_POINTER, "openslide_get_property_value", C_POINTER, C_POINTER);

static String openslide_get_property_value(OpenSlideRef osr, String name) {
if (name == null) {
return null;
}
MemorySegment ret;
try (Arena arena = Arena.ofConfined(); Ref.ScopedLock l = osr.lock()) {
ret = (MemorySegment) get_property_value.invokeExact(
osr.getSegment(), arena.allocateFrom(name));
} catch (Throwable ex) {
throw wrapException(ex);
}
if (ret.equals(MemorySegment.NULL)) {
return null;
try (Ref.ScopedLock l = osr.lock()) {
try (Arena arena = Arena.ofConfined()) {
ret = (MemorySegment) get_property_value.invokeExact(
osr.getSegment(), arena.allocateFrom(name));
} catch (Throwable ex) {
throw wrapException(ex);
}
if (ret.equals(MemorySegment.NULL)) {
return null;
}
return ret.getString(0);
}
return ret.getString(0);
}

private static final MethodHandle get_associated_image_names = function(
Expand All @@ -412,12 +409,14 @@ static String openslide_get_property_value(OpenSlideRef osr, String name) {
static String[] openslide_get_associated_image_names(OpenSlideRef osr) {
MemorySegment ret;
try (Ref.ScopedLock l = osr.lock()) {
ret = (MemorySegment) get_associated_image_names.invokeExact(
osr.getSegment());
} catch (Throwable ex) {
throw wrapException(ex);
try {
ret = (MemorySegment) get_associated_image_names.invokeExact(
osr.getSegment());
} catch (Throwable ex) {
throw wrapException(ex);
}
return segment_to_string_array(ret);
}
return segment_to_string_array(ret);
}

private static final MethodHandle get_associated_image_dimensions = function(
Expand All @@ -426,9 +425,6 @@ static String[] openslide_get_associated_image_names(OpenSlideRef osr) {

static void openslide_get_associated_image_dimensions(OpenSlideRef osr,
String name, long dim[]) {
if (name == null) {
return;
}
try (Arena arena = Arena.ofConfined()) {
MemorySegment w = arena.allocateFrom(JAVA_LONG, 0);
MemorySegment h = arena.allocateFrom(JAVA_LONG, 0);
Expand All @@ -449,9 +445,6 @@ static void openslide_get_associated_image_dimensions(OpenSlideRef osr,

static void openslide_read_associated_image(OpenSlideRef osr, String name,
int dest[]) {
if (name == null) {
return;
}
try (Arena arena = Arena.ofConfined()) {
MemorySegment buf = arena.allocate(JAVA_INT, dest.length);
try (Ref.ScopedLock l = osr.lock()) {
Expand All @@ -470,9 +463,6 @@ static void openslide_read_associated_image(OpenSlideRef osr, String name,

static long openslide_get_associated_image_icc_profile_size(
OpenSlideRef osr, String name) {
if (name == null) {
return -1;
}
try (Arena arena = Arena.ofConfined(); Ref.ScopedLock l = osr.lock()) {
return (long) get_associated_image_icc_profile_size.invokeExact(
osr.getSegment(), arena.allocateFrom(name));
Expand All @@ -487,9 +477,6 @@ static long openslide_get_associated_image_icc_profile_size(

static void openslide_read_associated_image_icc_profile(OpenSlideRef osr,
String name, byte dest[]) {
if (name == null) {
return;
}
try (Arena arena = Arena.ofConfined()) {
MemorySegment buf = arena.allocate(JAVA_BYTE, dest.length);
try (Ref.ScopedLock l = osr.lock()) {
Expand Down

0 comments on commit 8be2d71

Please sign in to comment.