diff options
author | Tres Seaver <tseaver@palladion.com> | 2014-11-17 11:25:05 -0500 |
---|---|---|
committer | Tres Seaver <tseaver@palladion.com> | 2014-11-17 11:26:45 -0500 |
commit | 83671c0514741a64433dd86a958e3df6bf9508c6 (patch) | |
tree | 5461fbc7cd22fc38d307d58d21ead7d7321d3c50 /src | |
parent | faf581d20866ad5e586b3e515f6c547d2dcec2c1 (diff) | |
download | protobuf-83671c0514741a64433dd86a958e3df6bf9508c6.tar.gz protobuf-83671c0514741a64433dd86a958e3df6bf9508c6.tar.bz2 protobuf-83671c0514741a64433dd86a958e3df6bf9508c6.zip |
Don't rely on non-standard 'INT32_MAX' / 'INT32_MIN'.
Define safe constants to use when padding enums.
Fixes #80.
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_enum.cc | 4 | ||||
-rw-r--r-- | src/google/protobuf/compiler/cpp/cpp_file.cc | 7 | ||||
-rw-r--r-- | src/google/protobuf/compiler/plugin.pb.h | 7 | ||||
-rw-r--r-- | src/google/protobuf/descriptor.pb.h | 7 |
4 files changed, 20 insertions, 5 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 32d5516e..769ea678 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -106,8 +106,8 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) { // INT32_MIN and INT32_MAX if (descriptor_->value_count() > 0) printer->Print(",\n"); printer->Print(vars, - "$classname$_$prefix$INT_MIN_SENTINEL_DO_NOT_USE_ = INT32_MIN,\n" - "$classname$_$prefix$INT_MAX_SENTINEL_DO_NOT_USE_ = INT32_MAX"); + "$classname$_$prefix$INT_MIN_SENTINEL_DO_NOT_USE_ = PROTOBUF_ENUM_MIN,\n" + "$classname$_$prefix$INT_MAX_SENTINEL_DO_NOT_USE_ = PROTOBUF_ENUM_MAX"); } printer->Outdent(); diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index dc8bf613..6b265dc6 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -105,7 +105,12 @@ void FileGenerator::GenerateHeader(io::Printer* printer) { "#define PROTOBUF_$filename_identifier$__INCLUDED\n" "\n" "#include <string>\n" - "#include <stdint.h>\n" // INT32_MIN, INT32_MAX + "#ifndef PROTOBUF_ENUM_MIN\n" + "#define PROTOBUF_ENUM_MIN (int32_t)0x80000000\n" + "#endif\n" + "#ifndef PROTOBUF_ENUM_MAX\n" + "#define PROTOBUF_ENUM_MAX (int32_t)0x7fffffff\n" + "#endif\n" "\n", "filename", file_->name(), "filename_identifier", filename_identifier); diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 636992a6..b752d6a1 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -5,7 +5,12 @@ #define PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED #include <string> -#include <stdint.h> +#ifndef PROTOBUF_ENUM_MIN +#define PROTOBUF_ENUM_MIN (int32_t)0x80000000 +#endif +#ifndef PROTOBUF_ENUM_MAX +#define PROTOBUF_ENUM_MAX (int32_t)0x7fffffff +#endif #include <google/protobuf/stubs/common.h> diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index 295b53f3..767517a3 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -5,7 +5,12 @@ #define PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED #include <string> -#include <stdint.h> +#ifndef PROTOBUF_ENUM_MIN +#define PROTOBUF_ENUM_MIN (int32_t)0x80000000 +#endif +#ifndef PROTOBUF_ENUM_MAX +#define PROTOBUF_ENUM_MAX (int32_t)0x7fffffff +#endif #include <google/protobuf/stubs/common.h> |