Fix Python min alignment
authorWouter van Oortmerssen <aardappel@gmail.com>
Mon, 9 Mar 2020 23:43:43 +0000 (16:43 -0700)
committerWouter van Oortmerssen <aardappel@gmail.com>
Mon, 9 Mar 2020 23:46:41 +0000 (16:46 -0700)
This was accidentally deleted in:
https://github.com/google/flatbuffers/commit/9fa8245e81a2fd8ad19f9ae8f3da3a00e796e462

Change-Id: I8cad721e075279f6a67aca81259f73fb75aba482

python/flatbuffers/builder.py

index 6249246..f9448b0 100644 (file)
@@ -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()