@Test public void testForeignNull() throws Exception { Dao<Foreign, Integer> dao = createDao(Foreign.class, true); Foreign foreign = new Foreign(); foreign.foo = null; assertEquals(1, dao.create(foreign)); Foreign foreign2 = dao.queryForId(foreign.id); assertNotNull(foreign2); assertNull(foreign2.foo); }
@Override public void freePages(long address, int pageCount) { Foreign.VirtualFree(address, 0, Foreign.MEM_RELEASE); }
/** * Allocates native memory. * * @param size The number of bytes of memory to allocate * @param clear Whether the memory should be cleared (each byte set to zero). * @return The native address of the allocated memory. */ public final long allocateMemory(long size, boolean clear) { return Foreign.allocateMemory(size, clear) & ADDRESS_MASK; }
/** * Gets the address of a symbol within the <tt>Library</tt>. * * @param name The name of the symbol to locate. * @return The address of the symbol within the current address space. */ public final long getSymbolAddress(String name) { try { return foreign.dlsym(handle, name); } catch (UnsatisfiedLinkError ex) { lastError.set(foreign.dlerror()); return 0; } }
private static InstanceHolder getInstanceHolder() { try { Init.load(); Foreign foreign = new Foreign(); if ((foreign.getVersion() & 0xffff00) != (VERSION_MAJOR << 16 | VERSION_MINOR << 8)) { String msg = String.format("incorrect native library version %d.%d, expected %d.%d", (foreign.getVersion() >> 16 & 0xff), (foreign.getVersion() >> 8 & 0xff), VERSION_MAJOR, VERSION_MINOR); return new InValidInstanceHolder(new UnsatisfiedLinkError(msg)); } foreign.init(); return new ValidInstanceHolder(foreign); } catch (Throwable throwable) { return new InValidInstanceHolder(throwable); } }
Magazine(CallContext ctx) { this.ctx = ctx; this.magazine = foreign.newClosureMagazine(ctx.getAddress(), Proxy.METHOD, false); ArrayList<Slot> slots = new ArrayList<Slot>(); for (;;) { long h; Proxy proxy = new Proxy(ctx); if ((h = foreign.closureMagazineGet(magazine, proxy)) == 0) { break; } Slot s = new Slot(h, proxy); slots.add(s); } this.slots = new Slot[slots.size()]; slots.toArray(this.slots); next = 0; freeCount = this.slots.length; }
public Closure.Handle allocate(Object proxy) { long closureAddress = foreign.closureMagazineGet(magazineAddress, proxy); return closureAddress != 0L ? new Handle(this, closureAddress, MemoryIO.getInstance().getAddress(closureAddress)) : null; }
@Override protected void finalize() throws Throwable { try { if (handle != 0L) { foreign.dlclose(handle); } } finally { super.finalize(); } } }
@Override public void protectPages(long address, int pageCount, int protection) { Foreign.VirtualProtect(address, (int) pageSize() * pageCount, w32prot(protection)); }
public final void _copyMemory(long src, long dst, long size) { Foreign.copyMemoryChecked(src, dst, size); } public final long getAddress(long address) {
public final void _copyMemory(long src, long dst, long size) { Foreign.copyMemory(src, dst, size); } public final void memcpy(long dst, long src, long size) {
@Override public long allocatePages(int pageCount, int protection) { return Foreign.VirtualAlloc(0, (int) pageSize() * pageCount, Foreign.MEM_COMMIT | Foreign.MEM_RESERVE, w32prot(protection)); }
private static InstanceHolder getInstanceHolder() { try { Init.load(); Foreign foreign = new Foreign(); if ((foreign.getVersion() & 0xffff00) != (VERSION_MAJOR << 16 | VERSION_MINOR << 8)) { String msg = String.format("incorrect native library version %d.%d, expected %d.%d", (foreign.getVersion() >> 16 & 0xff), (foreign.getVersion() >> 8 & 0xff), VERSION_MAJOR, VERSION_MINOR); return new InValidInstanceHolder(new UnsatisfiedLinkError(msg)); } foreign.init(); return new ValidInstanceHolder(foreign); } catch (Throwable throwable) { return new InValidInstanceHolder(throwable); } }
/** * Gets the address of a symbol within the <tt>Library</tt>. * * @param name The name of the symbol to locate. * @return The address of the symbol within the current address space. */ public final long getSymbolAddress(String name) { try { return foreign.dlsym(handle, name); } catch (UnsatisfiedLinkError ex) { lastError.set(foreign.dlerror()); return 0; } }
Magazine(CallContext ctx) { this.ctx = ctx; this.magazine = foreign.newClosureMagazine(ctx.getAddress(), Proxy.METHOD, false); ArrayList<Slot> slots = new ArrayList<Slot>(); for (;;) { long h; Proxy proxy = new Proxy(ctx); if ((h = foreign.closureMagazineGet(magazine, proxy)) == 0) { break; } Slot s = new Slot(h, proxy); slots.add(s); } this.slots = new Slot[slots.size()]; slots.toArray(this.slots); next = 0; freeCount = this.slots.length; }
public Closure.Handle allocate(Object proxy) { long closureAddress = foreign.closureMagazineGet(magazineAddress, proxy); return closureAddress != 0L ? new Handle(this, closureAddress, MemoryIO.getInstance().getAddress(closureAddress)) : null; }
@Override protected void finalize() throws Throwable { try { if (handle != 0L) { foreign.dlclose(handle); } } finally { super.finalize(); } } }
@Override public void protectPages(long address, int pageCount, int protection) { Foreign.VirtualProtect(address, (int) pageSize() * pageCount, w32prot(protection)); }
public final void _copyMemory(long src, long dst, long size) { Foreign.copyMemoryChecked(src, dst, size); } public final long getAddress(long address) {
public final void _copyMemory(long src, long dst, long size) { Foreign.copyMemory(src, dst, size); } public final void memcpy(long dst, long src, long size) {