diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3db1f3dc2b2..c1cfda746c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,6 @@ on: - "*" # new tag version, like `0.8.4` or else branches: - master - - flatbuffers-64 pull_request: branches: - master @@ -22,10 +21,10 @@ jobs: digests-gcc: ${{ steps.hash-gcc.outputs.hashes }} digests-clang: ${{ steps.hash-clang.outputs.hashes }} name: Build Linux - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core strategy: matrix: - cxx: [g++-10, clang++-14] + cxx: [g++-13, clang++-15] fail-fast: false steps: - uses: actions/checkout@v3 @@ -39,10 +38,6 @@ jobs: run: | chmod +x flatc ./flatc --version - # - name: flatc tests - # run: | - # yarn global add esbuild - # python3 tests/flatc/main.py - name: upload build artifacts uses: actions/upload-artifact@v1 with: @@ -58,27 +53,29 @@ jobs: with: files: Linux.flatc.binary.${{ matrix.cxx }}.zip - name: Generate SLSA subjects - clang - if: matrix.cxx == 'clang++-14' && startsWith(github.ref, 'refs/tags/') + if: matrix.cxx == 'clang++-15' && startsWith(github.ref, 'refs/tags/') id: hash-clang run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT - name: Generate SLSA subjects - gcc - if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/') + if: matrix.cxx == 'g++-13' && startsWith(github.ref, 'refs/tags/') id: hash-gcc run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT build-linux-no-file-tests: name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: cmake - run: CXX=clang++-14 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" . + run: CXX=clang++-15 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" . - name: build run: make -j + - name: test + run: ./flattests build-linux-out-of-source: name: Build Linux with out-of-source build location - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: make build directory @@ -86,7 +83,7 @@ jobs: - name: cmake working-directory: build run: > - CXX=clang++-14 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON + CXX=clang++-15 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_CPP_STD=17 - name: build working-directory: build @@ -100,16 +97,17 @@ jobs: build-linux-cpp-std: name: Build Linux C++ - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core strategy: fail-fast: false matrix: std: [11, 14, 17, 20, 23] - cxx: [g++-10, clang++-14] + cxx: [g++-13, clang++-15] exclude: - # GCC 10.3.0 doesn't support std 23 - - cxx: g++-10 - std: 23 + # Clang++15 10.3.0 stdlibc++ doesn't fully support std 23 + - cxx: clang++-15 + std: 23 + steps: - uses: actions/checkout@v3 - name: cmake @@ -126,7 +124,7 @@ jobs: if: matrix.std >= 17 run: ./flattests_cpp17 - build-windows-cpp-std: + build-cpp-std: name: Build Windows C++ runs-on: windows-2019 strategy: @@ -168,8 +166,6 @@ jobs: run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 - name: test run: Release\flattests.exe - # - name: flatc tests - # run: python3 tests/flatc/main.py --flatc Release\flatc.exe - name: upload build artifacts uses: actions/upload-artifact@v1 with: @@ -220,7 +216,7 @@ jobs: build-dotnet-windows: name: Build .NET Windows - runs-on: windows-2019 + runs-on: windows-2022-64core strategy: matrix: configuration: [ @@ -270,8 +266,6 @@ jobs: run: | chmod +x Release/flatc Release/flatc --version - # - name: flatc tests - # run: python3 tests/flatc/main.py --flatc Release/flatc - name: upload build artifacts uses: actions/upload-artifact@v1 with: @@ -336,7 +330,7 @@ jobs: build-android: name: Build Android (on Linux) - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: set up Java @@ -355,10 +349,10 @@ jobs: build-generator: name: Check Generated Code - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core strategy: matrix: - cxx: [g++-10, clang++-14] + cxx: [g++-13, clang++-15] steps: - uses: actions/checkout@v3 - name: cmake @@ -386,10 +380,10 @@ jobs: build-benchmarks: name: Build Benchmarks (on Linux) - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core strategy: matrix: - cxx: [g++-10] + cxx: [g++-13] steps: - uses: actions/checkout@v3 - name: cmake @@ -404,7 +398,7 @@ jobs: build-java: name: Build Java - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: test @@ -433,7 +427,7 @@ jobs: build-kotlin-linux: name: Build Kotlin Linux - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - name: Checkout uses: actions/checkout@v3 @@ -456,7 +450,7 @@ jobs: build-rust-linux: name: Build Rust Linux - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: test @@ -465,7 +459,7 @@ jobs: build-rust-windows: name: Build Rust Windows - runs-on: windows-2019 + runs-on: windows-2022-64core steps: - uses: actions/checkout@v3 - name: test @@ -474,7 +468,7 @@ jobs: build-python: name: Build Python - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: flatc @@ -486,7 +480,7 @@ jobs: build-go: name: Build Go - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: flatc @@ -498,7 +492,7 @@ jobs: build-php: name: Build PHP - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: flatc @@ -512,7 +506,7 @@ jobs: build-swift: name: Build Swift - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: test @@ -523,7 +517,7 @@ jobs: build-swift-wasm: name: Build Swift Wasm - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core container: image: ghcr.io/swiftwasm/carton:0.15.3 steps: @@ -536,7 +530,7 @@ jobs: build-ts: name: Build TS - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: flatc @@ -554,7 +548,7 @@ jobs: build-dart: name: Build Dart - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 @@ -569,7 +563,7 @@ jobs: build-nim: name: Build Nim - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - uses: actions/checkout@v3 - name: flatc @@ -588,7 +582,7 @@ jobs: needs: [build-linux, build-windows, build-mac-intel, build-mac-universal] outputs: digests: ${{ steps.hash.outputs.digests }} - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-64core steps: - name: Merge results id: hash diff --git a/CMake/Version.cmake b/CMake/Version.cmake index f50e31a6119..c94240a9a33 100644 --- a/CMake/Version.cmake +++ b/CMake/Version.cmake @@ -29,7 +29,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v..-") endif() else() - message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}") + message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}\nMake sure you cloned with tags or run 'git fetch --tags'.") endif() else() message(WARNING "git is not found") diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a2e83499da..fd4418b7714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -556,7 +556,11 @@ if(FLATBUFFERS_BUILD_TESTS) # Add a library so there is a single target that the generated samples can # link too. - add_library(flatsample INTERFACE) + if(MSVC) + add_library(flatsample INTERFACE) + else() + add_library(flatsample STATIC) + endif() # Since flatsample has no sources, we have to explicitly set the linker lang. set_target_properties(flatsample PROPERTIES LINKER_LANGUAGE CXX) diff --git a/dart/CHANGELOG.md b/dart/CHANGELOG.md index a582e2eafed..9562920965c 100644 --- a/dart/CHANGELOG.md +++ b/dart/CHANGELOG.md @@ -1,3 +1,17 @@ +# Changelog + +## 23.5.26 + +- omit type annotationes for local variables (#7067, #7069, #7070) +- remove BSD 3-clause license (#7073) +- correctly parse lists of enums (#7157) +- align naming conventions for generated code (#7187) +- add `putBool` to fix errors when serializing structs with booleans (#7359) +- fix handling of +/-inf defaults in codegen (#7588) +- fix import issues in generated code (#7621) +- Fix incorrect storage of floats as ints in some cases (#7703) +- add final modifiers to the library implementation (#7943) + ## 2.0.5 - switch to null safety (#6696) diff --git a/dart/README.md b/dart/README.md index 123cdc38d6a..a07bc258ff6 100644 --- a/dart/README.md +++ b/dart/README.md @@ -3,7 +3,7 @@ This package is used to read and write [FlatBuffers](https://google.github.io/flatbuffers/). Most consumers will want to use the [`flatc` - FlatBuffer compiler](https://github.com/google/flatbuffers) binary for your platform. -You can find it in the `generator/{Platform}` directory of the [released package archive](https://pub.dev/packages/flat_buffers/versions/2.0.5.tar.gz). +You can download the flatc version matching your dart package version from [GitHub releases](https://github.com/google/flatbuffers/releases). The FlatBuffer compiler `flatc` reads a FlatBuffers IDL schema and generates Dart code. The generated classes can be used to read or write binary data/files that are interoperable with @@ -13,11 +13,3 @@ examples folder. For more details and documentation, head over to the official site and read the [Tutorial](https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html) and how to [use FlatBuffers in Dart](https://google.github.io/flatbuffers/flatbuffers_guide_use_dart.html). - -## Dart 2.0 notes -Version 2.0.5 ships with it's own custom build of `flatc` because this is an extraordinary release to catch-up -with FlatBuffers for other platforms. This generator can only generate dart code (to avoid generating code for other platforms which isn't released yet). -On the other hand, the generated code still produces standard binary FlatBuffers compatible with other languages. -In other words: only `flatc --dart ...` works with this generator, but your app will be able to produce and read standard binary (`Uint8List`) FlatBuffers that are fully compotible with other languages supporting FlatBuffers (e.g. Java, C++, ...). - -In the future a common `flatc` binary for all platforms would be shipped through GitHub release page instead. diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml index 347712caa42..f2830de290e 100644 --- a/dart/pubspec.yaml +++ b/dart/pubspec.yaml @@ -5,11 +5,10 @@ homepage: https://github.com/google/flatbuffers documentation: https://google.github.io/flatbuffers/index.html environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.12.0 <4.0.0' dev_dependencies: test: ^1.17.7 test_reflective_loader: ^0.2.0 path: ^1.8.0 lints: ^1.0.1 - diff --git a/dart/test/flat_buffers_test.dart b/dart/test/flat_buffers_test.dart index 000ccff68ca..caf2fc79a9e 100644 --- a/dart/test/flat_buffers_test.dart +++ b/dart/test/flat_buffers_test.dart @@ -11,7 +11,6 @@ import './monster_test_my_game.example_generated.dart' as example; import './monster_test_my_game.example2_generated.dart' as example2; import './list_of_enums_generated.dart' as example3; import './bool_structs_generated.dart' as example4; -import './keyword_test_keyword_test_generated.dart' as keyword_test; main() { defineReflectiveSuite(() { @@ -62,92 +61,91 @@ class CheckOtherLangaugesData { // this will fail if accessing any field fails. expect( - mon.toString(), - 'Monster{' - 'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, ' - 'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], ' - 'color: Color{value: 8}, testType: AnyTypeId{value: 1}, ' - 'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' - 'inventory: null, color: Color{value: 8}, testType: null, ' - 'test: null, test4: null, testarrayofstring: null, ' - 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, ' - 'testempty: null, testbool: false, testhashs32Fnv1: 0, ' - 'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, ' - 'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, ' - 'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, ' - 'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, ' - 'testarrayofsortedstruct: null, flex: null, test5: null, ' - 'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, ' - 'vectorOfReferrables: null, singleWeakReference: 0, ' - 'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, ' - 'coOwningReference: 0, vectorOfCoOwningReferences: null, ' - 'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' - 'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, ' - 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' - 'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, ' - 'nativeInline: null, ' - 'longEnumNonEnumDefault: LongEnum{value: 0}, ' - 'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' - 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' - 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' - '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, ' - 'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], ' - 'testarrayofstring: [test1, test2], testarrayoftables: null, ' - 'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' - 'inventory: null, color: Color{value: 8}, testType: null, ' - 'test: null, test4: null, testarrayofstring: null, ' - 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, ' - 'testempty: null, testbool: false, testhashs32Fnv1: 0, ' - 'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, ' - 'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, ' - 'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, ' - 'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, ' - 'testarrayofsortedstruct: null, flex: null, test5: null, ' - 'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, ' - 'vectorOfReferrables: null, singleWeakReference: 0, ' - 'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, ' - 'coOwningReference: 0, vectorOfCoOwningReferences: null, ' - 'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' - 'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, ' - 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' - 'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, ' - 'nativeInline: null, ' - 'longEnumNonEnumDefault: LongEnum{value: 0}, ' - 'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' - 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' - 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' - '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, ' - 'testnestedflatbuffer: null, testempty: null, testbool: true, ' - 'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, ' - 'testhashs64Fnv1: 7930699090847568257, ' - 'testhashu64Fnv1: 7930699090847568257, ' - 'testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, ' - 'testhashs64Fnv1a: 4898026182817603057, ' - 'testhashu64Fnv1a: 4898026182817603057, ' - 'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, ' - 'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: [' - 'Ability{id: 0, distance: 45}, Ability{id: 1, distance: 21}, ' - 'Ability{id: 5, distance: 12}], ' - 'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], ' - 'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], ' - 'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], ' - 'parentNamespaceTest: null, vectorOfReferrables: null, ' - 'singleWeakReference: 0, vectorOfWeakReferences: null, ' - 'vectorOfStrongReferrables: null, coOwningReference: 0, ' - 'vectorOfCoOwningReferences: null, nonOwningReference: 0, ' - 'vectorOfNonOwningReferences: null, ' - 'anyUniqueType: null, anyUnique: null, ' - 'anyAmbiguousType: null, ' - 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' - 'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: ' - 'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], ' - 'nativeInline: Test{a: 1, b: 2}, ' - 'longEnumNonEnumDefault: LongEnum{value: 0}, ' - 'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' - 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' - 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' - '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}' - ); + mon.toString(), + 'Monster{' + 'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, ' + 'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], ' + 'color: Color{value: 8}, testType: AnyTypeId{value: 1}, ' + 'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' + 'inventory: null, color: Color{value: 8}, testType: null, ' + 'test: null, test4: null, testarrayofstring: null, ' + 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, ' + 'testempty: null, testbool: false, testhashs32Fnv1: 0, ' + 'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, ' + 'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, ' + 'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, ' + 'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, ' + 'testarrayofsortedstruct: null, flex: null, test5: null, ' + 'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, ' + 'vectorOfReferrables: null, singleWeakReference: 0, ' + 'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, ' + 'coOwningReference: 0, vectorOfCoOwningReferences: null, ' + 'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' + 'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, ' + 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' + 'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, ' + 'nativeInline: null, ' + 'longEnumNonEnumDefault: LongEnum{value: 0}, ' + 'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' + 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' + 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' + '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, ' + 'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], ' + 'testarrayofstring: [test1, test2], testarrayoftables: null, ' + 'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, ' + 'inventory: null, color: Color{value: 8}, testType: null, ' + 'test: null, test4: null, testarrayofstring: null, ' + 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, ' + 'testempty: null, testbool: false, testhashs32Fnv1: 0, ' + 'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, ' + 'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, ' + 'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, ' + 'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, ' + 'testarrayofsortedstruct: null, flex: null, test5: null, ' + 'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, ' + 'vectorOfReferrables: null, singleWeakReference: 0, ' + 'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, ' + 'coOwningReference: 0, vectorOfCoOwningReferences: null, ' + 'nonOwningReference: 0, vectorOfNonOwningReferences: null, ' + 'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, ' + 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' + 'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, ' + 'nativeInline: null, ' + 'longEnumNonEnumDefault: LongEnum{value: 0}, ' + 'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' + 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' + 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' + '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, ' + 'testnestedflatbuffer: null, testempty: null, testbool: true, ' + 'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, ' + 'testhashs64Fnv1: 7930699090847568257, ' + 'testhashu64Fnv1: 7930699090847568257, ' + 'testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, ' + 'testhashs64Fnv1a: 4898026182817603057, ' + 'testhashu64Fnv1a: 4898026182817603057, ' + 'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, ' + 'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: [' + 'Ability{id: 0, distance: 45}, Ability{id: 1, distance: 21}, ' + 'Ability{id: 5, distance: 12}], ' + 'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], ' + 'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], ' + 'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], ' + 'parentNamespaceTest: null, vectorOfReferrables: null, ' + 'singleWeakReference: 0, vectorOfWeakReferences: null, ' + 'vectorOfStrongReferrables: null, coOwningReference: 0, ' + 'vectorOfCoOwningReferences: null, nonOwningReference: 0, ' + 'vectorOfNonOwningReferences: null, ' + 'anyUniqueType: null, anyUnique: null, ' + 'anyAmbiguousType: null, ' + 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, ' + 'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: ' + 'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], ' + 'nativeInline: Test{a: 1, b: 2}, ' + 'longEnumNonEnumDefault: LongEnum{value: 0}, ' + 'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, ' + 'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: ' + 'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: ' + '-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}'); } } @@ -769,7 +767,6 @@ class BuilderTest { class ObjectAPITest { void test_tableStat() { final object1 = example.StatT(count: 3, id: "foo", val: 4); - expect(object1 is Packable, isTrue); final fbb = Builder(); fbb.finish(object1.pack(fbb)); final object2 = example.Stat(fbb.buffer).unpack(); diff --git a/dart/test/monster_test.fbs b/dart/test/monster_test.fbs index 8a124f25ac1..b40ecf58f95 100644 --- a/dart/test/monster_test.fbs +++ b/dart/test/monster_test.fbs @@ -59,8 +59,6 @@ struct Vec3 (force_align: 8) { test3:Test; } -// Stats for monster - struct Ability { id:uint(key); distance:uint; diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md index 7571a4252ae..ff71378b526 100644 --- a/docs/source/Compiler.md +++ b/docs/source/Compiler.md @@ -23,31 +23,35 @@ For any schema input files, one or more generators can be specified: - `--java`, `-j` : Generate Java code. -- `--kotlin`, `-k` : Generate Kotlin code. +- `--kotlin` , `--kotlin-kmp` : Generate Kotlin code. - `--csharp`, `-n` : Generate C# code. - `--go`, `-g` : Generate Go code. -- `--python`, `-p`: Generate Python code. +- `--python`, `-p` : Generate Python code. -- `--js`, `-s`: Generate JavaScript code. +- `--js`, `-s` : Generate JavaScript code. -- `--ts`: Generate TypeScript code. +- `--ts`, `-T` : Generate TypeScript code. -- `--php`: Generate PHP code. +- `--php` : Generate PHP code. -- `--grpc`: Generate RPC stub code for GRPC. +- `--grpc` : Generate RPC stub code for GRPC. -- `--dart`: Generate Dart code. +- `--dart`, `-d` : Generate Dart code. -- `--lua`: Generate Lua code. +- `--lua`, `-l` : Generate Lua code. -- `--lobster`: Generate Lobster code. +- `--lobster` : Generate Lobster code. - `--rust`, `-r` : Generate Rust code. -- `--swift`: Generate Swift code. +- `--swift` : Generate Swift code. + +- `--nim` : Generate Nim code. + + For any data input files: @@ -58,6 +62,8 @@ For any data input files: - `--json`, `-t` : If data is contained in this file, generate a `filename.json` representing the data in the flatbuffer. +- `--jsonschema` : Generate Json schema + Additional options: - `-o PATH` : Output all generated files to PATH (either absolute, or @@ -115,7 +121,7 @@ Additional options: - `--gen-compare` : Generate operator== for object-based API types. -- `--gen-nullable` : Add Clang _Nullable for C++ pointer. or @Nullable for Java. +- `--gen-nullable` : Add Clang \_Nullable for C++ pointer. or @Nullable for Java. - `--gen-generated` : Add @Generated annotation for Java. @@ -189,7 +195,7 @@ Additional options: `--conform PATH`. - `--filename-suffix SUFFIX` : The suffix appended to the generated - file names. Default is '_generated'. + file names. Default is '\_generated'. - `--filename-ext EXTENSION` : The extension appended to the generated file names. Default is language-specific (e.g. "h" for C++). This @@ -227,5 +233,10 @@ Additional options: vector of bytes in JSON, which is unsafe unless checked by a verifier afterwards. +- `--python-no-type-prefix-suffix` : Skip emission of Python functions that are prefixed + with typenames + +- `--python-typing` : Generate Python type annotations + NOTE: short-form options for generators are deprecated, use the long form whenever possible. diff --git a/grpc/examples/go/greeter/client/go.mod b/grpc/examples/go/greeter/client/go.mod index 69c551158ab..d0f219855c7 100644 --- a/grpc/examples/go/greeter/client/go.mod +++ b/grpc/examples/go/greeter/client/go.mod @@ -5,7 +5,7 @@ go 1.15 replace github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 => ../models require ( - github.com/google/flatbuffers v1.12.0 + github.com/google/flatbuffers v2.0.8+incompatible github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 - google.golang.org/grpc v1.53.0 + google.golang.org/grpc v1.56.3 ) diff --git a/grpc/examples/go/greeter/models/go.mod b/grpc/examples/go/greeter/models/go.mod index d9e2e19e704..31d6cdcb5e2 100644 --- a/grpc/examples/go/greeter/models/go.mod +++ b/grpc/examples/go/greeter/models/go.mod @@ -3,6 +3,6 @@ module github.com/google/flatbuffers/grpc/examples/go/greeter/models go 1.15 require ( - github.com/google/flatbuffers v1.12.0 - google.golang.org/grpc v1.53.0 + github.com/google/flatbuffers v2.0.8+incompatible + google.golang.org/grpc v1.56.3 ) diff --git a/grpc/examples/go/greeter/server/go.mod b/grpc/examples/go/greeter/server/go.mod index 8769bde3181..eeb9e538ae2 100644 --- a/grpc/examples/go/greeter/server/go.mod +++ b/grpc/examples/go/greeter/server/go.mod @@ -5,7 +5,7 @@ go 1.15 replace github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 => ../models require ( - github.com/google/flatbuffers v1.12.0 + github.com/google/flatbuffers v2.0.8+incompatible github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 - google.golang.org/grpc v1.53.0 + google.golang.org/grpc v1.56.3 ) diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h index 58f15d06500..97d76a6e645 100644 --- a/include/flatbuffers/base.h +++ b/include/flatbuffers/base.h @@ -363,7 +363,6 @@ inline bool VerifyAlignmentRequirements(size_t align, size_t min_align = 1) { } #if defined(_MSC_VER) - #pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized #pragma warning(push) #pragma warning(disable: 4127) // C4127: conditional expression is constant #endif diff --git a/include/flatbuffers/flatbuffer_builder.h b/include/flatbuffers/flatbuffer_builder.h index 84bf936d507..6ee4d8e7b1b 100644 --- a/include/flatbuffers/flatbuffer_builder.h +++ b/include/flatbuffers/flatbuffer_builder.h @@ -589,14 +589,14 @@ template class FlatBufferBuilderImpl { /// @brief Store a string in the buffer, which can contain any binary data. /// @param[in] str A const reference to a std::string like type with support - /// of T::c_str() and T::length() to store in the buffer. + /// of T::data() and T::length() to store in the buffer. /// @return Returns the offset in the buffer where the string starts. template class OffsetT = Offset, // No need to explicitly declare the T type, let the compiler deduce // it. int &...ExplicitArgumentBarrier, typename T> OffsetT CreateString(const T &str) { - return CreateString(str.c_str(), str.length()); + return CreateString(str.data(), str.length()); } /// @brief Store a string in the buffer, which can contain any binary data. diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h index 6651157b831..f262558e4cb 100644 --- a/include/flatbuffers/flexbuffers.h +++ b/include/flatbuffers/flexbuffers.h @@ -1720,7 +1720,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS { max_vectors_(buf_len), check_alignment_(_check_alignment), reuse_tracker_(reuse_tracker) { - FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE); + FLATBUFFERS_ASSERT(static_cast(size_) < FLATBUFFERS_MAX_BUFFER_SIZE); if (reuse_tracker_) { reuse_tracker_->clear(); reuse_tracker_->resize(size_, PackedType(BIT_WIDTH_8, FBT_NULL)); diff --git a/include/flatbuffers/minireflect.h b/include/flatbuffers/minireflect.h index 1e04bfff02a..09ff66c334a 100644 --- a/include/flatbuffers/minireflect.h +++ b/include/flatbuffers/minireflect.h @@ -408,8 +408,9 @@ inline std::string FlatBufferToString(const uint8_t *buffer, const TypeTable *type_table, bool multi_line = false, bool vector_delimited = true, - const std::string &indent = "") { - ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, indent, + const std::string &indent = "", + bool quotes = false) { + ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", quotes, indent, vector_delimited); IterateFlatBuffer(buffer, type_table, &tostring_visitor); return tostring_visitor.s; diff --git a/include/flatbuffers/stl_emulation.h b/include/flatbuffers/stl_emulation.h index fd3a8cda71c..5f19eaf8d41 100644 --- a/include/flatbuffers/stl_emulation.h +++ b/include/flatbuffers/stl_emulation.h @@ -45,7 +45,8 @@ // Testing __cpp_lib_span requires including either or , // both of which were added in C++20. // See: https://en.cppreference.com/w/cpp/utility/feature_test - #if defined(__cplusplus) && __cplusplus >= 202002L + #if defined(__cplusplus) && __cplusplus >= 202002L \ + || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) #define FLATBUFFERS_USE_STD_SPAN 1 #endif #endif // FLATBUFFERS_USE_STD_SPAN diff --git a/java/src/main/java/com/google/flatbuffers/Utf8Old.java b/java/src/main/java/com/google/flatbuffers/Utf8Old.java index 3dac714bb67..c568105a01c 100644 --- a/java/src/main/java/com/google/flatbuffers/Utf8Old.java +++ b/java/src/main/java/com/google/flatbuffers/Utf8Old.java @@ -42,8 +42,15 @@ private static class Cache { } } + // ThreadLocal.withInitial() is not used to make the following code compatible with Android API + // level 23. private static final ThreadLocal CACHE = - ThreadLocal.withInitial(() -> new Cache()); + new ThreadLocal() { + @Override + protected Cache initialValue() { + return new Cache(); + } + }; // Play some games so that the old encoder doesn't pay twice for computing // the length of the encoded string. diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs index e08db847be8..4df4f8c6737 100644 --- a/net/FlatBuffers/FlatBufferBuilder.cs +++ b/net/FlatBuffers/FlatBufferBuilder.cs @@ -67,7 +67,7 @@ public FlatBufferBuilder(int initialSize) } /// - /// Create a FlatBufferBuilder backed by the pased in ByteBuffer + /// Create a FlatBufferBuilder backed by the passed in ByteBuffer /// /// The ByteBuffer to write to public FlatBufferBuilder(ByteBuffer buffer) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8dfe73dc88d..ccdab334b2f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + devDependencies: '@types/node': specifier: 18.16.3 @@ -978,7 +982,7 @@ packages: levn: 0.4.1 prelude-ls: 1.2.1 type-check: 0.4.0 - word-wrap: 1.2.3 + word-wrap: 1.2.4 dev: true /p-limit@3.1.0: @@ -1165,8 +1169,8 @@ packages: isexe: 2.0.0 dev: true - /word-wrap@1.2.3: - resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==} + /word-wrap@1.2.4: + resolution: {integrity: sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==} engines: {node: '>=0.10.0'} dev: true diff --git a/swift/Sources/FlatBuffers/Verifiable.swift b/swift/Sources/FlatBuffers/Verifiable.swift index b445c4ce13a..09f1a354db3 100644 --- a/swift/Sources/FlatBuffers/Verifiable.swift +++ b/swift/Sources/FlatBuffers/Verifiable.swift @@ -129,7 +129,7 @@ public enum Vector: Verifiable where U: Verifiable, S: Verifiable { let range = try verifyRange(&verifier, at: position, of: UOffset.self) for index in stride( from: range.start, - to: Int(clamping: range.start &+ range.count), + to: Int(clamping: range.start &+ (range.count &* MemoryLayout.size)), by: MemoryLayout.size) { try U.verify(&verifier, at: index, of: U.self) diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift index f9a967066a5..8fe5f81311c 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift @@ -439,11 +439,26 @@ class FlatBuffersMonsterWriterTests: XCTestCase { let fbb = createMonster(withPrefix: false) var sizedBuffer = fbb.sizedBuffer do { + struct Test: Decodable { + struct Pos: Decodable { + let x, y, z: Int + } + let hp: Int + let inventory: [UInt8] + let name: String + let pos: Pos + } let reader: Monster = try getCheckedRoot(byteBuffer: &sizedBuffer) let encoder = JSONEncoder() encoder.keyEncodingStrategy = .convertToSnakeCase let data = try encoder.encode(reader) - XCTAssertEqual(data, jsonData.data(using: .utf8)) + let decoder = JSONDecoder() + decoder.keyDecodingStrategy = .convertFromSnakeCase + let value = try decoder.decode(Test.self, from: data) + XCTAssertEqual(value.name, "MyMonster") + XCTAssertEqual(value.pos.x, 1) + XCTAssertEqual(value.pos.y, 2) + XCTAssertEqual(value.pos.z, 3) } catch { XCTFail(error.localizedDescription) } diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift index 30d16b199ba..96b5614e66a 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift @@ -50,6 +50,12 @@ final class FlatBuffersNanInfTests: XCTestCase { let fbb = createTestTable() var bb = fbb.sizedBuffer do { + struct Test: Decodable { + let valueInf: Double + let value: Int + let valueNan: Double + let valueNinf: Double + } let reader: Swift_Tests_NanInfTable = try getCheckedRoot(byteBuffer: &bb) let encoder = JSONEncoder() encoder.keyEncodingStrategy = .convertToSnakeCase @@ -59,14 +65,19 @@ final class FlatBuffersNanInfTests: XCTestCase { negativeInfinity: "-inf", nan: "nan") let data = try encoder.encode(reader) - XCTAssertEqual(data, jsonData.data(using: .utf8)) + let decoder = JSONDecoder() + decoder.nonConformingFloatDecodingStrategy = .convertFromString( + positiveInfinity: "inf", + negativeInfinity: "-inf", + nan: "nan") + decoder.keyDecodingStrategy = .convertFromSnakeCase + let value = try decoder.decode(Test.self, from: data) + XCTAssertEqual(value.value, 100) + XCTAssertEqual(value.valueInf, .infinity) + XCTAssertEqual(value.valueNinf, -.infinity) } catch { XCTFail(error.localizedDescription) } } - var jsonData: String { - "{\"value_inf\":\"inf\",\"value\":100,\"value_nan\":\"nan\",\"value_ninf\":\"-inf\"}" - } - } diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift index ee6110257d5..4eb3f345b99 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift @@ -244,8 +244,7 @@ final class FlatBuffersUnionTests: XCTestCase { let reader: Movie = try getCheckedRoot(byteBuffer: &sizedBuffer) let encoder = JSONEncoder() encoder.keyEncodingStrategy = .convertToSnakeCase - let data = try encoder.encode(reader) - XCTAssertEqual(data, jsonData.data(using: .utf8)) + _ = try encoder.encode(reader) } catch { XCTFail(error.localizedDescription) } diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift index 39e13b115dd..45be6cf6c26 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersMoreDefaults.swift @@ -65,17 +65,22 @@ class FlatBuffersMoreDefaults: XCTestCase { fbb.finish(offset: root) var sizedBuffer = fbb.sizedBuffer do { + struct Test: Decodable { + var emptyString: String + var someString: String + } let reader: MoreDefaults = try getCheckedRoot(byteBuffer: &sizedBuffer) let encoder = JSONEncoder() encoder.keyEncodingStrategy = .convertToSnakeCase let data = try encoder.encode(reader) - XCTAssertEqual(data, jsonData.data(using: .utf8)) + let decoder = JSONDecoder() + decoder.keyDecodingStrategy = .convertFromSnakeCase + let value = try decoder.decode(Test.self, from: data) + XCTAssertEqual(value.someString, "some") + XCTAssertEqual(value.emptyString, "") } catch { XCTFail(error.localizedDescription) } } - var jsonData: String { - "{\"empty_string\":\"\",\"some_string\":\"some\"}" - } } diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift index d7f949b1836..cb52d1168c7 100644 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift +++ b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatbuffersVerifierTests.swift @@ -30,6 +30,8 @@ final class FlatbuffersVerifierTests: XCTestCase { var validFlatbuffersObject: ByteBuffer! var invalidFlatbuffersObject: ByteBuffer! + var invalidFlatbuffersObject2: ByteBuffer! + var invalidFlatbuffersObject3: ByteBuffer! override func setUp() { // swiftformat:disable all @@ -41,6 +43,11 @@ final class FlatbuffersVerifierTests: XCTestCase { invalidFlatbuffersObject = ByteBuffer(bytes: [0, 48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]) + // Array failure within a the inventory array + invalidFlatbuffersObject2 = ByteBuffer(bytes: [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 0x00, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 111, 0, 0, 0]) + + // Array failure within a the strings array + invalidFlatbuffersObject3 = ByteBuffer(bytes: [48, 0, 0, 0, 77, 79, 78, 83, 0, 0, 0, 0, 36, 0, 72, 0, 40, 0, 0, 0, 38, 0, 32, 0, 0, 0, 28, 0, 0, 0, 27, 0, 20, 0, 16, 0, 12, 0, 4, 0, 0, 0, 0, 0, 0, 0, 11, 0, 36, 0, 0, 0, 164, 0, 0, 0, 0, 0, 0, 1, 60, 0, 0, 0, 68, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 1, 88, 0, 0, 0, 120, 0, 0, 0, 0, 0, 80, 0, 0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 64, 2, 0, 5, 0, 6, 0, 0, 0, 2, 0, 0, 0, 64, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 30, 0, 40, 0, 10, 0, 20, 0, 152, 255, 255, 255, 4, 0, 0, 0, 4, 0, 0, 0, 70, 114, 101, 100, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 50, 0, 0, 0, 5, 0, 0, 0, 116, 101, 115, 116, 49, 0, 0, 0, 9, 0, 0, 0, 77, 121, 77, 111, 110, 115, 116, 101, 114, 0, 0, 0, 3, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 4, 0, 0, 0, 240, 255, 255, 255, 32, 0, 0, 0, 248, 255, 255, 255, 36, 0, 0, 0, 12, 0, 8, 0, 0, 0, 0, 0, 0, 0, 4, 0, 12, 0, 0, 0, 28, 0, 0, 0, 5, 0, 0, 0, 87, 105, 108, 109, 97, 0, 0, 0, 6, 0, 0, 0, 66, 97, 114, 110, 101, 121, 0, 0, 5, 0, 0, 0, 70, 114, 111, 100, 0x00, 111, 0, 0, 0]) // swiftformat:enable all } @@ -237,6 +244,18 @@ final class FlatbuffersVerifierTests: XCTestCase { byteBuffer: &invalidFlatbuffersObject) as MyGame_Example_Monster) } + func testInvalidBuffer2() { + XCTAssertThrowsError( + try getCheckedRoot( + byteBuffer: &invalidFlatbuffersObject2) as MyGame_Example_Monster) + } + + func testInvalidBuffer3() { + XCTAssertThrowsError( + try getCheckedRoot( + byteBuffer: &invalidFlatbuffersObject3) as MyGame_Example_Monster) + } + func testValidUnionBuffer() { let string = "Awesome \\\\t\t\nstring!" var fb = FlatBufferBuilder() diff --git a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift b/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift deleted file mode 100644 index e164fc3be6a..00000000000 --- a/tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/XCTestManifests.swift +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2023 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if !canImport(ObjectiveC) -import XCTest - -extension FlatBuffersDoubleTests { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersDoubleTests = [ - ("testCreateFinish", testCreateFinish), - ("testCreateFinishWithPrefix", testCreateFinishWithPrefix), - ] -} - -extension FlatBuffersMonsterWriterTests { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersMonsterWriterTests = [ - ("testArrayOfBools", testArrayOfBools), - ("testCreateMonster", testCreateMonster), - ("testCreateMonsterPrefixed", testCreateMonsterPrefixed), - ("testCreateMonsterResizedBuffer", testCreateMonsterResizedBuffer), - ( - "testCreateMonsterUsingCreateMonsterMethodWithNilPos", - testCreateMonsterUsingCreateMonsterMethodWithNilPos), - ( - "testCreateMonsterUsingCreateMonsterMethodWithPosX", - testCreateMonsterUsingCreateMonsterMethodWithPosX), - ("testData", testData), - ("testReadFromOtherLanguages", testReadFromOtherLanguages), - ( - "testReadMonsterFromUnsafePointerWithoutCopying", - testReadMonsterFromUnsafePointerWithoutCopying), - ] -} - -extension FlatBuffersMoreDefaults { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersMoreDefaults = [ - ("testFlatbuffersObject", testFlatbuffersObject), - ("testFlatbuffersObjectAPI", testFlatbuffersObjectAPI), - ] -} - -extension FlatBuffersStructsTests { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersStructsTests = [ - ("testWritingAndMutatingBools", testWritingAndMutatingBools), - ] -} - -extension FlatBuffersTests { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersTests = [ - ("testCreateFinish", testCreateFinish), - ("testCreateFinishWithPrefix", testCreateFinishWithPrefix), - ("testCreateString", testCreateString), - ("testEndian", testEndian), - ("testOffset", testOffset), - ("testReadCountry", testReadCountry), - ("testStartTable", testStartTable), - ("testWriteNullableStrings", testWriteNullableStrings), - ("testWriteOptionalValues", testWriteOptionalValues), - ] -} - -extension FlatBuffersUnionTests { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersUnionTests = [ - ("testCreateMonstor", testCreateMonstor), - ("testEndTableFinish", testEndTableFinish), - ("testEnumVector", testEnumVector), - ("testStringUnion", testStringUnion), - ("testUnionVector", testUnionVector), - ] -} - -extension FlatBuffersVectors { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatBuffersVectors = [ - ("testCreateEmptyIntArray", testCreateEmptyIntArray), - ("testCreateIntArray", testCreateIntArray), - ("testCreateSharedStringVector", testCreateSharedStringVector), - ("testCreateVectorOfStrings", testCreateVectorOfStrings), - ("testCreatingTwoCountries", testCreatingTwoCountries), - ("testHasForArray", testHasForArray), - ("testReadDoubleArray", testReadDoubleArray), - ("testReadInt32Array", testReadInt32Array), - ] -} - -extension FlatbuffersVerifierTests { - // DO NOT MODIFY: This is autogenerated, use: - // `swift test --generate-linuxmain` - // to regenerate. - static let __allTests__FlatbuffersVerifierTests = [ - ("testFullVerifier", testFullVerifier), - ("testInvalidBuffer", testInvalidBuffer), - ("testPositionInBuffer", testPositionInBuffer), - ("testRangeInBuffer", testRangeInBuffer), - ("testTableVerifier", testTableVerifier), - ("testValidUnionBuffer", testValidUnionBuffer), - ("testVeriferInitFailing", testVeriferInitFailing), - ("testVeriferInitPassing", testVeriferInitPassing), - ("testVerifierCheckAlignment", testVerifierCheckAlignment), - ("testVerifyUnionVectors", testVerifyUnionVectors), - ("testVisitTable", testVisitTable), - ] -} - -public func __allTests() -> [XCTestCaseEntry] { - [ - testCase(FlatBuffersDoubleTests.__allTests__FlatBuffersDoubleTests), - testCase( - FlatBuffersMonsterWriterTests - .__allTests__FlatBuffersMonsterWriterTests), - testCase(FlatBuffersMoreDefaults.__allTests__FlatBuffersMoreDefaults), - testCase(FlatBuffersStructsTests.__allTests__FlatBuffersStructsTests), - testCase(FlatBuffersTests.__allTests__FlatBuffersTests), - testCase(FlatBuffersUnionTests.__allTests__FlatBuffersUnionTests), - testCase(FlatBuffersVectors.__allTests__FlatBuffersVectors), - testCase(FlatbuffersVerifierTests.__allTests__FlatbuffersVerifierTests), - ] -} -#endif diff --git a/tests/swift/tests/Tests/LinuxMain.swift b/tests/swift/tests/Tests/LinuxMain.swift deleted file mode 100644 index a959fc76980..00000000000 --- a/tests/swift/tests/Tests/LinuxMain.swift +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2023 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import XCTest - -import FlatBuffers_Test_SwiftTests - -var tests = [XCTestCaseEntry]() -tests += FlatBuffers_Test_SwiftTests.__allTests() - -XCTMain(tests) diff --git a/tests/test.cpp b/tests/test.cpp index be2811efee4..af8cd63479a 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -86,7 +86,7 @@ void TriviallyCopyableTest() { // clang-format off #if __GNUG__ && __GNUC__ < 5 && \ !(defined(__clang__) && __clang_major__ >= 16) - TEST_EQ(__has_trivial_copy(Vec3), true); + TEST_EQ(__is_trivially_copyable(Vec3), true); #else #if __cplusplus >= 201103L TEST_EQ(std::is_trivially_copyable::value, true);