From 89b6183ee95a58cab32b9bc8af3137ed5533b2e7 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 9 Mar 2020 16:43:43 -0700 Subject: [PATCH] Fix Python min alignment This was accidentally deleted in: https://github.com/google/flatbuffers/commit/9fa8245e81a2fd8ad19f9ae8f3da3a00e796e462 Change-Id: I8cad721e075279f6a67aca81259f73fb75aba482 --- python/flatbuffers/builder.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/python/flatbuffers/builder.py b/python/flatbuffers/builder.py index 6249246..f9448b0 100644 --- a/python/flatbuffers/builder.py +++ b/python/flatbuffers/builder.py @@ -466,7 +466,7 @@ class Builder(object): # tobytes ensures c_contiguous ordering self.Bytes[self.Head():self.Head()+l] = x_lend.tobytes(order='C') - + return self.EndVector(x.size) ## @cond FLATBUFFERS_INTERNAL @@ -514,9 +514,16 @@ class Builder(object): """Finish finalizes a buffer, pointing to the given `rootTable`.""" N.enforce_number(rootTable, N.UOffsetTFlags) + prepSize = N.UOffsetTFlags.bytewidth + if file_identifier is not None: + prepSize += N.Int32Flags.bytewidth + if sizePrefix: + prepSize += N.Int32Flags.bytewidth + self.Prep(self.minalign, prepSize) + if file_identifier is not None: self.Prep(N.UOffsetTFlags.bytewidth, encode.FILE_IDENTIFIER_LENGTH) - + # Convert bytes object file_identifier to an array of 4 8-bit integers, # and use big-endian to enforce size compliance. # https://docs.python.org/2/library/struct.html#format-characters @@ -524,7 +531,7 @@ class Builder(object): for i in range(encode.FILE_IDENTIFIER_LENGTH-1, -1, -1): # Place the bytes of the file_identifer in reverse order: self.Place(file_identifier[i], N.Uint8Flags) - + self.PrependUOffsetTRelative(rootTable) if sizePrefix: size = len(self.Bytes) - self.Head() -- 2.7.4