Commit Graph

1525 Commits

Author SHA1 Message Date
Sergey Avseyev 86153fd740 Remove unnecessary const qualifier (#4698)
In file included from include/flatbuffers/flexbuffers.h:24,
                 from src/idl_gen_text.cpp:20:
include/flatbuffers/util.h: In function 'int flatbuffers::FromUTF8(const char**)':
include/flatbuffers/util.h:324:45: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
   if ((static_cast<const unsigned char>(**in) << len) & 0x80) return -1;  // Bit after leading 1's must be 0.
                                             ^
cc1plus: all warnings being treated as errors
make[2]: *** [CMakeFiles/flatbuffers_shared.dir/build.make:92: CMakeFiles/flatbuffers_shared.dir/src/idl_gen_text.cpp.o] Error 1
2018-04-06 11:33:07 -07:00
Vladimir Glavnyy 7eb4c6098e An user-defined attribute name validation (#4689)
* User-declared attribute should be either identifier or string with the identifier.

* Attribute can be identifier or string in metadata.
2018-04-06 09:07:59 -07:00
Paul Reimer af3c598189 Rename MANUALLY_ALIGNED_STRUCT to add FLATBUFFERS_ prefix in generated code within tests/. Via running `cd tests && sh generate_code.sh` (#4696) 2018-04-05 16:36:42 -07:00
Paul Reimer eac0bc6490 Add FLATBUFFERS_ prefix to defines [C++] (#4695)
* Rename STRUCT_END to add FLATBUFFERS_ prefix, now FLATBUFFERS_STRUCT_END. Via running `ag -l STRUCT_END | xargs rpl STRUCT_END FLATBUFFERS_STRUCT_END`

* Rename MANUALLY_ALIGNED_STRUCT to add FLATBUFFERS_ prefix, now FLATBUFFERS_MANUALLY_ALIGNED_STRUCT. Via running `ag -l MANUALLY_ALIGNED_STRUCT | xargs rpl MANUALLY_ALIGNED_STRUCT FLATBUFFERS_MANUALLY_ALIGNED_STRUCT && cd tests && sh generate_code.sh`

* Rename DEFINE_BITMASK_OPERATORS to add FLATBUFFERS_ prefix, now FLATBUFFERS_DEFINE_BITMASK_OPERATORS. Via running `ag -l DEFINE_BITMASK_OPERATORS | xargs rpl DEFINE_BITMASK_OPERATORS FLATBUFFERS_DEFINE_BITMASK_OPERATORS`
2018-04-05 16:00:54 -07:00
Wouter van Oortmerssen 20a400e940 Update version number to 1.9
Change-Id: I0b0ed43129c4d8fc88a177792df50adfeb52a1e3
2018-04-05 15:11:52 -07:00
Wouter van Oortmerssen 676f0248aa Added missing generated code files.
Change-Id: I59af6ca1825870461c0badc7e7a045b97befdc1a
2018-04-05 15:01:35 -07:00
Kamil Rojewski 34b8b80f15 Missing TS links in docs (#4693)
* Eclipse ignore

* TypeScript support

* Prefixing enums

* Test results

* Merged JS and TS generators

* Fixed AppVeyor build problems

* Fixed more AppVeyor build problems

* Fixed more AppVeyor build problems

* Changed TS flag to options struct

* Storing options by value

* Removed unneeded const

* Re-export support for unions

* Uint support

* Casting bools to numbers for mutation

* TS shell tests

* Reverted generates js test file to original version

* Backing up js tests and properly generating test data

* Not importing flatbuffers for TS test generation

* Not overwriting generated js for tests

* AppVeyor test fixes

* Generating the most strict TS code possible

* Not returning null when creating vectors

* Not returning null from struct contructors

* Vector of unions for ts/js

* Sanity check for languages

* Indentation fix + output test files

* Vectors of unions for php

* Fixes to union vector handling + tests

* Fix for strictPropertyInitialization

* Fix for new aligned operator new for gcc >= 7.1

* Not generating imports/ns prefixes with --gen-all

* TypeScript docs

* Missing imports of enums

* Missing TS links
2018-04-05 09:54:37 -07:00
Juyeon Yoon 0998861e0f Remove line break of CMakeLists.txt (#4691)
Fix #4650
2018-04-05 09:17:33 -07:00
David Stephan 2e3d3cbcb5 Fix typos in C++ tutorial (#4685)
CreateMonster and MonsterBuilder examples fixed for C++
2018-04-02 09:25:05 -07:00
Kamil Rojewski d3a00f7730 Fix for missing enum imports (#4683)
* Eclipse ignore

* TypeScript support

* Prefixing enums

* Test results

* Merged JS and TS generators

* Fixed AppVeyor build problems

* Fixed more AppVeyor build problems

* Fixed more AppVeyor build problems

* Changed TS flag to options struct

* Storing options by value

* Removed unneeded const

* Re-export support for unions

* Uint support

* Casting bools to numbers for mutation

* TS shell tests

* Reverted generates js test file to original version

* Backing up js tests and properly generating test data

* Not importing flatbuffers for TS test generation

* Not overwriting generated js for tests

* AppVeyor test fixes

* Generating the most strict TS code possible

* Not returning null when creating vectors

* Not returning null from struct contructors

* Vector of unions for ts/js

* Sanity check for languages

* Indentation fix + output test files

* Vectors of unions for php

* Fixes to union vector handling + tests

* Fix for strictPropertyInitialization

* Fix for new aligned operator new for gcc >= 7.1

* Not generating imports/ns prefixes with --gen-all

* TypeScript docs

* Missing imports of enums
2018-03-26 10:29:45 -07:00
Kamil Rojewski cc54963830 TypeScript docs (#4680)
* Eclipse ignore

* TypeScript support

* Prefixing enums

* Test results

* Merged JS and TS generators

* Fixed AppVeyor build problems

* Fixed more AppVeyor build problems

* Fixed more AppVeyor build problems

* Changed TS flag to options struct

* Storing options by value

* Removed unneeded const

* Re-export support for unions

* Uint support

* Casting bools to numbers for mutation

* TS shell tests

* Reverted generates js test file to original version

* Backing up js tests and properly generating test data

* Not importing flatbuffers for TS test generation

* Not overwriting generated js for tests

* AppVeyor test fixes

* Generating the most strict TS code possible

* Not returning null when creating vectors

* Not returning null from struct contructors

* Vector of unions for ts/js

* Sanity check for languages

* Indentation fix + output test files

* Vectors of unions for php

* Fixes to union vector handling + tests

* Fix for strictPropertyInitialization

* Fix for new aligned operator new for gcc >= 7.1

* Not generating imports/ns prefixes with --gen-all

* TypeScript docs
2018-03-23 09:01:39 -07:00
Flaviu 79f62ee353 Const correctness in generated code and in code generators. Added missing \reflection\generate_code.bat file. (#4679) 2018-03-23 08:58:07 -07:00
Andreas Bergmeier c0a6e5120d [C++, Go, Bazel]: Fix up Bazel support (#4672)
* Add Bazel support for Go library

* Make flatc compile again.

Was missing java_generator, which is now referenced from source.
2018-03-15 12:31:16 -07:00
Robert Schmidtke 08cf50c54a Java/C#/Python prefixed size support (#4445)
* initial changes to support size prefixed buffers in Java

* add slice equivalent to CSharp ByteBuffer

* resolve TODO for slicing in CSharp code generation

* add newly generated Java and CSharp test sources

* fix typo in comment

* add FinishSizePrefixed methods to CSharp FlatBufferBuilder as well

* add option to allow writing the prefix as well

* generate size-prefixed monster binary as well

* extend JavaTest to test the size prefixed binary as well

* use constants for size prefix length

* fuse common code for getRootAs and getSizePrefixedRootAs

* pulled file identifier out of if

* add FinishSizePrefixed, GetSizePrefixedRootAs support for Python

* Revert "extend JavaTest to test the size prefixed binary as well"

This reverts commit 68be4420dd.

* Revert "generate size-prefixed monster binary as well"

This reverts commit 2939516fdf.

* fix ByteBuffer.cs Slice() method; add proper CSharp and Java tests

* fix unused parameter

* increment version number

* pulled out generated methods into separate utility class

* pulled out generated methods into separate utility class for Python

* fix indentation

* remove unnecessary comment

* fix newline and copyright

* add ByteBufferUtil to csproj compilation

* hide ByteBuffer's internal data; track offset into parent's array

* test unsafe versions as well; compile and run in debug mode

* clarify help text for size prefix

* move ByteBuffer slicing behavior to subclass

* fix protection levels

* add size prefix support for text generation

* add ByteBufferSlice to csproj compilation

* revert size prefix handling for nested buffers

* use duplicate instead of slice for removing size prefix

* remove slice subclass and use duplicate for removing size prefix

* remove slice specific tests

* remove superfluous command line option
2018-03-12 11:30:46 -07:00
Sergey Avseyev 6b3f057bdc Remove unnecessary const qualifier from cast (#4666)
Const does not make sense here, and compiler actually throws warning
(error with -Werror) when you would try to compile it.

    In file included from include/flatbuffers/flexbuffers.h:24,
                     from include/flatbuffers/idl.h:26,
                     from include/flatbuffers/code_generators.h:22,
                     from src/code_generators.cpp:17:
    include/flatbuffers/util.h: In function ‘int flatbuffers::FromUTF8(const char**)’:
    include/flatbuffers/util.h:325:44: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
       if ((static_cast<const unsigned char>(tmp) << len) & 0x80) return -1;  // Bit after leading 1's must be 0.
                                            ^
    cc1plus: all warnings being treated as errors

This warning caught by gcc8:

    $ g++ --version
    g++ (GCC) 8.0.1 20180222 (Red Hat 8.0.1-0.16)
2018-03-12 08:22:17 -07:00
ianXian 60de374486 Convert to unsigned char before applying bit shift operator (#4664)
* Convert to unsigned char before applying bit shift operator

* convert to const unsigned char inline

* convert to unsigned char inline
2018-03-09 09:45:47 -08:00
desqaz e78825e7a0 Json : Add --size-prefixed option to flatc (#4645)
to be able to convert to json size prefixed buffers.
2018-03-09 08:21:28 -08:00
Montoli cc158e7009 Swapped the order of two conditions in an assert. (#4663)
An assert in flexbuffers was bit-shifting a 64-bit number by
64 bits, which throws up warnings in some automated tools.

The same assert also checks to see if the number of bytes
being shifted is 8.  Swapped the order, so that the bitshift
only occurs if the number of bits being shifted is not 64.

Should be the same behavior, but plays nicer with diagnostic
tools.
2018-03-08 14:18:41 -08:00
desqaz 5377957b14 Update .gitignore with Ninja stuff (#4659) 2018-03-08 10:36:27 -08:00
Wouter van Oortmerssen 4bc6de9a88 Fix broken Java/C# codegen 2018-03-05 16:37:04 -08:00
Wouter van Oortmerssen 3a62813f0e Added missing generated code files.
Change-Id: Ie1cab284cb6e0fe5bd2b2c293c3136c148927ac3
2018-03-05 15:47:16 -08:00
Nik Hemmings fb94af8899 Protobufs: Added '--oneof-union' option. (#4647)
* Added '--oneof-union' option.

Used with the .proto -> .fbs converter, will translate protobuff oneofs to flatbuffer unions.
Updated proto test to check both methods of converting oneofs.

* Added '--oneof-union' option.

Used with the .proto -> .fbs converter, will translate protobuff oneofs to flatbuffer unions.
Updated proto test to check both methods of converting oneofs.

* FlatBuffers: Moved MakeCamel() into idl_parser.cpp

Removes library dependency on Java/C# generator code.
2018-03-05 08:45:25 -08:00
smillius 77b458bee5 Make nested flatbuffer lookup consistent. (#4656)
Lookup type of nested flatbuffer field with either raw name or fully qualified name as already done in the parser.
LookupCreateStruct tries both the raw name and the fully qualified one.
Without this, we cannot reference types outside of the current namespace, e.g. in a different module.
2018-03-05 08:44:14 -08:00
Christian Helmich 9ce98dd77d Support attribute "cpp_ptr_type" on table elements marked as "hash" (#4643)
* added intended use-cases to monster_test.fbs

* added check for `cpp_ptr_type` on hashed fields
added default value 'naked' to `cpp_ptr_type` on hashed fields

* added C++ generation of cpp_type vectors
removed ctor call for vector fields
added condition !vector for cpp_type check
added Pack() and UnPack() code generation for vector of hashes
added generation of correct resolve/rehash for cpp_type elements

* added attribute 'cpp_ptr_type_get' to hold accessor for pointer types possible where '.get()' does not work
use case: cpp_ptr_type:"std::weak_ptr", cpp_ptr_type_get:".lock().get()"

* run flatc to re-generate headers

* added bool param is_ctor to GetDefaultScalarValue() to differentiate between usage places

* modified monster_test.fbs to remove usage of shared_ptr/weak_ptr
reason: STLport does not support std::shared_ptr and std::weak_ptr

* run flatc again to re-generate headers

* fixed symbol unique_ptr not in namespace std when building with STLport
2018-03-05 08:40:55 -08:00
Mitchel 4ea1be53d4 Java + C#, reuse object in lookup_by_key (#4648)
* Java + C#, reuse object in lookup_by_key

* Java + C#, reuse object in lookup_by_key
2018-03-02 15:22:46 -08:00
Mitchel 0068b25132 Fix for Java infinite loop encoding into 0-sized buffer (#4654) 2018-03-02 15:21:08 -08:00
Christian Helmich ec74f58b94 made HashFnv functions constexpr (#4640)
* added FLATBUFFERS_CONSTEXPR_CPP14 define for C++14 and above constexpr

* made HashFnv functions constexpr (depending on FLATBUFFERS_CONSTEXPR)
2018-03-02 09:13:55 -08:00
Kamil Rojewski 48d8232584 Not generating imports/ns prefixes with --gen-all (#4644)
* Eclipse ignore

* TypeScript support

* Prefixing enums

* Test results

* Merged JS and TS generators

* Fixed AppVeyor build problems

* Fixed more AppVeyor build problems

* Fixed more AppVeyor build problems

* Changed TS flag to options struct

* Storing options by value

* Removed unneeded const

* Re-export support for unions

* Uint support

* Casting bools to numbers for mutation

* TS shell tests

* Reverted generates js test file to original version

* Backing up js tests and properly generating test data

* Not importing flatbuffers for TS test generation

* Not overwriting generated js for tests

* AppVeyor test fixes

* Generating the most strict TS code possible

* Not returning null when creating vectors

* Not returning null from struct contructors

* Vector of unions for ts/js

* Sanity check for languages

* Indentation fix + output test files

* Vectors of unions for php

* Fixes to union vector handling + tests

* Fix for strictPropertyInitialization

* Fix for new aligned operator new for gcc >= 7.1

* Not generating imports/ns prefixes with --gen-all
2018-02-26 08:56:04 -08:00
Mitchel 55ddb84eb2 In Java, allow reusing ByteBuffer in getters (#4633)
* In Java, allow reusing ByteBuffer in getters

* In Java, allow reusing ByteBuffer in getters

* In Java, allow reusing ByteBuffer in getters
2018-02-23 14:01:05 -08:00
Christian Helmich 6e2e909b5c template specialized Hash functions for 16-bit hash types (#4631)
added access to HashFunction for 16 bit
2018-02-23 10:29:37 -08:00
Philip S Doctor b24c0b07a3 When Java raises a CharacterCodingException, the catch block rethrows this exception as a java.lang.Error. Per the docs https://docs.oracle.com/javase/8/docs/api/java/lang/Error.html an Error is a serious problem that applications should not attempt to catch such as ThreadDeath. In this case, it is reasonable for a consumer to try to catch this error as it likely indicates a problem with the underlying data. (#4630)
As Error does not inherit from Exception, a generic `catch(Exception ex)` will not catch this error.

A simple change from `Error` to `Exception` is not sufficient as an `Exception` is checked by the compiler, so in order to keep this issue unchecked, I am proposing raising a `RuntimeException` which is not checked, but is still a subclass of `Exception`.

The only possible breaking change would be if a consumer was explicitly catching `Error` already for this library.

https://github.com/google/flatbuffers/issues/4629
2018-02-22 14:54:35 -08:00
Christian Helmich 59e26017cb added support for parsing hash on vector elements (#4502)
* added support for parsing hash on vector elements

reversed check for scalar to check for vector

added C++ generation of cpp_type vectors

removed ctor call for vector fields
added condition !vector for cpp_type check

added Pack() and UnPack() code generation for vector of hashes

* schema change:
added table Referrable and weak references towards it from Monster

added single_weak_reference to Monster table
changed order with vector_of_weak_references

* re-generated monster schema dependent code

added Referrable.cs to FlatBuffers.Test.csproj
2018-02-22 11:04:26 -08:00
desqaz 132e6a8220 Add new c++ helpers to ease usage of size prefixed FlatBuffers (#4626)
It was missing some helpers when we choose to use
size prefixed FlatBuffers.

* Add general helper : GetPrefixedSize
* Add generated helpers :
 * GetSizePrefixedXXX
 * VerfifySizePrefixedXXXBuffer
 * FinishSizePrefixedXXXBuffer
2018-02-22 09:19:08 -08:00
Masato Nagai 19c81b11b3 [C++] better type mismatch error (#4623)
* better parse error

* pass str as a pointer instead of a reference for more efficient performance
2018-02-16 08:32:50 -08:00
Alexander Gallego 36f8564846 C++: mini_reflect: Add DefaultTypeTable (#4614)
* mini_reflect: Add DefaultTypeTable

Currently it's very easy to make a mistake when it comes to
instantiating the TypeTable to print a buffer because it is not type
safe.

This will allow us to write safer cpp code:

flatbuffers::FlatBufferToString(reinterpret_cast<const uint8_t *>(&t),
                                decltype(t)::DefaultTypeTable());

* c++: mini_reflect: update generated code

* Ensure types and names are set for mini_reflect

* c++: mini_refelct: update unit tests with new typed TypeTable

* Adding PR feedback of sylte and naming convention
2018-02-15 14:58:06 -08:00
Dmitry Volosnykh daf0a420be Support version compatibility checks via find_package command (#4625) 2018-02-15 13:39:15 -08:00
Kamil Rojewski 474ba68bba Fix for aligned new for gcc >= 7.1 (#4621)
* Eclipse ignore

* TypeScript support

* Prefixing enums

* Test results

* Merged JS and TS generators

* Fixed AppVeyor build problems

* Fixed more AppVeyor build problems

* Fixed more AppVeyor build problems

* Changed TS flag to options struct

* Storing options by value

* Removed unneeded const

* Re-export support for unions

* Uint support

* Casting bools to numbers for mutation

* TS shell tests

* Reverted generates js test file to original version

* Backing up js tests and properly generating test data

* Not importing flatbuffers for TS test generation

* Not overwriting generated js for tests

* AppVeyor test fixes

* Generating the most strict TS code possible

* Not returning null when creating vectors

* Not returning null from struct contructors

* Vector of unions for ts/js

* Sanity check for languages

* Indentation fix + output test files

* Vectors of unions for php

* Fixes to union vector handling + tests

* Fix for strictPropertyInitialization

* Fix for new aligned operator new for gcc >= 7.1
2018-02-12 08:37:51 -08:00
vglavnyy 9de0861104 Fix vector_data failure under debug (#4606) 2018-02-08 15:15:17 -08:00
Wouter van Oortmerssen b513db86c7 Misc fixes from internal integration / clang tidy.
Change-Id: Ic5e8f6a423b426abb9f8b90d39db0f85f28b94be
Tested: on Linux.
2018-02-08 14:58:16 -08:00
Sergey Avseyev 6a1acdc23b Fix compiler errors in parser (#4612)
src/idl_parser.cpp: In member function 'flatbuffers::CheckedError flatbuffers::Parser::ParseHexNum(int, uint64_t*)':
src/idl_parser.cpp:220:62: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
     if (!isxdigit(static_cast<const unsigned char>(cursor_[i])))
                                                              ^
src/idl_parser.cpp: In member function 'flatbuffers::CheckedError flatbuffers::Parser::Next()':
src/idl_parser.cpp:260:62: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers]
         if(!isdigit(static_cast<const unsigned char>(*cursor_))) return NoError();
                                                              ^
cc1plus: all warnings being treated as errors
2018-02-05 12:04:55 -08:00
Joe Schafer c696422558 Add initial Bazel WORKSPACE and BUILD (#4608)
For #4574.

To test:

    bazel test --verbose_failures //:flatbuffers_test
2018-02-05 10:23:15 -08:00
Wouter van Oortmerssen e93d2bda07 Cleaned up & fixed buffer alignment handling.
- Fixed ForceVectorAlignment (and possibly other call-sites) not
  setting minalign_.
- Fixed flipped alignment parameters in CopyTable (reflection).
- Made aligment for FlatBufferBuilder internal buffer configurable
  (useful when reading a constructed buffer directly).
- Ensured Alignment rounding is always up.

Change-Id: I33ca4887d92a09cb11a369c14a109f4b07ae707a
Tested: on Linux.
2018-01-29 11:46:30 -08:00
Wouter van Oortmerssen bbf4dac6a3 Made doubles output with higher precision in JSON and elsewhere.
Change-Id: I5dd8f3a7c315c40b86a67aba5c2cca4d36363523
Tested: on Linux.
2018-01-22 10:24:45 -08:00
Wouter van Oortmerssen 8df2d9a3ef Removed truncating of enum vals to int in ReverseLookup.
Some implementations (e.g. C++98) won't support 64-bit enum values,
but there is no reason to silently truncate them.

Change-Id: I8629563523a96e887068f9c0efcd53741f60e0d6
Tested: on Linux.
2018-01-22 09:51:17 -08:00
Li-Deng 462ce03ebe Fix the spell mistake (#4599) 2018-01-22 09:08:13 -08:00
Wouter van Oortmerssen 020012e69c Fixed native_include not requiring a ; terminator.
Change-Id: Ic4f49e94c67ba23f07e5ba7e87ca94e8db5d5906
Tested: on Linux.
2018-01-22 09:06:13 -08:00
Wouter van Oortmerssen f431a96523 New error: declaring an enum field without a default in range of the enum.
Change-Id: I4db7f032440c00d31c7434975b8a3f17c29d74b9
Tested: on Linux.
2018-01-18 12:06:01 -08:00
Wouter van Oortmerssen 3694ae0817 Disallow defaults on structs.
Change-Id: Ia098126c92ea6f8abe94561bd9c09b29ac8f61f5
Context: https://github.com/google/flatbuffers/issues/4591
Tested: on Linux.
2018-01-18 11:41:43 -08:00
Wouter van Oortmerssen 2265129e14 Removed date/time from generated code, causing commit polution.
Change-Id: I79724416110a3d2241d7eeecf0e12aa6d5b760a0
2018-01-18 11:21:10 -08:00
Wouter van Oortmerssen 4bddc6cc0c Added missing generated code.
Change-Id: I9420bf01d2bdb6ccfe3703c835297be73457c0d7
2018-01-18 11:20:58 -08:00