Skip to content

Commit f7834a1

Browse files
committed
Fix a bug in serialization.
1 parent 20cf880 commit f7834a1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

typed_python/TupleOrListOfType.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include "Type.hpp"
20+
#include "Format.hpp"
2021

2122
class TupleOrListOfType : public Type {
2223
public:
@@ -436,7 +437,7 @@ class TupleOrListOfType : public Type {
436437

437438
buffer.writeUnsignedVarintObject(0, ct);
438439

439-
if (m_element_type->isPOD() && buffer.getContext().serializePodListsInline()) {
440+
if (ct && m_element_type->isPOD() && buffer.getContext().serializePodListsInline()) {
440441
if (m_element_type->getTypeCategory() == TypeCategory::catInt64) {
441442
serializeIntList(
442443
(int64_t*)this->eltPtr(self, 0),
@@ -485,7 +486,12 @@ class TupleOrListOfType : public Type {
485486
if (ptr) {
486487
((layout**)self)[0] = (layout*)ptr;
487488
((layout**)self)[0]->refcount++;
488-
buffer.finishCompoundMessage(wireType);
489+
try {
490+
buffer.finishCompoundMessage(wireType);
491+
} catch(...) {
492+
throw std::runtime_error("1. Failed finishing: " + name());
493+
}
494+
489495
return;
490496
}
491497
}
@@ -550,7 +556,13 @@ class TupleOrListOfType : public Type {
550556
}
551557
}
552558

553-
buffer.finishCompoundMessage(wireType);
559+
try {
560+
buffer.finishCompoundMessage(wireType);
561+
}
562+
catch(...) {
563+
throw std::runtime_error("2. Failed finishing: " + name() + ": " + format(ct));
564+
}
565+
554566
}
555567

556568
protected:

typed_python/types_serialization_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ def check_idempotence(x):
364364
check_idempotence(ListOf(int)([1, 2, 3] * 1000 + [11111111111111] + [1, 2, 3] * 1000))
365365
check_idempotence(ListOf(float)(range(100)))
366366

367+
aList = ListOf(float)(range(100))
368+
check_idempotence((aList, aList))
369+
370+
aList.resize(0)
371+
check_idempotence((aList, aList))
372+
367373
def test_serialize_lists_compression_and_threads(self):
368374
someFloats = ListOf(float)(range(1000000))
369375
for _ in range(6):

0 commit comments

Comments
 (0)