Skip to content

Commit 618a935

Browse files
byrnHDFlrknox
andauthored
Fix critical pinning for JNI (#20)
* Fix critical pinning for JNI * Fix CMake ext lib to match hdf5 and fix jni typo * Add test for native function to verify link Co-authored-by: Larry Knox <lrknox@hdfgroup.org>
1 parent 65091a0 commit 618a935

File tree

9 files changed

+78
-34
lines changed

9 files changed

+78
-34
lines changed

CMakeFilters.cmake

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Options for HDF4 Filters
44
#-----------------------------------------------------------------------------
55
option (USE_LIBAEC "Use AEC library as SZip Filter" OFF)
6+
option (USE_LIBAEC_STATIC "Use static AEC library " OFF)
67

78
include (ExternalProject)
89
#option (HDF4_ALLOW_EXTERNAL_SUPPORT "Allow External Library Building (NO GIT TGZ)" "NO")
@@ -24,11 +25,29 @@ if (HDF4_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT" OR HDF4_ALLOW_EXTERNAL_SUPPORT MAT
2425
set (TGZPATH ${HDF4_SOURCE_DIR})
2526
endif ()
2627
set (JPEG_URL ${TGZPATH}/${JPEG_TGZ_NAME})
28+
if (NOT EXISTS "${JPEG_URL}")
29+
set (HDF4_ENABLE_JPEG_SUPPORT OFF CACHE BOOL "" FORCE)
30+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
31+
message (VERBOSE "Filter JPEG file ${JPEG_URL} not found")
32+
endif ()
33+
endif ()
2734
set (ZLIB_URL ${TGZPATH}/${ZLIB_TGZ_NAME})
35+
if (NOT EXISTS "${ZLIB_URL}")
36+
set (HDF4_ENABLE_Z_LIB_SUPPORT OFF CACHE BOOL "" FORCE)
37+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
38+
message (VERBOSE "Filter ZLIB file ${ZLIB_URL} not found")
39+
endif ()
40+
endif ()
2841
set (SZIP_URL ${TGZPATH}/${SZIP_TGZ_NAME})
2942
if (USE_LIBAEC)
3043
set (SZIP_URL ${TGZPATH}/${SZAEC_TGZ_NAME})
3144
endif ()
45+
if (NOT EXISTS "${SZIP_URL}")
46+
set (HDF4_ENABLE_SZIP_SUPPORT OFF CACHE BOOL "" FORCE)
47+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
48+
message (VERBOSE "Filter SZIP file ${SZIP_URL} not found")
49+
endif ()
50+
endif ()
3251
else ()
3352
set (JPEG_USE_EXTERNAL 0)
3453
set (ZLIB_USE_EXTERNAL 0)
@@ -117,7 +136,9 @@ if (HDF4_ENABLE_Z_LIB_SUPPORT)
117136
set (H4_HAVE_FILTER_DEFLATE 1)
118137
set (H4_HAVE_ZLIB_H 1)
119138
set (H4_HAVE_LIBZ 1)
120-
message (STATUS "Filter ZLIB is built")
139+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
140+
message (VERBOSE "Filter HDF4_ZLIB is built")
141+
endif ()
121142
else ()
122143
message (FATAL_ERROR " ZLib is Required for ZLib support in HDF4")
123144
endif ()
@@ -130,7 +151,9 @@ if (HDF4_ENABLE_Z_LIB_SUPPORT)
130151
endif ()
131152
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${ZLIB_STATIC_LIBRARY})
132153
INCLUDE_DIRECTORIES (${ZLIB_INCLUDE_DIRS})
133-
message (STATUS "Filter ZLIB is ON")
154+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
155+
message (VERBOSE "Filter HDF4_ZLIB is ON")
156+
endif ()
134157
endif ()
135158

136159
#-----------------------------------------------------------------------------
@@ -141,13 +164,24 @@ set (SZIP_INFO "disabled")
141164
if (HDF4_ENABLE_SZIP_SUPPORT)
142165
option (HDF4_ENABLE_SZIP_ENCODING "Use SZip Encoding" OFF)
143166
if (NOT SZIP_USE_EXTERNAL)
144-
find_package (SZIP NAMES ${SZIP_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS static shared)
145-
if (NOT SZIP_FOUND)
146-
find_package (SZIP) # Legacy find
167+
set(SZIP_FOUND FALSE)
168+
if (USE_LIBAEC)
169+
set(libaec_USE_STATIC_LIBS ${USE_LIBAEC_STATIC})
170+
find_package (libaec 1.0.5 CONFIG)
147171
if (SZIP_FOUND)
148172
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_LIBRARIES})
149173
endif ()
150174
endif ()
175+
176+
if (NOT SZIP_FOUND)
177+
find_package (SZIP NAMES ${SZIP_PACKAGE_NAME}${HDF_PACKAGE_EXT} COMPONENTS static shared)
178+
if (NOT SZIP_FOUND)
179+
find_package (SZIP) # Legacy find
180+
if (SZIP_FOUND)
181+
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_LIBRARIES})
182+
endif ()
183+
endif ()
184+
endif ()
151185
endif ()
152186
if (SZIP_FOUND)
153187
set (H4_HAVE_FILTER_SZIP 1)
@@ -161,20 +195,26 @@ if (HDF4_ENABLE_SZIP_SUPPORT)
161195
set (H4_HAVE_FILTER_SZIP 1)
162196
set (H4_HAVE_SZLIB_H 1)
163197
set (H4_HAVE_LIBSZ 1)
164-
message (STATUS "Filter SZIP is built")
198+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
199+
message (VERBOSE "Filter SZIP is built")
200+
endif ()
165201
if (USE_LIBAEC)
166-
message (STATUS "... with library AEC")
167-
set (SZ_PACKAGE_NAME ${LIBAEC_PACKAGE_NAME})
202+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
203+
message (VERBOSE "... with library AEC")
204+
endif ()
205+
set (SZIP_PACKAGE_NAME ${LIBAEC_PACKAGE_NAME})
168206
else ()
169-
set (SZ_PACKAGE_NAME ${SZIP_PACKAGE_NAME})
207+
set (SZIP_PACKAGE_NAME ${SZIP_PACKAGE_NAME})
170208
endif ()
171209
else ()
172210
message (FATAL_ERROR "SZIP is Required for SZIP support in HDF4")
173211
endif ()
174212
endif ()
175213
set (LINK_COMP_LIBS ${LINK_COMP_LIBS} ${SZIP_STATIC_LIBRARY})
176214
INCLUDE_DIRECTORIES (${SZIP_INCLUDE_DIRS})
177-
message (STATUS "Filter SZIP is ON")
215+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15.0")
216+
message (VERBOSE "Filter SZIP is ON")
217+
endif ()
178218
if (HDF4_ENABLE_SZIP_ENCODING)
179219
set (H4_HAVE_SZIP_ENCODER 1)
180220
set (SZIP_INFO "enabled with encoder")

CMakeInstallation.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ if (NOT HDF4_EXTERNALLY_CONFIGURED AND NOT HDF4_NO_PACKAGES)
278278
set (CPACK_PACKAGE_ICON "${HDF_RESOURCES_EXT_DIR}/hdf.bmp")
279279

280280
set (CPACK_GENERATOR "TGZ")
281-
if (WIN32 OR MINGW)
281+
if (WIN32)
282282
set (CPACK_GENERATOR "ZIP")
283283

284284
if (NSIS_EXECUTABLE)
@@ -443,7 +443,7 @@ The HDF data model, file format, API, library, and tools are open and distribute
443443
if (HDF4_PACKAGE_EXTLIBS)
444444
if (HDF4_ALLOW_EXTERNAL_SUPPORT MATCHES "GIT" OR HDF4_ALLOW_EXTERNAL_SUPPORT MATCHES "TGZ")
445445
if (JPEG_FOUND AND JPEG_USE_EXTERNAL)
446-
if (WIN32 OR MINGW)
446+
if (WIN32)
447447
set (CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS};${JPEG_INCLUDE_DIR_GEN};JPEG;ALL;/")
448448
else ()
449449
set (CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS};${JPEG_INCLUDE_DIR_GEN};JPEG;libraries;/")
@@ -452,7 +452,7 @@ The HDF data model, file format, API, library, and tools are open and distribute
452452
endif ()
453453
endif ()
454454
if (ZLIB_FOUND AND ZLIB_USE_EXTERNAL)
455-
if (WIN32 OR MINGW)
455+
if (WIN32)
456456
set (CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS};${ZLIB_INCLUDE_DIR_GEN};ZLIB;ALL;/")
457457
else ()
458458
set (CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS};${ZLIB_INCLUDE_DIR_GEN};ZLIB;libraries;/")
@@ -461,7 +461,7 @@ The HDF data model, file format, API, library, and tools are open and distribute
461461
endif ()
462462
endif ()
463463
if (SZIP_FOUND AND SZIP_USE_EXTERNAL)
464-
if (WIN32 OR MINGW)
464+
if (WIN32)
465465
set (CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS};${SZIP_INCLUDE_DIR_GEN};SZIP;ALL;/")
466466
else ()
467467
set (CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_INSTALL_CMAKE_PROJECTS};${SZIP_INCLUDE_DIR_GEN};SZIP;libraries;/")

CMakeLists.txt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ endif ()
3434

3535
# CMake version 3.14 added option --ignore-eol to compare files
3636
# cmake -E compare_files --ignore-eol file1 file2
37-
#if(CMAKE_VERSION VERSION_LESS "3.14.0" AND WIN32)
38-
# MESSAGE(FATAL_ERROR "Windows builds requires a minimum of CMake 3.14")
39-
#endif()
37+
set (CMAKE_IGNORE_EOL "--ignore-eol")
38+
if (CMAKE_VERSION VERSION_LESS "3.14.0")
39+
set (CMAKE_IGNORE_EOL "")
40+
# if (WIN32)
41+
# message (FATAL_ERROR "Windows builds require a minimum of CMake 3.14")
42+
# endif()
43+
endif ()
4044

4145
#-----------------------------------------------------------------------------
4246
# Instructions for use : Sub-Project Build
@@ -393,12 +397,11 @@ INCLUDE_DIRECTORIES (${HDF4_INCLUDE_DIRECTORIES} )
393397
# Certain systems may add /Debug or /Release to output paths
394398
# and we need to call the executable from inside the CMake configuration
395399
#-----------------------------------------------------------------------------
396-
set (EXE_EXT "")
397-
if (WIN32 OR MINGW)
398-
set (EXE_EXT ".exe")
399-
add_definitions (-D_BIND_TO_CURRENT_VCLIBS_VERSION=1)
400-
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
401-
add_definitions (-D_CONSOLE)
400+
if (WIN32)
401+
add_compile_definitions (_CRT_SECURE_NO_WARNINGS)
402+
if (MSVC)
403+
add_compile_definitions (_BIND_TO_CURRENT_VCLIBS_VERSION=1 _CONSOLE)
404+
endif ()
402405
endif ()
403406

404407
if (MSVC)
@@ -408,7 +411,7 @@ if (MSVC)
408411
endif ()
409412

410413
set (MAKE_SYSTEM)
411-
if (CMAKE_BUILD_TOOL MATCHES "make")
414+
if (CMAKE_MAKE_PROGRAM MATCHES "make")
412415
set (MAKE_SYSTEM 1)
413416
endif ()
414417

config/cmake_ext_mod/ConfigureChecks.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ CHECK_INCLUDE_FILE_CONCAT (stdbool.h ${HDF_PREFIX}_HAVE_STDBOOL_H)
147147
CHECK_INCLUDE_FILE_CONCAT ("arpa/inet.h" ${HDF_PREFIX}_HAVE_INET_H)
148148
CHECK_INCLUDE_FILE_CONCAT ("sys/param.h" ${HDF_PREFIX}_HAVE_PARAM_H)
149149

150-
## Check for non-standard extenstion quadmath.h
150+
## Check for non-standard extension quadmath.h
151151

152152
CHECK_INCLUDE_FILES(quadmath.h C_HAVE_QUADMATH)
153153
if (${C_HAVE_QUADMATH})

config/cmake_ext_mod/runTest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ if (NOT TEST_SKIP_COMPARE)
222222
list (SORT v1)
223223
list (SORT v2)
224224
if (NOT v1 STREQUAL v2)
225-
set(TEST_COMPARE_RESULT 1)
225+
set (TEST_COMPARE_RESULT 1)
226226
endif ()
227227
endif ()
228228

java/src/jni/hdfsdsImp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ Java_hdf_hdflib_HDFLibrary_SDwritedata(JNIEnv *env, jclass clss, jlong sdsid, ji
13331333
if (stride != NULL)
13341334
PIN_INT_ARRAY(ENVONLY, stride, strd, &isCopy, "SDwritedata: stride not pinned");
13351335

1336-
if ((rval = SDwritedata(id, strt, strd, e, d)) == FAIL)
1336+
if ((rval = SDwritedata(id, strt, strd, e, (VOIDP)d)) == FAIL)
13371337
H4_LIBRARY_ERROR(ENVONLY);
13381338

13391339
done:

java/src/jni/hdfvgroupImp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ Java_hdf_hdflib_HDFLibrary_Vntagrefs(JNIEnv *env, jclass clss, jlong vgroup_id)
298298
return (jint)rval;
299299
}
300300

301-
JNIEXPORT jint
301+
JNIEXPORT jint JNICALL
302302
Java_hdf_hdflib_HDFLibrary_Vinqtagref(JNIEnv *env, jclass clss, jlong vgroup_id, jint tag, jint ref)
303303
{
304304
int32 rval = FAIL;
@@ -728,7 +728,7 @@ Java_hdf_hdflib_HDFLibrary_Vgetversion(JNIEnv *env, jclass clss, jlong id)
728728
return (jint)rval;
729729
}
730730

731-
JNIEXPORT jint
731+
JNIEXPORT jint JNICALL
732732
Java_hdf_hdflib_HDFLibrary_Vnattrs(JNIEnv *env, jclass clss, jlong id)
733733
{
734734
int32 rval = FAIL;

java/test/TestH4Vparams.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ public void testVgetattrIllegalId() throws Throwable {
359359
// HDFLibrary.Vgetversion(-1);
360360
// }
361361

362-
// @Test(expected = HDFException.class)
363-
// public void testVnattrsIllegalId() throws Throwable {
364-
// HDFLibrary.Vnattrs(-1);
365-
// }
362+
@Test(expected = HDFException.class)
363+
public void testVnattrsIllegalId() throws Throwable {
364+
HDFLibrary.Vnattrs(-1);
365+
}
366366

367367
@Test(expected = NullPointerException.class)
368368
public void testVsetattrNullName() throws Throwable {

java/test/testfiles/JUnit-TestH4Vparams.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ JUnit version 4.11
33
.testVisvsIllegalId
44
.testVsetattrNullName2
55
.testVinquireIllegalNEntriesArgument
6+
.testVnattrsIllegalId
67
.testVgetnameIllegalArgument
78
.testVfindclassNullClassName
89
.testVattrinfoNullArgv
@@ -50,5 +51,5 @@ JUnit version 4.11
5051

5152
Time: XXXX
5253

53-
OK (48 tests)
54+
OK (49 tests)
5455

0 commit comments

Comments
 (0)