Browse Source

Fixed CLI marshaling of in/out parameters under some cases.

Closes pull #269.
pull/269/merge
triton 11 years ago
parent
commit
5a27285f65
  1. 7
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 39
      src/Generator/Generators/CLI/CLISourcesTemplate.cs

7
src/Generator/Generators/CLI/CLIMarshal.cs

@ -451,9 +451,12 @@ namespace CppSharp.Generators.CLI @@ -451,9 +451,12 @@ namespace CppSharp.Generators.CLI
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
Context.Parameter.Usage == ParameterUsage.InOut;
ArgumentPrefix.Write("&");
Context.Return.Write("(::{0})*{1}", @enum.QualifiedOriginalName,
Context.Parameter.Name);
Context.Return.Write("(::{0}){1}{2}", @enum.QualifiedOriginalName,
isRef ? string.Empty : "*", Context.Parameter.Name);
return true;
}

39
src/Generator/Generators/CLI/CLISourcesTemplate.cs

@ -1063,47 +1063,56 @@ namespace CppSharp.Generators.CLI @@ -1063,47 +1063,56 @@ namespace CppSharp.Generators.CLI
var argName = "arg" + paramIndex.ToString(CultureInfo.InvariantCulture);
if (param.IsOut || param.IsInOut)
{
var isRef = param.IsOut || param.IsInOut;
// Since both pointers and references to types are wrapped as CLI
// tracking references when using in/out, we normalize them here to be able
// to use the same code for marshaling.
var paramType = param.Type;
if (paramType is PointerType)
if (paramType is PointerType && isRef)
{
if (!paramType.IsReference())
paramMarshal.Prefix = "&";
paramType = (paramType as PointerType).Pointee;
}
var typePrinter = new CppTypePrinter(Driver.TypeDatabase);
var type = paramType.Visit(typePrinter);
if (param.IsInOut)
WriteLine("{0} {1} = {2};", type, argName, param.Name);
else
WriteLine("{0} {1};", type, argName);
}
else
var effectiveParam = new Parameter(param)
{
QualifiedType = new QualifiedType(paramType)
};
var ctx = new MarshalContext(Driver)
{
Parameter = param,
Parameter = effectiveParam,
ParameterIndex = paramIndex,
ArgName = argName,
Function = function
};
var marshal = new CLIMarshalManagedToNativePrinter(ctx);
param.Visit(marshal);
effectiveParam.Visit(marshal);
if (string.IsNullOrEmpty(marshal.Context.Return))
throw new Exception(string.Format("Cannot marshal argument of function '{0}'",
function.QualifiedOriginalName));
if (isRef)
{
var typePrinter = new CppTypePrinter(Driver.TypeDatabase);
var type = paramType.Visit(typePrinter);
if (param.IsInOut)
WriteLine("{0} {1} = {2};", type, argName, marshal.Context.Return);
else
WriteLine("{0} {1};", type, argName);
}
else
{
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
WriteLine("auto {0}{1} = {2};", marshal.VarPrefix, argName,
marshal.Context.Return);
argName = marshal.ArgumentPrefix + argName;
paramMarshal.Prefix = marshal.ArgumentPrefix;
}
paramMarshal.Name = argName;

Loading…
Cancel
Save