Skip to content

Commit

Permalink
Fixed compile errors in VS / gcc for recent commits.
Browse files Browse the repository at this point in the history
Tested: on Windows & Linux.

Change-Id: I90e18c448fc2fafeb83a6cdc3776174479874562
  • Loading branch information
Wouter van Oortmerssen committed Aug 25, 2014
1 parent 11b7436 commit bc5fa9d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ set(CMAKE_BUILD_TYPE Debug)
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})

if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra")
elseif(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra")

if(FLATBUFFERS_CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS
Expand Down
4 changes: 2 additions & 2 deletions include/flatbuffers/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ inline void EnsureDirExists(const std::string &filepath) {
auto parent = StripFileName(filepath);
if (parent.length()) EnsureDirExists(parent);
#ifdef _WIN32
_mkdir(filepath.c_str())
_mkdir(filepath.c_str());
#else
mkdir(filepath.c_str(), S_IRWXU|S_IRGRP|S_IXGRP);
#endif
Expand All @@ -154,7 +154,7 @@ inline int ToUTF8(uint32_t ucc, std::string *out) {
for (int i = 0; i < 6; i++) {
// Max bits this encoding can represent.
uint32_t max_bits = 6 + i * 5 + static_cast<int>(!i);
if (ucc < (1 << max_bits)) { // does it fit?
if (ucc < (1u << max_bits)) { // does it fit?
// Remaining bits not encoded in the first byte, store 6 bits each
uint32_t remain_bits = i * 6;
// Store first byte:
Expand Down
24 changes: 14 additions & 10 deletions samples/monster_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

#include "flatbuffers/flatbuffers.h"


namespace MyGame {
namespace Sample {

struct Vec3;
struct Monster;

enum {
Color_Red = 0,
Color_Green = 1,
Expand All @@ -33,10 +37,7 @@ inline const char **EnumNamesAny() {

inline const char *EnumNameAny(int e) { return EnumNamesAny()[e]; }

bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type);

struct Vec3;
struct Monster;
bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type);

MANUALLY_ALIGNED_STRUCT(4) Vec3 {
private:
Expand All @@ -46,7 +47,7 @@ MANUALLY_ALIGNED_STRUCT(4) Vec3 {

public:
Vec3(float x, float y, float z)
: x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)) {}
: x_(flatbuffers::EndianScalar(x)), y_(flatbuffers::EndianScalar(y)), z_(flatbuffers::EndianScalar(z)) { }

float x() const { return flatbuffers::EndianScalar(x_); }
float y() const { return flatbuffers::EndianScalar(y_); }
Expand All @@ -61,16 +62,17 @@ struct Monster : private flatbuffers::Table {
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(10); }
const flatbuffers::Vector<uint8_t> *inventory() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(14); }
int8_t color() const { return GetField<int8_t>(16, 2); }
bool Verify(const flatbuffers::Verifier &verifier) const {
return VerifyTable(verifier) &&
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyField<Vec3>(verifier, 4 /* pos */) &&
VerifyField<int16_t>(verifier, 6 /* mana */) &&
VerifyField<int16_t>(verifier, 8 /* hp */) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* name */) &&
verifier.Verify(name()) &&
VerifyField<flatbuffers::uoffset_t>(verifier, 14 /* inventory */) &&
verifier.Verify(inventory()) &&
VerifyField<int8_t>(verifier, 16 /* color */);
VerifyField<int8_t>(verifier, 16 /* color */) &&
verifier.EndTable();
}
};

Expand Down Expand Up @@ -105,7 +107,7 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
return builder_.Finish();
}

bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) {
bool VerifyAny(flatbuffers::Verifier &verifier, const void *union_obj, uint8_t type) {
switch (type) {
case Any_NONE: return true;
case Any_Monster: return verifier.VerifyTable(reinterpret_cast<const Monster *>(union_obj));
Expand All @@ -115,7 +117,9 @@ bool VerifyAny(const flatbuffers::Verifier &verifier, const void *union_obj, uin

inline const Monster *GetMonster(const void *buf) { return flatbuffers::GetRoot<Monster>(buf); }

inline bool VerifyMonsterBuffer(const flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<Monster>(); }
inline bool VerifyMonsterBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<Monster>(); }

inline void FinishMonsterBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<Monster> root) { fbb.Finish(root); }

} // namespace Sample
} // namespace MyGame
Expand Down
3 changes: 2 additions & 1 deletion src/idl_gen_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ static void EscapeString(const String &s, std::string *_text) {
// Parses as Unicode within JSON's \uXXXX range, so use that.
text += "\\u";
text += IntToStringHex(ucc, 4);
i = utf8 - s.c_str() - 1; // Skip past characters recognized.
// Skip past characters recognized.
i = static_cast<uoffset_t>(utf8 - s.c_str() - 1);
} else {
// It's either unprintable ASCII, arbitrary binary, or Unicode data
// that doesn't fit \uXXXX, so use \xXX escape code instead.
Expand Down

0 comments on commit bc5fa9d

Please sign in to comment.