Skip to content

Namespace for Unsafe is not imported in the generated code #609

@rlaf99

Description

@rlaf99

clangsharppinvokegenerator --version

ClangSharp P/Invoke Binding Generator version 20.1.2
  clang version 20.1.2 (https://github.com/llvm/llvm-project 58df0ef89dd64126512e4ee27b4ac3fd8ddf6247)
  clangsharp version 20.1.2

When generating for the following code from (https://github.com/libgit2/libgit2/blob/5ab90d3c273766c81fefb7d156574a87c0f9fb01/include/git2/sys/credential.h#L40C1-L43C3)

struct git_credential_username {
	git_credential parent; /**< The parent credential */
	char username[1];      /**< The username to authenticate as */
};

The generated code is like

...
        [NativeTypeName("char[1]")]
        public _username_e__FixedBuffer username;

        public partial struct _username_e__FixedBuffer
        {
            public sbyte e0;

            [UnscopedRef]
            public ref sbyte this[int index]
            {
                get
                {
                    return ref Unsafe.Add(ref e0, index);
                }
            }

            [UnscopedRef]
            public Span<sbyte> AsSpan(int length) => MemoryMarshal.CreateSpan(ref e0, length);
        }

However, System.Runtime.CompilerServices, the namespace that contains Unsafe, is not imported in the generated code.

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