Browse Source

Fixed the mapping of std::string not to destroy values when a reference (&) is returned.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/719/head 0.7.11
Dimitar Dobrev 9 years ago
parent
commit
5f0840d117
  1. 4
      src/Generator/Types/Std/Stdlib.cs
  2. 2
      tests/Common/Common.Tests.cs
  3. 33
      tests/Common/Common.cpp
  4. 51
      tests/Common/Common.h

4
src/Generator/Types/Std/Stdlib.cs

@ -92,13 +92,13 @@ namespace CppSharp.Types.Std @@ -92,13 +92,13 @@ namespace CppSharp.Types.Std
public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
{
var type = ctx.ReturnType.Type;
var type = ctx.ReturnType.Type.Desugar();
ClassTemplateSpecialization basicString = GetBasicString(type);
Declaration c_str = basicString.Methods.FirstOrDefault(m => m.OriginalName == "c_str");
if (!c_str.IsGenerated)
c_str = basicString.Properties.First(p => p.OriginalName == "c_str");
var typePrinter = new CSharpTypePrinter(ctx.Context);
if (type.IsPointer() || ctx.Declaration is Field)
if (type.IsAddress() || ctx.Declaration is Field)
{
ctx.Return.Write("{0}.{1}({2}).{3}{4}",
basicString.Visit(typePrinter), Helpers.CreateInstanceIdentifier,

2
tests/Common/Common.Tests.cs

@ -665,6 +665,8 @@ This is a very long string. This is a very long string. This is a very long stri @@ -665,6 +665,8 @@ This is a very long string. This is a very long string. This is a very long stri
Assert.That(hasStdString.testStdString(t), Is.EqualTo(t + "_test"));
hasStdString.s = t;
Assert.That(hasStdString.s, Is.EqualTo(t));
Assert.That(hasStdString.stdString, Is.EqualTo(t));
Assert.That(hasStdString.stdString, Is.EqualTo(t));
}
}

33
tests/Common/Common.cpp

@ -234,40 +234,40 @@ void Hello::EnumOutRef(int value, CS_OUT Enum& e) @@ -234,40 +234,40 @@ void Hello::EnumOutRef(int value, CS_OUT Enum& e)
void Hello::EnumInOut(CS_IN_OUT Enum* e)
{
if (*e == Enum::E)
*e = Enum::F;
if (*e == Enum::E)
*e = Enum::F;
}
void Hello::EnumInOutRef(CS_IN_OUT Enum& e)
{
if (e == Enum::E)
e = Enum::F;
if (e == Enum::E)
e = Enum::F;
}
void Hello::StringOut(CS_OUT const char** str)
{
*str = "HelloStringOut";
*str = "HelloStringOut";
}
void Hello::StringOutRef(CS_OUT const char*& str)
{
str = "HelloStringOutRef";
str = "HelloStringOutRef";
}
void Hello::StringInOut(CS_IN_OUT const char** str)
{
if (strcmp(*str, "Hello") == 0)
*str = "StringInOut";
else
*str = "Failed";
if (strcmp(*str, "Hello") == 0)
*str = "StringInOut";
else
*str = "Failed";
}
void Hello::StringInOutRef(CS_IN_OUT const char*& str)
{
if (strcmp(str, "Hello") == 0)
str = "StringInOutRef";
else
str = "Failed";
if (strcmp(str, "Hello") == 0)
str = "StringInOutRef";
else
str = "Failed";
}
void Hello::StringTypedef(const TypedefChar* str)
@ -430,6 +430,11 @@ std::string HasStdString::testStdString(std::string s) @@ -430,6 +430,11 @@ std::string HasStdString::testStdString(std::string s)
return s + "_test";
}
std::string& HasStdString::getStdString()
{
return s;
}
TypeMappedIndex::TypeMappedIndex()
{
}

51
tests/Common/Common.h

@ -315,7 +315,7 @@ DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1, @@ -315,7 +315,7 @@ DLL_API TestMoveOperatorToClass operator+(const TestMoveOperatorToClass& b1,
// Not a valid operator overload for Foo2 in managed code - comparison operators need to return bool.
DLL_API int operator==(const Foo2& a, const Foo2& b)
{
return 0;
return 0;
}
// Tests delegates
@ -381,13 +381,13 @@ struct DLL_API TestStaticClass @@ -381,13 +381,13 @@ struct DLL_API TestStaticClass
{
static int Add(int a, int b);
static int GetOneTwoThree();
static int GetOneTwoThree();
protected:
static int _Mult(int a, int b);
static int _Mult(int a, int b);
static int GetFourFiveSix();
static int GetFourFiveSix();
private:
TestStaticClass();
@ -414,9 +414,9 @@ int TestStaticClassDerived::Foo() { return 0; } @@ -414,9 +414,9 @@ int TestStaticClassDerived::Foo() { return 0; }
class DLL_API TestNotStaticClass
{
public:
static TestNotStaticClass StaticFunction();
static TestNotStaticClass StaticFunction();
private:
TestNotStaticClass();
TestNotStaticClass();
};
TestNotStaticClass::TestNotStaticClass()
@ -425,7 +425,7 @@ TestNotStaticClass::TestNotStaticClass() @@ -425,7 +425,7 @@ TestNotStaticClass::TestNotStaticClass()
TestNotStaticClass TestNotStaticClass::StaticFunction()
{
return TestNotStaticClass();
return TestNotStaticClass();
}
class HasIgnoredField
@ -473,8 +473,8 @@ struct EmptyNamedNestedEnum @@ -473,8 +473,8 @@ struct EmptyNamedNestedEnum
typedef unsigned long foo_t;
typedef struct DLL_API SomeStruct
{
SomeStruct();
foo_t p;
SomeStruct();
foo_t p;
} SomeStruct;
SomeStruct::SomeStruct() : p(1) {}
@ -485,11 +485,11 @@ class DLL_API SomeClassExtendingTheStruct : public SomeStruct @@ -485,11 +485,11 @@ class DLL_API SomeClassExtendingTheStruct : public SomeStruct
namespace SomeNamespace
{
class DLL_API AbstractClass
{
public:
virtual void AbstractMethod() = 0;
};
class DLL_API AbstractClass
{
public:
virtual void AbstractMethod() = 0;
};
}
// Test operator overloads
@ -498,11 +498,11 @@ class DLL_API ClassWithOverloadedOperators @@ -498,11 +498,11 @@ class DLL_API ClassWithOverloadedOperators
public:
ClassWithOverloadedOperators();
operator char();
operator int();
operator short();
operator char();
operator int();
operator short();
virtual bool operator<(const ClassWithOverloadedOperators &other) const;
virtual bool operator<(const ClassWithOverloadedOperators &other) const;
};
ClassWithOverloadedOperators::ClassWithOverloadedOperators() {}
@ -627,7 +627,7 @@ class DLL_API TestFixedArrays @@ -627,7 +627,7 @@ class DLL_API TestFixedArrays
{
public:
TestFixedArrays();
VoidPtrRetFunctionTypedef Array[10];
VoidPtrRetFunctionTypedef Array[10];
};
TestFixedArrays::TestFixedArrays() {}
@ -655,7 +655,7 @@ int TestGetterSetterToProperties::getWidth() { return 640; } @@ -655,7 +655,7 @@ int TestGetterSetterToProperties::getWidth() { return 640; }
int TestGetterSetterToProperties::getHeight() { return 480; }
// Tests conversion operators of classes
class DLL_API ClassA
class DLL_API ClassA
{
public:
ClassA(int value);
@ -759,6 +759,7 @@ class DLL_API HasStdString @@ -759,6 +759,7 @@ class DLL_API HasStdString
public:
std::string testStdString(std::string s);
std::string s;
std::string& getStdString();
};
class DLL_API InternalCtorAmbiguity
@ -832,10 +833,10 @@ void DLL_API funcTryRefTypeOut(CS_OUT RefTypeClassPassTry classTry); @@ -832,10 +833,10 @@ void DLL_API funcTryRefTypeOut(CS_OUT RefTypeClassPassTry classTry);
#define CS_VALUE_TYPE
struct CS_VALUE_TYPE ValueTypeArrays
{
float firstValueTypeArrray[ARRAY_LENGTH];
int secondValueTypeArray[ARRAY_LENGTH];
char thirdValueTypeArray[ARRAY_LENGTH];
size_t size;
float firstValueTypeArrray[ARRAY_LENGTH];
int secondValueTypeArray[ARRAY_LENGTH];
char thirdValueTypeArray[ARRAY_LENGTH];
size_t size;
};
class DLL_API HasVirtualProperty
@ -1070,7 +1071,7 @@ void TemplateWithVirtual<T>::v() @@ -1070,7 +1071,7 @@ void TemplateWithVirtual<T>::v()
template <typename T>
int FunctionTemplateWithDependentTypeDefaultExpr(size_t size = sizeof(T)) {
return size;
return size;
}
class DLL_API DerivedFromTemplateInstantiationWithVirtual : public TemplateWithVirtual<int>

Loading…
Cancel
Save