Skip to content

Commit 8125763

Browse files
authored
Merge branch 'google:master' into csharp-array-span-accessors
2 parents a340c0c + 3c1bb67 commit 8125763

36 files changed

Lines changed: 2644 additions & 100 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ jobs:
197197
configuration: [
198198
'',
199199
'-p:UnsafeByteBuffer=true',
200-
# Fails two tests currently.
201-
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
200+
'-p:EnableSpanT=true,UnsafeByteBuffer=true'
202201
]
203202
steps:
204203
- uses: actions/checkout@v6
@@ -209,7 +208,7 @@ jobs:
209208
- name: Build
210209
run: |
211210
cd tests\FlatBuffers.Test
212-
dotnet new sln --force --name FlatBuffers.Test
211+
dotnet new sln --force --name FlatBuffers.Test --format sln
213212
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
214213
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
215214
- name: Run net6.0

docs/source/flatc.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ list of `FILES...`.
7979
`myschema.fbs` to JSON:
8080

8181
```sh
82-
flatc --json myschema.fbs mydata.bin
82+
flatc --json myschema.fbs -- mydata.bin
8383
```
8484

85-
This will generate a `mydata.json` file.
86-
85+
This will generate a `mydata.json` file. If there is no
86+
[`file_identifier`](schema.md/#file-identification-and-extension) defined
87+
for this schema, you will need to use the `--raw-binary` option.
8788

8889
### Additional options
8990

goldens/rust/basic_generated.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
// automatically generated by the FlatBuffers compiler, do not modify
22
// @generated
3-
extern crate alloc;
43

4+
extern crate alloc;
55

66
#[allow(unused_imports, dead_code)]
77
pub mod flatbuffers {
88

9+
extern crate alloc;
910
#[allow(unused_imports, dead_code)]
1011
pub mod goldens {
1112

13+
extern crate alloc;
1214

1315
pub enum GalaxyOffset {}
1416
#[derive(Copy, Clone, PartialEq)]

include/flatbuffers/flatbuffers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ inline const char* flatbuffers_version_string() {
260260
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ~ (E lhs){\
261261
return E(~T(lhs));\
262262
}\
263-
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator |= (E &lhs, E rhs){\
263+
inline FLATBUFFERS_CONSTEXPR_CPP14 E operator |= (E &lhs, E rhs){\
264264
lhs = lhs | rhs;\
265265
return lhs;\
266266
}\
267-
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator &= (E &lhs, E rhs){\
267+
inline FLATBUFFERS_CONSTEXPR_CPP14 E operator &= (E &lhs, E rhs){\
268268
lhs = lhs & rhs;\
269269
return lhs;\
270270
}\
271-
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^= (E &lhs, E rhs){\
271+
inline FLATBUFFERS_CONSTEXPR_CPP14 E operator ^= (E &lhs, E rhs){\
272272
lhs = lhs ^ rhs;\
273273
return lhs;\
274274
}\

include/flatbuffers/idl.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ struct Type {
223223
uint16_t fixed_length; // only set if t == BASE_TYPE_ARRAY
224224
};
225225

226-
// Represents a parsed scalar value, it's type, and field offset.
226+
// Represents a parsed scalar value, its type, and field offset.
227227
struct Value {
228228
Value()
229229
: constant("0"),
@@ -395,13 +395,20 @@ struct FieldDef : public Definition {
395395
};
396396

397397
struct StructDef : public Definition {
398+
enum class CycleStatus {
399+
NotChecked,
400+
InProgress,
401+
Checked,
402+
};
403+
398404
StructDef()
399405
: fixed(false),
400406
predecl(true),
401407
sortbysize(true),
402408
has_key(false),
403409
minalign(1),
404-
bytesize(0) {}
410+
bytesize(0),
411+
cycle_status{CycleStatus::NotChecked} {}
405412

406413
void PadLastField(size_t min_align) {
407414
auto padding = PaddingBytes(bytesize, min_align);
@@ -423,6 +430,8 @@ struct StructDef : public Definition {
423430
size_t minalign; // What the whole object needs to be aligned to.
424431
size_t bytesize; // Size if fixed.
425432

433+
CycleStatus cycle_status; // used for determining if we have circular references
434+
426435
flatbuffers::unique_ptr<std::string> original_location;
427436
std::vector<voffset_t> reserved_ids;
428437
};
@@ -734,6 +743,7 @@ struct IDLOptions {
734743
bool python_gen_numpy;
735744

736745
bool ts_omit_entrypoint;
746+
bool ts_undefined_for_optionals;
737747
ProtoIdGapAction proto_id_gap_action;
738748

739749
// Possible options for the more general generator below.
@@ -860,6 +870,7 @@ struct IDLOptions {
860870
python_typing(false),
861871
python_gen_numpy(true),
862872
ts_omit_entrypoint(false),
873+
ts_undefined_for_optionals(false),
863874
proto_id_gap_action(ProtoIdGapAction::WARNING),
864875
mini_reflect(IDLOptions::kNone),
865876
require_explicit_ids(false),
@@ -1099,6 +1110,8 @@ class Parser : public ParserState {
10991110
// others includes.
11001111
std::vector<IncludedFile> GetIncludedFiles() const;
11011112

1113+
bool HasCircularStructDependency();
1114+
11021115
private:
11031116
class ParseDepthGuard;
11041117

kotlin/flatbuffers-kotlin/src/nativeMain/kotlin/com/google/flatbuffers/kotlin/ByteArray.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
* limitations under the License.
1515
*/
1616
@file:Suppress("NOTHING_TO_INLINE")
17+
@file:OptIn(ExperimentalNativeApi::class)
1718

1819
package com.google.flatbuffers.kotlin
1920

21+
import kotlin.experimental.ExperimentalNativeApi
22+
2023
/**
2124
* This implementation assumes that of native macOSX64 the byte order of the implementation is
2225
* Little Endian.

lua/flatbuffers/builder.lua

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,62 @@ function mt:Slot(slotnum)
296296
self.currentVTable[slotnum + 1] = self:Offset()
297297
end
298298

299-
local function finish(self, rootTable, sizePrefix)
299+
local function finish(self, rootTable, sizePrefix, fileIdentifier)
300300
UOffsetT:EnforceNumber(rootTable)
301-
self:Prep(self.minalign, sizePrefix and 8 or 4)
302-
self:PrependUOffsetTRelative(rootTable)
301+
local hasFid = fileIdentifier ~= nil
302+
if hasFid then
303+
assert(#fileIdentifier == 4, "File identifier must be exactly 4 bytes")
304+
end
305+
306+
local fid_byte_count = (hasFid and 4 or 0)
307+
308+
-- alignment:
309+
-- root offset (4)
310+
-- optional file id (4)
311+
-- optional size prefix (4)
312+
self:Prep(
313+
self.minalign,
314+
(sizePrefix and 4 or 0) +
315+
4 +
316+
fid_byte_count
317+
)
318+
319+
-- root offset (points past file identifier if present)
320+
self:PrependUOffsetTRelative(rootTable + fid_byte_count)
321+
322+
-- file identifier
323+
if hasFid then
324+
for i = 4, 1, -1 do
325+
self:PrependByte(string.byte(fileIdentifier, i))
326+
end
327+
end
328+
329+
-- size prefix
303330
if sizePrefix then
304331
local size = self.bytes.size - self.head
305332
Int32:EnforceNumber(size)
306333
self:PrependInt32(size)
307334
end
335+
308336
self.finished = true
309337
return self.head
310338
end
311339

340+
312341
function mt:Finish(rootTable)
313-
return finish(self, rootTable, false)
342+
return finish(self, rootTable, false, nil)
314343
end
315344

316345
function mt:FinishSizePrefixed(rootTable)
317-
return finish(self, rootTable, true)
346+
return finish(self, rootTable, true, nil)
347+
end
348+
349+
function mt:FinishWithIdentifier(rootTable, fileIdentifier)
350+
return finish(self, rootTable, false, fileIdentifier)
351+
end
352+
353+
function mt:FinishSizePrefixedWithIdentifier(rootTable, fileIdentifier)
354+
return finish(self, rootTable, true, fileIdentifier)
318355
end
319356

320357
function mt:Prepend(flags, off)

net/FlatBuffers/Table.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public T[] __vector_as_array<T>(int offset)
150150

151151
var pos = this.__vector(o);
152152
var len = this.__vector_len(o);
153-
return bb.ToArray<T>(pos, len);
153+
return bb.ToArray<T>(pos, len * ByteBuffer.SizeOf<T>());
154154
}
155155

156156
// Initialize any Table-derived type to point to the union at the given offset.

rust/flatbuffers/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ impl<'fbb, A: Allocator> FlatBufferBuilder<'fbb, A> {
611611
// Write the VTable (we may delete it afterwards, if it is a duplicate):
612612
let vt_start_pos = self.head;
613613
let vt_end_pos = self.head + vtable_byte_len;
614+
// Zero out the vtable space - make_space only reserves but doesn't initialize
615+
self.allocator[vt_start_pos.range_to(vt_end_pos)].fill(0);
614616
{
615617
// write the vtable header:
616618
let vtfw =

rust/flexbuffers/src/builder/ser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ impl<'a> Serializer for MapKeySerializer<'a> {
421421
type SerializeStruct = Impossible<(), Error>;
422422
type SerializeStructVariant = Impossible<(), Error>;
423423

424+
fn is_human_readable(&self) -> bool {
425+
self.0.is_human_readable()
426+
}
424427
fn serialize_bool(self, _value: bool) -> Result<(), Error> {
425428
key_must_be_a_string()
426429
}

0 commit comments

Comments
 (0)