Description
Saving methods generated by DMDEmitMethodBuilderGenerator on Mono crashes Mono due to passing empty array to DefineMethod type modifiers parameters instead of nulls
Mono crashes with * Assertion at sre-encode.c:290, condition 'count > 0' not met
MonoMod logs:
Detected runtime: Mono 6.8.0.105 using Framework corelib
Examples
var assemblyName = new AssemblyName("Example");
var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave);
var dynamicModule = assemblyBuilder.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".dll");
var typeBuilder = dynamicModule.DefineType("Test");
var dmd = new DynamicMethodDefinition("Test", typeof(void), []);
var il = dmd.GetILGenerator();
il.Emit(OpCodes.Ret);
DMDEmitMethodBuilderGenerator.GenerateMethodBuilder(dmd, typeBuilder);
typeBuilder.CreateType();
assemblyBuilder.Save("Example.dll");
Switches.SetSwitchValue("DMDType", "methodbuilder");
Switches.SetSwitchValue("DMDDumpTo", "Example");
DynamicMethodDefinition dmd = new("Test", typeof(void), []);
var il = dmd.GetILGenerator();
il.Emit(OpCodes.Ret);
dmd.Generate();
Example of working DefineMethod call
typeBuilder.DefineMethod(
"Test",
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
typeof(void), null, null, [], [], []
);
and example of crashing DefineMethod call
typeBuilder.DefineMethod(
"Test",
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
typeof(void), [], [], [], [], []
);
do note that parameter modifiers are also affected, so this works
typeBuilder.DefineMethod(
"Test",
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
typeof(void),
null, null,
[typeof(int)], /* parameter types */
[null], [null]
);
and this crashes
typeBuilder.DefineMethod(
"Test",
MethodAttributes.Public | MethodAttributes.Static,
CallingConventions.Standard,
typeof(void),
null, null,
[typeof(int)], /* parameter types */
[[]], [[]]
);
Fix suggestion
I suggest making _DMDEmit.ResolveWithModifiers return nulls instead of empty arrays on Mono
Description
Saving methods generated by
DMDEmitMethodBuilderGeneratoron Mono crashes Mono due to passing empty array toDefineMethodtype modifiers parameters instead of nullsMono crashes with
* Assertion at sre-encode.c:290, condition 'count > 0' not metMonoMod logs:
Examples
Example of working DefineMethod call
and example of crashing DefineMethod call
do note that parameter modifiers are also affected, so this works
and this crashes
Fix suggestion
I suggest making
_DMDEmit.ResolveWithModifiersreturn nulls instead of empty arrays on Mono