Browse Source

Fixed CLI and CSharp support for out parameter const char strings.

Added test for out parameter const char strings.
pull/306/head
Tom Spilman 12 years ago
parent
commit
d4e4aaffad
  1. 18
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 3
      src/Generator/Generators/CLI/CLITypePrinter.cs
  3. 12
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  4. 3
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  5. 4
      tests/Basic/Basic.Tests.cs
  6. 5
      tests/Basic/Basic.cpp
  7. 2
      tests/Basic/Basic.h

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

@ -67,15 +67,6 @@ namespace CppSharp.Generators.CLI @@ -67,15 +67,6 @@ namespace CppSharp.Generators.CLI
var pointee = pointer.Pointee.Desugar();
PrimitiveType primitive;
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut) &&
pointee.IsPrimitiveType(out primitive))
{
Context.Return.Write(Context.ReturnVarName);
return true;
}
if (pointee.IsPrimitiveType(PrimitiveType.Void))
{
Context.Return.Write(Context.ReturnVarName);
@ -89,6 +80,15 @@ namespace CppSharp.Generators.CLI @@ -89,6 +80,15 @@ namespace CppSharp.Generators.CLI
return true;
}
PrimitiveType primitive;
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut) &&
pointee.IsPrimitiveType(out primitive))
{
Context.Return.Write(Context.ReturnVarName);
return true;
}
if (pointee.IsPrimitiveType(out primitive))
{
var returnVarName = Context.ReturnVarName;

3
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -155,8 +155,7 @@ namespace CppSharp.Generators.CLI @@ -155,8 +155,7 @@ namespace CppSharp.Generators.CLI
{
// Skip one indirection if passed by reference
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee)
if (param != null && (param.IsOut || param.IsInOut))
return pointee.Visit(this, quals);
return pointee.Visit(this, quals) + "*";

12
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -430,8 +430,16 @@ namespace CppSharp.Generators.CSharp @@ -430,8 +430,16 @@ namespace CppSharp.Generators.CSharp
pointee.IsPrimitiveType(PrimitiveType.WideChar)) &&
pointer.QualifiedPointee.Qualifiers.IsConst)
{
Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
if (Context.Parameter.IsOut)
{
Context.Return.Write("IntPtr.Zero");
CSharpContext.ArgumentPrefix.Write("&");
}
else
{
Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
}
return true;
}

3
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -217,8 +217,7 @@ namespace CppSharp.Generators.CSharp @@ -217,8 +217,7 @@ namespace CppSharp.Generators.CSharp
{
// Skip one indirection if passed by reference
var param = Context.Parameter;
if (isManagedContext && param != null && (param.IsOut || param.IsInOut)
&& pointee == finalPointee)
if (isManagedContext && param != null && (param.IsOut || param.IsInOut))
return pointee.Visit(this, quals);
if (ContextKind == CSharpTypePrinterContextKind.GenericDelegate)

4
tests/Basic/Basic.Tests.cs

@ -55,6 +55,10 @@ public class BasicTests : GeneratorTestFixture @@ -55,6 +55,10 @@ public class BasicTests : GeneratorTestFixture
//Assert.That(hello.RetEnum(Enum.D), Is.EqualTo(-2147483648));
Assert.That(hello.RetEnum(Enum.E), Is.EqualTo(1));
Assert.That(hello.RetEnum(Enum.F), Is.EqualTo(-9));
string str;
hello.StringOut(out str);
Assert.That(str, Is.EqualTo("HelloStringOut"));
}
[Test]

5
tests/Basic/Basic.cpp

@ -203,6 +203,11 @@ void Hello::EnumInOutRef(CS_IN_OUT Enum& e) @@ -203,6 +203,11 @@ void Hello::EnumInOutRef(CS_IN_OUT Enum& e)
e = Enum::F;
}
void Hello::StringOut(CS_OUT const char** str)
{
*str = "HelloStringOut";
}
int unsafeFunction(const Bar& ret, char* testForString, void (*foo)(int))
{
return ret.A;

2
tests/Basic/Basic.h

@ -132,6 +132,8 @@ public: @@ -132,6 +132,8 @@ public:
void EnumInOut(CS_IN_OUT Enum* e);
void EnumInOutRef(CS_IN_OUT Enum& e);
void StringOut(CS_OUT const char** str);
};
class DLL_API AbstractFoo

Loading…
Cancel
Save