Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/grpc-python-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fliiiix authored Nov 13, 2024
2 parents 95c0ab2 + 5f453ef commit 4aad523
Show file tree
Hide file tree
Showing 57 changed files with 516 additions and 137 deletions.
5 changes: 3 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ platforms:
macos:
xcode_version: "14.3"
build_targets:
- "//..."
- "//:flatbuffers"
- "//:flatc"
test_targets:
- "//..."
- "//tests:flatbuffers_test"
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
- master
schedule:
# Run daily at 4:45 A.M. to catch dependencies that break us.
- cron: '45 4 * * *'
- cron: '45 4 * * *'

jobs:
build-linux:
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
chmod +x flatc
./flatc --version
- name: upload build artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: Linux flatc binary ${{ matrix.cxx }}
path: flatc
Expand Down Expand Up @@ -170,7 +170,7 @@ jobs:
- name: test
run: Release\flattests.exe
- name: upload build artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: Windows flatc binary
path: Release\flatc.exe
Expand Down Expand Up @@ -242,9 +242,9 @@ jobs:
chmod +x Release/flatc
Release/flatc --version
- name: upload build artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: Mac flatc binary
name: Mac flatc binary Intel
path: Release/flatc
# Below if only for release.
- name: Zip file
Expand Down Expand Up @@ -285,9 +285,9 @@ jobs:
chmod +x Release/flatc
Release/flatc --version
- name: upload build artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: Mac flatc binary
name: Mac flatc binary Universal
path: Release/flatc
# Below if only for release.
- name: Zip file
Expand Down Expand Up @@ -366,7 +366,7 @@ jobs:
- name: Run benchmarks
run: ./flatbenchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true --benchmark_out_format=console --benchmark_out=benchmarks/results_${{matrix.cxx}}
- name: Upload benchmarks results
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: Linux flatbenchmark results ${{matrix.cxx}}
path: benchmarks/results_${{matrix.cxx}}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: OSS-Fuzz
permissions: read-all

on:
on:
pull_request:
branches:
- master
Expand All @@ -27,7 +27,7 @@ jobs:
language: c++
fuzz-seconds: 60
- name: Upload Crash
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Upload the results as artifacts (optional).
- name: "Upload artifact"
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0
uses: actions/upload-artifact@v4
with:
name: SARIF file
path: results.sarif
Expand Down
7 changes: 5 additions & 2 deletions FlatBuffers.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ Pod::Spec.new do |s|

s.homepage = 'https://github.com/google/flatbuffers'
s.license = { :type => 'Apache2.0', :file => 'LICENSE' }
s.author = { 'mustii' => '[email protected]' }
s.source = { :git => 'https://github.com/google/flatbuffers.git', :tag => s.version.to_s, :submodules => true }
s.author = { 'mustii' => '[email protected]' }
s.source = { :git => 'https://github.com/google/flatbuffers.git', :tag => "v" + s.version.to_s, :submodules => true }

s.ios.deployment_target = '11.0'
s.osx.deployment_target = '10.14'

s.swift_version = '5.0'
s.source_files = 'swift/Sources/Flatbuffers/*.swift'
s.pod_target_xcconfig = {
'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
}
end
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ maximum memory efficiency. It allows you to directly access serialized data with

1. Build the compiler for flatbuffers (`flatc`)

Use `cmake` to create the build files for your platform and then perform the compliation (Linux example).
Use `cmake` to create the build files for your platform and then perform the compilation (Linux example).

```
cmake -G "Unix Makefiles"
Expand Down
2 changes: 1 addition & 1 deletion grpc/flatbuffers-java-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</developer>
</developers>
<properties>
<gRPC.version>1.36.0</gRPC.version>
<gRPC.version>1.67.1</gRPC.version>
</properties>
<dependencies>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions include/flatbuffers/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ typedef uint16_t voffset_t;
typedef uintmax_t largest_scalar_t;

// In 32bits, this evaluates to 2GB - 1
#define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t>::max()
#define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t>::max()
#define FLATBUFFERS_MAX_BUFFER_SIZE (std::numeric_limits<::flatbuffers::soffset_t>::max)()
#define FLATBUFFERS_MAX_64_BUFFER_SIZE (std::numeric_limits<::flatbuffers::soffset64_t>::max)()

// The minimum size buffer that can be a valid flatbuffer.
// Includes the offset to the root table (uoffset_t), the offset to the vtable
Expand Down
5 changes: 5 additions & 0 deletions include/flatbuffers/detached_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class DetachedBuffer {

size_t size() const { return size_; }

uint8_t *begin() { return data(); }
const uint8_t *begin() const { return data(); }
uint8_t *end() { return data() + size(); }
const uint8_t *end() const { return data() + size(); }

// These may change access mode, leave these at end of public section
FLATBUFFERS_DELETE_FUNC(DetachedBuffer(const DetachedBuffer &other));
FLATBUFFERS_DELETE_FUNC(
Expand Down
25 changes: 15 additions & 10 deletions include/flatbuffers/flexbuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ inline void IndentString(std::string &s, int indent,

template<typename T>
void AppendToString(std::string &s, T &&v, bool keys_quoted, bool indented,
int cur_indent, const char *indent_string) {
int cur_indent, const char *indent_string,
bool natural_utf8) {
s += "[";
s += indented ? "\n" : " ";
for (size_t i = 0; i < v.size(); i++) {
Expand All @@ -377,7 +378,7 @@ void AppendToString(std::string &s, T &&v, bool keys_quoted, bool indented,
}
if (indented) IndentString(s, cur_indent, indent_string);
v[i].ToString(true, keys_quoted, s, indented, cur_indent,
indent_string);
indent_string, natural_utf8);
}
if (indented) {
s += "\n";
Expand Down Expand Up @@ -567,23 +568,24 @@ class Reference {
// string values at the top level receive "" quotes (inside other values
// they always do). keys_quoted determines if keys are quoted, at any level.
void ToString(bool strings_quoted, bool keys_quoted, std::string &s) const {
ToString(strings_quoted, keys_quoted, s, false, 0, "");
ToString(strings_quoted, keys_quoted, s, false, 0, "", false);
}

// This version additionally allow you to specify if you want indentation.
void ToString(bool strings_quoted, bool keys_quoted, std::string &s,
bool indented, int cur_indent, const char *indent_string) const {
bool indented, int cur_indent, const char *indent_string,
bool natural_utf8 = false) const {
if (type_ == FBT_STRING) {
String str(Indirect(), byte_width_);
if (strings_quoted) {
flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, false);
flatbuffers::EscapeString(str.c_str(), str.length(), &s, true, natural_utf8);
} else {
s.append(str.c_str(), str.length());
}
} else if (IsKey()) {
auto str = AsKey();
if (keys_quoted) {
flatbuffers::EscapeString(str, strlen(str), &s, true, false);
flatbuffers::EscapeString(str, strlen(str), &s, true, natural_utf8);
} else {
s += str;
}
Expand Down Expand Up @@ -623,7 +625,8 @@ class Reference {
if (indented) IndentString(s, cur_indent + 1, indent_string);
keys[i].ToString(true, kq, s);
s += ": ";
vals[i].ToString(true, keys_quoted, s, indented, cur_indent + 1, indent_string);
vals[i].ToString(true, keys_quoted, s, indented, cur_indent + 1, indent_string,
natural_utf8);
if (i < keys.size() - 1) {
s += ",";
if (!indented) s += " ";
Expand All @@ -635,13 +638,15 @@ class Reference {
s += "}";
} else if (IsVector()) {
AppendToString<Vector>(s, AsVector(), keys_quoted, indented,
cur_indent + 1, indent_string);
cur_indent + 1, indent_string, natural_utf8);
} else if (IsTypedVector()) {
AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted, indented,
cur_indent + 1, indent_string);
cur_indent + 1, indent_string,
natural_utf8);
} else if (IsFixedTypedVector()) {
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted,
indented, cur_indent + 1, indent_string);
indented, cur_indent + 1, indent_string,
natural_utf8);
} else if (IsBlob()) {
auto blob = AsBlob();
flatbuffers::EscapeString(reinterpret_cast<const char *>(blob.data()),
Expand Down
5 changes: 5 additions & 0 deletions include/flatbuffers/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ template<typename T, typename SizeT = uoffset_t> class Vector {

SizeT size() const { return EndianScalar(length_); }

// Returns true if the vector is empty.
//
// This just provides another standardized method that is expected of vectors.
bool empty() const { return size() == 0; }

// Deprecated: use size(). Here for backwards compatibility.
FLATBUFFERS_ATTRIBUTE([[deprecated("use size() instead")]])
SizeT Length() const { return size(); }
Expand Down
2 changes: 1 addition & 1 deletion kotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugin-kotlin = "1.6.10"
plugin-gver = "0.42.0"
kotlinx-benchmark = "0.4.8"
junit = "4.12"
gson = "2.8.5"
gson = "2.8.9"
moshi-kotlin = "1.11.0"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ universal=1

[metadata]
license_files =
../license
../LICENSE
1 change: 0 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
name='flatbuffers',
version='24.3.25',
license='Apache 2.0',
license_files='../LICENSE',
author='Derek Bailey',
author_email='[email protected]',
url='https://google.github.io/flatbuffers/',
Expand Down
2 changes: 1 addition & 1 deletion rust/flatbuffers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub use crate::builder::{Allocator, DefaultAllocator, FlatBufferBuilder};
pub use crate::endian_scalar::{emplace_scalar, read_scalar, read_scalar_at, EndianScalar};
pub use crate::follow::{Follow, FollowStart};
pub use crate::primitives::*;
pub use crate::push::Push;
pub use crate::push::{Push, PushAlignment};
pub use crate::table::{buffer_has_identifier, Table};
pub use crate::vector::{follow_cast_ref, Vector, VectorIter};
pub use crate::verifier::{
Expand Down
2 changes: 1 addition & 1 deletion samples/monster_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
}

public var pos: MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Sample_Vec3.self, at: o) }
public var mutablePos: MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: o + _accessor.postion) }
public var mutablePos: MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: o + _accessor.position) }
public var mana: Int16 { let o = _accessor.offset(VTOFFSET.mana.v); return o == 0 ? 150 : _accessor.readBuffer(of: Int16.self, at: o) }
@discardableResult public func mutate(mana: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.mana.v); return _accessor.mutate(mana, index: o) }
public var hp: Int16 { let o = _accessor.offset(VTOFFSET.hp.v); return o == 0 ? 100 : _accessor.readBuffer(of: Int16.self, at: o) }
Expand Down
6 changes: 5 additions & 1 deletion samples/rust_generated/my_game/sample/vec_3_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, <Self as flatbuffers::Push>::size());
dst.copy_from_slice(src);
}
#[inline]
fn alignment() -> flatbuffers::PushAlignment {
flatbuffers::PushAlignment::new(4)
}
}

impl<'a> flatbuffers::Verifiable for Vec3 {
Expand Down
8 changes: 5 additions & 3 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ static std::set<std::string> RustKeywords() {
// Terms that we use ourselves
"follow",
"push",
"size",
"alignment",
"to_little_endian",
"from_little_endian",
"ENUM_MAX",
Expand Down Expand Up @@ -2700,9 +2698,13 @@ class RustGenerator : public BaseGenerator {
code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {";
code_ +=
" let src = ::core::slice::from_raw_parts(self as *const "
"{{STRUCT_TY}} as *const u8, Self::size());";
"{{STRUCT_TY}} as *const u8, <Self as flatbuffers::Push>::size());";
code_ += " dst.copy_from_slice(src);";
code_ += " }";
code_ += " #[inline]";
code_ += " fn alignment() -> flatbuffers::PushAlignment {";
code_ += " flatbuffers::PushAlignment::new({{ALIGN}})";
code_ += " }";
code_ += "}";
code_ += "";

Expand Down
8 changes: 4 additions & 4 deletions src/idl_gen_swift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class SwiftGenerator : public BaseGenerator {
} else {
code_ +=
"_{{FIELDVAR}} = {{VALUETYPE}}({{ACCESS}}.bb, o: "
"{{ACCESS}}.postion + {{OFFSET}})";
"{{ACCESS}}.position + {{OFFSET}})";
}
}
Outdent();
Expand Down Expand Up @@ -361,7 +361,7 @@ class SwiftGenerator : public BaseGenerator {
} else if (IsStruct(field.value.type)) {
code_.SetValue("VALUETYPE", GenType(field.value.type) + Mutable());
code_ += GenReaderMainBody() + "return " +
GenConstructor("{{ACCESS}}.postion + {{OFFSET}}");
GenConstructor("{{ACCESS}}.position + {{OFFSET}}");
}
if (parser_.opts.mutable_buffer && !IsStruct(field.value.type))
code_ += GenMutate("{{OFFSET}}", "", IsEnum(field.value.type));
Expand Down Expand Up @@ -754,7 +754,7 @@ class SwiftGenerator : public BaseGenerator {
code_.SetValue("VALUETYPE", GenType(field.value.type) + Mutable());
code_.SetValue("CONSTANT", "nil");
code_ += GenReaderMainBody(is_required) + GenOffset() + required_reader +
GenConstructor("o + {{ACCESS}}.postion");
GenConstructor("o + {{ACCESS}}.position");
return;
}
switch (field.value.type.base_type) {
Expand All @@ -763,7 +763,7 @@ class SwiftGenerator : public BaseGenerator {
code_.SetValue("CONSTANT", "nil");
code_ += GenReaderMainBody(is_required) + GenOffset() +
required_reader +
GenConstructor(GenIndirect("o + {{ACCESS}}.postion"));
GenConstructor(GenIndirect("o + {{ACCESS}}.position"));
break;

case BASE_TYPE_STRING: {
Expand Down
3 changes: 1 addition & 2 deletions swift/Sources/FlatBuffers/ByteBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public struct ByteBuffer {

/// The size of the elements written to the buffer + their paddings
private var _writerSize: Int = 0
/// Aliginment of the current memory being written to the buffer
/// Alignment of the current memory being written to the buffer
var alignment = 1
/// Current Index which is being used to write to the buffer, it is written from the end to the start of the buffer
var writerIndex: Int { _storage.capacity &- _writerSize }
Expand Down Expand Up @@ -474,7 +474,6 @@ public struct ByteBuffer {
/// - Parameters:
/// - index: index of the string in the buffer
/// - count: length of the string
/// - type: Encoding of the string
@inline(__always)
public func readString(
at index: Int,
Expand Down
2 changes: 1 addition & 1 deletion swift/Sources/FlatBuffers/FlatBufferBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ public struct FlatBufferBuilder {
/// *NOTE: Never call this manually*
///
/// - Parameter element: Element to insert
/// - returns: Postion of the Element
/// - returns: position of the Element
@inline(__always)
@discardableResult
mutating public func push<T: Scalar>(element: T) -> UOffset {
Expand Down
2 changes: 2 additions & 0 deletions swift/Sources/FlatBuffers/FlatbuffersErrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import Foundation
/// Collection of thrown from the Flatbuffer verifier
public enum FlatbuffersErrors: Error, Equatable {

/// Thrown when trying to verify a buffer that doesnt have the length of an ID
case bufferDoesntContainID
/// Thrown when verifying a file id that doesnt match buffer id
case bufferIdDidntMatchPassedId
/// Prefixed size doesnt match the current (readable) buffer size
Expand Down
Loading

0 comments on commit 4aad523

Please sign in to comment.