Skip to content

Invalid generated code from libX11 #360

Closed
@Beyley

Description

@Beyley

running ClangSharpPInvokeGenerator -x c -l X11 -o output/ -n Silk.NET.X11 -f Xlib.h -f Xutil.h -f XKBlib.h -f Xlib-xcb.h -f Xcms.h -I /opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/14.0.6/include/ -c multi-file -c compatible-codegen -c generate-helper-types on the commit 9a90b3a63d02da92dc8692ed3f6269d3e0c7c8cc in libX11 produces code which contains invalid c# such as

        [FieldOffset(0)]
        [NativeTypeName("XEvent")]
        public union _XEvent core;

        [DllImport("X11", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
        public static extern int XIfEvent([NativeTypeName("Display *")] _XDisplay* param0, [NativeTypeName("XEvent *")] union _XEvent* param1, [NativeTypeName("int (*)(Display *, XEvent *, XPointer)")] delegate* unmanaged[Cdecl]<_XDisplay*, union _XEvent*, sbyte*, int> param2, [NativeTypeName("XPointer")] sbyte* param3);

(see the nonsense union keyword)

Also even with the compatible-codegen flag it generates code that uses functions only available in net standard 2.1

public Span<nint> AsSpan() => MemoryMarshal.CreateSpan(ref e0, 24);

Most notably it seems to skip over or not see certain structs, while still generating functions that need them

        [DllImport("X11", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
        public static extern int XkbAllocCompatMap([NativeTypeName("XkbDescPtr")] _XkbDesc* param0, [NativeTypeName("unsigned int")] uint param1, [NativeTypeName("unsigned int")] uint param2);

        [DllImport("X11", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
        public static extern void XkbFreeCompatMap([NativeTypeName("XkbDescPtr")] _XkbDesc* param0, [NativeTypeName("unsigned int")] uint param1, int param2);

_XkbDesc isnt generated here, causing it to not compile

The output of the generator is

Processing 'Xlib.h'
Processing 'Xutil.h'
Processing 'XKBlib.h'
Processing 'Xlib-xcb.h'
Processing 'Xcms.h'
Diagnostics for binding generation of Xcms.h:
    Warning (Line 3578, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3583, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3596, Column 12 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3609, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3614, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3847, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3851, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3863, Column 12 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3891, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3895, Column 14 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.
    Warning (Line 3935, Column 22 in Xlib.h): Unsupported attribute: 'Sentinel'. Generated bindings may be incomplete.

I put the generated code in a repository here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions