aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar xiaofeng@google.com <xiaofeng@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2012-09-24 06:48:20 +0000
committerGravatar xiaofeng@google.com <xiaofeng@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2012-09-24 06:48:20 +0000
commitfcb8a50b5017673a90dd9d7eef9999a101151c30 (patch)
tree8bc7283f6bdbde32d600eb707d41be7ef742db4e
parentb55a20fa2c669b181f47ea9219b8e74d1263da19 (diff)
Update MSVC project files and fix compilation issues in MSVC.
-rw-r--r--src/google/protobuf/repeated_field.cc17
-rw-r--r--src/google/protobuf/repeated_field.h53
-rw-r--r--src/google/protobuf/stubs/stringprintf.cc5
-rw-r--r--src/google/protobuf/stubs/stringprintf_unittest.cc4
-rw-r--r--src/google/protobuf/wire_format_unittest.cc2
-rwxr-xr-xvsprojects/extract_includes.bat1
-rw-r--r--vsprojects/libprotobuf-lite.vcproj18
-rw-r--r--vsprojects/libprotobuf.vcproj18
-rw-r--r--vsprojects/libprotoc.vcproj12
-rw-r--r--vsprojects/lite-test.vcproj32
-rw-r--r--vsprojects/tests.vcproj56
11 files changed, 160 insertions, 58 deletions
diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc
index 87ce28c8..2c1f74c5 100644
--- a/src/google/protobuf/repeated_field.cc
+++ b/src/google/protobuf/repeated_field.cc
@@ -49,8 +49,8 @@ void RepeatedPtrFieldBase::Reserve(int new_size) {
total_size_ = max(kMinRepeatedFieldAllocationSize,
max(total_size_ * 2, new_size));
elements_ = new void*[total_size_];
- memcpy(elements_, old_elements, allocated_size_ * sizeof(elements_[0]));
- if (old_elements != initial_space_) {
+ if (old_elements != NULL) {
+ memcpy(elements_, old_elements, allocated_size_ * sizeof(elements_[0]));
delete [] old_elements;
}
}
@@ -61,29 +61,16 @@ void RepeatedPtrFieldBase::Swap(RepeatedPtrFieldBase* other) {
int swap_current_size = current_size_;
int swap_allocated_size = allocated_size_;
int swap_total_size = total_size_;
- // We may not be using initial_space_ but it's not worth checking. Just
- // copy it anyway.
- void* swap_initial_space[kInitialSize];
- memcpy(swap_initial_space, initial_space_, sizeof(initial_space_));
elements_ = other->elements_;
current_size_ = other->current_size_;
allocated_size_ = other->allocated_size_;
total_size_ = other->total_size_;
- memcpy(initial_space_, other->initial_space_, sizeof(initial_space_));
other->elements_ = swap_elements;
other->current_size_ = swap_current_size;
other->allocated_size_ = swap_allocated_size;
other->total_size_ = swap_total_size;
- memcpy(other->initial_space_, swap_initial_space, sizeof(swap_initial_space));
-
- if (elements_ == other->initial_space_) {
- elements_ = initial_space_;
- }
- if (other->elements_ == initial_space_) {
- other->elements_ = other->initial_space_;
- }
}
string* StringTypeHandlerBase::New() {
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h
index f0032e7d..b9db2b61 100644
--- a/src/google/protobuf/repeated_field.h
+++ b/src/google/protobuf/repeated_field.h
@@ -171,10 +171,6 @@ class RepeatedField {
private:
static const int kInitialSize = 0;
- // This cannot be the last attribute defined if kInitialSize is 0 or
- // the checks elements_ != initial_space_ to delete are not valid.
- Element initial_space_[kInitialSize];
-
Element* elements_;
int current_size_;
int total_size_;
@@ -317,10 +313,6 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase {
static const int kInitialSize = 0;
- // This cannot be the last attribute defined if kInitialSize is 0 or
- // the checks elements_ != initial_space_ to delete are not valid.
- void* initial_space_[kInitialSize];
-
void** elements_;
int current_size_;
int allocated_size_;
@@ -557,14 +549,14 @@ class RepeatedPtrField : public internal::RepeatedPtrFieldBase {
template <typename Element>
inline RepeatedField<Element>::RepeatedField()
- : elements_(initial_space_),
+ : elements_(NULL),
current_size_(0),
total_size_(kInitialSize) {
}
template <typename Element>
inline RepeatedField<Element>::RepeatedField(const RepeatedField& other)
- : elements_(initial_space_),
+ : elements_(NULL),
current_size_(0),
total_size_(kInitialSize) {
CopyFrom(other);
@@ -573,7 +565,7 @@ inline RepeatedField<Element>::RepeatedField(const RepeatedField& other)
template <typename Element>
template <typename Iter>
inline RepeatedField<Element>::RepeatedField(Iter begin, const Iter& end)
- : elements_(initial_space_),
+ : elements_(NULL),
current_size_(0),
total_size_(kInitialSize) {
for (; begin != end; ++begin) {
@@ -583,9 +575,7 @@ inline RepeatedField<Element>::RepeatedField(Iter begin, const Iter& end)
template <typename Element>
RepeatedField<Element>::~RepeatedField() {
- if (elements_ != initial_space_) {
- delete [] elements_;
- }
+ delete [] elements_;
}
template <typename Element>
@@ -682,9 +672,11 @@ inline void RepeatedField<Element>::Clear() {
template <typename Element>
inline void RepeatedField<Element>::MergeFrom(const RepeatedField& other) {
- Reserve(current_size_ + other.current_size_);
- CopyArray(elements_ + current_size_, other.elements_, other.current_size_);
- current_size_ += other.current_size_;
+ if (other.current_size_ != 0) {
+ Reserve(current_size_ + other.current_size_);
+ CopyArray(elements_ + current_size_, other.elements_, other.current_size_);
+ current_size_ += other.current_size_;
+ }
}
template <typename Element>
@@ -710,27 +702,14 @@ void RepeatedField<Element>::Swap(RepeatedField* other) {
Element* swap_elements = elements_;
int swap_current_size = current_size_;
int swap_total_size = total_size_;
- // We may not be using initial_space_ but it's not worth checking. Just
- // copy it anyway.
- Element swap_initial_space[kInitialSize];
- MoveArray(swap_initial_space, initial_space_, kInitialSize);
elements_ = other->elements_;
current_size_ = other->current_size_;
total_size_ = other->total_size_;
- MoveArray(initial_space_, other->initial_space_, kInitialSize);
other->elements_ = swap_elements;
other->current_size_ = swap_current_size;
other->total_size_ = swap_total_size;
- MoveArray(other->initial_space_, swap_initial_space, kInitialSize);
-
- if (elements_ == other->initial_space_) {
- elements_ = initial_space_;
- }
- if (other->elements_ == initial_space_) {
- other->elements_ = other->initial_space_;
- }
}
template <typename Element>
@@ -761,7 +740,7 @@ RepeatedField<Element>::end() const {
template <typename Element>
inline int RepeatedField<Element>::SpaceUsedExcludingSelf() const {
- return (elements_ != initial_space_) ? total_size_ * sizeof(elements_[0]) : 0;
+ return (elements_ != NULL) ? total_size_ * sizeof(elements_[0]) : 0;
}
// Avoid inlining of Reserve(): new, copy, and delete[] lead to a significant
@@ -774,8 +753,8 @@ void RepeatedField<Element>::Reserve(int new_size) {
total_size_ = max(google::protobuf::internal::kMinRepeatedFieldAllocationSize,
max(total_size_ * 2, new_size));
elements_ = new Element[total_size_];
- MoveArray(elements_, old_elements, current_size_);
- if (old_elements != initial_space_) {
+ if (old_elements != NULL) {
+ MoveArray(elements_, old_elements, current_size_);
delete [] old_elements;
}
}
@@ -821,7 +800,7 @@ struct ElementCopier<Element, true> {
namespace internal {
inline RepeatedPtrFieldBase::RepeatedPtrFieldBase()
- : elements_(initial_space_),
+ : elements_(NULL),
current_size_(0),
allocated_size_(0),
total_size_(kInitialSize) {
@@ -832,9 +811,7 @@ void RepeatedPtrFieldBase::Destroy() {
for (int i = 0; i < allocated_size_; i++) {
TypeHandler::Delete(cast<TypeHandler>(elements_[i]));
}
- if (elements_ != initial_space_) {
- delete [] elements_;
- }
+ delete [] elements_;
}
inline int RepeatedPtrFieldBase::size() const {
@@ -930,7 +907,7 @@ inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) {
template <typename TypeHandler>
inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const {
int allocated_bytes =
- (elements_ != initial_space_) ? total_size_ * sizeof(elements_[0]) : 0;
+ (elements_ != NULL) ? total_size_ * sizeof(elements_[0]) : 0;
for (int i = 0; i < allocated_size_; ++i) {
allocated_bytes += TypeHandler::SpaceUsed(*cast<TypeHandler>(elements_[i]));
}
diff --git a/src/google/protobuf/stubs/stringprintf.cc b/src/google/protobuf/stubs/stringprintf.cc
index d66a497a..4a5b8582 100644
--- a/src/google/protobuf/stubs/stringprintf.cc
+++ b/src/google/protobuf/stubs/stringprintf.cc
@@ -44,6 +44,11 @@ namespace protobuf {
#ifdef _MSC_VER
enum { IS_COMPILER_MSVC = 1 };
+#ifndef va_copy
+// Define va_copy for MSVC. This is a hack, assuming va_list is simply a
+// pointer into the stack and is safe to copy.
+#define va_copy(dest, src) ((dest) = (src))
+#endif
#else
enum { IS_COMPILER_MSVC = 0 };
#endif
diff --git a/src/google/protobuf/stubs/stringprintf_unittest.cc b/src/google/protobuf/stubs/stringprintf_unittest.cc
index 5cf7fffc..a78a2027 100644
--- a/src/google/protobuf/stubs/stringprintf_unittest.cc
+++ b/src/google/protobuf/stubs/stringprintf_unittest.cc
@@ -55,9 +55,9 @@ TEST(StringPrintfTest, Empty) {
TEST(StringPrintfTest, Misc) {
// MSVC does not support $ format specifier.
-#if !defined(COMPILER_MSVC)
+#if !defined(_MSC_VER)
EXPECT_EQ("123hello w", StringPrintf("%3$d%2$s %1$c", 'w', "hello", 123));
-#endif // !COMPILER_MSVC
+#endif // !_MSC_VER
}
TEST(StringAppendFTest, Empty) {
diff --git a/src/google/protobuf/wire_format_unittest.cc b/src/google/protobuf/wire_format_unittest.cc
index 98c066a2..9822828b 100644
--- a/src/google/protobuf/wire_format_unittest.cc
+++ b/src/google/protobuf/wire_format_unittest.cc
@@ -497,7 +497,7 @@ TEST(WireFormatTest, ParseMessageSetWithReverseTagOrder) {
coded_output.WriteVarint32(message.ByteSize());
message.SerializeWithCachedSizes(&coded_output);
// Write the type id.
- uint32_t type_id = message.GetDescriptor()->extension(0)->number();
+ uint32 type_id = message.GetDescriptor()->extension(0)->number();
WireFormatLite::WriteUInt32(WireFormatLite::kMessageSetTypeIdNumber,
type_id, &coded_output);
coded_output.WriteTag(WireFormatLite::kMessageSetItemEndTag);
diff --git a/vsprojects/extract_includes.bat b/vsprojects/extract_includes.bat
index 4f11dfd0..f4852554 100755
--- a/vsprojects/extract_includes.bat
+++ b/vsprojects/extract_includes.bat
@@ -17,6 +17,7 @@ copy ..\src\google\protobuf\descriptor.pb.h include\google\protobuf\descriptor.p
copy ..\src\google\protobuf\descriptor_database.h include\google\protobuf\descriptor_database.h
copy ..\src\google\protobuf\dynamic_message.h include\google\protobuf\dynamic_message.h
copy ..\src\google\protobuf\extension_set.h include\google\protobuf\extension_set.h
+copy ..\src\google\protobuf\generated_enum_reflection.h include\google\protobuf\generated_enum_reflection.h
copy ..\src\google\protobuf\generated_message_util.h include\google\protobuf\generated_message_util.h
copy ..\src\google\protobuf\generated_message_reflection.h include\google\protobuf\generated_message_reflection.h
copy ..\src\google\protobuf\message.h include\google\protobuf\message.h
diff --git a/vsprojects/libprotobuf-lite.vcproj b/vsprojects/libprotobuf-lite.vcproj
index 1f959894..06b15988 100644
--- a/vsprojects/libprotobuf-lite.vcproj
+++ b/vsprojects/libprotobuf-lite.vcproj
@@ -204,7 +204,7 @@
>
</File>
<File
- RelativePath="..\src\google\protobuf\stubs\stl_util-inl.h"
+ RelativePath="..\src\google\protobuf\stubs\stl_util.h"
>
</File>
<File
@@ -223,6 +223,18 @@
RelativePath="..\src\google\protobuf\io\zero_copy_stream_impl_lite.h"
>
</File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\stringprintf.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\template_util.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\type_traits.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
@@ -279,6 +291,10 @@
RelativePath="..\src\google\protobuf\io\zero_copy_stream_impl_lite.cc"
>
</File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\stringprintf.cc"
+ >
+ </File>
</Filter>
</Files>
<Globals>
diff --git a/vsprojects/libprotobuf.vcproj b/vsprojects/libprotobuf.vcproj
index c87c30b2..fd47753d 100644
--- a/vsprojects/libprotobuf.vcproj
+++ b/vsprojects/libprotobuf.vcproj
@@ -252,7 +252,19 @@
>
</File>
<File
- RelativePath="..\src\google\protobuf\stubs\stl_util-inl.h"
+ RelativePath="..\src\google\protobuf\stubs\stl_util.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\stringprintf.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\template_util.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\type_traits.h"
>
</File>
<File
@@ -439,6 +451,10 @@
RelativePath="..\src\google\protobuf\io\zero_copy_stream_impl_lite.cc"
>
</File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\stringprintf.cc"
+ >
+ </File>
</Filter>
</Files>
<Globals>
diff --git a/vsprojects/libprotoc.vcproj b/vsprojects/libprotoc.vcproj
index d55e24e0..b7030288 100644
--- a/vsprojects/libprotoc.vcproj
+++ b/vsprojects/libprotoc.vcproj
@@ -208,6 +208,10 @@
>
</File>
<File
+ RelativePath="..\src\google\protobuf\compiler\cpp\cpp_options.h"
+ >
+ </File>
+ <File
RelativePath="..\src\google\protobuf\compiler\cpp\cpp_primitive_field.h"
>
</File>
@@ -268,6 +272,14 @@
>
</File>
<File
+ RelativePath="..\src\google\protobuf\compiler\java\java_doc_comment.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\compiler\java\java_doc_comment.cc"
+ >
+ </File>
+ <File
RelativePath="..\src\google\protobuf\compiler\python\python_generator.h"
>
</File>
diff --git a/vsprojects/lite-test.vcproj b/vsprojects/lite-test.vcproj
index f66556ab..8020a500 100644
--- a/vsprojects/lite-test.vcproj
+++ b/vsprojects/lite-test.vcproj
@@ -190,6 +190,10 @@
RelativePath=".\google\protobuf\unittest_import_lite.pb.h"
>
</File>
+ <File
+ RelativePath=".\google\protobuf\unittest_import_public_lite.pb.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
@@ -218,6 +222,10 @@
RelativePath=".\google\protobuf\unittest_import_lite.pb.cc"
>
</File>
+ <File
+ RelativePath=".\google\protobuf\unittest_import_public_lite.pb.cc"
+ >
+ </File>
</Filter>
<File
RelativePath="..\src\google\protobuf\unittest_lite.proto"
@@ -267,6 +275,30 @@
/>
</FileConfiguration>
</File>
+ <File
+ RelativePath="..\src\google\protobuf\unittest_import_public_lite.proto"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="Generating unittest_import_public_lite.pb.{h,cc}..."
+ CommandLine="Debug\protoc -I../src --cpp_out=. ../src/google/protobuf/unittest_import_public_lite.proto&#x0D;&#x0A;"
+ Outputs="google\protobuf\unittest_import_public_lite.pb.h;google\protobuf\unittest_import_public_lite.pb.cc"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="Generating unittest_import_public_lite.pb.{h,cc}..."
+ CommandLine="Release\protoc -I../src --cpp_out=. ../src/google/protobuf/unittest_import_public_lite.proto&#x0D;&#x0A;"
+ Outputs="google\protobuf\unittest_import_public_lite.pb.h;google\protobuf\unittest_import_public_lite.pb.cc"
+ />
+ </FileConfiguration>
+ </File>
</Files>
<Globals>
</Globals>
diff --git a/vsprojects/tests.vcproj b/vsprojects/tests.vcproj
index 6df659ae..fb815b5a 100644
--- a/vsprojects/tests.vcproj
+++ b/vsprojects/tests.vcproj
@@ -215,6 +215,10 @@
>
</File>
<File
+ RelativePath=".\google\protobuf\unittest_import_public.pb.h"
+ >
+ </File>
+ <File
RelativePath=".\google\protobuf\unittest_lite_imports_nonline.pb.h"
>
</File>
@@ -263,6 +267,10 @@
>
</File>
<File
+ RelativePath="..\src\google\protobuf\compiler\cpp\cpp_unittest.cc"
+ >
+ </File>
+ <File
RelativePath=".\google\protobuf\compiler\cpp\cpp_test_bad_identifiers.pb.cc"
>
</File>
@@ -279,6 +287,10 @@
>
</File>
<File
+ RelativePath="..\src\google\protobuf\compiler\java\java_doc_comment_unittest.cc"
+ >
+ </File>
+ <File
RelativePath="..\src\google\protobuf\compiler\python\python_plugin_unittest.cc"
>
</File>
@@ -339,10 +351,26 @@
>
</File>
<File
+ RelativePath="..\src\google\protobuf\repeated_field_reflection_unittest.cc"
+ >
+ </File>
+ <File
RelativePath="..\src\google\protobuf\stubs\structurally_valid_unittest.cc"
>
</File>
<File
+ RelativePath="..\src\google\protobuf\stubs\stringprintf_unittest.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\template_util_unittest.cc"
+ >
+ </File>
+ <File
+ RelativePath="..\src\google\protobuf\stubs\type_traits_unittest.cc"
+ >
+ </File>
+ <File
RelativePath="..\src\google\protobuf\stubs\strutil_unittest.cc"
>
</File>
@@ -375,6 +403,10 @@
>
</File>
<File
+ RelativePath=".\google\protobuf\unittest_import_public.pb.cc"
+ >
+ </File>
+ <File
RelativePath=".\google\protobuf\unittest_lite_imports_nonlite.pb.cc"
>
</File>
@@ -524,6 +556,30 @@
</FileConfiguration>
</File>
<File
+ RelativePath="..\src\google\protobuf\unittest_import_public.proto"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="Generating unittest_import_public.pb.{h,cc}..."
+ CommandLine="Debug\protoc -I../src --cpp_out=. ../src/google/protobuf/unittest_import_public.proto&#x0D;&#x0A;"
+ Outputs="google\protobuf\unittest_import_public.pb.h;google\protobuf\unittest_import_public.pb.cc"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ Description="Generating unittest_import_public.pb.{h,cc}..."
+ CommandLine="Release\protoc -I../src --cpp_out=. ../src/google/protobuf/unittest_import_public.proto&#x0D;&#x0A;"
+ Outputs="google\protobuf\unittest_import_public.pb.h;google\protobuf\unittest_import_public.pb.cc"
+ />
+ </FileConfiguration>
+ </File>
+ <File
RelativePath="..\src\google\protobuf\unittest_lite_imports_nonlite.proto"
>
<FileConfiguration