Skip to content

Commit 3e2873e

Browse files
committed
BridJ: Add BRIDJ_WARN_STRUCT_FIELDS=0 / -Dbridj.warnStructFields=false to mute obnoxious warning
1 parent 97a0763 commit 3e2873e

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

libraries/BridJ/src/main/java/org/bridj/BridJ.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ enum Switch {
403403
"Align doubles on 8 bytes boundaries even on Linux 32 bits (see -malign-double GCC option)."),
404404
LogCalls("bridj.logCalls", "BRIDJ_LOG_CALLS", false,
405405
"Log each native call performed (or call from native to Java callback)"),
406+
WarnStructFields("bridj.warnStructFields", "BRIDJ_WARN_STRUCT_FIELDS", true,
407+
"Warn when struct fields are implemented with Java fields instead of methods")
406408
Protected("bridj.protected", "BRIDJ_PROTECTED", false,
407409
"Protect all native calls (including memory accesses) against native crashes (disables assembly optimizations and adds quite some overhead)."),
408410
Destructors("bridj.destructors", "BRIDJ_DESTRUCTORS", true,
@@ -498,6 +500,7 @@ static void checkOptions() {
498500
public static final boolean verbose = debug || veryVerbose || Switch.Verbose.enabled;
499501
public static final boolean quiet = Switch.Quiet.enabled;
500502
public static final boolean logCalls = Switch.LogCalls.enabled;
503+
public static final boolean warnStructFields = Switch.LogCalls.enabled;
501504
public static final boolean protectedMode = Switch.Protected.enabled;
502505
public static final boolean enableDestructors = Switch.Destructors.enabled;
503506
public static final boolean alignDoubles = Switch.AlignDouble.enabled;

libraries/BridJ/src/main/java/org/bridj/StructFieldDeclaration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ protected static List<StructFieldDeclaration> listFields(Class<?> structClass) {
102102
}
103103
}
104104
}
105-
if (nFieldFields > 0) {
106-
BridJ.warning("Struct " + structClass.getName() + " has " + nFieldFields + " struct fields implemented as Java fields, which won't give the best performance and might require counter-intuitive calls to BridJ.readFromNative / .writeToNative. Please consider using JNAerator to generate your struct instead.");
105+
if (nFieldFields > 0 && BridJ.warnStructFields) {
106+
BridJ.warning("Struct " + structClass.getName() + " has " + nFieldFields + " struct fields implemented as Java fields, which won't give the best performance and might require counter-intuitive calls to BridJ.readFromNative / .writeToNative. Please consider using JNAerator to generate your struct instead, or use BRIDJ_WARN_STRUCT_FIELDS=0 or -Dbridj.warnStructFields=false to mute this warning.");
107107
}
108108

109109
return list;

0 commit comments

Comments
 (0)