mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 21:26:54 +00:00
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.
This commit is contained in:
@@ -54,12 +54,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
#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_MAJOR 1
|
||||||
#define FLATBUFFERS_VERSION_MINOR 0
|
#define FLATBUFFERS_VERSION_MINOR 0
|
||||||
#define FLATBUFFERS_VERSION_REVISION 0
|
#define FLATBUFFERS_VERSION_REVISION 0
|
||||||
@@ -345,6 +339,10 @@ class vector_downward {
|
|||||||
void pop(size_t bytes_to_remove) { cur_ += bytes_to_remove; }
|
void pop(size_t bytes_to_remove) { cur_ += bytes_to_remove; }
|
||||||
|
|
||||||
private:
|
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_;
|
size_t reserved_;
|
||||||
uint8_t *buf_;
|
uint8_t *buf_;
|
||||||
uint8_t *cur_; // Points at location between empty (below) and used (above).
|
uint8_t *cur_; // Points at location between empty (below) and used (above).
|
||||||
@@ -594,7 +592,7 @@ class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> Offset<Vector<T>> CreateVector(const std::vector<T> &v){
|
template<typename T> Offset<Vector<T>> CreateVector(const std::vector<T> &v){
|
||||||
return CreateVector(&v[0], v.size());
|
return CreateVector(v.begin(), v.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> Offset<Vector<const T *>> CreateVectorOfStructs(
|
template<typename T> Offset<Vector<const T *>> CreateVectorOfStructs(
|
||||||
@@ -607,7 +605,7 @@ class FlatBufferBuilder {
|
|||||||
|
|
||||||
template<typename T> Offset<Vector<const T *>> CreateVectorOfStructs(
|
template<typename T> Offset<Vector<const T *>> CreateVectorOfStructs(
|
||||||
const std::vector<T> &v) {
|
const std::vector<T> &v) {
|
||||||
return CreateVectorOfStructs(&v[0], v.size());
|
return CreateVectorOfStructs(v.begin(), v.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finish serializing a buffer by writing the root offset.
|
// Finish serializing a buffer by writing the root offset.
|
||||||
@@ -618,6 +616,10 @@ class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// You shouldn't really be copying instances of this class.
|
||||||
|
FlatBufferBuilder(const FlatBufferBuilder &);
|
||||||
|
FlatBufferBuilder &operator=(const FlatBufferBuilder &);
|
||||||
|
|
||||||
struct FieldLoc {
|
struct FieldLoc {
|
||||||
uoffset_t off;
|
uoffset_t off;
|
||||||
voffset_t id;
|
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
|
// to measure popularity. You are free to remove it (of course) but we would
|
||||||
// appreciate if you left it in.
|
// appreciate if you left it in.
|
||||||
|
|
||||||
extern volatile FLATBUFFERS_WEAK const char *flatbuffer_version_string;
|
// Weak linkage is culled by VS & doesn't work on cygwin.
|
||||||
volatile FLATBUFFERS_WEAK const char *flatbuffer_version_string =
|
#if !defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
|
||||||
|
extern volatile __attribute__((weak)) const char *flatbuffer_version_string;
|
||||||
|
volatile __attribute__((weak)) const char *flatbuffer_version_string =
|
||||||
"FlatBuffers "
|
"FlatBuffers "
|
||||||
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
|
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
|
||||||
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
|
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
|
||||||
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
|
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
|
||||||
|
|
||||||
|
#endif // !defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|
||||||
#endif // FLATBUFFERS_H_
|
#endif // FLATBUFFERS_H_
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ std::string StripExtension(const std::string &filename) {
|
|||||||
|
|
||||||
std::string StripPath(const std::string &filename) {
|
std::string StripPath(const std::string &filename) {
|
||||||
size_t i = filename.find_last_of(
|
size_t i = filename.find_last_of(
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
"\\:"
|
"\\:"
|
||||||
#else
|
#else
|
||||||
"/"
|
"/"
|
||||||
|
|||||||
Reference in New Issue
Block a user