From 9270a99d2e64d08a438729522330d1f1bd1e4716 Mon Sep 17 00:00:00 2001 From: "kenton@google.com" Date: Sat, 1 Aug 2009 02:16:55 +0000 Subject: Make DLLs work again. --- src/google/protobuf/lite_unittest.cc | 2 +- src/google/protobuf/repeated_field.cc | 4 ++-- src/google/protobuf/repeated_field.h | 15 +++++++++++++-- src/google/protobuf/wire_format_lite.cc | 1 - 4 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/google') diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 83932859..ffeec3c4 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -107,6 +107,6 @@ int main(int argc, char* argv[]) { google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message); } - cout << "PASS"; + cout << "PASS" << endl; return 0; } diff --git a/src/google/protobuf/repeated_field.cc b/src/google/protobuf/repeated_field.cc index 270ef064..3230c04c 100644 --- a/src/google/protobuf/repeated_field.cc +++ b/src/google/protobuf/repeated_field.cc @@ -69,10 +69,10 @@ void RepeatedPtrFieldBase::Swap(RepeatedPtrFieldBase* other) { } } -string* StringTypeHandler::New() { +string* StringTypeHandlerBase::New() { return new string; } -void StringTypeHandler::Delete(string* value) { +void StringTypeHandlerBase::Delete(string* value) { delete value; } diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index cbe26521..43c9f3f0 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -262,19 +262,30 @@ inline void GenericTypeHandler::Merge( to->CheckTypeAndMergeFrom(from); } -class LIBPROTOBUF_EXPORT StringTypeHandler { +// HACK: If a class is declared as DLL-exported in MSVC, it insists on +// generating copies of all its methods -- even inline ones -- to include +// in the DLL. But SpaceUsed() calls StringSpaceUsedExcludingSelf() which +// isn't in the lite library, therefore the lite library cannot link if +// StringTypeHandler is exported. So, we factor out StringTypeHandlerBase, +// export that, then make StringTypeHandler be a subclass which is NOT +// exported. +// TODO(kenton): There has to be a better way. +class LIBPROTOBUF_EXPORT StringTypeHandlerBase { public: typedef string Type; static string* New(); static void Delete(string* value); static void Clear(string* value) { value->clear(); } static void Merge(const string& from, string* to) { *to = from; } +}; + +class StringTypeHandler : public StringTypeHandlerBase { + public: static int SpaceUsed(const string& value) { return sizeof(value) + StringSpaceUsedExcludingSelf(value); } }; - } // namespace internal // RepeatedPtrField is like RepeatedField, but used for repeated strings or diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index bbbf5236..5d09803a 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -42,7 +42,6 @@ #include #include #include -#include namespace google { namespace protobuf { -- cgit v1.2.3