aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am1
-rw-r--r--appveyor.bat14
-rw-r--r--appveyor.yml20
-rw-r--r--cmake/CMakeLists.txt11
-rw-r--r--cmake/libprotobuf-lite.cmake8
-rw-r--r--cmake/libprotobuf.cmake8
-rw-r--r--cmake/libprotoc.cmake8
-rw-r--r--cmake/protoc.cmake11
-rw-r--r--cmake/tests.cmake4
-rw-r--r--cmake/version.rc.in45
-rw-r--r--configure.ac2
-rw-r--r--csharp/build_packages.bat2
-rw-r--r--csharp/src/Google.Protobuf/Google.Protobuf.csproj6
-rw-r--r--java/core/src/main/java/com/google/protobuf/UnsafeUtil.java27
-rw-r--r--java/core/src/main/java/com/google/protobuf/Utf8.java10
-rwxr-xr-xkokoro/linux/benchmark/build.sh5
-rw-r--r--php/tests/proto/test_empty_php_namespace.proto1
-rw-r--r--php/tests/proto/test_no_namespace.proto2
-rw-r--r--php/tests/proto/test_php_namespace.proto1
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc2
-rw-r--r--src/google/protobuf/compiler/php/php_generator.cc54
-rw-r--r--src/google/protobuf/descriptor.cc14
22 files changed, 177 insertions, 79 deletions
diff --git a/Makefile.am b/Makefile.am
index 48f2c034..2ad619a7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1033,6 +1033,7 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
cmake/protobuf.pc.cmake \
cmake/protoc.cmake \
cmake/tests.cmake \
+ cmake/version.rc.in \
editors/README.txt \
editors/proto.vim \
editors/protobuf-mode.el \
diff --git a/appveyor.bat b/appveyor.bat
index e59ebccc..29ec4922 100644
--- a/appveyor.bat
+++ b/appveyor.bat
@@ -1,11 +1,23 @@
setlocal
+IF %platform%==MinGW GOTO build_mingw
IF %language%==cpp GOTO build_cpp
IF %language%==csharp GOTO build_csharp
-echo Unsupported language %language%. Exiting.
+echo Unsupported language %language% and platform %platform%. Exiting.
goto :error
+:build_mingw
+echo Building MinGW
+set PATH=C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH:C:\Program Files\Git\usr\bin;=%
+mkdir build_mingw
+cd build_mingw
+cmake -G "%generator%" -Dprotobuf_BUILD_SHARED_LIBS=%BUILD_DLL% -Dprotobuf_UNICODE=%UNICODE% -Dprotobuf_BUILD_TESTS=0 ../cmake
+mingw32-make -j8 all || goto error
+rem cd %configuration%
+rem tests.exe || goto error
+goto :EOF
+
:build_cpp
echo Building C++
mkdir build_msvc
diff --git a/appveyor.yml b/appveyor.yml
index 02e0d313..1dd076a4 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,20 +1,23 @@
-# Only test one combination: "Visual Studio 12 + Win64 + Debug + DLL". We can
-# test more combinations but AppVeyor just takes too long to finish (each
-# combination takes ~15mins).
-platform:
- - Win64
-
configuration:
- Debug
environment:
matrix:
- - language: cpp
+ # Only test few combinations: "Visual Studio 2015 (14) + Win64/MinGW + Debug + DLL". We can
+ # test more combinations but AppVeyor just takes too long to finish (each
+ # combination takes ~15mins).
+ - platform: MinGW
+ language: cpp
+ image: Visual Studio 2015
+
+ - platform: Win64
+ language: cpp
image: Visual Studio 2015
BUILD_DLL: ON
UNICODE: ON
- - language: csharp
+ - platform: Win64
+ language: csharp
image: Visual Studio 2017
# Our build scripts run tests automatically; we don't want AppVeyor
@@ -25,6 +28,7 @@ install:
- git submodule update --init --recursive
before_build:
+ - if %platform%==MinGW set generator=MinGW Makefiles
- if %platform%==Win32 set generator=Visual Studio 14
- if %platform%==Win64 set generator=Visual Studio 14 Win64
- if %platform%==Win32 set vcplatform=Win32
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index 02174e96..ada9dc25 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -166,12 +166,23 @@ if (MSVC)
add_definitions(/bigobj)
string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR})
string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR})
+ string(REPLACE "." "," protobuf_RC_FILEVERSION "${protobuf_VERSION}")
configure_file(extract_includes.bat.in extract_includes.bat)
# Suppress linker warnings about files with no symbols defined.
set(CMAKE_STATIC_LINKER_FLAGS /ignore:4221)
+
+ # Configure Resource Compiler
+ enable_language(RC)
+ # use English language (0x409) in resource compiler
+ set(rc_flags "/l0x409")
+ # fix rc.exe invocations because of usage of add_definitions()
+ set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_flags} <DEFINES> /fo<OBJECT> <SOURCE>")
+
+ configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
endif (MSVC)
+
get_filename_component(protobuf_source_dir ${protobuf_SOURCE_DIR} PATH)
include_directories(
diff --git a/cmake/libprotobuf-lite.cmake b/cmake/libprotobuf-lite.cmake
index 911fce5e..1d0b0b84 100644
--- a/cmake/libprotobuf-lite.cmake
+++ b/cmake/libprotobuf-lite.cmake
@@ -48,8 +48,14 @@ set(libprotobuf_lite_includes
${protobuf_source_dir}/src/google/protobuf/wire_format_lite.h
)
+if (MSVC)
+set(libprotobuf_lite_rc_files
+ ${CMAKE_CURRENT_BINARY_DIR}/version.rc
+)
+endif()
+
add_library(libprotobuf-lite ${protobuf_SHARED_OR_STATIC}
- ${libprotobuf_lite_files} ${libprotobuf_lite_includes})
+ ${libprotobuf_lite_files} ${libprotobuf_lite_includes} ${libprotobuf_lite_rc_files})
target_link_libraries(libprotobuf-lite ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(libprotobuf-lite PUBLIC ${protobuf_source_dir}/src)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
diff --git a/cmake/libprotobuf.cmake b/cmake/libprotobuf.cmake
index 65d05c19..bd570be7 100644
--- a/cmake/libprotobuf.cmake
+++ b/cmake/libprotobuf.cmake
@@ -112,8 +112,14 @@ set(libprotobuf_includes
${protobuf_source_dir}/src/google/protobuf/wrappers.pb.h
)
+if (MSVC)
+set(libprotobuf_rc_files
+ ${CMAKE_CURRENT_BINARY_DIR}/version.rc
+)
+endif()
+
add_library(libprotobuf ${protobuf_SHARED_OR_STATIC}
- ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes})
+ ${libprotobuf_lite_files} ${libprotobuf_files} ${libprotobuf_includes} ${libprotobuf_rc_files})
target_link_libraries(libprotobuf ${CMAKE_THREAD_LIBS_INIT})
if(protobuf_WITH_ZLIB)
target_link_libraries(libprotobuf ${ZLIB_LIBRARIES})
diff --git a/cmake/libprotoc.cmake b/cmake/libprotoc.cmake
index ec6958bc..04701818 100644
--- a/cmake/libprotoc.cmake
+++ b/cmake/libprotoc.cmake
@@ -161,6 +161,12 @@ set(libprotoc_headers
${protobuf_source_dir}/src/google/protobuf/compiler/zip_writer.h
)
+if (MSVC)
+set(libprotoc_rc_files
+ ${CMAKE_CURRENT_BINARY_DIR}/version.rc
+)
+endif()
+
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
@@ -174,7 +180,7 @@ add_custom_command(
)
add_library(libprotoc ${protobuf_SHARED_OR_STATIC}
- ${libprotoc_files} ${libprotoc_headers})
+ ${libprotoc_files} ${libprotoc_headers} ${libprotoc_rc_files})
target_link_libraries(libprotoc libprotobuf)
if(MSVC AND protobuf_BUILD_SHARED_LIBS)
target_compile_definitions(libprotoc
diff --git a/cmake/protoc.cmake b/cmake/protoc.cmake
index 5777b16e..bb160f47 100644
--- a/cmake/protoc.cmake
+++ b/cmake/protoc.cmake
@@ -2,6 +2,15 @@ set(protoc_files
${protobuf_source_dir}/src/google/protobuf/compiler/main.cc
)
-add_executable(protoc ${protoc_files})
+if (MSVC)
+set(protoc_rc_files
+ ${CMAKE_CURRENT_BINARY_DIR}/version.rc
+)
+endif()
+
+add_executable(protoc ${protoc_files} ${protoc_rc_files})
target_link_libraries(protoc libprotobuf libprotoc)
add_executable(protobuf::protoc ALIAS protoc)
+
+set_target_properties(protoc PROPERTIES
+ VERSION ${protobuf_VERSION})
diff --git a/cmake/tests.cmake b/cmake/tests.cmake
index ec790e33..f91567b8 100644
--- a/cmake/tests.cmake
+++ b/cmake/tests.cmake
@@ -204,6 +204,10 @@ if(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>")
endif()
+if(MINGW)
+ set_source_files_properties(${tests_files} PROPERTIES COMPILE_FLAGS "-Wno-narrowing")
+endif()
+
add_executable(tests ${tests_files} ${common_test_files} ${tests_proto_files} ${lite_test_proto_files})
target_link_libraries(tests libprotoc libprotobuf gmock_main)
diff --git a/cmake/version.rc.in b/cmake/version.rc.in
new file mode 100644
index 00000000..cbce1e53
--- /dev/null
+++ b/cmake/version.rc.in
@@ -0,0 +1,45 @@
+#define VS_FF_DEBUG 0x1L
+#define VS_VERSION_INFO 0x1L
+#define VS_FFI_FILEFLAGSMASK 0x17L
+#define VER_PRIVATEBUILD 0x0L
+#define VER_PRERELEASE 0x0L
+#define VOS__WINDOWS32 0x4L
+#define VFT_DLL 0x2L
+#define VFT2_UNKNOWN 0x0L
+
+#ifndef DEBUG
+#define VER_DEBUG 0
+#else
+#define VER_DEBUG VS_FF_DEBUG
+#endif
+
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @protobuf_RC_FILEVERSION@,0
+ PRODUCTVERSION @protobuf_RC_FILEVERSION@,0
+ FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+ FILEFLAGS VER_DEBUG
+ FILEOS VOS__WINDOWS32
+ FILETYPE VFT_DLL
+BEGIN
+ BLOCK "VarFileInfo"
+ BEGIN
+ // English language (0x409) and the Windows Unicode codepage (1200)
+ VALUE "Translation", 0x409, 1200
+ END
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "Compiled with @CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPILER_VERSION@\0"
+ VALUE "ProductVersion", "@protobuf_VERSION@\0"
+ VALUE "FileVersion", "@protobuf_VERSION@\0"
+ VALUE "InternalName", "protobuf\0"
+ VALUE "ProductName", "Protocol Buffers - Google's Data Interchange Format\0"
+ VALUE "CompanyName", "Google Inc.\0"
+ VALUE "LegalCopyright", "Copyright 2008 Google Inc. All rights reserved.\0"
+ VALUE "Licence", "BSD\0"
+ VALUE "Info", "https://developers.google.com/protocol-buffers/\0"
+ END
+ END
+END
diff --git a/configure.ac b/configure.ac
index 6e9ce1f5..7a5e3ab2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -190,7 +190,7 @@ AM_CONDITIONAL([HAVE_PTHREAD], [test "x$ax_pthread_ok" = "xyes"])
AC_CXX_STL_HASH
case "$target_os" in
- mingw* | cygwin* | win* | aix*)
+ mingw* | cygwin* | win* | aix* | *android* )
;;
*)
# Need to link against rt on Solaris
diff --git a/csharp/build_packages.bat b/csharp/build_packages.bat
index d7205659..8157bbab 100644
--- a/csharp/build_packages.bat
+++ b/csharp/build_packages.bat
@@ -1,7 +1,7 @@
@rem Builds Google.Protobuf NuGet packages
dotnet restore src/Google.Protobuf.sln
-dotnet pack -c Release src/Google.Protobuf.sln || goto :error
+dotnet pack -c Release src/Google.Protobuf.sln /p:SourceLinkCreate=true || goto :error
goto :EOF
diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj
index 6e4e1e2b..93dcd854 100644
--- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj
+++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj
@@ -17,8 +17,6 @@
<PackageLicenseUrl>https://github.com/google/protobuf/blob/master/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/google/protobuf.git</RepositoryUrl>
- <IncludeSymbols>true</IncludeSymbols>
- <IncludeSource>true</IncludeSource>
</PropertyGroup>
<!--
@@ -30,4 +28,8 @@
<TargetFrameworks>netstandard1.0</TargetFrameworks>
</PropertyGroup>
+ <ItemGroup>
+ <PackageReference Include="SourceLink.Create.CommandLine" Version="2.7.6" PrivateAssets="All" />
+ </ItemGroup>
+
</Project>
diff --git a/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java b/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
index c9e2904b..d84ef3c5 100644
--- a/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
+++ b/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java
@@ -33,7 +33,6 @@ package com.google.protobuf;
import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.logging.Level;
@@ -72,8 +71,6 @@ final class UnsafeUtil {
private static final long BUFFER_ADDRESS_OFFSET = fieldOffset(bufferAddressField());
- private static final long STRING_VALUE_OFFSET = fieldOffset(stringValueField());
-
private UnsafeUtil() {}
static boolean hasUnsafeArrayOperations() {
@@ -149,10 +146,6 @@ final class UnsafeUtil {
return MEMORY_ACCESSOR.getObject(target, offset);
}
- static void putObject(Object target, long offset, Object value) {
- MEMORY_ACCESSOR.putObject(target, offset, value);
- }
-
static byte getByte(byte[] target, long index) {
return MEMORY_ACCESSOR.getByte(target, BYTE_ARRAY_BASE_OFFSET + index);
}
@@ -262,26 +255,6 @@ final class UnsafeUtil {
return MEMORY_ACCESSOR.getLong(buffer, BUFFER_ADDRESS_OFFSET);
}
- /**
- * Returns a new {@link String} backed by the given {@code chars}. The char array should not
- * be mutated any more after calling this function.
- */
- static String moveToString(char[] chars) {
- if (STRING_VALUE_OFFSET == -1) {
- // In the off-chance that this JDK does not implement String as we'd expect, just do a copy.
- return new String(chars);
- }
- final String str;
- try {
- str = (String) UNSAFE.allocateInstance(String.class);
- } catch (InstantiationException e) {
- // This should never happen, but return a copy as a fallback just in case.
- return new String(chars);
- }
- putObject(str, STRING_VALUE_OFFSET, chars);
- return str;
- }
-
static Object getStaticObject(Field field) {
return MEMORY_ACCESSOR.getStaticObject(field);
}
diff --git a/java/core/src/main/java/com/google/protobuf/Utf8.java b/java/core/src/main/java/com/google/protobuf/Utf8.java
index 6968abb3..de75fe6b 100644
--- a/java/core/src/main/java/com/google/protobuf/Utf8.java
+++ b/java/core/src/main/java/com/google/protobuf/Utf8.java
@@ -1474,10 +1474,7 @@ final class Utf8 {
}
}
- if (resultPos < resultArr.length) {
- resultArr = Arrays.copyOf(resultArr, resultPos);
- }
- return UnsafeUtil.moveToString(resultArr);
+ return new String(resultArr, 0, resultPos);
}
@Override
@@ -1553,10 +1550,7 @@ final class Utf8 {
}
}
- if (resultPos < resultArr.length) {
- resultArr = Arrays.copyOf(resultArr, resultPos);
- }
- return UnsafeUtil.moveToString(resultArr);
+ return new String(resultArr, 0, resultPos);
}
@Override
diff --git a/kokoro/linux/benchmark/build.sh b/kokoro/linux/benchmark/build.sh
index 750c3e5c..f29a16fd 100755
--- a/kokoro/linux/benchmark/build.sh
+++ b/kokoro/linux/benchmark/build.sh
@@ -27,8 +27,8 @@ cd $oldpwd
./configure CXXFLAGS="-fPIC -O2"
make -j8
cd python
-python setup.py -q build --cpp_implementation
-pip install .
+python setup.py build --cpp_implementation
+pip install . --user
# build and run Python benchmark
@@ -78,6 +78,7 @@ echo "benchmarking go..."
make java-benchmark
echo "benchmarking java..."
./java-benchmark -Cresults.file.options.file="tmp/java_result.json" $datasets
+cat $(find /tmp -name "trail-1.log")
# upload result to bq
make python_add_init
diff --git a/php/tests/proto/test_empty_php_namespace.proto b/php/tests/proto/test_empty_php_namespace.proto
index 7b4bc74d..1d02f760 100644
--- a/php/tests/proto/test_empty_php_namespace.proto
+++ b/php/tests/proto/test_empty_php_namespace.proto
@@ -2,6 +2,7 @@ syntax = "proto3";
package foo;
option php_namespace = "";
+option php_metadata_namespace = "";
message TestEmptyNamespace {
int32 a = 1;
diff --git a/php/tests/proto/test_no_namespace.proto b/php/tests/proto/test_no_namespace.proto
index 58f13d47..03f89270 100644
--- a/php/tests/proto/test_no_namespace.proto
+++ b/php/tests/proto/test_no_namespace.proto
@@ -1,5 +1,7 @@
syntax = "proto3";
+option php_metadata_namespace = "\\";
+
message NoNamespaceMessage {
int32 a = 1;
diff --git a/php/tests/proto/test_php_namespace.proto b/php/tests/proto/test_php_namespace.proto
index 713187b9..bb57d617 100644
--- a/php/tests/proto/test_php_namespace.proto
+++ b/php/tests/proto/test_php_namespace.proto
@@ -2,6 +2,7 @@ syntax = "proto3";
package foo;
option php_namespace = "Php\\Test";
+option php_metadata_namespace = "Metadata\\Php\\Test";
message TestNamespace {
int32 a = 1;
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
index 5bca1ffa..04b61074 100644
--- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -169,7 +169,7 @@ std::string UnderscoresToCamelCase(const std::string& input,
}
}
// Add a trailing "_" if the name should be altered.
- if (input[input.size() - 1] == '#') {
+ if (input.size() > 0 && input[input.size() - 1] == '#') {
result += '_';
}
return result;
diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc
index 4e237fc7..a37380e3 100644
--- a/src/google/protobuf/compiler/php/php_generator.cc
+++ b/src/google/protobuf/compiler/php/php_generator.cc
@@ -83,7 +83,7 @@ std::string PhpName(const std::string& full_name, bool is_descriptor);
std::string DefaultForField(FieldDescriptor* field);
std::string IntToString(int32 value);
std::string FilenameToClassname(const string& filename);
-std::string GeneratedMetadataFileName(const std::string& proto_file,
+std::string GeneratedMetadataFileName(const FileDescriptor* file,
bool is_descriptor);
std::string LabelForField(FieldDescriptor* field);
std::string TypeName(FieldDescriptor* field);
@@ -268,11 +268,12 @@ std::string DefaultForField(const FieldDescriptor* field) {
}
}
-std::string GeneratedMetadataFileName(const std::string& proto_file,
+std::string GeneratedMetadataFileName(const FileDescriptor* file,
bool is_descriptor) {
+ const string& proto_file = file->name();
int start_index = 0;
int first_index = proto_file.find_first_of("/", start_index);
- std::string result = "GPBMetadata/";
+ std::string result = "";
if (proto_file == kEmptyFile) {
return kEmptyMetadataFile;
@@ -290,17 +291,36 @@ std::string GeneratedMetadataFileName(const std::string& proto_file,
file_no_suffix = proto_file.substr(0, lastindex);
}
- while (first_index != string::npos) {
- result += UnderscoresToCamelCase(
- file_no_suffix.substr(start_index, first_index - start_index), true);
- result += "/";
- start_index = first_index + 1;
- first_index = file_no_suffix.find_first_of("/", start_index);
+ if (file->options().has_php_metadata_namespace()) {
+ const string& php_metadata_namespace =
+ file->options().php_metadata_namespace();
+ if (php_metadata_namespace != "" && php_metadata_namespace != "\\") {
+ result += php_metadata_namespace;
+ std::replace(result.begin(), result.end(), '\\', '/');
+ if (result.at(result.size() - 1) != '/') {
+ result += "/";
+ }
+ }
+ } else {
+ result += "GPBMetadata/";
+ while (first_index != string::npos) {
+ result += UnderscoresToCamelCase(
+ file_no_suffix.substr(start_index, first_index - start_index), true);
+ result += "/";
+ start_index = first_index + 1;
+ first_index = file_no_suffix.find_first_of("/", start_index);
+ }
}
// Append file name.
+ int file_name_start = file_no_suffix.find_last_of("/");
+ if (file_name_start == string::npos) {
+ file_name_start = 0;
+ } else {
+ file_name_start += 1;
+ }
result += RenameEmpty(UnderscoresToCamelCase(
- file_no_suffix.substr(start_index, first_index - start_index), true));
+ file_no_suffix.substr(file_name_start, first_index - file_name_start), true));
return result += ".php";
}
@@ -851,7 +871,7 @@ void GenerateAddFileToPool(const FileDescriptor* file, bool is_descriptor,
continue;
}
std::string dependency_filename =
- GeneratedMetadataFileName(name, is_descriptor);
+ GeneratedMetadataFileName(file->dependency(i), is_descriptor);
printer->Print(
"\\^name^::initOnce();\n",
"name", FilenameToClassname(dependency_filename));
@@ -945,7 +965,7 @@ std::string FilenameToClassname(const string& filename) {
void GenerateMetadataFile(const FileDescriptor* file,
bool is_descriptor,
GeneratorContext* generator_context) {
- std::string filename = GeneratedMetadataFileName(file->name(), is_descriptor);
+ std::string filename = GeneratedMetadataFileName(file, is_descriptor);
std::unique_ptr<io::ZeroCopyOutputStream> output(
generator_context->Open(filename));
io::Printer printer(output.get(), '^');
@@ -955,12 +975,12 @@ void GenerateMetadataFile(const FileDescriptor* file,
std::string fullname = FilenameToClassname(filename);
int lastindex = fullname.find_last_of("\\");
- printer.Print(
- "namespace ^name^;\n\n",
- "name", fullname.substr(0, lastindex));
-
if (lastindex != string::npos) {
printer.Print(
+ "namespace ^name^;\n\n",
+ "name", fullname.substr(0, lastindex));
+
+ printer.Print(
"class ^name^\n"
"{\n",
"name", fullname.substr(lastindex + 1));
@@ -1094,7 +1114,7 @@ void GenerateMessageFile(const FileDescriptor* file, const Descriptor* message,
Indent(&printer);
std::string metadata_filename =
- GeneratedMetadataFileName(file->name(), is_descriptor);
+ GeneratedMetadataFileName(file, is_descriptor);
std::string metadata_fullname = FilenameToClassname(metadata_filename);
printer.Print(
"\\^fullname^::initOnce();\n"
diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc
index d466dd8b..dae24f9e 100644
--- a/src/google/protobuf/descriptor.cc
+++ b/src/google/protobuf/descriptor.cc
@@ -406,9 +406,10 @@ typedef std::pair<const EnumDescriptor*, int> EnumIntPair;
template<typename PairType>
struct PointerIntegerPairHash {
size_t operator()(const PairType& p) const {
- // FIXME(kenton): What is the best way to compute this hash? I have
- // no idea! This seems a bit better than an XOR.
- return reinterpret_cast<intptr_t>(p.first) * ((1 << 16) - 1) + p.second;
+ static const size_t prime1 = 16777499;
+ static const size_t prime2 = 16777619;
+ return reinterpret_cast<size_t>(p.first) * prime1 ^
+ static_cast<size_t>(p.second) * prime2;
}
#ifdef _MSC_VER
@@ -424,11 +425,10 @@ struct PointerIntegerPairHash {
struct PointerStringPairHash {
size_t operator()(const PointerStringPair& p) const {
- // FIXME(kenton): What is the best way to compute this hash? I have
- // no idea! This seems a bit better than an XOR.
+ static const size_t prime = 16777619;
hash<const char*> cstring_hash;
- return reinterpret_cast<intptr_t>(p.first) * ((1 << 16) - 1) +
- cstring_hash(p.second);
+ return reinterpret_cast<size_t>(p.first) * prime ^
+ static_cast<size_t>(cstring_hash(p.second));
}
#ifdef _MSC_VER