From: Wouter van Oortmerssen Date: Tue, 15 Jul 2014 23:27:44 +0000 (-0700) Subject: Small fixes to the core C++ FlatBuffers implementation. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9143a93312b65955511838fafddf56301716be41;p=platform%2Fupstream%2Fflatbuffers.git Small fixes to the core C++ FlatBuffers implementation. - Ensured weak linkage with the version string is not used on Windows, especially cygwin (which throws a linker error). - Avoided a VS debug error for taking the address of the first element of an empty vector. - Made copy/assignment constructors for downward_vector and FlatBufferBuilder private, to avoid people unintentionally making expensive copies. - Using the more correct _WIN32 instead of WIN32 Change-Id: I801b5c8b159e3721af6d1ef0978a3247ba168bab Tested: on Windows (VS + Cygwin) and Linux. --- diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index 82df488..ab473b0 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -54,12 +54,6 @@ #endif #endif // !defined(FLATBUFFERS_LITTLEENDIAN) -#if !defined(_MSC_VER) -#define FLATBUFFERS_WEAK __attribute__((weak)) -#else -#define FLATBUFFERS_WEAK __declspec(selectany) -#endif // WIN32 - #define FLATBUFFERS_VERSION_MAJOR 1 #define FLATBUFFERS_VERSION_MINOR 0 #define FLATBUFFERS_VERSION_REVISION 0 @@ -345,6 +339,10 @@ class vector_downward { void pop(size_t bytes_to_remove) { cur_ += bytes_to_remove; } private: + // You shouldn't really be copying instances of this class. + vector_downward(const vector_downward &); + vector_downward &operator=(const vector_downward &); + size_t reserved_; uint8_t *buf_; uint8_t *cur_; // Points at location between empty (below) and used (above). @@ -594,7 +592,7 @@ class FlatBufferBuilder { } template Offset> CreateVector(const std::vector &v){ - return CreateVector(&v[0], v.size()); + return CreateVector(v.begin(), v.size()); } template Offset> CreateVectorOfStructs( @@ -607,7 +605,7 @@ class FlatBufferBuilder { template Offset> CreateVectorOfStructs( const std::vector &v) { - return CreateVectorOfStructs(&v[0], v.size()); + return CreateVectorOfStructs(v.begin(), v.size()); } // Finish serializing a buffer by writing the root offset. @@ -618,6 +616,10 @@ class FlatBufferBuilder { } private: + // You shouldn't really be copying instances of this class. + FlatBufferBuilder(const FlatBufferBuilder &); + FlatBufferBuilder &operator=(const FlatBufferBuilder &); + struct FieldLoc { uoffset_t off; voffset_t id; @@ -877,13 +879,18 @@ inline int LookupEnum(const char **names, const char *name) { // to measure popularity. You are free to remove it (of course) but we would // appreciate if you left it in. -extern volatile FLATBUFFERS_WEAK const char *flatbuffer_version_string; -volatile FLATBUFFERS_WEAK const char *flatbuffer_version_string = +// Weak linkage is culled by VS & doesn't work on cygwin. +#if !defined(_WIN32) && !defined(__CYGWIN__) + +extern volatile __attribute__((weak)) const char *flatbuffer_version_string; +volatile __attribute__((weak)) const char *flatbuffer_version_string = "FlatBuffers " FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "." FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "." FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION); +#endif // !defined(_WIN32) && !defined(__CYGWIN__) + } // namespace flatbuffers #endif // FLATBUFFERS_H_ diff --git a/src/flatc.cpp b/src/flatc.cpp index ab87347..43646da 100755 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -106,7 +106,7 @@ std::string StripExtension(const std::string &filename) { std::string StripPath(const std::string &filename) { size_t i = filename.find_last_of( - #ifdef WIN32 + #ifdef _WIN32 "\\:" #else "/"