mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-23 18:08:28 +00:00
Fix out String parameters
This commit is contained in:
parent
8914faa216
commit
e9e471f785
|
@ -545,7 +545,7 @@ namespace OpenTK.Rewrite
|
||||||
{
|
{
|
||||||
foreach (var p in wrapper.Parameters)
|
foreach (var p in wrapper.Parameters)
|
||||||
{
|
{
|
||||||
if (!p.ParameterType.IsArray && p.ParameterType.Name == "String" && p.IsOut)
|
if (!p.ParameterType.IsArray && p.ParameterType.Name == "String&")
|
||||||
{
|
{
|
||||||
EmitStringOutEpilogue(wrapper, native, p, body, il, GetGeneratedVariable(generatedVariables, p.Name + "_string_ptr", body));
|
EmitStringOutEpilogue(wrapper, native, p, body, il, GetGeneratedVariable(generatedVariables, p.Name + "_string_ptr", body));
|
||||||
}
|
}
|
||||||
|
@ -587,6 +587,10 @@ namespace OpenTK.Rewrite
|
||||||
// finally {
|
// finally {
|
||||||
// Marshal.FreeHGlobal(foo_string_ptr);
|
// Marshal.FreeHGlobal(foo_string_ptr);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// Pop off the string parameter that would of just been loaded
|
||||||
|
il.Emit(OpCodes.Pop);
|
||||||
|
|
||||||
// Make sure we have imported Marshal::AllocHGlobal
|
// Make sure we have imported Marshal::AllocHGlobal
|
||||||
var alloc_hglobal = method.Module.ImportReference(TypeMarshal.Methods.First(m => m.Name == "AllocHGlobal"));
|
var alloc_hglobal = method.Module.ImportReference(TypeMarshal.Methods.First(m => m.Name == "AllocHGlobal"));
|
||||||
|
|
||||||
|
@ -621,11 +625,18 @@ namespace OpenTK.Rewrite
|
||||||
}
|
}
|
||||||
else if (count.Computed != null)
|
else if (count.Computed != null)
|
||||||
{
|
{
|
||||||
// We don't handle count.Computed. Computed counts are hard and
|
if (method.Name == "GetActiveVarying")
|
||||||
// require manual reading of the specification for each one.
|
{
|
||||||
// But currently no string out parameters require it.
|
// GetActiveVaryingNV's name parameter has a count of "COMPSIZE(program,index,bufSize)" but really it should be bufSize.
|
||||||
|
var countVariable = EmitCountVariable(method, body, il, "bufSize");
|
||||||
|
il.Emit(OpCodes.Ldloc, countVariable.Index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Computed counts are hard and require manual reading of the specification for each one.
|
||||||
throw new NotSupportedException(string.Format("{0}({1}) requires a computed count: {2}", method.Name, parameter.Name, count.Computed));
|
throw new NotSupportedException(string.Format("{0}({1}) requires a computed count: {2}", method.Name, parameter.Name, count.Computed));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
il.Emit(OpCodes.Ldc_I4, 1);
|
il.Emit(OpCodes.Ldc_I4, 1);
|
||||||
il.Emit(OpCodes.Add);
|
il.Emit(OpCodes.Add);
|
||||||
|
@ -665,10 +676,10 @@ namespace OpenTK.Rewrite
|
||||||
var block = new ExceptionHandler(ExceptionHandlerType.Finally);
|
var block = new ExceptionHandler(ExceptionHandlerType.Finally);
|
||||||
block.TryStart = body.Instructions[0];
|
block.TryStart = body.Instructions[0];
|
||||||
|
|
||||||
il.Emit(OpCodes.Ldloc, generatedPtrVar.Definition.Index);
|
|
||||||
il.Emit(OpCodes.Ldarg, parameter.Index);
|
il.Emit(OpCodes.Ldarg, parameter.Index);
|
||||||
|
il.Emit(OpCodes.Ldloc, generatedPtrVar.Definition.Index);
|
||||||
il.Emit(OpCodes.Call, ptr_to_str);
|
il.Emit(OpCodes.Call, ptr_to_str);
|
||||||
il.Emit(OpCodes.Starg, parameter.Index);
|
il.Emit(OpCodes.Stind_Ref);
|
||||||
|
|
||||||
block.TryEnd = body.Instructions.Last();
|
block.TryEnd = body.Instructions.Last();
|
||||||
block.HandlerStart = body.Instructions.Last();
|
block.HandlerStart = body.Instructions.Last();
|
||||||
|
@ -907,7 +918,7 @@ namespace OpenTK.Rewrite
|
||||||
// We need to convert the loaded argument to IntPtr.
|
// We need to convert the loaded argument to IntPtr.
|
||||||
il.Emit(OpCodes.Conv_I);
|
il.Emit(OpCodes.Conv_I);
|
||||||
}
|
}
|
||||||
else if (p.Name == "String" && !p.IsArray && parameter.IsOut)
|
else if (p.Name == "String&" && !p.IsArray)
|
||||||
{
|
{
|
||||||
generatedVariables.Add(EmitStringOutParameter(method, parameter, body, il));
|
generatedVariables.Add(EmitStringOutParameter(method, parameter, body, il));
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace OpenTK
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
sbyte* str = (sbyte*)ptr.ToPointer();
|
sbyte* str = (sbyte*)ptr;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while (*str != 0)
|
while (*str != 0)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +93,7 @@ namespace OpenTK
|
||||||
++str;
|
++str;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new string(str, 0, len, null);
|
return new string((sbyte*)ptr, 0, len, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue