Browse Source

Expose a bug when passing a const char* without copying it

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
bug-pass-const-char-star-no-copy
Dimitar Dobrev 6 years ago
parent
commit
0361715810
  1. 6
      tests/CSharp/CSharp.Tests.cs
  2. 18
      tests/CSharp/CSharp.cpp
  3. 12
      tests/CSharp/CSharp.h

6
tests/CSharp/CSharp.Tests.cs

@ -1283,6 +1283,12 @@ public unsafe class CSharpTests : GeneratorTestFixture @@ -1283,6 +1283,12 @@ public unsafe class CSharpTests : GeneratorTestFixture
[Test]
public void TakeRefToPointerToObject()
{
const string test = "test";
using (Latin1 l = new Latin1(test))
{
Assert.That(l.Size, Is.EqualTo(test.Length));
Assert.That(l.Data, Is.EqualTo(test));
}
using (Foo foo = new Foo { A = 25 })
{
Foo returnedFoo = CSharp.CSharp.TakeReturnReferenceToPointer(foo);

18
tests/CSharp/CSharp.cpp

@ -35,6 +35,24 @@ Foo::Foo(const Foo& other) : A(other.A), P(other.P), @@ -35,6 +35,24 @@ Foo::Foo(const Foo& other) : A(other.A), P(other.P),
{
}
Latin1::Latin1(const char *s) : m_size(s ? int(strlen(s)) : 0), m_data(s)
{
}
Latin1::~Latin1()
{
}
int Latin1::size() const
{
return m_size;
}
const char* Latin1::data() const
{
return m_data;
}
Foo::~Foo()
{
}

12
tests/CSharp/CSharp.h

@ -8,6 +8,18 @@ @@ -8,6 +8,18 @@
#include "AnotherUnit.h"
#include "CSharpTemplates.h"
class DLL_API Latin1
{
public:
explicit Latin1(const char *s);
~Latin1();
int size() const;
const char* data() const;
private:
int m_size;
const char *m_data;
};
class DLL_API Foo
{
public:

Loading…
Cancel
Save