Skip to content

Commit

Permalink
Make NativeLibrary#encoding final, #options and #callFlags private
Browse files Browse the repository at this point in the history
Reported by: @sebbASF
Closes: #1560
  • Loading branch information
matthiasblaesing committed Dec 4, 2023
1 parent 3656295 commit 458adcf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/com/sun/jna/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static Function getFunction(Pointer p, int callFlags, String encoding) {
this.library = library;
this.functionName = functionName;
this.callFlags = callFlags;
this.options = library.options;
this.options = library.getOptions();
this.encoding = encoding != null ? encoding : Native.getDefaultStringEncoding();
try {
this.peer = library.getSymbolAddress(functionName);
Expand Down
14 changes: 8 additions & 6 deletions src/com/sun/jna/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public long getSymbolAddress(long handle, String name, SymbolProvider parent) {
private final String libraryPath;
private final Map<String, Function> functions = new HashMap<>();
private final SymbolProvider symbolProvider;
final int callFlags;
private String encoding;
final Map<String, ?> options;
private final int callFlags;
private final String encoding;
private final Map<String, ?> options;

private static final Map<String, Reference<NativeLibrary>> libraries = new HashMap<>();

Expand All @@ -120,6 +120,7 @@ private static String functionKey(String name, int flags, String encoding) {
return name + "|" + flags + "|" + encoding;
}

@SuppressWarnings("LeakingThisInConstructor")
private NativeLibrary(String libraryName, String libraryPath, long handle, Map<String, ?> options) {
this.libraryName = getLibraryName(libraryName);
this.libraryPath = libraryPath;
Expand All @@ -129,17 +130,18 @@ private NativeLibrary(String libraryName, String libraryPath, long handle, Map<S
int callingConvention = option instanceof Number ? ((Number)option).intValue() : Function.C_CONVENTION;
this.callFlags = callingConvention;
this.options = options;
this.encoding = (String)options.get(Library.OPTION_STRING_ENCODING);
SymbolProvider optionSymbolProvider = (SymbolProvider)options.get(Library.OPTION_SYMBOL_PROVIDER);
if (optionSymbolProvider == null) {
this.symbolProvider = NATIVE_SYMBOL_PROVIDER;
} else {
this.symbolProvider = optionSymbolProvider;
}

if (this.encoding == null) {
this.encoding = Native.getDefaultStringEncoding();
String encodingValue = (String) options.get(Library.OPTION_STRING_ENCODING);
if (encodingValue == null) {
encodingValue = Native.getDefaultStringEncoding();
}
this.encoding = encodingValue;

// Special workaround for w32 kernel32.GetLastError
// Short-circuit the function to use built-in GetLastError access
Expand Down

0 comments on commit 458adcf

Please sign in to comment.