Fix JNI wrapper interfaces
This commit is contained in:
parent
61de0555db
commit
7be32f4746
15
Makefile
15
Makefile
|
@ -4,13 +4,16 @@ include Makefile.common
|
|||
all: snappy
|
||||
|
||||
SNAPPY_ARCHIVE:=$(TARGET)/snappy-$(VERSION).tar.gz
|
||||
SNAPPY_CC:=snappy-sinksource.cc snappy-stubs-internal.cc snappy.cc
|
||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) SnappyNative.o)
|
||||
|
||||
|
||||
$(SNAPPY_ARCHIVE):
|
||||
@mkdir -p $(@D)
|
||||
curl -o$@ http://snappy.googlecode.com/files/snappy-$(VERSION).tar.gz
|
||||
|
||||
|
||||
$(SNAPPY_SRC): $(SNAPPY_ARCHIVE)
|
||||
$(TARGET)/snappy-$(VERSION): $(SNAPPY_ARCHIVE)
|
||||
tar xvfz $< -C $(TARGET)
|
||||
|
||||
|
||||
|
@ -18,21 +21,17 @@ $(SRC)/org/xerial/snappy/SnappyNative.h: $(SRC)/org/xerial/snappy/Snappy.java
|
|||
javah -classpath $(TARGET)/classes -o $@ org.xerial.snappy.Snappy
|
||||
|
||||
|
||||
SNAPPY_CC:=snappy-sinksource.cc snappy-stubs-internal.cc snappy.cc
|
||||
SNAPPY_OBJ:=$(addprefix $(SNAPPY_OUT)/,$(patsubst %.cc,%.o,$(SNAPPY_CC)) SnappyNative.o)
|
||||
|
||||
|
||||
|
||||
$(SNAPPY_OUT)/%.o : $(SNAPPY_SRC)/%.cc $(SNAPPY_SRC)
|
||||
$(SNAPPY_OUT)/%.o : $(TARGET)/snappy-$(VERSION)/%.cc
|
||||
@mkdir -p $(@D)
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
$(SNAPPY_OUT)/%.o : $(SRC)/org/xerial/snappy/SnappyNative.cpp $(SRC)/org/xerial/snappy/SnappyNative.h $(SNAPPY_SRC)
|
||||
$(SNAPPY_OUT)/%.o : $(SRC)/org/xerial/snappy/SnappyNative.cpp $(SRC)/org/xerial/snappy/SnappyNative.h
|
||||
@mkdir -p $(@D)
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
$(SNAPPY_OUT)/$(LIBNAME): $(SNAPPY_OBJ)
|
||||
$(CXX) $(CXXFLAGS) $(LINKFLAGS) -o $@ $*
|
||||
$(CXX) $(CXXFLAGS) $(LINKFLAGS) $+ -o $@
|
||||
$(STRIP) $@
|
||||
|
||||
clean-native:
|
||||
|
|
|
@ -90,12 +90,12 @@ Windows-x86_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
|
|||
Windows-x86_LIBNAME := snappy.dll
|
||||
Windows-x86_SNAPPY_FLAGS :=
|
||||
|
||||
#Windows-amd64_CXX := x86_64-w64-mingw32-g++
|
||||
#Windows-amd64_STRIP := x86_64-w64-mingw32-strip
|
||||
Windows-amd64_CXX := i686-w64-mingw32-g++
|
||||
Windows-amd64_STRIP := i686-w64-mingw32-strip
|
||||
Windows-amd64_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-amd64_LINKFLAGS := -Wl,--kill-at -shared -static-libgcc
|
||||
Windows-amd64_CXX := x86_64-w64-mingw32-g++
|
||||
Windows-amd64_STRIP := x86_64-w64-mingw32-strip
|
||||
#Windows-amd64_CXX := i686-w64-mingw32-g++
|
||||
#Windows-amd64_STRIP := i686-w64-mingw32-strip
|
||||
Windows-amd64_CXXFLAGS := -Ilib/inc_win -Os
|
||||
Windows-amd64_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-amd64_LIBNAME := snappy.dll
|
||||
Windows-amd64_SNAPPY_FLAGS :=
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* @(#)jni.h 1.56 03/12/19
|
||||
* @(#)jni.h 1.63 10/03/23
|
||||
*
|
||||
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
||||
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -117,6 +117,15 @@ typedef struct _jfieldID *jfieldID;
|
|||
struct _jmethodID;
|
||||
typedef struct _jmethodID *jmethodID;
|
||||
|
||||
/* Return values from jobjectRefType */
|
||||
typedef enum _jobjectType {
|
||||
JNIInvalidRefType = 0,
|
||||
JNILocalRefType = 1,
|
||||
JNIGlobalRefType = 2,
|
||||
JNIWeakGlobalRefType = 3
|
||||
} jobjectRefType;
|
||||
|
||||
|
||||
#endif /* JNI_TYPES_ALREADY_DEFINED_IN_JNI_MD_H */
|
||||
|
||||
/*
|
||||
|
@ -733,6 +742,11 @@ struct JNINativeInterface_ {
|
|||
(JNIEnv* env, jobject buf);
|
||||
jlong (JNICALL *GetDirectBufferCapacity)
|
||||
(JNIEnv* env, jobject buf);
|
||||
|
||||
/* New JNI 1.6 Features */
|
||||
|
||||
jobjectRefType (JNICALL *GetObjectRefType)
|
||||
(JNIEnv* env, jobject obj);
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1821,6 +1835,9 @@ struct JNIEnv_ {
|
|||
jlong GetDirectBufferCapacity(jobject buf) {
|
||||
return functions->GetDirectBufferCapacity(this, buf);
|
||||
}
|
||||
jobjectRefType GetObjectRefType(jobject obj) {
|
||||
return functions->GetObjectRefType(this, obj);
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
};
|
||||
|
@ -1845,35 +1862,7 @@ typedef struct JavaVMAttachArgs {
|
|||
jobject group;
|
||||
} JavaVMAttachArgs;
|
||||
|
||||
/* These structures will be VM-specific. */
|
||||
|
||||
typedef struct JDK1_1InitArgs {
|
||||
jint version;
|
||||
|
||||
char **properties;
|
||||
jint checkSource;
|
||||
jint nativeStackSize;
|
||||
jint javaStackSize;
|
||||
jint minHeapSize;
|
||||
jint maxHeapSize;
|
||||
jint verifyMode;
|
||||
char *classpath;
|
||||
|
||||
jint (JNICALL *vfprintf)(FILE *fp, const char *format, va_list args);
|
||||
void (JNICALL *exit)(jint code);
|
||||
void (JNICALL *abort)(void);
|
||||
|
||||
jint enableClassGC;
|
||||
jint enableVerboseGC;
|
||||
jint disableAsyncGC;
|
||||
jint verbose;
|
||||
jboolean debugging;
|
||||
jint debugPort;
|
||||
} JDK1_1InitArgs;
|
||||
|
||||
typedef struct JDK1_1AttachArgs {
|
||||
void * __padding; /* C compilers don't allow empty structures. */
|
||||
} JDK1_1AttachArgs;
|
||||
/* These will be VM-specific. */
|
||||
|
||||
#define JDK1_2
|
||||
#define JDK1_4
|
||||
|
@ -1943,9 +1932,13 @@ JNI_OnUnload(JavaVM *vm, void *reserved);
|
|||
#define JNI_VERSION_1_1 0x00010001
|
||||
#define JNI_VERSION_1_2 0x00010002
|
||||
#define JNI_VERSION_1_4 0x00010004
|
||||
#define JNI_VERSION_1_6 0x00010006
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* !_JAVASOFT_JNI_H_ */
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* @(#)jni_md.h 1.14 03/12/19
|
||||
* @(#)jni_md.h 1.16 10/03/23
|
||||
*
|
||||
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
||||
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
||||
*/
|
||||
|
||||
#ifndef _JAVASOFT_JNI_MD_H_
|
||||
|
|
9
pom.xml
9
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>org/xerial/snappy/native/**</include>
|
||||
<include>org/xerial/snappy/native/**</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
|
@ -76,5 +76,12 @@
|
|||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xerial</groupId>
|
||||
<artifactId>xerial-core</artifactId>
|
||||
<version>2.0.2</version>
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -17,6 +17,8 @@ public class Snappy
|
|||
LoadSnappy.initialize();
|
||||
}
|
||||
|
||||
public native static String nativeLibraryVersion();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Generic compression/decompression routines.
|
||||
// ------------------------------------------------------------------------
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
#include <snappy.h>
|
||||
#include "SnappyNative.h"
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_Snappy_nativeLibraryVersion
|
||||
(JNIEnv * env, jclass self)
|
||||
{
|
||||
return env->NewStringUTF("1.0.1");
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: compress
|
||||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_Snappy_compress
|
||||
(JNIEnv *, jobject, jobject, jobject)
|
||||
(JNIEnv* env, jclass self, jobject uncompressed, jobject compressed)
|
||||
{
|
||||
void* uncompressedBuffer = env->GetDirectBufferAddress(uncompressed);
|
||||
|
||||
|
||||
return (jlong) 0;
|
||||
}
|
||||
|
||||
|
@ -18,7 +27,7 @@ JNIEXPORT jlong JNICALL Java_org_xerial_snappy_Snappy_compress
|
|||
* Signature: (Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_Snappy_uncompress
|
||||
(JNIEnv *, jobject, jobject, jobject)
|
||||
(JNIEnv *, jclass, jobject, jobject)
|
||||
{
|
||||
|
||||
return (jboolean) true;
|
||||
|
@ -30,7 +39,7 @@ JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_Snappy_uncompress
|
|||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_Snappy_maxCompressedLength
|
||||
(JNIEnv *, jobject, jlong)
|
||||
(JNIEnv *, jclass, jlong)
|
||||
{
|
||||
|
||||
return (jlong) 0;
|
||||
|
|
|
@ -7,6 +7,14 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: nativeLibraryVersion
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_Snappy_nativeLibraryVersion
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_xerial_snappy_Snappy
|
||||
* Method: compress
|
||||
|
|
|
@ -12,9 +12,18 @@ package org.xerial.snappy;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xerial.util.log.Logger;
|
||||
|
||||
public class SnappyTest
|
||||
{
|
||||
private static Logger _logger = Logger.getLogger(SnappyTest.class);
|
||||
|
||||
@Test
|
||||
public void getVersion() throws Exception {
|
||||
String version = Snappy.nativeLibraryVersion();
|
||||
_logger.info("version: " + version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void load() throws Exception {
|
||||
|
||||
|
|
Loading…
Reference in New Issue