platform/upstream/flatbuffers.git
3 years ago[CI] fixes buildkite (#6544)
mustiikhalil [Mon, 5 Apr 2021 09:34:42 +0000 (12:34 +0300)]
[CI] fixes buildkite (#6544)

3 years agoLimit formatter to pull requests only (#6540)
mustiikhalil [Thu, 1 Apr 2021 17:09:43 +0000 (20:09 +0300)]
Limit formatter to pull requests only (#6540)

3 years agoRust structz (#6539)
Casper [Mon, 29 Mar 2021 23:56:45 +0000 (19:56 -0400)]
Rust structz (#6539)

* Rust structz

* struct of structs test

* swift tmp variables

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[Kotlin][FlexBuffers] JSON support for Flexbuffers (#6417)
Paulo Pinheiro [Mon, 29 Mar 2021 22:57:23 +0000 (00:57 +0200)]
[Kotlin][FlexBuffers] JSON support for Flexbuffers (#6417)

* [Kotlin][FlexBuffers] Add JSON support for FlexBuffers

* [Kotlin][Flexbuffers] Re-implement JSON parser with a tokenizer.

3 years ago[grpc] Support latest version of grpc PoC (#6338)
Jeong YunWon [Thu, 25 Mar 2021 19:12:35 +0000 (04:12 +0900)]
[grpc] Support latest version of grpc PoC (#6338)

* use grpcpp rather than deprecated grpc++

* grpcpp Deserialize take ByteBuffer instead of grpc_byte_buffer

* grpc 1.36.0

* Fix to use grpc 1.36.0

* Fix CMakeLists to refer gRPC

* add find_package(Threads)

* Update bazel deps

* Apply workaround about boringssl build error

* Install latest cmake for osx on travis-ci

Co-authored-by: Yeom Gyusun <omniavinco@gmail.com>
3 years agofixed packing structs (#6530)
Kamil Rojewski [Thu, 25 Mar 2021 17:25:00 +0000 (18:25 +0100)]
fixed packing structs (#6530)

* fixed packing structs in nested buffers

* fixed packing structs

3 years ago[GO] Tries to add go format to the CI (#6518)
mustiikhalil [Thu, 18 Mar 2021 18:03:44 +0000 (21:03 +0300)]
[GO] Tries to add go format to the CI (#6518)

* Trys to add go format to the CI

Adds Gofmt to CI

* Adds formatting for go dir in grpc

* Small fix

3 years ago[C++] #6501 - Problem when mapping a native type multiple times (#6514)
Michael [Thu, 18 Mar 2021 18:01:50 +0000 (19:01 +0100)]
[C++] #6501 - Problem when mapping a native type multiple times (#6514)

* [C++] #6501 - Problem when mapping a native type multiple times
- idl.h:
added "native_type_pack_name"
- flatbuffers.h:
added CreateVectorOfNativeStructs variants which receive a pointer to the serialization function
- idl_gen_cpp.cpp:
adapted code generation in case "native_type_pack_name" attribute is present
- extended tests & docs; improved surrounding native_type docs a little

* integrated review feedback

3 years ago[fuzzer] Add `monster_debug` target (#6513)
Vladimir Glavnyy [Thu, 18 Mar 2021 17:56:28 +0000 (00:56 +0700)]
[fuzzer] Add `monster_debug` target (#6513)

Add the `monster_debug` target for better troubleshooting.
Improve oss-fuzz logs.

3 years ago[Swift] Removes allman rule (#6519)
mustiikhalil [Wed, 17 Mar 2021 10:22:49 +0000 (13:22 +0300)]
[Swift] Removes allman rule (#6519)

3 years ago[flexbuffers, json] Parse `nan` and `inf` (#6512)
Vladimir Glavnyy [Mon, 15 Mar 2021 18:44:42 +0000 (01:44 +0700)]
[flexbuffers, json] Parse `nan` and `inf` (#6512)

3 years agofixed packing structs in nested buffers (#6509)
Kamil Rojewski [Thu, 11 Mar 2021 19:14:23 +0000 (20:14 +0100)]
fixed packing structs in nested buffers (#6509)

3 years ago[idl_parser] Add kTokenNumericConstant token (#6432)
Vladimir Glavnyy [Thu, 11 Mar 2021 19:12:06 +0000 (02:12 +0700)]
[idl_parser] Add kTokenNumericConstant token (#6432)

* [idl_parser] Add kTokenNumericConstant token

This commit adds the new token for correct parsing of signed numeric constants.
Before this expressions `-nan` or `-inf` were treated as kTokenStringConstant.
This was ambiguous if a real string field parsed.
For example, `{ "text_field" : -name }` was accepted by the parser as valid JSON object.

Related oss-fuzz issue: 6200301176619008

* Add additional positive tests fo 'inf' and 'nan' as identifiers

* Rebase to HEAD

* Move processing of signed constants to ParseSingleValue method.

* Add missed `--cpp-static-reflection` (#6324) to pass CI

* Remove `flatbuffers.pc` from repository to unblock CI (#6455).

Probably the generated flatbuffers.pc should not be a part of repo.

* Fix FieldIdentifierTest()

3 years agoRemove `flatbuffers.pc` from the repository (#6508)
Vladimir Glavnyy [Thu, 11 Mar 2021 19:11:04 +0000 (02:11 +0700)]
Remove `flatbuffers.pc` from the repository (#6508)

3 years agoBump grpc to 1.0.0 (#6507)
mustiikhalil [Tue, 9 Mar 2021 07:56:06 +0000 (10:56 +0300)]
Bump grpc to 1.0.0 (#6507)

Adds void to keywords

3 years agoMove Traits struct and Create method out of --cpp-static-reflection. (#6503)
dpacbach [Mon, 8 Mar 2021 18:59:17 +0000 (13:59 -0500)]
Move Traits struct and Create method out of --cpp-static-reflection. (#6503)

3 years agoDisable x64-specific optimizations for ARM64EC ReadInt64 (#6506)
Ben Niu [Mon, 8 Mar 2021 18:53:04 +0000 (10:53 -0800)]
Disable x64-specific optimizations for ARM64EC ReadInt64 (#6506)

ARM64EC is a new ARM64 ABI designed by Microsoft to support x64 application emulation on ARM64 CPUs. When compiling for ARM64EC, both the _M_X64 and _M_ARM64EC macros are defined. However, that causes problem in compiling this file, because the __movsb intrinsic, which is lowered to rep movsb, is not supported on ARM64, so the optimization for native x64 should be disabled for ARM64EC.

3 years agoAdd --cpp-static-reflection to generate_code.bat. (#6502)
dpacbach [Sat, 6 Mar 2021 15:28:27 +0000 (10:28 -0500)]
Add --cpp-static-reflection to generate_code.bat. (#6502)

3 years ago[C++17] Add compile-time reflection for fields. (#6324)
David P. Sicilia [Fri, 5 Mar 2021 18:01:40 +0000 (13:01 -0500)]
[C++17] Add compile-time reflection for fields. (#6324)

* [C++17] Add compile-time reflection for fields.

Included in this commit is the following:

  - The C++ generator has been modified so that,
    when in C++17 mode, it will emit Table and
    Struct field traits that can be used at com-
    pile time as a form of static reflection. This
    includes field types, field names, and a tuple
    of field getter results.

  - Diffs to the cpp17 generated files. No other
    generated files are affected.

  - A unit test that also serves as an example. It
    demonstrates how to use the full power of this
    reflection to implement a full recursive
    JSON-like stringifier for Flatbuffers types,
    but without needing any runtime access to the
    *.fbs definition files; the computation is
    done using only static reflection.

Tested on Linux with gcc 10.2.0.

Fixes #6285.

* Fix int-conversion warning on MSVC.

* Try to fix std::to_string ambiguity on MSVC.

* Fix clang-format diffs.

* Fix more clang-format diffs.

* Fix last clang-format diff.

* Enable C++17 build/test for VC 19 platform in CI.

* Forgot to add value to cmake command line variable.

* Various fixes/changes in response to @vglavnyy's feedback.

* Replace "fields pack" with index-based getters.

* Fix MSVC error.

* Fix clang-format diffs.

* getter_for method returns result instead of address-of-getter.

* Next round of reviewer suggestions.

* Use type instead of hardcoded struct name.

* Fix clang-format diff.

* Add test for FieldType since it is not used in the stringify test.

* Add fields_number field to Traits struct.

* Add --cpp-static-reflection flag and put those features behind it.

* Fix clang-format diffs.

* Remove <tuple> include.

3 years agofixed invalid TS call and added test files (#6495)
Kamil Rojewski [Thu, 4 Mar 2021 20:12:44 +0000 (21:12 +0100)]
fixed invalid TS call and added test files (#6495)

e581013e3d42af13d2fe37b0ac46a3fd43f3638c broke TS generation - please don't use "replace" to refactor function names :)

3 years agodisable clippy (#6494)
Casper [Mon, 1 Mar 2021 21:51:22 +0000 (16:51 -0500)]
disable clippy (#6494)

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[idl_parser, JSON] Disable parsing of JSON for incomplete schemes (#6493)
Vladimir Glavnyy [Mon, 1 Mar 2021 21:40:58 +0000 (04:40 +0700)]
[idl_parser, JSON] Disable parsing of JSON for incomplete schemes (#6493)

This commit disable JSON parsing for an incomplete scheme if JSON object is embedded into one file with the scheme.
This should improve the quality of OSS-Fuzz inputs for the parser_fuzzer target.

3 years ago[idl_parser] Track included files by hash (#6434)
Mark Spatz [Mon, 1 Mar 2021 20:34:01 +0000 (14:34 -0600)]
[idl_parser] Track included files by hash (#6434)

* [idl_gen] Delete ts::GenPrefixedImport()

I don't know what this is for, but it's the only piece of code external
to idl_parser.cpp that expects the key of Parser::included_files_ to be
a path. And it appears to be unused.

* [idl_parser] Track included files by hash

Parser::included_files_ is a map whose main purpose is to keep track of
which files have already been parsed in order to protect against
multiple inclusion. Its key is the path that the file was found at
during parsing (or, if it's an in-memory file, just its name).

This commit changes the key to be the 64 bit FNV-1a hash of the file's
name (just the name, not the complete path) xor'd with the hash of the
file's contents (unless it's an in-memory file, then we only hash the
name.)

This allows multiple include protection to function even in the face of
unique per-file include paths (fixes #6425).

* Ran tests/generate_code.sh

CI told me to do it.

* Gracefullt handle case where source_filename == nullptr

I just learned source_filename might also be null. In that case, we
should exclude it from the hash instead of hashing a zero length
string, just like we exclude source when it is null.

Presumably nameless files will never be included (they can't, can they?)
so this doesn't really matter, but I think it's prettier anyways.

3 years agofix for noUncheckedIndexedAccess in ts (#6474)
Kamil Rojewski [Thu, 25 Feb 2021 22:57:10 +0000 (23:57 +0100)]
fix for noUncheckedIndexedAccess in ts (#6474)

3 years agoWorking on a python example plus fixing python grpc code (#6456)
mustiikhalil [Thu, 25 Feb 2021 22:38:12 +0000 (01:38 +0300)]
Working on a python example plus fixing python grpc code (#6456)

Refactored python grpc code gen

Adds example server & client + fixes ci

Fixes generated code

Making sure we encode the reply string as utf8

Adds Readme details to clarify issue regarding encoding when python is sending/receiving

3 years ago[rust] Remove debug code (#6475)
Colin [Wed, 24 Feb 2021 18:00:18 +0000 (13:00 -0500)]
[rust] Remove debug code (#6475)

* Remove debug code

This was added for testing in the recent genericize PR for flexbuffer Reader.

* Added alloc tests -> MapReader::{is_empty, index_key, len}

* Added , accessible through Deref to deprecation warning

3 years agoRevert "[C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)" (#6488)
Derek Bailey [Tue, 23 Feb 2021 19:30:07 +0000 (11:30 -0800)]
Revert "[C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)" (#6488)

This reverts commit cbbbaa61b34c31f17773c2fef354c31664e9562e.

3 years ago[C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)
Björn Harrtell [Tue, 23 Feb 2021 17:34:20 +0000 (18:34 +0100)]
[C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)

* WIP: Fix returned truncated ArraySegment<byte> if elementSize is not byte

* Fix

* Regenerated test code

3 years ago[CI] Adds Code Generation tests on Github Actions (#6482)
mustiikhalil [Tue, 23 Feb 2021 05:51:39 +0000 (08:51 +0300)]
[CI] Adds Code Generation tests on Github Actions (#6482)

Moves check-grpc-generation to scripts

3 years ago[CMake] generate pkg-config flatbuffers.pc file (#6455)
Millian Poquet [Mon, 22 Feb 2021 18:23:38 +0000 (19:23 +0100)]
[CMake] generate pkg-config flatbuffers.pc file (#6455)

This commit enables CMake to generate a flatbuffers.pc file on install.

pkg-config eases the utilization of software libraries by enabling the
developers of a library to define how the library should be used.

It can be used as a tool by build systems to find and manage dependencies,
this is notably the default Meson behavior and optionally used by CMake.

3 years ago[Swift] Moves grpc example to grpc/examples (#6479)
mustiikhalil [Sat, 20 Feb 2021 20:07:48 +0000 (23:07 +0300)]
[Swift] Moves grpc example to grpc/examples (#6479)

Updates generated Code

Removes grpc generation code from tests dir

Small fix to generate.sh

3 years ago[TS] Moves grpc code to examples folder (#6476)
mustiikhalil [Sat, 20 Feb 2021 17:31:00 +0000 (20:31 +0300)]
[TS] Moves grpc code to examples folder (#6476)

Adds readme

3 years agoFixes grammer (#6477)
mustiikhalil [Fri, 19 Feb 2021 20:16:38 +0000 (23:16 +0300)]
Fixes grammer (#6477)

Updates docs

3 years agoFix sample_binary.py to use latest EndVector without a size. (#6478)
Richard A Hofer [Fri, 19 Feb 2021 20:13:50 +0000 (15:13 -0500)]
Fix sample_binary.py to use latest EndVector without a size. (#6478)

3 years agoupdated JS docs to reflect current status (#6436)
Kamil Rojewski [Fri, 19 Feb 2021 20:05:02 +0000 (21:05 +0100)]
updated JS docs to reflect current status (#6436)

3 years ago[Go] Working on a go example plus fixing go grpc code (#6448)
mustiikhalil [Fri, 19 Feb 2021 09:47:59 +0000 (12:47 +0300)]
[Go] Working on a go example plus fixing go grpc code (#6448)

Implemented server.go and half implemented client.go

Finishes implementation for greeter go example

Update grpc code for monster.fbs

Adds a couple of cpp methods

Adhere to gofmt standards

Adds a readme for issues with grpc

3 years ago[Swift] adds support for default vectors and strings (#6461)
mustiikhalil [Fri, 19 Feb 2021 09:47:28 +0000 (12:47 +0300)]
[Swift] adds support for default vectors and strings (#6461)

Small fix

Adhere to the new protocol names

3 years agoUpdate Building.md (#6473)
Arnaud LE CAM [Fri, 19 Feb 2021 03:51:41 +0000 (04:51 +0100)]
Update Building.md (#6473)

`cmake . -D FLATBUFFERS_CXX_FLAGS="Wno-error"` returns an error (file 'Wno-error' not found)

3 years agoGetUOffsetT must get value by GetUint32 not GetInt32 (#6072)
Thanabodee Charoenpiriyakij [Fri, 19 Feb 2021 02:38:25 +0000 (09:38 +0700)]
GetUOffsetT must get value by GetUint32 not GetInt32 (#6072)

3 years agoFix a typo in Swift codegen (#6470)
Liu Liu [Wed, 17 Feb 2021 06:34:39 +0000 (22:34 -0800)]
Fix a typo in Swift codegen (#6470)

* Fix a typo in Swift codegen

* Fix code formatting.

3 years ago[rust] Genericize flexbuffer reader (#6450)
Colin [Tue, 16 Feb 2021 13:04:48 +0000 (08:04 -0500)]
[rust] Genericize flexbuffer reader (#6450)

* feature/rust-tokio-bytes added feature name for tokio-bytes

* Added flexbuffer implementation, TODO: typecast to avoid recurse

* Converted codebase to utilize FlexBuffer implementation, need to resolve deserialization issues

* Added todo for lifetime issue, may use &'de [u8] for deserializer instead of current method

* Added proper &[u8] implementation

* Removed unused struct

* Added experimental fix to get_slice

* Added experimental fix to get_slice

* Avoided lifetime issues via ref structs, need to check if this hurts peformance

* Updated deserializer implementation to allow for borrowed data from Reader struct

* Fixed bug with str

* Removed unnecessary generic parameter

* Added unsafe to avoid lifetime complaints, current tests pass, need to review alternatives to unsafe

* Opinionated: Removed bytes crate as this implementation could be done in a separate crate

* Cleaned up flatbuffer

* Fixed sample / example

* Resolved PR feedback, need to resolve issues with tests

* Cleaned up FlexBuffer trait to be an auto impl

* Removed TODO

* Reverted Deserializer to only support &'de [u8]

* Cleaned up / renamed function for clarification

* Renamed FlexBuffer -> InternalBuffer for clarification on it's purpose

* Fixed issue with key bytes

* resolved issues with broken tests, confirming this is a breaking change

* Removed FIXME that's solved by splitting String and Key variants

* Implemented associated types approach

* Fixed backward slice logic

* Fixed MapReader compile error

* Added from_buffer for deserialization, removed  function since it's only needed for deserialization

* Removed dead code

* Cleaned up buffer, removed AsRef in favor of Deref

* Renamed Buffer::as_str -> Buffer::buffer_str

* Minor cleanup

* Updated documentation, need to fix tests

* Removed unnecessary &

* Removed unused lifetime

* removed unnecessary as_ref

* Minor optimization wrap-up

* resolved issue with Clone

* Added test to verify no deep-copy

* Added  for optimization

* Updated to use empty fn instead of default

* Updated comments / test name - plus the 0.3.0 version bump

* comment

3 years ago[Swift] Renaming protocols (#6469)
mustiikhalil [Tue, 16 Feb 2021 11:55:47 +0000 (14:55 +0300)]
[Swift] Renaming protocols (#6469)

* Renaming protocols

* Updates Generated code

* format code

3 years agoUpdate swift docs (#6460)
mustiikhalil [Sun, 14 Feb 2021 07:09:11 +0000 (10:09 +0300)]
Update swift docs (#6460)

3 years agoDefault strings and vectors: Parser + Rust support (#6421)
Casper [Fri, 12 Feb 2021 14:41:10 +0000 (09:41 -0500)]
Default strings and vectors: Parser + Rust support (#6421)

* Fix tests.cpp

* Parser support for vector/string defaults

* tests and default empty vectors

* addressed comments

* Default strings and vectors for Rust

* Tested Rust more_defaults

* git-clang-format

* add more_defaults_test

* fixed vector default

* removed commented out code

* more unreachable

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[CMake] Renames BUILD files (#6457)
mustiikhalil [Thu, 11 Feb 2021 18:16:57 +0000 (21:16 +0300)]
[CMake] Renames BUILD files (#6457)

* Renamed build to build.bazel to stop xcode from complaining about it

* Renamed all build to build.bazel

* Fixes small ci issue

3 years ago[Build, cmake] Add -Werror override option (#6429)
Vladimir Glavnyy [Wed, 10 Feb 2021 19:49:34 +0000 (02:49 +0700)]
[Build, cmake] Add -Werror override option (#6429)

* [Build, cmake] Add -Werror override option

This commit adds FLATBUFFERS_CXX_FLAGS cmake option.
This option allows override the -Werror flag (or any other flags).
Related issues:  #6337, #5930

* Remove CMAKE_CXX_FLAGS replace option

3 years ago[C++]Fix extra char generation for byte type during json schema generation (#6276)
blueshift155 [Wed, 10 Feb 2021 19:48:24 +0000 (01:18 +0530)]
[C++]Fix extra char generation for byte type during json schema generation (#6276)

* Fix extra char generation for the byte type

* Fix unit tests for JSON

3 years agoUpdating working code (#6441)
mustiikhalil [Wed, 10 Feb 2021 19:46:45 +0000 (22:46 +0300)]
Updating working code (#6441)

Fixes issues with namespaces in grpc ts

Renamed welcome -> models

3 years agoJSON schema - tailing double quotes for maximum (#6452)
tira-misu [Wed, 10 Feb 2021 19:45:34 +0000 (20:45 +0100)]
JSON schema - tailing double quotes for maximum (#6452)

* Fix C/C++ Create<Type>Direct with sorted vectors

If a struct has a key the vector has to be sorted. To sort the vector
you can't use "const".

* Changes due to code review

* Improve code readability

* Add generate of JSON schema to string to lib

* option indent_step is supported

* Remove unused variables

* Fix break in test

* Fix style to be consistent with rest of the code

* Fix  double quotes for (u)int8 in json schema

* Fix reference file for JSON schema test

* Fix reference file for JSON schema test

3 years ago[idl_parser] Validate `force_align` on all possible paths (#6430)
Vladimir Glavnyy [Wed, 10 Feb 2021 19:37:16 +0000 (02:37 +0700)]
[idl_parser] Validate `force_align` on all possible paths (#6430)

* [idl_parser] Validate `force_align` on all possible paths

- added validation of `force_align` for `Vector`.
- added assertion to `flatbuffers::PreAlign` method

These changes should resolve following oss-fuzz issues:
6275816289861632
5713529908887552
4761242994606080

* size_t problem on Mac

* Fix review notes

3 years agoImplement Rust object API defaults (#6444)
Casper [Sun, 7 Feb 2021 21:51:33 +0000 (16:51 -0500)]
Implement Rust object API defaults (#6444)

* Implment Rust object API defaults

* satisfy return analysis

* git clang format

Co-authored-by: Casper Neo <cneo@google.com>
3 years agoUpgrade swift grpc to alpha 24 (#6439)
mustiikhalil [Wed, 3 Feb 2021 23:01:18 +0000 (02:01 +0300)]
Upgrade swift grpc to alpha 24 (#6439)

Upgrade swift grpc to alpha 24

3 years ago[fuzzer] Limit parser_fuzzer execution time (#6431)
Vladimir Glavnyy [Sat, 30 Jan 2021 14:43:31 +0000 (21:43 +0700)]
[fuzzer] Limit parser_fuzzer execution time (#6431)

Limit the length of the fuzzer input to 16384 characters to prevent timeout
in JSON parser (Vector of tables with key).

Related oss-fuzz issues:
5742497110294528

3 years agoThis commit contains the initial implementation of Flexbuffers in Kotlin. The code...
Paulo Pinheiro [Thu, 28 Jan 2021 22:49:25 +0000 (23:49 +0100)]
This commit contains the initial implementation of Flexbuffers in Kotlin. The code was ported based (#6387)

on the current Java Implementation.

The code dependencies related to JVM were removed and the project is able to target all available platforms.

The only requirement to implement to fully support a target is to implement functions described in `ByteArray.kt`.
Right now the code support JVM and native targets. JS port still missing, but just be trivial to introduce.

Currently, only the `jvm` and `macosX64` targets are enabled until we figure out how to enable tests on all
platforms on CI.

A submodule called "benchmark" is also introduced. It contains a series
of benchmarks comparing Java and Kotlin implementations of FlexBuffers and the UTF8 API.

Finally, this commit does not contain the scripts necessary to publish the artifacts. This will
be introduced at a later stage once the team has an agreement on how to rollout Kotlin releases.

3 years agoBetter python generated code naming (#6336)
Richard A Hofer [Thu, 28 Jan 2021 20:35:37 +0000 (15:35 -0500)]
Better python generated code naming (#6336)

* Remove a lot of redundancy from the Python generated code.

Update tutorial to reflect new Python generated code.

* Add aliases for newly deprecated Python generated methods.

This should help with backwards compatibility.

* Fix incorrect names in deprecated comments.

3 years agoRust: remove inner attributes (#6410)
Casper [Tue, 26 Jan 2021 16:09:29 +0000 (11:09 -0500)]
Rust: remove inner attributes (#6410)

* remove inner attributes

* Added test for outdir in Rust

* add bin/outdir

* Moved outdir test to its own package and only run it if flatc is available

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[Rust] Ensure unions are referenced with the correct path (#6422)
William Bain [Mon, 25 Jan 2021 17:33:47 +0000 (12:33 -0500)]
[Rust] Ensure unions are referenced with the correct path (#6422)

* Add codegen test for namespaced unions

* [Rust] Handle cross-namespace union use

* [Rust] Test namespace handling

* [Rust] Drop trailing whitespace in codegen

* [Rust] Set flags in generate_code.bat to match .sh

* [C#] Add additional namespace test file

3 years agoRefactor FieldDef to model presense as an enum rather than 2 bools. (#6420)
Casper [Mon, 25 Jan 2021 17:29:43 +0000 (12:29 -0500)]
Refactor FieldDef to model presense as an enum rather than 2 bools. (#6420)

* Define presence.

* Migrate to IsRequired and IsOptional methods

* moved stuff around

* Removed optional and required bools from FieldDef

* change assert to return error

* Fix tests.cpp

* MakeFieldPresence helper

* fmt

* old c++ compatibility stuff

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[c++] Apply NativeName before WrapInNameSpace in idl_gen_cpp.cpp (#6419)
Andreas Kabel [Mon, 25 Jan 2021 17:22:01 +0000 (09:22 -0800)]
[c++] Apply NativeName before WrapInNameSpace in idl_gen_cpp.cpp (#6419)

* Apply NativeName before WrapInNameSpace in idl_gen_cpp.cpp

* remove actual_type argument from GetUnionElement -- it's always true

* Merge GetUnionElement's native_type and wrap_native argument -- they always have the same value.

* Use convenience method WrapNativeNameInNameSpace

* Remove wrap_namespace argument from GetUnionElement

* Move declaration closer to first use.

3 years agoFormats cpp code (#6349)
mustiikhalil [Fri, 22 Jan 2021 18:46:53 +0000 (21:46 +0300)]
Formats cpp code (#6349)

3 years agoRust Object API (#6070)
Casper [Fri, 22 Jan 2021 18:07:32 +0000 (13:07 -0500)]
Rust Object API (#6070)

* inital commit of rust object api

* Required fields support.

* clang fallthrough

* Fix unused variables

* just don't fall through

* remove comment

* s/panic/unreachable

* Tests for object API

* Added defaults

* deleted unintentionally added files and updated .bat file

* fix bat file

* clang format

* Cargo clippy checks

* remove commented out code

* clippy allows

* Remove matches! macro since we're not yet at Rust v1.42

* install clippy in RustTest.sh

* move line

Co-authored-by: Casper Neo <cneo@google.com>
3 years agoClarify that (Flat|Flex)Buffers do not deduplicate vector elements (#6415)
Juan Cruz Viotti [Fri, 22 Jan 2021 00:09:35 +0000 (20:09 -0400)]
Clarify that (Flat|Flex)Buffers do not deduplicate vector elements (#6415)

I'm also clarifying that while elements are not deduplicated, vectors
may contain more than one offset to the same value.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
3 years agoClarify that FlatBuffers unions do not support scalars (#6416)
Juan Cruz Viotti [Fri, 22 Jan 2021 00:08:29 +0000 (20:08 -0400)]
Clarify that FlatBuffers unions do not support scalars (#6416)

I mention that a common practice is to wrap the scalar value in a table
or a struct.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
3 years agoExplain how FlatBuffers encodes unions (#6414)
Juan Cruz Viotti [Fri, 22 Jan 2021 00:07:34 +0000 (20:07 -0400)]
Explain how FlatBuffers encodes unions (#6414)

This is an attempt to explain how FlatBuffers encodes union types as an
extra section in the "FlatBuffers internals" document.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
3 years agodart Builder - expose finished buffer size (#6403)
Ivan Dlugos [Fri, 22 Jan 2021 00:06:11 +0000 (01:06 +0100)]
dart Builder - expose finished buffer size (#6403)

3 years agoRemove invalid claim that Protocol Buffers does not support unions (#6413)
Juan Cruz Viotti [Thu, 21 Jan 2021 20:23:54 +0000 (16:23 -0400)]
Remove invalid claim that Protocol Buffers does not support unions (#6413)

Protocol Buffers v3 supports the `oneof` operator:
https://developers.google.com/protocol-buffers/docs/proto3#oneof

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
3 years ago[TS/JS] New gen TS code gen (#6302)
Björn Harrtell [Tue, 19 Jan 2021 20:51:13 +0000 (21:51 +0100)]
[TS/JS] New gen TS code gen (#6302)

* TS/ES6 modules spike iteration 1

* Initial modularized dasherized output

* Remove obsoleted parts and namespace wrapping

* Use _flatbuffers_ prefix

* First part of imports logic

* Second part of imports logic

* Fix TS/JS code removal mixup

* Alias imported symbols if same name from different namespaces and some fixes

* Use star import for bare imports

* Fix messed up string concat

* var to const and remove not needed semi

* Remove some cases of ns prefixing

* Add missing space

* Cleanups

* Completed initial import tracking logic

* Compilable output

* Adjust TypeScriptTest and dependents to work

* Use local flatbuffers package for tests

* Refactor away use of any

* Remove obsolete imported_fileset and reexport_map

* Still need any and fix JavaScriptTest.sh

* Fix test runs out of the box

* Temp add generated files

* TypeScriptTest replaces JavaScriptTest and cleanups

* Also remove reference to JavaScriptTest in TestAll.sh

* Remove old generated ts/js files

* Remove use of --js in generate_code scripts

* idl_gen_js_ts to idl_gen_ts and removal of js gen

* Remove obsoleted options

* Fix obsolete ts test detection

* Tweak ts compilation be as strict as possible

* Remove jsdoc type annotation generation

* Generated test ts files

* Fix search and replace messup

* Regenerated ts test output

* Use CharToLower

* Use normal for loop

* Rework namespacedir

* Revert "Rework namespacedir"

This reverts commit 6f4eb0104ceeb86011bb076ebca901138c48e068.

* Revert "Use normal for loop"

This reverts commit 676b2135bfaa1853dfbb06c92b5c16a0d81bb13a.

* Revert "Use CharToLower"

This reverts commit 2d08648d0d72d0af201fad80d54cdc76412b35e9.

* Again do rework but correct

* Avoid runtime cast

* Fix test runs

* Also add npm install to get tsc

* Bump node test versions

* for range to std for loop

* Clang format

* Missed one clang format

* Move accessor to later

* Attempt to make windows version of TypeScriptTest

* Want to see the output

* Try to get newer node at appveyor

* Style changes

3 years ago[idl_parser] Improve symbols lookup thru parent namespaces (#6407)
Vladimir Glavnyy [Tue, 19 Jan 2021 20:49:24 +0000 (03:49 +0700)]
[idl_parser] Improve symbols lookup thru parent namespaces (#6407)

Added the new method LookupTableByName for searching symbols in parent namespaces.
This method speedup (x50 or greater) symbol resolution (enum or struct) in parent namespaces.
The speedup was measured without `table.empty()` guard condition.

This method should suppress fuzzer timeout issue without artificial limits for nested namespaces (https://oss-fuzz.com/testcase-detail/6244168439169024).

Additionally, this commit speedup (x5) the GetFullyQualifiedName method by removing unnecessary temporary std::string object.

3 years agoSearch for includes in the directory containg the current file (#6371)
Mark Spatz [Tue, 19 Jan 2021 20:26:34 +0000 (12:26 -0800)]
Search for includes in the directory containg the current file (#6371)

* [codegen] Search for includes in the directory containg the current file

This matches the behavior of a C preprocessor, see:
https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

* Skip FileExists() when file is guaranteed to not exist

* end comment with period to match others

3 years agoUpgrade Rust dependencies (#6406)
Casper [Tue, 19 Jan 2021 18:39:29 +0000 (13:39 -0500)]
Upgrade Rust dependencies (#6406)

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[TS/JS] New gen TS code gen prequel to preserve history (#6404)
Björn Harrtell [Thu, 14 Jan 2021 19:34:44 +0000 (20:34 +0100)]
[TS/JS] New gen TS code gen prequel to preserve history (#6404)

* Rename idl_gen_js_ts to idl_gen_ts to preserve history

* Change build related files

3 years agoUnset FieldDef.optional if its key (#6402)
Casper [Tue, 12 Jan 2021 19:06:43 +0000 (14:06 -0500)]
Unset FieldDef.optional if its key (#6402)

* Unset FieldDef.optional if its key

* removed StringKey table, just removed an extra "required, key"

* removed extra newline

Co-authored-by: Casper Neo <cneo@google.com>
3 years ago[fuzzer] Fix the binary schema loading in the monster_fuzzer (#6396)
Vladimir Glavnyy [Tue, 12 Jan 2021 18:20:47 +0000 (01:20 +0700)]
[fuzzer] Fix the binary schema loading in the monster_fuzzer (#6396)

This commit should fix issue 29374 in oss-fuzz.

3 years agoFix Rust UB problems (#6393)
Casper [Mon, 11 Jan 2021 20:24:52 +0000 (15:24 -0500)]
Fix Rust UB problems (#6393)

* Fix miri problems by assuming alignment is 1 in rust

* Removed is_aligned fn from rust verifier.

* Add back is_aligned, but make it w.r.t. buffer[0]

* touch unused variable

* touch unused variable

* +nightly

* Move Rust miri testing into its own docker

* fix bash

* missing one endian conversion

* fix endianness2

* format stuff

Co-authored-by: Casper Neo <cneo@google.com>
3 years agoDefine Vector::value_type for STL compatibility (#6394)
brian-brt [Fri, 8 Jan 2021 19:35:55 +0000 (11:35 -0800)]
Define Vector::value_type for STL compatibility (#6394)

Specifically, this lets the googlemock container matchers work with a
flatbuffers::Vector.

https://github.com/google/googletest/blob/master/googlemock/docs/cheat_sheet.md#container-matchers

3 years ago[fuzzer] Debug the monster_tets.bfbs on clusterfuzz server (#6392)
Vladimir Glavnyy [Fri, 8 Jan 2021 19:09:41 +0000 (02:09 +0700)]
[fuzzer] Debug the monster_tets.bfbs on clusterfuzz server (#6392)

For some reason, this fuzzer failed to load the binary schema file
when run on the `/clusterfuzz` server.
Issue: https://oss-fuzz.com/testcase-detail/6215075358703616
This issue doesn't reproduce locally with the latest oss-fuzz docker image.

3 years agoFix up scripts, fix generated enum value for strong mode, regenerate files (#6389)
Dan Field [Thu, 7 Jan 2021 22:51:52 +0000 (14:51 -0800)]
Fix up scripts, fix generated enum value for strong mode, regenerate files (#6389)

* Fix up scripts, fix generated enum value for strong mode, regenerate files

* missing files

* GH action

* remove action

3 years ago[go] tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs. (#6388)
Aaron Son [Thu, 7 Jan 2021 19:54:00 +0000 (11:54 -0800)]
[go] tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs. (#6388)

* tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs.

Calling flags.Parse() within init() races with other packages which register
flags in their init(), and in particular with the testing package itself. It is
more reliable to call flags.Parse() from a TestMain implementation.

See https://github.com/golang/go/issues/31859,
https://github.com/golang/go/issues/33869.

* .github: Enable build-go action in build.yaml workflow.

3 years agofix Dart Builder._writeString() - always write trailing zero byte (#6390)
Ivan Dlugos [Thu, 7 Jan 2021 19:40:47 +0000 (20:40 +0100)]
fix Dart Builder._writeString() - always write trailing zero byte (#6390)

3 years agofix Dart Builder.reset() - clear vTables (#6386)
Ivan Dlugos [Thu, 7 Jan 2021 19:28:33 +0000 (20:28 +0100)]
fix Dart Builder.reset() - clear vTables (#6386)

3 years ago[C++, JSON] Fix nullptr access when reading a key with a default value. (#6375)
Vladimir Glavnyy [Thu, 7 Jan 2021 19:24:59 +0000 (02:24 +0700)]
[C++, JSON] Fix nullptr access when reading a key with a default value. (#6375)

This commit fixes handling of default and NULL `key` fields in `Parser::ParseVector` (#5928).

The JSON generator updated. It outputs `key` fields even if the `--force-defaults` option is inactive.

Additional test cases for `key` added.

3 years agoFix generated EndVector. (#6385)
Richard A Hofer [Tue, 5 Jan 2021 22:45:23 +0000 (17:45 -0500)]
Fix generated EndVector. (#6385)

3 years agoImplements type promotion for Java enum (#6382)
Stefan de Konink [Tue, 5 Jan 2021 19:11:29 +0000 (20:11 +0100)]
Implements type promotion for Java enum  (#6382)

* Implements type promotion for Java enum as suggested in #3890, #5111, #6369

* After generate_code.sh

3 years agoDelete label_notify.yml
Derek Bailey [Tue, 5 Jan 2021 18:06:33 +0000 (10:06 -0800)]
Delete label_notify.yml

Removing this workflow as it isn't used.

3 years agoDisabled PHP CI (#6381)
Wouter van Oortmerssen [Mon, 4 Jan 2021 22:50:56 +0000 (14:50 -0800)]
Disabled PHP CI (#6381)

It errors with "Fatal error: Uncaught exception 'InvalidArgumentException' with message 'bad number  for type byte.. in /home/runner/work/flatbuffers/flatbuffers/php/ByteBuffer.php:490" which I can't reproduce locally, and trying to fix it on CI runs into PHP's insane handling of numbers vs strings.

3 years agofixed warnings (#6355)
Kamil Rojewski [Mon, 4 Jan 2021 22:11:59 +0000 (23:11 +0100)]
fixed warnings (#6355)

* semver-compatible deprecations

* removed unneeded lifetimes (+ clippy warnings)

* silenced too many args warning

3 years agoFix multiple fbs code generation failure (#6365)
Bruno ZIKI Kongawi [Mon, 4 Jan 2021 21:29:32 +0000 (13:29 -0800)]
Fix multiple fbs code generation failure (#6365)

3 years ago[idl_parser] Improve stack overflow protection (#6364)
Vladimir Glavnyy [Mon, 4 Jan 2021 20:39:12 +0000 (03:39 +0700)]
[idl_parser] Improve stack overflow protection (#6364)

* [idl_parser] Improve stack overflow protection

Add stack overflow protection for Flexbuffer and nested Flatbuffer parsers.
Replaces the `Recurse()` method by the new ParseDepthGuard RAII class.

* Remove move operator from Parser.

It was wrong decision to add move ctor and assignment into Parser class.
These operators will make it extremely difficult to add constant or reference fields in the future.

* Remove ';' from definition of FLATBUFFERS_DELETE_FUNC

* Format code

* Make this PR compatible with MSVC2010 (it doesn't support inherited ctor)

3 years ago[idl_parser] Check the range of explicitly set field's id value (#6363)
Vladimir Glavnyy [Mon, 4 Jan 2021 20:33:31 +0000 (03:33 +0700)]
[idl_parser] Check the range of explicitly set field's id value (#6363)

* [idl_parser] Check the range of explicitly set field's id value

The explicitly set `id` attribute should be a non-negative value of the `voffset_t` type.

* Format FieldIdentifierTest()

3 years agoGenerate code to encode and decode nested flatbuffers in Python. (#6354)
Richard A Hofer [Mon, 4 Jan 2021 20:18:19 +0000 (15:18 -0500)]
Generate code to encode and decode nested flatbuffers in Python. (#6354)

* Generate code to encode and decode nested flatbuffers in Python.

* Delete accidental trailing whitespace.

* Fully delete trailing whitespace.

3 years ago[Rust] Shared String (#6367)
mustiikhalil [Mon, 4 Jan 2021 14:18:35 +0000 (17:18 +0300)]
[Rust] Shared String (#6367)

* Adds shared strings and tests for shared strings

* Adds resets on string_map

* Moved shared strings to use vector instead of hashmap

* Addresses all the issues

* Resolves some comments

3 years agoUpdates license date to 2021 (#6378)
mustiikhalil [Sat, 2 Jan 2021 08:46:46 +0000 (11:46 +0300)]
Updates license  date to 2021 (#6378)

3 years agoinclude_prefix support for rust (#6330)
Kamil Rojewski [Wed, 30 Dec 2020 20:02:36 +0000 (21:02 +0100)]
include_prefix support for rust (#6330)

* include_prefix support for rust

* include_prefix support for java

* formatting fixes

* Revert "include_prefix support for java"

* style fix

3 years ago[Swift] Rebuild the way swift handles structs from scratch (#6326)
mustiikhalil [Thu, 17 Dec 2020 22:55:32 +0000 (01:55 +0300)]
[Swift] Rebuild the way swift handles structs from scratch (#6326)

* Rebuild the way swift handles structs from scratch

* Updates docs, and sample binary

* Replaces InMemory to Mutable

* Migrates docs from inmemory

* use inline for some functions

* Renamed Mutable objects

* Updates documentation

3 years agoFix typos in usage/comments; Make rust generator respect to --filenam… (#6342)
mqy [Thu, 17 Dec 2020 21:15:27 +0000 (05:15 +0800)]
Fix typos in usage/comments; Make rust generator respect to --filenam… (#6342)

* Fix typos in usage/comments; Make rust generator respect to --filename-suffix

* run clang format

3 years agoRenaming infinity variables in test.cpp (#6340)
Kjetil Østerås [Thu, 17 Dec 2020 21:08:23 +0000 (22:08 +0100)]
Renaming infinity variables in test.cpp (#6340)

The infinityf symbol is causing a conflict when building for cygwin. In
the cygwin math.h header there is also a symbol called infinityf. So
this patch is needed to be able to build the flatbuffer tests in a
cygwin environment.

3 years agoAdd vectorNumElements attribute to Builder for simpler vector creation. (#6328)
Richard A Hofer [Mon, 14 Dec 2020 20:00:28 +0000 (15:00 -0500)]
Add vectorNumElements attribute to Builder for simpler vector creation. (#6328)

* Add vectorNumElements attribute to Builder for simpler vector creation.

This adds a default to EndVector which should simplify its use.

* Update tutorial to reflect new default arg in Python EndVector.

* Remove optional argument to Python EndVector.

* Add generated files.

* Unset Builder.vectorNumElems when not in use.

3 years ago[CI] Adds formatter to CI (#6272)
mustiikhalil [Fri, 11 Dec 2020 18:46:10 +0000 (21:46 +0300)]
[CI] Adds formatter to CI (#6272)

* Adds formatters CI

Adds Error message & setup formatting like cpp

Adds Swift

Adds typescript

Adds python

tests yarn

Adds format.md

* Removes unneeded scripts + moves install script to install phase

* Adds format.md content

* Adds cpp to the formatter.md and fixes ci

* Adds cpp to formatter ci

3 years agoFix Max CI build path (#6333)
Wouter van Oortmerssen [Fri, 11 Dec 2020 18:31:20 +0000 (10:31 -0800)]
Fix Max CI build path (#6333)

apparently the default xcodebuild path of ./build clashes with the BUILD file present (case insensitive file system?)

3 years agoGenerate nullable properties in C# object-based API for optional scalars. (without...
Stefan F [Fri, 11 Dec 2020 00:50:30 +0000 (01:50 +0100)]
Generate nullable properties in C# object-based API for optional scalars. (without -gen-mutable) (#6273)

* Added missing EndTable() call to VerifyObject()

VerifyObject called VerifyTableStart() but not EndTable(). This made Verifier::VerifyComplexity() increase depth_ with each table, not with the depth of tables.

https://groups.google.com/forum/#!topic/flatbuffers/OpxtW5UFAdg

* Added Check to VerifyAlignment

https://stackoverflow.com/questions/59376308/flatbuffers-verifier-returns-false-without-any-assertion-flatbuffers-debug-veri

* Add GetStringView (Convenience function to get string_view from a String returning an empty string_view on null pointer) like GetString, GetCstring

* flatc should warn, when an attribute is attached more than once.

flatc.exe -b duplicate.fbs
warning: duplicate.fbs(5, 36): warning: attribute already found: priority

duplicate.fbs:

namespace MyGame;

attribute "priority";

table Monster (priority:1, priority:2) {
}

root_type Monster;

* flatc should support --binary --schema with optional scalar fields.

This fixes 'error: Optional scalars are not yet supported in at least one the of the specified programming languages.' when calling flatc.exe --binary --schema with a schema containing optional scalars.

* Generate nullable properties in C# object-based API for optional scalars.
tests\generate_code.bat extended to test this.

Ran tests\generate_code.bat
Ran tests\Flatbuffers.Test\NetTest.bat

* %TEST_BASE_FLAGS% replaced with --gen-object-api in generate_code.bat, because only this is part of this PR. Added this same flag to generate_code.sh

* generate_code.bat and generate_code.sh changed to only test c# with object based api.