@Override public void postInvoke(Struct[] structs, Pointer primitive, ToNativeContext context) { if (structs != null && primitive != null) { try { int off = 0; for (int i = 0; i < structs.length; i++) { structs[i] = constructor.newInstance(runtime); int structSize = align(Struct.size(structs[i]), Struct.alignment(structs[i])); structs[i].useMemory(primitive.slice(off = align(off, Struct.alignment(structs[i])), structSize)); off += structSize; } } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } } } }
@Override public void postInvoke(Struct[] structs, Pointer primitive, ToNativeContext context) { if (structs != null && primitive != null) { try { int off = 0; for (int i = 0; i < structs.length; i++) { structs[i] = constructor.newInstance(runtime); int structSize = align(Struct.size(structs[i]), Struct.alignment(structs[i])); structs[i].useMemory(primitive.slice(off = align(off, Struct.alignment(structs[i])), structSize)); off += structSize; } } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } } } }
@Override public void postInvoke(Struct[] structs, Pointer primitive, ToNativeContext context) { if (structs != null && primitive != null) { try { int off = 0; for (int i = 0; i < structs.length; i++) { structs[i] = constructor.newInstance(runtime); int structSize = align(Struct.size(structs[i]), Struct.alignment(structs[i])); structs[i].useMemory(primitive.slice(off = align(off, Struct.alignment(structs[i])), structSize)); off += structSize; } } catch (InstantiationException ie) { throw new RuntimeException(ie); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } } } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
@SuppressWarnings("unchecked") public static <T extends Struct> T[] arrayOf(Runtime runtime, Class<T> type, int length) { try { T[] array = (T[]) Array.newInstance(type, length); Constructor<T> c = type.getConstructor(Runtime.class); for (int i = 0; i < length; ++i) { array[i] = c.newInstance(runtime); } if (array.length > 0) { final int structSize = align(Struct.size(array[0]), Struct.alignment(array[0])); jnr.ffi.Pointer memory = runtime.getMemoryManager().allocateDirect(structSize * length); for (int i = 0; i < array.length; ++i) { array[i].useMemory(memory.slice(structSize * i, structSize)); } } return array; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }