Skip to content
Snippets Groups Projects
Commit 622b8d05 authored by Wouter van Oortmerssen's avatar Wouter van Oortmerssen Committed by Wouter van Oortmerssen
Browse files

Fixed warnings on Windows

parent 5faa0ab1
No related branches found
No related tags found
No related merge requests found
...@@ -265,6 +265,7 @@ ...@@ -265,6 +265,7 @@
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" /> <ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" />
<ClInclude Include="..\..\include\flatbuffers\idl.h" /> <ClInclude Include="..\..\include\flatbuffers\idl.h" />
<ClInclude Include="..\..\include\flatbuffers\reflection.h" />
<ClInclude Include="..\..\include\flatbuffers\util.h" /> <ClInclude Include="..\..\include\flatbuffers\util.h" />
<ClInclude Include="..\..\tests\monster_test_generated.h" /> <ClInclude Include="..\..\tests\monster_test_generated.h" />
<ClCompile Include="..\..\src\idl_gen_fbs.cpp" /> <ClCompile Include="..\..\src\idl_gen_fbs.cpp" />
...@@ -276,4 +277,4 @@ ...@@ -276,4 +277,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>
</Project> </Project>
\ No newline at end of file
...@@ -48,14 +48,16 @@ inline const Table *GetAnyRoot(const uint8_t *flatbuf) { ...@@ -48,14 +48,16 @@ inline const Table *GetAnyRoot(const uint8_t *flatbuf) {
template<typename T> T GetFieldI(const Table *table, template<typename T> T GetFieldI(const Table *table,
const reflection::Field *field) { const reflection::Field *field) {
assert(sizeof(T) == GetTypeSize(field->type()->base_type())); assert(sizeof(T) == GetTypeSize(field->type()->base_type()));
return table->GetField<T>(field->offset(), field->default_integer()); return table->GetField<T>(field->offset(),
static_cast<T>(field->default_integer()));
} }
// Get a field, if you know it's floating point and its exact type. // Get a field, if you know it's floating point and its exact type.
template<typename T> T GetFieldF(const Table *table, template<typename T> T GetFieldF(const Table *table,
const reflection::Field *field) { const reflection::Field *field) {
assert(sizeof(T) == GetTypeSize(field->type()->base_type())); assert(sizeof(T) == GetTypeSize(field->type()->base_type()));
return table->GetField<T>(field->offset(), field->default_real()); return table->GetField<T>(field->offset(),
static_cast<T>(field->default_real()));
} }
// Get a field, if you know it's a string. // Get a field, if you know it's a string.
...@@ -106,7 +108,7 @@ inline double GetAnyFieldF(const Table *table, ...@@ -106,7 +108,7 @@ inline double GetAnyFieldF(const Table *table,
case reflection::Double: return GetFieldF<double>(table, field); case reflection::Double: return GetFieldF<double>(table, field);
case reflection::String: return strtod(GetFieldS(table, field)->c_str(), case reflection::String: return strtod(GetFieldS(table, field)->c_str(),
nullptr); nullptr);
default: return GetAnyFieldI(table, field); default: return static_cast<double>(GetAnyFieldI(table, field));
} }
} }
...@@ -191,6 +193,7 @@ template<typename T, typename U> class pointer_inside_vector { ...@@ -191,6 +193,7 @@ template<typename T, typename U> class pointer_inside_vector {
const T *operator->() const { const T *operator->() const {
return operator*(); return operator*();
} }
void operator=(const pointer_inside_vector &piv);
private: private:
size_t offset_; size_t offset_;
const std::vector<U> &vec_; const std::vector<U> &vec_;
...@@ -220,7 +223,7 @@ class ResizeContext { ...@@ -220,7 +223,7 @@ class ResizeContext {
if (!delta_) return; // We can't shrink by less than largest_scalar_t. if (!delta_) return; // We can't shrink by less than largest_scalar_t.
// Now change all the offsets by delta_. // Now change all the offsets by delta_.
auto root = GetAnyRoot(buf_.data()); auto root = GetAnyRoot(buf_.data());
Straddle<uoffset_t>(buf_.data(), root, buf_.data()); Straddle<uoffset_t, 1>(buf_.data(), root, buf_.data());
ResizeTable(schema.root_table(), root); ResizeTable(schema.root_table(), root);
// We can now add or remove bytes at start. // We can now add or remove bytes at start.
if (delta_ > 0) buf_.insert(buf_.begin() + start, delta_, 0); if (delta_ > 0) buf_.insert(buf_.begin() + start, delta_, 0);
...@@ -230,8 +233,8 @@ class ResizeContext { ...@@ -230,8 +233,8 @@ class ResizeContext {
// Check if the range between first (lower address) and second straddles // Check if the range between first (lower address) and second straddles
// the insertion point. If it does, change the offset at offsetloc (of // the insertion point. If it does, change the offset at offsetloc (of
// type T, with direction D). // type T, with direction D).
template<typename T, int D = 1> void Straddle(void *first, void *second, template<typename T, int D> void Straddle(void *first, void *second,
void *offsetloc) { void *offsetloc) {
if (first <= startptr_ && second >= startptr_) { if (first <= startptr_ && second >= startptr_) {
WriteScalar<T>(offsetloc, ReadScalar<T>(offsetloc) + delta_ * D); WriteScalar<T>(offsetloc, ReadScalar<T>(offsetloc) + delta_ * D);
DagCheck(offsetloc) = true; DagCheck(offsetloc) = true;
...@@ -283,7 +286,7 @@ class ResizeContext { ...@@ -283,7 +286,7 @@ class ResizeContext {
if (DagCheck(offsetloc)) if (DagCheck(offsetloc))
continue; // This offset already visited. continue; // This offset already visited.
auto ref = offsetloc + ReadScalar<uoffset_t>(offsetloc); auto ref = offsetloc + ReadScalar<uoffset_t>(offsetloc);
Straddle<uoffset_t>(offsetloc, ref, offsetloc); Straddle<uoffset_t, 1>(offsetloc, ref, offsetloc);
// Recurse. // Recurse.
switch (base_type) { switch (base_type) {
case reflection::Obj: { case reflection::Obj: {
...@@ -301,7 +304,7 @@ class ResizeContext { ...@@ -301,7 +304,7 @@ class ResizeContext {
if (DagCheck(loc)) if (DagCheck(loc))
continue; // This offset already visited. continue; // This offset already visited.
auto dest = loc + vec->Get(i); auto dest = loc + vec->Get(i);
Straddle<uoffset_t>(loc, dest ,loc); Straddle<uoffset_t, 1>(loc, dest ,loc);
ResizeTable(elemobjectdef, reinterpret_cast<Table *>(dest)); ResizeTable(elemobjectdef, reinterpret_cast<Table *>(dest));
} }
break; break;
...@@ -325,6 +328,8 @@ class ResizeContext { ...@@ -325,6 +328,8 @@ class ResizeContext {
} }
} }
void operator=(const ResizeContext &rc);
private: private:
const reflection::Schema &schema_; const reflection::Schema &schema_;
uint8_t *startptr_; uint8_t *startptr_;
...@@ -361,7 +366,7 @@ template<typename T> void ResizeVector(const reflection::Schema &schema, ...@@ -361,7 +366,7 @@ template<typename T> void ResizeVector(const reflection::Schema &schema,
uoffset_t newsize, T val, uoffset_t newsize, T val,
const Vector<T> *vec, const Vector<T> *vec,
std::vector<uint8_t> *flatbuf) { std::vector<uint8_t> *flatbuf) {
auto delta_elem = newsize - static_cast<int>(vec->size()); auto delta_elem = static_cast<int>(newsize) - static_cast<int>(vec->size());
auto delta_bytes = delta_elem * static_cast<int>(sizeof(T)); auto delta_bytes = delta_elem * static_cast<int>(sizeof(T));
auto vec_start = reinterpret_cast<const uint8_t *>(vec) - flatbuf->data(); auto vec_start = reinterpret_cast<const uint8_t *>(vec) - flatbuf->data();
auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) + auto start = static_cast<uoffset_t>(vec_start + sizeof(uoffset_t) +
...@@ -372,7 +377,8 @@ template<typename T> void ResizeVector(const reflection::Schema &schema, ...@@ -372,7 +377,8 @@ template<typename T> void ResizeVector(const reflection::Schema &schema,
// Set new elements to "val". // Set new elements to "val".
for (int i = 0; i < delta_elem; i++) { for (int i = 0; i < delta_elem; i++) {
auto loc = flatbuf->data() + start + i * sizeof(T); auto loc = flatbuf->data() + start + i * sizeof(T);
if (std::is_scalar<T>::value) { auto is_scalar = std::is_scalar<T>::value;
if (is_scalar) {
WriteScalar(loc, val); WriteScalar(loc, val);
} else { // struct } else { // struct
*reinterpret_cast<T *>(loc) = val; *reinterpret_cast<T *>(loc) = val;
......
...@@ -40,7 +40,7 @@ const char kTypeSizes[] = { ...@@ -40,7 +40,7 @@ const char kTypeSizes[] = {
// The enums in the reflection schema should match the ones we use internally. // The enums in the reflection schema should match the ones we use internally.
// Compare the last element to check if these go out of sync. // Compare the last element to check if these go out of sync.
static_assert(BASE_TYPE_UNION == static_assert(BASE_TYPE_UNION ==
static_cast<BaseType>(reflection::BaseType::Union), static_cast<BaseType>(reflection::Union),
"enums don't match"); "enums don't match");
static void Error(const std::string &msg) { static void Error(const std::string &msg) {
...@@ -1346,7 +1346,9 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder) ...@@ -1346,7 +1346,9 @@ Offset<reflection::Object> StructDef::Serialize(FlatBufferBuilder *builder)
const { const {
std::vector<Offset<reflection::Field>> field_offsets; std::vector<Offset<reflection::Field>> field_offsets;
for (auto it = fields.vec.begin(); it != fields.vec.end(); ++it) { for (auto it = fields.vec.begin(); it != fields.vec.end(); ++it) {
field_offsets.push_back((*it)->Serialize(builder, it - fields.vec.begin())); field_offsets.push_back(
(*it)->Serialize(builder,
static_cast<uint16_t>(it - fields.vec.begin())));
} }
return reflection::CreateObject(*builder, return reflection::CreateObject(*builder,
builder->CreateString(name), builder->CreateString(name),
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE 1
#include "flatbuffers/flatbuffers.h" #include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h" #include "flatbuffers/idl.h"
#include "flatbuffers/util.h" #include "flatbuffers/util.h"
...@@ -292,7 +294,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) { ...@@ -292,7 +294,12 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
// Load a binary schema. // Load a binary schema.
std::string bfbsfile; std::string bfbsfile;
TEST_EQ(flatbuffers::LoadFile( TEST_EQ(flatbuffers::LoadFile(
"tests/monster_test.bfbs", false, &bfbsfile), true); "tests/monster_test.bfbs", true, &bfbsfile), true);
// Verify it, just in case:
flatbuffers::Verifier verifier(
reinterpret_cast<const uint8_t *>(bfbsfile.c_str()), bfbsfile.length());
TEST_EQ(reflection::VerifySchemaBuffer(verifier), true);
// Make sure the schema is what we expect it to be. // Make sure the schema is what we expect it to be.
auto schema = reflection::GetSchema(bfbsfile.c_str()); auto schema = reflection::GetSchema(bfbsfile.c_str());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment