From ac82ac9dae67f14509f7c62438350d12531ef9ca Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Mon, 22 Jan 2024 06:03:20 +0900 Subject: [PATCH 1/3] [osx] fix memory usage for global constants structure --- .../vavix/rococoa/corefoundation/CFLib.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java b/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java index fab026c2..9289d043 100644 --- a/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java +++ b/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java @@ -14,6 +14,7 @@ import com.sun.jna.Callback; import com.sun.jna.CallbackReference; import com.sun.jna.Library; +import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.NativeLibrary; import com.sun.jna.NativeLong; @@ -87,14 +88,23 @@ public interface EqualCallback extends Callback { public CopyDescriptionCallback copyDescription; public EqualCallback equal; + Memory memory; + + public CFArrayCallBacks() { + setAutoWrite(false); + memory = new Memory(8 * 5); + useMemory(memory); + } + public CFArrayCallBacks(Pointer p) { - super(p); + this(); version = getPointer().getNativeLong(0); retain = (RetqinCallback) CallbackReference.getCallback(RetqinCallback.class, p.getPointer(0x08)); release = (ReleaseCallback) CallbackReference.getCallback(ReleaseCallback.class, p.getPointer(0x10)); copyDescription = (CopyDescriptionCallback) CallbackReference.getCallback(CopyDescriptionCallback.class, p.getPointer(0x18)); equal = (EqualCallback) CallbackReference.getCallback(EqualCallback.class, p.getPointer(0x20)); - log.fine(this.toString()); + write(); +log.fine(this.toString()); } @Override @@ -103,8 +113,7 @@ protected List getFieldOrder() { } } - CFArrayCallBacks kCFTypeArrayCallBacks = new CFArrayCallBacks(NATIVE_LIBRARY - .getGlobalVariableAddress("kCFTypeArrayCallBacks")); + CFArrayCallBacks kCFTypeArrayCallBacks = new CFArrayCallBacks(NATIVE_LIBRARY.getGlobalVariableAddress("kCFTypeArrayCallBacks")); /** Creates a new immutable array with the given values. */ CFArray CFArrayCreate(CFAllocator allocator, Pointer[] values, CFIndex numValues, CFArrayCallBacks callBacks); @@ -324,20 +333,24 @@ interface CFDictionaryApplierFunction extends Callback { class CFDictionaryKeyCallBacks extends Structure { - public NativeLong version; + public CFIndex version; public CFDictionaryRetainCallBack retain; public CFDictionaryReleaseCallBack release; public CFDictionaryCopyDescriptionCallBack copyDescription; public CFDictionaryEqualCallBack equal; public CFDictionaryHashCallBack hash; + Memory memory; + public CFDictionaryKeyCallBacks() { + setAutoWrite(false); + memory = new Memory(8 * 6); + useMemory(memory); } public CFDictionaryKeyCallBacks(Pointer p) { - super(p); - - version = getPointer().getNativeLong(0); + this(); + version = CFIndex.of(p.getNativeLong(0)); retain = (CFDictionaryRetainCallBack) CallbackReference.getCallback(CFDictionaryRetainCallBack.class, p.getPointer(0x08)); release = (CFDictionaryReleaseCallBack) CallbackReference.getCallback(CFDictionaryReleaseCallBack.class, p.getPointer(0x10)); copyDescription = (CFDictionaryCopyDescriptionCallBack) CallbackReference.getCallback(CFDictionaryCopyDescriptionCallBack.class, p.getPointer(0x18)); @@ -394,19 +407,23 @@ protected List getFieldOrder() { class CFDictionaryValueCallBacks extends Structure { - public NativeLong version; + public CFIndex version; public CFDictionaryRetainCallBack retain; public CFDictionaryReleaseCallBack release; public CFDictionaryCopyDescriptionCallBack copyDescription; public CFDictionaryEqualCallBack equal; + Memory memory; + public CFDictionaryValueCallBacks() { + setAutoWrite(false); + memory = new Memory(8 * 5); + useMemory(memory); } public CFDictionaryValueCallBacks(Pointer p) { - super(p); - - version = getPointer().getNativeLong(0); + this(); + version = CFIndex.of(p.getNativeLong(0)); retain = (CFDictionaryRetainCallBack) CallbackReference.getCallback(CFDictionaryRetainCallBack.class, p.getPointer(0x08)); release = (CFDictionaryReleaseCallBack) CallbackReference.getCallback(CFDictionaryReleaseCallBack.class, p.getPointer(0x10)); copyDescription = (CFDictionaryCopyDescriptionCallBack) CallbackReference.getCallback(CFDictionaryCopyDescriptionCallBack.class, p.getPointer(0x18)); From 10e9eeda665225842055113cf28e26140e644109 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Mon, 22 Jan 2024 06:03:35 +0900 Subject: [PATCH 2/3] clean up --- .../vavix/rococoa/corefoundation/CFLib.java | 98 +++---------------- 1 file changed, 13 insertions(+), 85 deletions(-) diff --git a/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java b/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java index 9289d043..58570d2a 100644 --- a/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java +++ b/plugins/OSX/src/main/java/vavix/rococoa/corefoundation/CFLib.java @@ -70,18 +70,23 @@ public interface CFLib extends Library { //#region CFArray class CFArrayCallBacks extends Structure { + public interface RetqinCallback extends Callback { void fn(Pointer a, Pointer b); } + public interface ReleaseCallback extends Callback { void fn(Pointer a, Pointer b); } + public interface CopyDescriptionCallback extends Callback { Pointer fn(Pointer a); } + public interface EqualCallback extends Callback { boolean fn(Pointer a, Pointer b); } + public NativeLong version; public RetqinCallback retain; public ReleaseCallback release; @@ -299,6 +304,9 @@ interface CFNumberType { //#region CFDictionary + // https://opensource.apple.com/source/CF/CF-635/CFDictionary.h.auto.html + // https://github.com/code-orchestra/code-orchestra-core/blob/master/core/actionScript/source/com/semaphore/jna/cf/CFLibrary.java + interface CFDictionaryRetainCallBack extends Callback { Pointer invoke(CFAllocator allocator, CFType value); @@ -356,47 +364,7 @@ public CFDictionaryKeyCallBacks(Pointer p) { copyDescription = (CFDictionaryCopyDescriptionCallBack) CallbackReference.getCallback(CFDictionaryCopyDescriptionCallBack.class, p.getPointer(0x18)); equal = (CFDictionaryEqualCallBack) CallbackReference.getCallback(CFDictionaryEqualCallBack.class, p.getPointer(0x20)); hash = (CFDictionaryHashCallBack) CallbackReference.getCallback(CFDictionaryHashCallBack.class, p.getPointer(0x28)); - } - - public CFDictionaryKeyCallBacks(NativeLong version, CFDictionaryRetainCallBack retain, CFDictionaryReleaseCallBack release, CFDictionaryCopyDescriptionCallBack copyDescription, CFDictionaryEqualCallBack equal, CFDictionaryHashCallBack hash) { - this.version = version; - this.retain = retain; - this.release = release; - this.copyDescription = copyDescription; - this.equal = equal; - this.hash = hash; - } - - protected ByReference newByReference() { - ByReference s = new ByReference(); - s.useMemory(getPointer()); write(); - s.read(); - return s; - } - - protected ByValue newByValue() { - ByValue s = new ByValue(); - s.useMemory(getPointer()); - write(); - s.read(); - return s; - } - - protected CFDictionaryKeyCallBacks newInstance() { - CFDictionaryKeyCallBacks s = new CFDictionaryKeyCallBacks(); - s.useMemory(getPointer()); - write(); - s.read(); - return s; - } - - public static class ByReference extends CFDictionaryKeyCallBacks implements Structure.ByReference { - - } - - public static class ByValue extends CFDictionaryKeyCallBacks implements Structure.ByValue { - } @Override @@ -428,47 +396,7 @@ public CFDictionaryValueCallBacks(Pointer p) { release = (CFDictionaryReleaseCallBack) CallbackReference.getCallback(CFDictionaryReleaseCallBack.class, p.getPointer(0x10)); copyDescription = (CFDictionaryCopyDescriptionCallBack) CallbackReference.getCallback(CFDictionaryCopyDescriptionCallBack.class, p.getPointer(0x18)); equal = (CFDictionaryEqualCallBack) CallbackReference.getCallback(CFDictionaryEqualCallBack.class, p.getPointer(0x20)); - } - - public CFDictionaryValueCallBacks(NativeLong version, CFDictionaryRetainCallBack retain, CFDictionaryReleaseCallBack release, CFDictionaryCopyDescriptionCallBack copyDescription, CFDictionaryEqualCallBack equal) { - super(); - this.version = version; - this.retain = retain; - this.release = release; - this.copyDescription = copyDescription; - this.equal = equal; - } - - protected ByReference newByReference() { - ByReference s = new ByReference(); - s.useMemory(getPointer()); write(); - s.read(); - return s; - } - - protected ByValue newByValue() { - ByValue s = new ByValue(); - s.useMemory(getPointer()); - write(); - s.read(); - return s; - } - - protected CFDictionaryValueCallBacks newInstance() { - CFDictionaryValueCallBacks s = new CFDictionaryValueCallBacks(); - s.useMemory(getPointer()); - write(); - s.read(); - return s; - } - - public static class ByReference extends CFDictionaryValueCallBacks implements Structure.ByReference { - - } - - public static class ByValue extends CFDictionaryValueCallBacks implements Structure.ByValue { - } @Override @@ -479,15 +407,17 @@ protected List getFieldOrder() { CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks = new CFDictionaryKeyCallBacks(NATIVE_LIBRARY.getGlobalVariableAddress("kCFTypeDictionaryKeyCallBacks")); + CFDictionaryKeyCallBacks kCFCopyStringDictionaryKeyCallBacks = new CFDictionaryKeyCallBacks(NATIVE_LIBRARY.getGlobalVariableAddress("kCFCopyStringDictionaryKeyCallBacks")); + CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks = new CFDictionaryValueCallBacks(NATIVE_LIBRARY.getGlobalVariableAddress("kCFTypeDictionaryValueCallBacks")); - CFDictionary CFDictionaryCreate(CFAllocator allocator, CFString[] keys, CFType[] values, NativeLong numValues, CFDictionaryKeyCallBacks keyCallBacks, CFDictionaryValueCallBacks valueCallBacks); + CFDictionary CFDictionaryCreate(CFAllocator allocator, CFString[] keys, CFType[] values, CFIndex numValues, CFDictionaryKeyCallBacks keyCallBacks, CFDictionaryValueCallBacks valueCallBacks); CFDictionary CFDictionaryCreateCopy(CFAllocator allocator, CFDictionary theDict); - CFDictionary CFDictionaryCreateMutable(CFAllocator allocator, NativeLong capacity, CFDictionaryKeyCallBacks keyCallBacks, CFDictionaryValueCallBacks valueCallBacks); + CFDictionary CFDictionaryCreateMutable(CFAllocator allocator, CFIndex capacity, CFDictionaryKeyCallBacks keyCallBacks, CFDictionaryValueCallBacks valueCallBacks); - CFDictionary CFDictionaryCreateMutableCopy(CFAllocator allocator, NativeLong capacity, CFDictionary theDict); + CFDictionary CFDictionaryCreateMutableCopy(CFAllocator allocator, CFIndex capacity, CFDictionary theDict); NativeLong CFDictionaryGetCount(CFDictionary theDict); @@ -517,8 +447,6 @@ protected List getFieldOrder() { void CFDictionaryRemoveAllValues(CFDictionary theDict); - Pointer /* CFMutableDictionaryRef */ CFDictionaryCreateMutable(CFAllocator allocator, CFIndex capacity, CFDictionaryKeyCallBacks keyCallBacks, CFDictionaryValueCallBacks valueCallBacks); - //#endregion CFDictionary //#region CFDate From ac5af15c6f820ffe6ab539f1f841e65f27b04253 Mon Sep 17 00:00:00 2001 From: Naohide Sano Date: Mon, 22 Jan 2024 06:06:37 +0900 Subject: [PATCH 3/3] bump version --- coreAPI/pom.xml | 2 +- examples/pom.xml | 2 +- plugins/OSX/pom.xml | 2 +- plugins/awt/pom.xml | 2 +- plugins/linux/pom.xml | 2 +- plugins/pom.xml | 2 +- plugins/windows/pom.xml | 2 +- plugins/wintab/pom.xml | 2 +- pom.xml | 2 +- tests/pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/coreAPI/pom.xml b/coreAPI/pom.xml index 1e1d67cb..4b252665 100644 --- a/coreAPI/pom.xml +++ b/coreAPI/pom.xml @@ -5,7 +5,7 @@ net.java.jinput jinput-parent - 2.0.13v + 2.0.14v coreapi diff --git a/examples/pom.xml b/examples/pom.xml index c6f2d69b..7f161d75 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ net.java.jinput jinput-parent - 2.0.13v + 2.0.14v examples diff --git a/plugins/OSX/pom.xml b/plugins/OSX/pom.xml index bcf1ee8c..7251ff04 100644 --- a/plugins/OSX/pom.xml +++ b/plugins/OSX/pom.xml @@ -5,7 +5,7 @@ net.java.jinput plugins - 2.0.13v + 2.0.14v osx-plugin diff --git a/plugins/awt/pom.xml b/plugins/awt/pom.xml index 6ec2f0b7..23f7e8b2 100644 --- a/plugins/awt/pom.xml +++ b/plugins/awt/pom.xml @@ -5,7 +5,7 @@ net.java.jinput plugins - 2.0.13v + 2.0.14v awt-plugin diff --git a/plugins/linux/pom.xml b/plugins/linux/pom.xml index 37343930..f62ff6b8 100644 --- a/plugins/linux/pom.xml +++ b/plugins/linux/pom.xml @@ -5,7 +5,7 @@ net.java.jinput plugins - 2.0.13v + 2.0.14v linux-plugin diff --git a/plugins/pom.xml b/plugins/pom.xml index 2dd60f44..554cc110 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -5,7 +5,7 @@ net.java.jinput jinput-parent - 2.0.13v + 2.0.14v plugins diff --git a/plugins/windows/pom.xml b/plugins/windows/pom.xml index a5e52ba8..8a98433e 100644 --- a/plugins/windows/pom.xml +++ b/plugins/windows/pom.xml @@ -5,7 +5,7 @@ net.java.jinput plugins - 2.0.13v + 2.0.14v windows-plugin diff --git a/plugins/wintab/pom.xml b/plugins/wintab/pom.xml index ca965a76..251709a9 100644 --- a/plugins/wintab/pom.xml +++ b/plugins/wintab/pom.xml @@ -5,7 +5,7 @@ net.java.jinput plugins - 2.0.13v + 2.0.14v ../ diff --git a/pom.xml b/pom.xml index 5bef3f0c..fd97c67d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.java.jinput jinput-parent - 2.0.13v + 2.0.14v pom JInput diff --git a/tests/pom.xml b/tests/pom.xml index 6b47b2be..dadca73d 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -5,7 +5,7 @@ net.java.jinput jinput-parent - 2.0.13v + 2.0.14v tests