Skip to content

Commit

Permalink
Merge branch 'master' into dart/enhanced-enums
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel authored Nov 18, 2024
2 parents e68854e + 5f453ef commit 2d5d698
Show file tree
Hide file tree
Showing 47 changed files with 466 additions and 112 deletions.
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 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
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
2 changes: 1 addition & 1 deletion rust/flatbuffers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ std = []
serialize = ["serde"]

[dependencies]
bitflags = "2.6.0"
bitflags = "1.2.1"
serde = { version = "1.0", optional = true }

[build-dependencies]
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
4 changes: 2 additions & 2 deletions rust/flexbuffers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ deserialize_human_readable = []
serde = "1.0.119"
serde_derive = "1.0.119"
byteorder = "1.4.2"
num_enum = "0.7.3"
bitflags = "2.6.0"
num_enum = "0.5.1"
bitflags = "1.2.1"
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
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
6 changes: 3 additions & 3 deletions swift/Sources/FlatBuffers/Mutable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public protocol Mutable {
/// makes Flatbuffer accessed within the Protocol
var bb: ByteBuffer { get }
/// makes position of the ``Table``/``Struct`` accessed within the Protocol
var postion: Int32 { get }
var position: Int32 { get }
}

extension Mutable {
Expand All @@ -45,7 +45,7 @@ extension Mutable where Self == Table {
/// - index: index of the Element
public func mutate<T: Scalar>(_ value: T, index: Int32) -> Bool {
guard index != 0 else { return false }
return mutate(value: value, o: index + postion)
return mutate(value: value, o: index + position)
}

/// Directly mutates the element by calling mutate
Expand All @@ -66,7 +66,7 @@ extension Mutable where Self == Struct {
/// - value: New value to be inserted to the buffer
/// - index: index of the Element
public func mutate<T: Scalar>(_ value: T, index: Int32) -> Bool {
mutate(value: value, o: index + postion)
mutate(value: value, o: index + position)
}

/// Directly mutates the element by calling mutate
Expand Down
6 changes: 3 additions & 3 deletions swift/Sources/FlatBuffers/Struct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public struct Struct {
/// Hosting Bytebuffer
public private(set) var bb: ByteBuffer
/// Current position of the struct
public private(set) var postion: Int32
public private(set) var position: Int32

/// Initializer for a mutable flatbuffers struct
/// - Parameters:
/// - bb: Current hosting Bytebuffer
/// - position: Current position for the struct in the ByteBuffer
public init(bb: ByteBuffer, position: Int32 = 0) {
self.bb = bb
postion = position
self.position = position
}

/// Reads data from the buffer directly at offset O
Expand All @@ -41,7 +41,7 @@ public struct Struct {
/// - o: Current offset of the data
/// - Returns: Data of Type T that conforms to type Scalar
public func readBuffer<T: Scalar>(of type: T.Type, at o: Int32) -> T {
let r = bb.read(def: T.self, position: Int(o + postion))
let r = bb.read(def: T.self, position: Int(o + position))
return r
}
}
Loading

0 comments on commit 2d5d698

Please sign in to comment.