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

Fix support for constant arrays of void* #221

Open
PathogenDavid opened this issue Oct 21, 2021 · 1 comment
Open

Fix support for constant arrays of void* #221

PathogenDavid opened this issue Oct 21, 2021 · 1 comment
Labels
Bug Concept-OutputUsability Issues concerning whether or not the output from Biohazrd is actually usable EdgeCase Language-C# Issues specific to C#

Comments

@PathogenDavid
Copy link
Member

Right now constant arrays of void* tries to emit an array helper with the following enumerator:

public ConstantArrayOfPointersEnumerator<void> GetEnumerator()
    => new ConstantArrayOfPointersEnumerator<void>(Element0Pointer, 2000);

This isn't valid since void cannot be a generic type argument. We need to special-case void* arrays.

@PathogenDavid PathogenDavid added Bug Concept-OutputUsability Issues concerning whether or not the output from Biohazrd is actually usable EdgeCase labels Oct 21, 2021
@PathogenDavid PathogenDavid added this to High in Prioritization Oct 21, 2021
@PathogenDavid PathogenDavid added the Language-C# Issues specific to C# label Oct 21, 2021
@PathogenDavid
Copy link
Member Author

PathogenDavid commented Oct 21, 2021

Workaround transformation to rewrite the constant arrays to byte*[] arrays:

using Biohazrd;
using Biohazrd.CSharp;
using Biohazrd.Transformation;

namespace Mochi.MuJoCo.Generator
{
    // This is a workaround for https://github.com/InfectedLibraries/Biohazrd/issues/221
    internal sealed class __WorkaroundBiohazrd221Transformation : CSharpTransformationBase
    {
        protected override TransformationResult TransformConstantArrayType(TransformationContext context, ConstantArrayTypeDeclaration declaration)
        {
            if (declaration.Type == VoidTypeReference.PointerInstance)
            {
                return declaration with { Type = new PointerTypeReference(CSharpBuiltinType.Byte) };
            }
            else
            { return declaration; }
        }
    }
}

(Note: This doesn't properly handle void** and other levels of indirection.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Concept-OutputUsability Issues concerning whether or not the output from Biohazrd is actually usable EdgeCase Language-C# Issues specific to C#
Projects
Development

No branches or pull requests

1 participant