mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-27 18:58:06 +00:00
Empties the sharedString map on reset on go and csharp (#6187)
Fixes go tests
This commit is contained in:
@@ -53,6 +53,12 @@ func (b *Builder) Reset() {
|
|||||||
b.vtable = b.vtable[:0]
|
b.vtable = b.vtable[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.sharedStrings != nil {
|
||||||
|
for key := range b.sharedStrings {
|
||||||
|
delete(b.sharedStrings, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b.head = UOffsetT(len(b.Bytes))
|
b.head = UOffsetT(len(b.Bytes))
|
||||||
b.minalign = 1
|
b.minalign = 1
|
||||||
b.nested = false
|
b.nested = false
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ namespace FlatBuffers
|
|||||||
_objectStart = 0;
|
_objectStart = 0;
|
||||||
_numVtables = 0;
|
_numVtables = 0;
|
||||||
_vectorNumElems = 0;
|
_vectorNumElems = 0;
|
||||||
|
if (_sharedStringMap != null)
|
||||||
|
{
|
||||||
|
_sharedStringMap.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -359,5 +359,20 @@ namespace FlatBuffers.Test
|
|||||||
Assert.AreEqual(fbb.CreateSharedString(s).Value, 0);
|
Assert.AreEqual(fbb.CreateSharedString(s).Value, 0);
|
||||||
Assert.AreEqual(fbb.CreateString(s).Value, 0);
|
Assert.AreEqual(fbb.CreateString(s).Value, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[FlatBuffersTestMethod]
|
||||||
|
public void FlatBufferBuilder_Empty_Builder()
|
||||||
|
{
|
||||||
|
var fbb = new FlatBufferBuilder(16);
|
||||||
|
var str = "Hello";
|
||||||
|
var flatbuffer = "Flatbuffers!";
|
||||||
|
var strOffset = fbb.CreateSharedString(str);
|
||||||
|
var flatbufferOffset = fbb.CreateSharedString(flatbuffer);
|
||||||
|
fbb.Clear();
|
||||||
|
var flatbufferOffset2 = fbb.CreateSharedString(flatbuffer);
|
||||||
|
var strOffset2 = fbb.CreateSharedString(str);
|
||||||
|
Assert.IsFalse(strOffset.Value == strOffset2.Value);
|
||||||
|
Assert.IsFalse(flatbufferOffset.Value == flatbufferOffset2.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ func TestAll(t *testing.T) {
|
|||||||
CheckStructIsNotInlineError(t.Fatalf)
|
CheckStructIsNotInlineError(t.Fatalf)
|
||||||
CheckFinishedBytesError(t.Fatalf)
|
CheckFinishedBytesError(t.Fatalf)
|
||||||
CheckSharedStrings(t.Fatalf)
|
CheckSharedStrings(t.Fatalf)
|
||||||
|
CheckEmptiedBuilder(t.Fatalf)
|
||||||
|
|
||||||
// Verify that GetRootAs works for non-root tables
|
// Verify that GetRootAs works for non-root tables
|
||||||
CheckGetRootAsForNonRootTable(t.Fatalf)
|
CheckGetRootAsForNonRootTable(t.Fatalf)
|
||||||
@@ -1377,6 +1378,27 @@ func CheckStringIsNestedError(fail func(string, ...interface{})) {
|
|||||||
b.CreateString("foo")
|
b.CreateString("foo")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckEmptiedBuilder(fail func(string, ...interface{})) {
|
||||||
|
f := func(a, b string) bool {
|
||||||
|
if a == b {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
builder := flatbuffers.NewBuilder(0)
|
||||||
|
|
||||||
|
a1 := builder.CreateSharedString(a)
|
||||||
|
b1 := builder.CreateSharedString(b)
|
||||||
|
builder.Reset()
|
||||||
|
b2 := builder.CreateSharedString(b)
|
||||||
|
a2 := builder.CreateSharedString(a)
|
||||||
|
|
||||||
|
return !(a1 == a2 || b1 == b2)
|
||||||
|
}
|
||||||
|
if err := quick.Check(f, nil); err != nil {
|
||||||
|
fail("expected different offset")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func CheckSharedStrings(fail func(string, ...interface{})) {
|
func CheckSharedStrings(fail func(string, ...interface{})) {
|
||||||
f := func(strings []string) bool {
|
f := func(strings []string) bool {
|
||||||
b := flatbuffers.NewBuilder(0)
|
b := flatbuffers.NewBuilder(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user