Mapping a type to a type of the same name causes stack overflow
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start at TypeMap.SignatureType and the calls to SignatureType(ctx).ToString() described in the issue, then trace how Type.ToString re-enters type-map handling. Reproduce the same-name MyFlags mapping and verify that printing the mapped type completes without stack overflow while retaining the desired enum parameter representation.
Written by the indexing model from the issue text.
Description
I have the following header:
typedef int MyFlags;
#define FLAG_ONE 1
#define FLAG_TWO 2
class Test {
public:
void MyMethod(MyFlags a);
};
I would like to end up with Test.MyMethod having MyFlags as a parameter instead of int.
To this end at first I var @enum = ctx.GenerateEnumFromMacros("MyFlags", "FLAG_(.*)").
I then use the following TypeMap:
[TypeMap("MyFlags")]
public class MyFlagsMap : TypeMap {
internal static TagType Type { private get; set; }
public override Type SignatureType(TypePrinterContext ctx) {
return Type;
}
}
whereas MyFlagsMap.Type = new TagType(@enum).
This results in a stack overflow on calls such as typeMap.SignatureType(ctx).ToString() (which are used at various points) as ToString on Type again goes over the type maps and calls ToString on the signature type, repeat ad infinitum.
One potential solution is adding the following method to TypeMap:
public virtual string Print(TypePrinterContext ctx)
{
return SignatureType(ctx).ToString();
}
and replacing all calls such as typeMap.SignatureType(ctx).ToString() with typeMap.Print(ctx).
However, this would require modifications on the end of the user which is not ideal. Some other way to avoid the cycles here seems preferable, but I don't see a straightforward way of achieving that atm..
P.S.: For anyone stumbling across this issue seeking to accomplish something similar to me while a fix hasn't yet been implemented:
A simple workaround is initially picking a different name for the generated enum and renaming it it in the Postprocess step.
- Dominant language
- C#
- Stars
- 3.4k
- Forks
- 541
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mono/CppSharp
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
How to get started Open
Difficulty 3/5 1-2 days Newbie friendliness 38/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100