|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | + |
| 26 | +// Generated by jextract |
| 27 | + |
| 28 | +package jdk.internal.ffi.generated.errno; |
| 29 | + |
| 30 | +import java.lang.foreign.*; |
| 31 | +import java.lang.invoke.*; |
| 32 | +import java.util.*; |
| 33 | +import java.util.stream.*; |
| 34 | + |
| 35 | +import static java.lang.foreign.ValueLayout.*; |
| 36 | + |
| 37 | +@SuppressWarnings("restricted") |
| 38 | +public class errno_h$shared { |
| 39 | + |
| 40 | + errno_h$shared() { |
| 41 | + // Should not be called directly |
| 42 | + } |
| 43 | + |
| 44 | + public static final OfBoolean C_BOOL = (OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool"); |
| 45 | + public static final OfByte C_CHAR =(OfByte)Linker.nativeLinker().canonicalLayouts().get("char"); |
| 46 | + public static final OfShort C_SHORT = (OfShort) Linker.nativeLinker().canonicalLayouts().get("short"); |
| 47 | + public static final OfInt C_INT = (OfInt) Linker.nativeLinker().canonicalLayouts().get("int"); |
| 48 | + public static final OfLong C_LONG_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long long"); |
| 49 | + public static final OfFloat C_FLOAT = (OfFloat) Linker.nativeLinker().canonicalLayouts().get("float"); |
| 50 | + public static final OfDouble C_DOUBLE = (OfDouble) Linker.nativeLinker().canonicalLayouts().get("double"); |
| 51 | + public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*")) |
| 52 | + .withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE, C_CHAR)); |
| 53 | + public static final OfLong C_LONG = (OfLong) Linker.nativeLinker().canonicalLayouts().get("long"); |
| 54 | + |
| 55 | + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); |
| 56 | + |
| 57 | + static void traceDowncall(String name, Object... args) { |
| 58 | + String traceArgs = Arrays.stream(args) |
| 59 | + .map(Object::toString) |
| 60 | + .collect(Collectors.joining(", ")); |
| 61 | + System.out.printf("%s(%s)\n", name, traceArgs); |
| 62 | + } |
| 63 | + |
| 64 | + static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) { |
| 65 | + try { |
| 66 | + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); |
| 67 | + } catch (ReflectiveOperationException ex) { |
| 68 | + throw new AssertionError(ex); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + static MemoryLayout align(MemoryLayout layout, long align) { |
| 73 | + return switch (layout) { |
| 74 | + case PaddingLayout p -> p; |
| 75 | + case ValueLayout v -> v.withByteAlignment(align); |
| 76 | + case GroupLayout g -> { |
| 77 | + MemoryLayout[] alignedMembers = g.memberLayouts().stream() |
| 78 | + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); |
| 79 | + yield g instanceof StructLayout ? |
| 80 | + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); |
| 81 | + } |
| 82 | + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); |
| 83 | + }; |
| 84 | + } |
| 85 | +} |
0 commit comments