Skip to content

Commit

Permalink
Merge branch 'calin-iorgulescu-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Apr 2, 2019
2 parents c5130eb + 9d38df2 commit 906aa15
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 65 deletions.
22 changes: 20 additions & 2 deletions hawtjni-example/src/main/java/test/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ static public class bar {
@JniField(cast="struct foo *")
public long prev;

@JniField(getter = "get_d()", setter = "set_d()", flags = { GETTER_NONMEMBER, SETTER_NONMEMBER })
private float d;

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -231,6 +234,7 @@ public int hashCode() {
result = prime * result + Arrays.hashCode(c);
result = prime * result + c5;
result = prime * result + (int) (prev ^ (prev >>> 32));
result = prime * result + Float.valueOf(d).hashCode();
return result;
}

Expand All @@ -253,12 +257,15 @@ public boolean equals(Object obj) {
return false;
if (prev != other.prev)
return false;
if (d != other.d) {
return false;
}
return true;
}

@Override
public String toString() {
return "foo [a=" + a + ", b=" + b + ", c=" + Arrays.toString(c) + ", c5=" + c5 + ", prev=" + prev + "]";
return "foo [a=" + a + ", b=" + b + ", c=" + Arrays.toString(c) + ", c5=" + c5 + ", prev=" + prev + ", d=" + d + "]";
}

}
Expand All @@ -282,7 +289,7 @@ public static final native void memmove (
@JniMethod(cast = "char *")
public static final native long char_add(@JniArg(cast="char *")long ptr, int count);

@JniClass(flags={ClassFlag.STRUCT, ClassFlag.TYPEDEF})
@JniClass(flags={ClassFlag.STRUCT, ClassFlag.TYPEDEF})
static public class point {
static {
LIBRARY.load();
Expand Down Expand Up @@ -326,4 +333,15 @@ static class Range {

public static final native void passingtheenv (String msg, JNIEnv env);

@JniClass(flags={ClassFlag.STRUCT})
static class ClassWithAccessors {
static {
LIBRARY.load();
}

@JniField(getter = "get_e()", setter = "set_e()")
private float e;


}
}
8 changes: 7 additions & 1 deletion hawtjni-example/src/main/native-package/src/foo.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
#include "foo.h"
#include <stdio.h>

float get_d(struct foo *arg) {
return 0.0f;
}
void set_d(struct foo *arg, float d) {
}

void print_foo(struct foo *arg) {
printf("foo@%p: { a: %d, b: %d, c: \"%s\", prev: @%p}\n", arg, arg->a, (int)arg->b, arg->c, arg->prev);
printf("foo@%p: { a: %d, b: %d, c: \"%s\", prev: @%p, d: %f}\n", arg, arg->a, (int)arg->b, arg->c, arg->prev, get_d(arg));
}

long foowork(struct foo **arg, int count) {
Expand Down
15 changes: 14 additions & 1 deletion hawtjni-example/src/main/native-package/src/foo.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ struct foo {
int a;
size_t b;
char c[20];
struct foo *prev;
struct foo *prev;
};

typedef struct _point {
int x;
int y;
} point;

struct ClassWithAccessors {
float e;

float (*get_e)();
void (*set_e)(float e);
};

float get_d(struct foo *arg);
void set_d(struct foo *arg, float d);

float ClassWithAccessors_get_e(struct foo *arg);
void ClassWithAccessors_set_e(struct foo *arg, float e);

struct foo * foo_add(struct foo *arg, int count);
char * char_add(char *arg, int count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.fusesource.hawtjni.generator.model.JNIClass;
import org.fusesource.hawtjni.generator.model.JNIField;
import org.fusesource.hawtjni.generator.model.JNIFieldAccessor;
import org.fusesource.hawtjni.generator.model.JNIMethod;
import org.fusesource.hawtjni.generator.model.JNIParameter;
import org.fusesource.hawtjni.generator.model.JNIType;
Expand Down Expand Up @@ -189,9 +190,7 @@ private void generateConstantsInitializer(JNIMethod method) {
boolean allowConversion = !type.equals(type64);

String simpleName = type.getSimpleName();
String accessor = field.getAccessor();
if (accessor == null || accessor.length() == 0)
accessor = field.getName();
JNIFieldAccessor accessor = field.getAccessor();

String fieldId = "(*env)->GetStaticFieldID(env, that, \""+field.getName()+"\", \""+type.getTypeSignature(allowConversion)+"\")";
if (isCPP) {
Expand All @@ -208,7 +207,7 @@ private void generateConstantsInitializer(JNIMethod method) {
if( field.isPointer() ) {
output("(intptr_t)");
}
output(accessor);
output(accessor.getter());
output(");");

} else if (type.isArray()) {
Expand Down Expand Up @@ -238,7 +237,7 @@ private void generateConstantsInitializer(JNIMethod method) {
} else {
output("ArrayRegion(env, lpObject1, 0, sizeof(");
}
output(accessor);
output(accessor.getter());
output(")");
if (!componentType.isType("byte")) {
output(" / sizeof(");
Expand All @@ -248,7 +247,7 @@ private void generateConstantsInitializer(JNIMethod method) {
output(", (");
output(type.getTypeSignature4(allowConversion, false));
output(")");
output(accessor);
output(accessor.getter());
outputln(");");
output("\t}");
} else {
Expand All @@ -268,7 +267,7 @@ private void generateConstantsInitializer(JNIMethod method) {
output("\tif (lpObject1 != NULL) set");
output(simpleName);
output("Fields(env, lpObject1, &lpStruct->");
output(accessor);
output(accessor.getter());
outputln(");");
output("\t}");
}
Expand Down

0 comments on commit 906aa15

Please sign in to comment.