diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | cmake/libprotoc.cmake | 12 | ||||
-rw-r--r-- | cmake/tests.cmake | 1 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf.Test/ByteStringTest.cs | 13 | ||||
-rw-r--r-- | csharp/src/Google.Protobuf/ByteString.cs | 2 | ||||
-rw-r--r-- | src/Makefile.am | 14 | ||||
-rwxr-xr-x | src/google/protobuf/arenastring.h | 15 | ||||
-rw-r--r-- | src/google/protobuf/compiler/code_generator.h | 2 | ||||
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_helpers.cc | 1 | ||||
-rw-r--r-- | src/google/protobuf/compiler/csharp/csharp_names.h | 9 | ||||
-rw-r--r-- | src/google/protobuf/compiler/js/embed.cc | 17 | ||||
-rwxr-xr-x | src/google/protobuf/compiler/js/well_known_types_embed.cc | 314 | ||||
-rw-r--r-- | src/google/protobuf/compiler/objectivec/objectivec_helpers.h | 72 |
13 files changed, 96 insertions, 378 deletions
@@ -47,6 +47,7 @@ any_test.pb.* map*unittest.pb.* unittest*.pb.* cpp_test*.pb.* +src/google/protobuf/compiler/js/well_known_types_embed.cc src/google/protobuf/util/**/*.pb.cc src/google/protobuf/util/**/*.pb.h @@ -60,6 +61,7 @@ python/build/ python/google/protobuf/compiler/ python/google/protobuf/util/ +src/js_embed src/protoc src/unittest_proto_middleman diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake index 2d238449..215abcd8 100644 --- a/cmake/libprotoc.cmake +++ b/cmake/libprotoc.cmake @@ -94,6 +94,18 @@ set(libprotoc_files ${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.cc ) +set(js_well_known_types_sources, + ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/any.js + ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/struct.js + ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types/timestamp.js +) +add_executable(js_embed ${protobuf_source_dir}/src/google/protobuf/compiler/js/embed.cc) +add_custom_command( + OUTPUT ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc + DEPENDS js_embed ${js_well_known_types_sources} + COMMAND js_embed ${js_well_known_types_sources} > ${protobuf_source_dir}/src/google/protobuf/compiler/js/well_known_types_embed.cc +) + add_library(libprotoc ${protobuf_SHARED_OR_STATIC} ${libprotoc_files}) target_link_libraries(libprotoc libprotobuf) diff --git a/cmake/tests.cmake b/cmake/tests.cmake index 30214e7d..bf8e5a6c 100644 --- a/cmake/tests.cmake +++ b/cmake/tests.cmake @@ -214,4 +214,5 @@ target_link_libraries(lite-arena-test libprotobuf-lite gmock_main) add_custom_target(check COMMAND tests + DEPENDS tests test_plugin WORKING_DIRECTORY ${protobuf_source_dir}) diff --git a/csharp/src/Google.Protobuf.Test/ByteStringTest.cs b/csharp/src/Google.Protobuf.Test/ByteStringTest.cs index 685e130a..ff2444a3 100644 --- a/csharp/src/Google.Protobuf.Test/ByteStringTest.cs +++ b/csharp/src/Google.Protobuf.Test/ByteStringTest.cs @@ -167,5 +167,18 @@ namespace Google.Protobuf // Optimization which also fixes issue 61.
Assert.AreSame(ByteString.Empty, ByteString.FromBase64(""));
}
+
+ [Test]
+ public void GetHashCode_Regression()
+ {
+ // We used to have an awful hash algorithm where only the last four
+ // bytes were relevant. This is a regression test for
+ // https://github.com/google/protobuf/issues/2511
+
+ ByteString b1 = ByteString.CopyFrom(100, 1, 2, 3, 4);
+ ByteString b2 = ByteString.CopyFrom(200, 1, 2, 3, 4);
+ Assert.AreNotEqual(b1.GetHashCode(), b2.GetHashCode());
+ }
+
}
}
\ No newline at end of file diff --git a/csharp/src/Google.Protobuf/ByteString.cs b/csharp/src/Google.Protobuf/ByteString.cs index dd7f22d6..5c652cc3 100644 --- a/csharp/src/Google.Protobuf/ByteString.cs +++ b/csharp/src/Google.Protobuf/ByteString.cs @@ -303,7 +303,7 @@ namespace Google.Protobuf int ret = 23;
foreach (byte b in bytes)
{
- ret = (ret << 8) | b;
+ ret = (ret * 31) + b;
}
return ret;
}
diff --git a/src/Makefile.am b/src/Makefile.am index d6f27fa8..254d428f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -483,10 +483,20 @@ libprotoc_la_SOURCES = \ google/protobuf/compiler/csharp/csharp_wrapper_field.cc \ google/protobuf/compiler/csharp/csharp_wrapper_field.h -bin_PROGRAMS = protoc +bin_PROGRAMS = protoc js_embed protoc_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la protoc_SOURCES = google/protobuf/compiler/main.cc +# The special JS code for the well-known types is linked into the compiler via +# well_known_types_embed.cc, which is generated from .js source files. +js_embed_SOURCES = google/protobuf/compiler/js/embed.cc +js_well_known_types_sources = \ + google/protobuf/compiler/js/well_known_types/any.js \ + google/protobuf/compiler/js/well_known_types/struct.js \ + google/protobuf/compiler/js/well_known_types/timestamp.js +google/protobuf/compiler/js/well_known_types_embed.cc: js_embed$(EXEEXT) $(js_well_known_types_sources) + ./js_embed$(EXEEXT) $(js_well_known_types_sources) > $@ + # Tests ============================================================== protoc_inputs = \ @@ -661,7 +671,7 @@ protoc_outputs = \ google/protobuf/util/message_differencer_unittest.pb.cc \ google/protobuf/util/message_differencer_unittest.pb.h -BUILT_SOURCES = $(protoc_outputs) +BUILT_SOURCES = $(protoc_outputs) google/protobuf/compiler/js/well_known_types_embed.cc if USE_EXTERNAL_PROTOC diff --git a/src/google/protobuf/arenastring.h b/src/google/protobuf/arenastring.h index bc427ba2..a7efb752 100755 --- a/src/google/protobuf/arenastring.h +++ b/src/google/protobuf/arenastring.h @@ -293,22 +293,15 @@ struct LIBPROTOBUF_EXPORT ArenaStringPtr { GOOGLE_ATTRIBUTE_NOINLINE void CreateInstance(::google::protobuf::Arena* arena, const ::std::string* initial_value) { - // Assumes ptr_ is not NULL. - if (initial_value != NULL) { - ptr_ = new ::std::string(*initial_value); - } else { - ptr_ = new ::std::string(); - } + GOOGLE_DCHECK(initial_value != NULL); + ptr_ = new ::std::string(*initial_value); if (arena != NULL) { arena->Own(ptr_); } } GOOGLE_ATTRIBUTE_NOINLINE void CreateInstanceNoArena(const ::std::string* initial_value) { - if (initial_value != NULL) { - ptr_ = new ::std::string(*initial_value); - } else { - ptr_ = new ::std::string(); - } + GOOGLE_DCHECK(initial_value != NULL); + ptr_ = new ::std::string(*initial_value); } }; diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index b917d373..e2b2a661 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -162,7 +162,7 @@ typedef GeneratorContext OutputDirectory; // "foo=bar,baz,qux=corge" // parses to the pairs: // ("foo", "bar"), ("baz", ""), ("qux", "corge") -extern void ParseGeneratorParameter(const string&, +extern void LIBPROTOC_EXPORT ParseGeneratorParameter(const string&, std::vector<std::pair<string, string> >*); } // namespace compiler diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 6c154c5a..5bca1ffa 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -38,6 +38,7 @@ #include <vector> #include <google/protobuf/compiler/csharp/csharp_helpers.h> +#include <google/protobuf/compiler/csharp/csharp_names.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/wire_format.h> diff --git a/src/google/protobuf/compiler/csharp/csharp_names.h b/src/google/protobuf/compiler/csharp/csharp_names.h index 30805187..21758f28 100644 --- a/src/google/protobuf/compiler/csharp/csharp_names.h +++ b/src/google/protobuf/compiler/csharp/csharp_names.h @@ -39,6 +39,7 @@ #define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ #include <string> +#include <google/protobuf/stubs/port.h> namespace google { namespace protobuf { @@ -56,14 +57,14 @@ namespace csharp { // // Returns: // The namespace to use for given file descriptor. -string GetFileNamespace(const FileDescriptor* descriptor); +string LIBPROTOC_EXPORT GetFileNamespace(const FileDescriptor* descriptor); // Requires: // descriptor != NULL // // Returns: // The fully-qualified C# class name. -string GetClassName(const Descriptor* descriptor); +string LIBPROTOC_EXPORT GetClassName(const Descriptor* descriptor); // Requires: // descriptor != NULL @@ -72,7 +73,7 @@ string GetClassName(const Descriptor* descriptor); // The fully-qualified name of the C# class that provides // access to the file descriptor. Proto compiler generates // such class for each .proto file processed. -string GetReflectionClassName(const FileDescriptor* descriptor); +string LIBPROTOC_EXPORT GetReflectionClassName(const FileDescriptor* descriptor); // Generates output file name for given file descriptor. If generate_directories // is true, the output file will be put under directory corresponding to file's @@ -88,7 +89,7 @@ string GetReflectionClassName(const FileDescriptor* descriptor); // The file name to use as output file for given file descriptor. In case // of failure, this function will return empty string and error parameter // will contain the error message. -string GetOutputFile( +string LIBPROTOC_EXPORT GetOutputFile( const google::protobuf::FileDescriptor* descriptor, const string file_extension, const bool generate_directories, diff --git a/src/google/protobuf/compiler/js/embed.cc b/src/google/protobuf/compiler/js/embed.cc index be2ffdd4..d04fea2e 100644 --- a/src/google/protobuf/compiler/js/embed.cc +++ b/src/google/protobuf/compiler/js/embed.cc @@ -48,7 +48,8 @@ static char ToDecimalDigit(int num) { static std::string CEscape(const std::string& str) { std::string dest; - for (unsigned char ch : str) { + for (int i = 0; i < str.size(); ++i) { + unsigned char ch = str[i]; switch (ch) { case '\n': dest += "\\n"; break; case '\r': dest += "\\r"; break; @@ -96,18 +97,16 @@ static void AddFile(const char* name, std::basic_ostream<char>* out) { } int main(int argc, char *argv[]) { - auto& out = std::cout; - - out << "#include " - "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n"; - out << "struct FileToc well_known_types_js[] = {\n"; + std::cout << "#include " + "\"google/protobuf/compiler/js/well_known_types_embed.h\"\n"; + std::cout << "struct FileToc well_known_types_js[] = {\n"; for (int i = 1; i < argc; i++) { - AddFile(argv[i], &out); + AddFile(argv[i], &std::cout); } - out << " {NULL, NULL} // Terminate the list.\n"; - out << "};\n"; + std::cout << " {NULL, NULL} // Terminate the list.\n"; + std::cout << "};\n"; return EXIT_SUCCESS; } diff --git a/src/google/protobuf/compiler/js/well_known_types_embed.cc b/src/google/protobuf/compiler/js/well_known_types_embed.cc deleted file mode 100755 index 71fd557f..00000000 --- a/src/google/protobuf/compiler/js/well_known_types_embed.cc +++ /dev/null @@ -1,314 +0,0 @@ -#include <google/protobuf/compiler/js/well_known_types_embed.h> -struct FileToc well_known_types_js[] = { -{"any.js", - "// Protocol Buffers - Google's data interchange format\n" - "// Copyright 2008 Google Inc. All rights reserved.\n" - "// https://developers.google.com/protocol-buffers/\n" - "//\n" - "// Redistribution and use in source and binary forms, with or without\n" - "// modification, are permitted provided that the following conditions are\n" - "// met:\n" - "//\n" - "// * Redistributions of source code must retain the above copyright\n" - "// notice, this list of conditions and the following disclaimer.\n" - "// * Redistributions in binary form must reproduce the above\n" - "// copyright notice, this list of conditions and the following disclaimer\n" - "// in the documentation and/or other materials provided with the\n" - "// distribution.\n" - "// * Neither the name of Google Inc. nor the names of its\n" - "// contributors may be used to endorse or promote products derived from\n" - "// this software without specific prior written permission.\n" - "//\n" - "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" - "// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" - "// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" - "// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" - "// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" - "// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" - "// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" - "// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" - "// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" - "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" - "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" - "\n" - "/* This code will be inserted into generated code for\n" - " * google/protobuf/any.proto. */\n" - "\n" - "/**\n" - " * Returns the type name contained in this instance, if any.\n" - " * @return {string|undefined}\n" - " */\n" - "proto.google.protobuf.Any.prototype.getTypeName = function() {\n" - " return this.getTypeUrl().split('/').pop();\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Packs the given message instance into this Any.\n" - " * @param {!Uint8Array} serialized The serialized data to pack.\n" - " * @param {string} name The type name of this message object.\n" - " * @param {string=} opt_typeUrlPrefix the type URL prefix.\n" - " */\n" - "proto.google.protobuf.Any.prototype.pack = function(serialized, name,\n" - " opt_typeUrlPrefix) {\n" - " if (!opt_typeUrlPrefix) {\n" - " opt_typeUrlPrefix = 'type.googleapis.com/';\n" - " }\n" - "\n" - " if (opt_typeUrlPrefix.substr(-1) != '/') {\n" - " this.setTypeUrl(opt_typeUrlPrefix + '/' + name);\n" - " } else {\n" - " this.setTypeUrl(opt_typeUrlPrefix + name);\n" - " }\n" - "\n" - " this.setValue(serialized);\n" - "};\n" - "\n" - "\n" - "/**\n" - " * @template T\n" - " * Unpacks this Any into the given message object.\n" - " * @param {function(Uint8Array):T} deserialize Function that will deserialize\n" - " * the binary data properly.\n" - " * @param {string} name The expected type name of this message object.\n" - " * @return {?T} If the name matched the expected name, returns the deserialized\n" - " * object, otherwise returns undefined.\n" - " */\n" - "proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) {\n" - " if (this.getTypeName() == name) {\n" - " return deserialize(this.getValue_asU8());\n" - " } else {\n" - " return null;\n" - " }\n" - "};\n" -}, -{"timestamp.js", - "// Protocol Buffers - Google's data interchange format\n" - "// Copyright 2008 Google Inc. All rights reserved.\n" - "// https://developers.google.com/protocol-buffers/\n" - "//\n" - "// Redistribution and use in source and binary forms, with or without\n" - "// modification, are permitted provided that the following conditions are\n" - "// met:\n" - "//\n" - "// * Redistributions of source code must retain the above copyright\n" - "// notice, this list of conditions and the following disclaimer.\n" - "// * Redistributions in binary form must reproduce the above\n" - "// copyright notice, this list of conditions and the following disclaimer\n" - "// in the documentation and/or other materials provided with the\n" - "// distribution.\n" - "// * Neither the name of Google Inc. nor the names of its\n" - "// contributors may be used to endorse or promote products derived from\n" - "// this software without specific prior written permission.\n" - "//\n" - "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" - "// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" - "// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" - "// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" - "// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" - "// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" - "// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" - "// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" - "// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" - "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" - "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" - "\n" - "/* This code will be inserted into generated code for\n" - " * google/protobuf/timestamp.proto. */\n" - "\n" - "/**\n" - " * Returns a JavaScript 'Date' object corresponding to this Timestamp.\n" - " * @return {!Date}\n" - " */\n" - "proto.google.protobuf.Timestamp.prototype.toDate = function() {\n" - " // The '|| 0' clauses are necessary for as long as\n" - " // broken_proto3_semantics are specified for this rule inside Google.\n" - " var seconds = this.getSeconds() || 0;\n" - " var nanos = this.getNanos() || 0;\n" - "\n" - " return new Date((seconds * 1000) + (nanos / 1000000));\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Sets the value of this Timestamp object to be the given Date.\n" - " * @param {!Date} value The value to set.\n" - " */\n" - "proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {\n" - " var millis = value.getTime();\n" - " this.setSeconds(Math.floor(value.getTime() / 1000));\n" - " this.setNanos(value.getMilliseconds() * 1000000);\n" - "};\n" -}, -{"struct.js", - "// Protocol Buffers - Google's data interchange format\n" - "// Copyright 2008 Google Inc. All rights reserved.\n" - "// https://developers.google.com/protocol-buffers/\n" - "//\n" - "// Redistribution and use in source and binary forms, with or without\n" - "// modification, are permitted provided that the following conditions are\n" - "// met:\n" - "//\n" - "// * Redistributions of source code must retain the above copyright\n" - "// notice, this list of conditions and the following disclaimer.\n" - "// * Redistributions in binary form must reproduce the above\n" - "// copyright notice, this list of conditions and the following disclaimer\n" - "// in the documentation and/or other materials provided with the\n" - "// distribution.\n" - "// * Neither the name of Google Inc. nor the names of its\n" - "// contributors may be used to endorse or promote products derived from\n" - "// this software without specific prior written permission.\n" - "//\n" - "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" - "// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" - "// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" - "// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" - "// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" - "// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" - "// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" - "// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" - "// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" - "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" - "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" - "\n" - "/* This code will be inserted into generated code for\n" - " * google/protobuf/struct.proto. */\n" - "\n" - "/**\n" - " * Typedef representing plain JavaScript values that can go into a\n" - " * Struct.\n" - " * @typedef {null|number|string|boolean|Array|Object}\n" - " */\n" - "proto.google.protobuf.JavaScriptValue;\n" - "\n" - "\n" - "/**\n" - " * Converts this Value object to a plain JavaScript value.\n" - " * @return {?proto.google.protobuf.JavaScriptValue} a plain JavaScript\n" - " * value representing this Struct.\n" - " */\n" - "proto.google.protobuf.Value.prototype.toJavaScript = function() {\n" - " var kindCase = proto.google.protobuf.Value.KindCase;\n" - " switch (this.getKindCase()) {\n" - " case kindCase.NULL_VALUE:\n" - " return null;\n" - " case kindCase.NUMBER_VALUE:\n" - " return this.getNumberValue();\n" - " case kindCase.STRING_VALUE:\n" - " return this.getStringValue();\n" - " case kindCase.BOOL_VALUE:\n" - " return this.getBoolValue();\n" - " case kindCase.STRUCT_VALUE:\n" - " return this.getStructValue().toJavaScript();\n" - " case kindCase.LIST_VALUE:\n" - " return this.getListValue().toJavaScript();\n" - " default:\n" - " throw new Error('Unexpected struct type');\n" - " }\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Converts this JavaScript value to a new Value proto.\n" - " * @param {!proto.google.protobuf.JavaScriptValue} value The value to\n" - " * convert.\n" - " * @return {!proto.google.protobuf.Value} The newly constructed value.\n" - " */\n" - "proto.google.protobuf.Value.fromJavaScript = function(value) {\n" - " var ret = new proto.google.protobuf.Value();\n" - " switch (goog.typeOf(value)) {\n" - " case 'string':\n" - " ret.setStringValue(/** @type {string} */ (value));\n" - " break;\n" - " case 'number':\n" - " ret.setNumberValue(/** @type {number} */ (value));\n" - " break;\n" - " case 'boolean':\n" - " ret.setBoolValue(/** @type {boolean} */ (value));\n" - " break;\n" - " case 'null':\n" - " ret.setNullValue(proto.google.protobuf.NullValue.NULL_VALUE);\n" - " break;\n" - " case 'array':\n" - " ret.setListValue(proto.google.protobuf.ListValue.fromJavaScript(\n" - " /** @type{!Array} */ (value)));\n" - " break;\n" - " case 'object':\n" - " ret.setStructValue(proto.google.protobuf.Struct.fromJavaScript(\n" - " /** @type{!Object} */ (value)));\n" - " break;\n" - " default:\n" - " throw new Error('Unexpected struct type.');\n" - " }\n" - "\n" - " return ret;\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Converts this ListValue object to a plain JavaScript array.\n" - " * @return {!Array} a plain JavaScript array representing this List.\n" - " */\n" - "proto.google.protobuf.ListValue.prototype.toJavaScript = function() {\n" - " var ret = [];\n" - " var values = this.getValuesList();\n" - "\n" - " for (var i = 0; i < values.length; i++) {\n" - " ret[i] = values[i].toJavaScript();\n" - " }\n" - "\n" - " return ret;\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Constructs a ListValue protobuf from this plain JavaScript array.\n" - " * @param {!Array} array a plain JavaScript array\n" - " * @return {proto.google.protobuf.ListValue} a new ListValue object\n" - " */\n" - "proto.google.protobuf.ListValue.fromJavaScript = function(array) {\n" - " var ret = new proto.google.protobuf.ListValue();\n" - "\n" - " for (var i = 0; i < array.length; i++) {\n" - " ret.addValues(proto.google.protobuf.Value.fromJavaScript(array[i]));\n" - " }\n" - "\n" - " return ret;\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Converts this Struct object to a plain JavaScript object.\n" - " * @return {!Object<string, !proto.google.protobuf.JavaScriptValue>} a plain\n" - " * JavaScript object representing this Struct.\n" - " */\n" - "proto.google.protobuf.Struct.prototype.toJavaScript = function() {\n" - " var ret = {};\n" - "\n" - " this.getFieldsMap().forEach(function(value, key) {\n" - " ret[key] = value.toJavaScript();\n" - " });\n" - "\n" - " return ret;\n" - "};\n" - "\n" - "\n" - "/**\n" - " * Constructs a Struct protobuf from this plain JavaScript object.\n" - " * @param {!Object} obj a plain JavaScript object\n" - " * @return {proto.google.protobuf.Struct} a new Struct object\n" - " */\n" - "proto.google.protobuf.Struct.fromJavaScript = function(obj) {\n" - " var ret = new proto.google.protobuf.Struct();\n" - " var map = ret.getFieldsMap();\n" - "\n" - " for (var property in obj) {\n" - " var val = obj[property];\n" - " map.set(property, proto.google.protobuf.Value.fromJavaScript(val));\n" - " }\n" - "\n" - " return ret;\n" - "};\n" -}, - {NULL, NULL} // Terminate the list. -}; diff --git a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h index a2179446..c99262a1 100644 --- a/src/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ b/src/google/protobuf/compiler/objectivec/objectivec_helpers.h @@ -53,66 +53,66 @@ struct Options { }; // Escape C++ trigraphs by escaping question marks to "\?". -string EscapeTrigraphs(const string& to_escape); +string LIBPROTOC_EXPORT EscapeTrigraphs(const string& to_escape); // Strips ".proto" or ".protodevel" from the end of a filename. -string StripProto(const string& filename); +string LIBPROTOC_EXPORT StripProto(const string& filename); // Remove white space from either end of a StringPiece. -void StringPieceTrimWhitespace(StringPiece* input); +void LIBPROTOC_EXPORT StringPieceTrimWhitespace(StringPiece* input); // Returns true if the name requires a ns_returns_not_retained attribute applied // to it. -bool IsRetainedName(const string& name); +bool LIBPROTOC_EXPORT IsRetainedName(const string& name); // Returns true if the name starts with "init" and will need to have special // handling under ARC. -bool IsInitName(const string& name); +bool LIBPROTOC_EXPORT IsInitName(const string& name); // Gets the objc_class_prefix. -string FileClassPrefix(const FileDescriptor* file); +string LIBPROTOC_EXPORT FileClassPrefix(const FileDescriptor* file); // Gets the path of the file we're going to generate (sans the .pb.h // extension). The path will be dependent on the objectivec package // declared in the proto package. -string FilePath(const FileDescriptor* file); +string LIBPROTOC_EXPORT FilePath(const FileDescriptor* file); // Just like FilePath(), but without the directory part. -string FilePathBasename(const FileDescriptor* file); +string LIBPROTOC_EXPORT FilePathBasename(const FileDescriptor* file); // Gets the name of the root class we'll generate in the file. This class // is not meant for external consumption, but instead contains helpers that // the rest of the classes need -string FileClassName(const FileDescriptor* file); +string LIBPROTOC_EXPORT FileClassName(const FileDescriptor* file); // These return the fully-qualified class name corresponding to the given // descriptor. -string ClassName(const Descriptor* descriptor); -string ClassName(const Descriptor* descriptor, string* out_suffix_added); -string EnumName(const EnumDescriptor* descriptor); +string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor); +string LIBPROTOC_EXPORT ClassName(const Descriptor* descriptor, string* out_suffix_added); +string LIBPROTOC_EXPORT EnumName(const EnumDescriptor* descriptor); // Returns the fully-qualified name of the enum value corresponding to the // the descriptor. -string EnumValueName(const EnumValueDescriptor* descriptor); +string LIBPROTOC_EXPORT EnumValueName(const EnumValueDescriptor* descriptor); // Returns the name of the enum value corresponding to the descriptor. -string EnumValueShortName(const EnumValueDescriptor* descriptor); +string LIBPROTOC_EXPORT EnumValueShortName(const EnumValueDescriptor* descriptor); // Reverse what an enum does. -string UnCamelCaseEnumShortName(const string& name); +string LIBPROTOC_EXPORT UnCamelCaseEnumShortName(const string& name); // Returns the name to use for the extension (used as the method off the file's // Root class). -string ExtensionMethodName(const FieldDescriptor* descriptor); +string LIBPROTOC_EXPORT ExtensionMethodName(const FieldDescriptor* descriptor); // Returns the transformed field name. -string FieldName(const FieldDescriptor* field); -string FieldNameCapitalized(const FieldDescriptor* field); +string LIBPROTOC_EXPORT FieldName(const FieldDescriptor* field); +string LIBPROTOC_EXPORT FieldNameCapitalized(const FieldDescriptor* field); // Returns the transformed oneof name. -string OneofEnumName(const OneofDescriptor* descriptor); -string OneofName(const OneofDescriptor* descriptor); -string OneofNameCapitalized(const OneofDescriptor* descriptor); +string LIBPROTOC_EXPORT OneofEnumName(const OneofDescriptor* descriptor); +string LIBPROTOC_EXPORT OneofName(const OneofDescriptor* descriptor); +string LIBPROTOC_EXPORT OneofNameCapitalized(const OneofDescriptor* descriptor); inline bool HasFieldPresence(const FileDescriptor* file) { return file->syntax() != FileDescriptor::SYNTAX_PROTO3; @@ -127,7 +127,7 @@ inline bool IsMapEntryMessage(const Descriptor* descriptor) { } // Reverse of the above. -string UnCamelCaseFieldName(const string& name, const FieldDescriptor* field); +string LIBPROTOC_EXPORT UnCamelCaseFieldName(const string& name, const FieldDescriptor* field); enum ObjectiveCType { OBJECTIVECTYPE_INT32, @@ -175,42 +175,42 @@ string GetOptionalDeprecatedAttribute( } } -string GetCapitalizedType(const FieldDescriptor* field); +string LIBPROTOC_EXPORT GetCapitalizedType(const FieldDescriptor* field); -ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type); +ObjectiveCType LIBPROTOC_EXPORT GetObjectiveCType(FieldDescriptor::Type field_type); inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) { return GetObjectiveCType(field->type()); } -bool IsPrimitiveType(const FieldDescriptor* field); -bool IsReferenceType(const FieldDescriptor* field); +bool LIBPROTOC_EXPORT IsPrimitiveType(const FieldDescriptor* field); +bool LIBPROTOC_EXPORT IsReferenceType(const FieldDescriptor* field); -string GPBGenericValueFieldName(const FieldDescriptor* field); -string DefaultValue(const FieldDescriptor* field); -bool HasNonZeroDefaultValue(const FieldDescriptor* field); +string LIBPROTOC_EXPORT GPBGenericValueFieldName(const FieldDescriptor* field); +string LIBPROTOC_EXPORT DefaultValue(const FieldDescriptor* field); +bool LIBPROTOC_EXPORT HasNonZeroDefaultValue(const FieldDescriptor* field); -string BuildFlagsString(const FlagType type, const vector<string>& strings); +string LIBPROTOC_EXPORT BuildFlagsString(const FlagType type, const vector<string>& strings); // Builds HeaderDoc/appledoc style comments out of the comments in the .proto // file. -string BuildCommentsString(const SourceLocation& location, +string LIBPROTOC_EXPORT BuildCommentsString(const SourceLocation& location, bool prefer_single_line); // The name the commonly used by the library when built as a framework. // This lines up to the name used in the CocoaPod. -extern const char* const ProtobufLibraryFrameworkName; +extern LIBPROTOC_EXPORT const char* const ProtobufLibraryFrameworkName; // Returns the CPP symbol name to use as the gate for framework style imports // for the given framework name to use. -string ProtobufFrameworkImportSymbol(const string& framework_name); +string LIBPROTOC_EXPORT ProtobufFrameworkImportSymbol(const string& framework_name); // Checks if the file is one of the proto's bundled with the library. -bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); +bool LIBPROTOC_EXPORT IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); // Checks the prefix for the given files and outputs any warnings as needed. If // there are flat out errors, then out_error is filled in with the first error // and the result is false. -bool ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files, +bool LIBPROTOC_EXPORT ValidateObjCClassPrefixes(const vector<const FileDescriptor*>& files, const Options& generation_options, string* out_error); @@ -244,7 +244,7 @@ class LIBPROTOC_EXPORT LineConsumer { virtual bool ConsumeLine(const StringPiece& line, string* out_error) = 0; }; -bool ParseSimpleFile( +bool LIBPROTOC_EXPORT ParseSimpleFile( const string& path, LineConsumer* line_consumer, string* out_error); |