Skip to content

CppSharp generates incorrect cast for const char** in struct #1930

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

Open
perlun opened this issue Apr 11, 2025 · 1 comment
Open

CppSharp generates incorrect cast for const char** in struct #1930

perlun opened this issue Apr 11, 2025 · 1 comment

Comments

@perlun
Copy link

perlun commented Apr 11, 2025

Hi,

I am using CppSharp 1.1.5.3168 and it generally works fine, given its limitations, but... there's one annoying bug where it generates the wrong return type for the following construct:

namespace perlang::collections
{
    struct StringArray {
        const char** items;
        unsigned long size;
    };
}

This causes the following C# code to be generated:

public sbyte** Items
{
    get
    {
        return (string*) ((__Internal*)__Instance)->items;
    }
}

But this will, naturally, not fly. The return (string *) part there should be return (sbyte**). If I edit the generated code like this, it works perfectly, but it's a bit annoying to have to do this every time the interop code is regenerated. 🙂

If you can point me in the right direction in the codebase, I'm happy to attempt to provide a fix for this. Thanks for a nice tool. 🙏

@tritao
Copy link
Collaborator

tritao commented Apr 11, 2025

I think it could be going through this code path: https://github.com/mono/CppSharp/blob/main/src/Generator/Generators/CSharp/CSharpMarshal.cs#L556

Best thing is build from source and get the debugger on it so you can see what code it executes for that case.

If that's the case maybe you need to change IsConstCharString so it does not detect the ** as const string, but just *.

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

No branches or pull requests

2 participants