Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't apply --with-packing overrides to fixed buffer types #407

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

DaZombieKiller
Copy link
Contributor

Due to an oversight in #405, --with-packing on MyStruct will also apply to any nested fixed buffer types generated for its fields.

For example, the following C structure:

struct MyStruct
{
    size_t FixedBuffer[1];
};

Will currently generate the following C# code (latest-codegen):

using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;

namespace ClangSharp.Test
{
    [StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
    public partial struct MyStruct
    {
        [NativeTypeName("size_t[1]")]
        public _FixedBuffer_e__FixedBuffer FixedBuffer;

        [StructLayout(LayoutKind.Sequential, Pack = CustomPackValue)]
        public partial struct _FixedBuffer_e__FixedBuffer
        {
            public nuint e0;

            [UnscopedRef]
            public ref nuint this[int index]
            {
                get
                {
                    return ref AsSpan(int.MaxValue)[index];
                }
            }

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

This issue does not apply to fixed buffers of types supported naturally by C#, only those that require ClangSharp to generate an _e__FixedBuffer type.

Tests are covered in #406.

@tannergooding tannergooding merged commit 69391f1 into dotnet:main Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants