@Test public void testStructSizes() { if (!BridJ.Switch.StructsByValue.enabled) return; StructIO io = StructIO.getInstance(SimpleStruct.class); Pointer<DCstruct> struct = DyncallStructs.buildDCstruct(io.desc); assertNotNull(struct); }
public ValueType getValueType( int iParam, int nParams, Class<?> c, Type t, AnnotatedElement element, Annotation... directAnnotations) { boolean isPtr = isAnnotationPresent(Ptr.class, element, directAnnotations); boolean isCLong = isAnnotationPresent(org.bridj.ann.CLong.class, element, directAnnotations); Constructor cons = getAnnotation(Constructor.class, element, directAnnotations); if (isPtr || cons != null || isCLong) { if (!(c == Long.class || c == Long.TYPE)) throw new RuntimeException( "Annotation should only be used on a long parameter, not on a " + c.getName()); if (isPtr) { if (!Platform.is64Bits()) direct = false; } else if (isCLong) { if (Platform.CLONG_SIZE != 8) direct = false; } else if (cons != null) { isCPlusPlus = true; startsWithThis = true; if (iParam != 0) throw new RuntimeException( "Annotation " + Constructor.class.getName() + " cannot have more than one (long) argument"); } return ValueType.eSizeTValue; } if (c == null || c.equals(Void.TYPE)) return ValueType.eVoidValue; if (c == Integer.class || c == Integer.TYPE) return ValueType.eIntValue; if (c == Long.class || c == Long.TYPE) { return !isPtr || Platform.is64Bits() ? ValueType.eLongValue : ValueType.eIntValue; } if (c == Short.class || c == Short.TYPE) return ValueType.eShortValue; if (c == Byte.class || c == Byte.TYPE) return ValueType.eByteValue; if (c == Boolean.class || c == Boolean.TYPE) return ValueType.eBooleanValue; if (c == Float.class || c == Float.TYPE) { usesFloats(); return ValueType.eFloatValue; } if (c == char.class || c == Character.TYPE) { if (Platform.WCHAR_T_SIZE != 2) direct = false; return ValueType.eWCharValue; } if (c == Double.class || c == Double.TYPE) { usesFloats(); return ValueType.eDoubleValue; } if (c == CLong.class) { direct = false; return ValueType.eCLongObjectValue; } if (c == SizeT.class) { direct = false; return ValueType.eSizeTObjectValue; } if (c == TimeT.class) { direct = false; return ValueType.eTimeTObjectValue; } if (Pointer.class.isAssignableFrom(c)) { direct = false; CallIO cio = CallIO.Utils.createPointerCallIO(c, t); if (BridJ.veryVerbose) BridJ.info("CallIO : " + cio); addCallIO(cio); return ValueType.ePointerValue; } if (c.isArray() && iParam == nParams - 1) { direct = false; return ValueType.eEllipsis; } if (ValuedEnum.class.isAssignableFrom(c)) { direct = false; CallIO cio = CallIO.Utils.createValuedEnumCallIO( (Class) Utils.getClass(Utils.getUniqueParameterizedTypeParameter(t))); if (BridJ.veryVerbose) BridJ.info("CallIO : " + cio); addCallIO(cio); return ValueType.eIntFlagSet; } if (NativeObject.class.isAssignableFrom(c)) { Pointer<DCstruct> pStruct = null; if (StructObject.class.isAssignableFrom(c)) { StructIO io = StructIO.getInstance(c, t); try { pStruct = DyncallStructs.buildDCstruct(io.desc); } catch (Throwable th) { BridJ.error( "Unable to create low-level struct metadata for " + Utils.toString(t) + " : won't be able to use it as a by-value function argument.", th); } } addCallIO(new CallIO.NativeObjectHandler((Class<? extends NativeObject>) c, t, pStruct)); direct = false; return ValueType.eNativeObjectValue; } throw new NoSuchElementException( "No " + ValueType.class.getSimpleName() + " for class " + c.getName()); }