Hello,

I need Protobuf to work on Solaris, so attached is a patch to fix Solaris 
10 and and Solaris 11 support.

After I had already made the patch, I discovered in the issue tracker 
(issues 561 and 565) that someone else has tried to fix this before, but it 
doesn't appear their patch has been applied to the trunk, even though 
they're quite old now?
So, I'm posting my patch, because it fixes the above problems and more.
I hope someone can merge it to svn; it applies cleanly to the trunk of 
today's date.
Not sure if this is the proper way to go about it, but there are already 
multiple issues regarding Solaris support so I don't want to pollute the 
tracker further.
If I need to do something more to get someone to look at this, please let 
me know.

I have tested PB with my patch applied on the following configurations:

Solaris 10:
 * SPARC:
   * GCC 3.4.3:
     * 32-bit: PASS
     * 64-bit: PASS
   * Solaris Studio 12.3:
     * 32-bit: PASS
     * 64-bit: PASS
 * x86:
   * GCC 3.4.3:
     * 32-bit: PASS
     * 64-bit: PASS
   * Solaris Studio 12.3:
     * 32-bit: PASS
     * 64-bit: PASS

Solaris 11.1:
 * x86:
   * GCC 4.5.2:
     * 32-bit: PASS
     * 64-bit: PASS
   * Solaris Studio 12.3:
     * 32-bit: PASS
     * 64-bit: PASS

Ubuntu 13.10:
(This was a sanity-check to ensure I didn't inadvertently break something.)
 * x86:
    * GCC 4.8.1
      * 64-bit: PASS

Test procedure:

$ ./configure
 or (for 32-bit): $ ./configure --disable-64bit-solaris
$ make
$ make check

PASS = built and all tests passed.

I don't have access to a SPARC Solaris 11 machine so I have not been able 
to test that configuration, although I believe it should work.

Regards,
Lars

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.
Index: configure.ac
===================================================================
--- configure.ac	(revision 514)
+++ configure.ac	(working copy)
@@ -83,6 +83,9 @@
 AC_FUNC_STRTOD
 AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol])
 
+# Checks if -lrt is required for sched_yield.
+AC_SEARCH_LIBS([sched_yield], [rt])
+
 # Check for zlib.
 HAVE_ZLIB=0
 AS_IF([test "$with_zlib" != no], [
Index: m4/acx_check_suncc.m4
===================================================================
--- m4/acx_check_suncc.m4	(revision 514)
+++ m4/acx_check_suncc.m4	(working copy)
@@ -26,7 +26,7 @@
   AS_IF([test "$SUNCC" = "yes" -a "x${ac_cv_env_CXXFLAGS_set}" = "x"],[
     dnl Sun Studio has a crashing bug with -xO4 in some cases. Keep this
     dnl at -xO3 until a proper test to detect those crashes can be done.
-    CXXFLAGS="-g0 -xO3 -xlibmil -xdepend -xbuiltin -mt -compat=5 -library=stlport4 -library=Crun -template=no%extdef ${CXXFLAGS}"
+    CXXFLAGS="-g0 -xO3 -xlibmil -xdepend -xbuiltin -mt -compat=5 -library=stlport4 -library=Crun -template=no%extdef -features=tmplrefstatic ${CXXFLAGS}"
   ])
 
   case $host_os in
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 514)
+++ src/Makefile.am	(working copy)
@@ -45,6 +45,7 @@
   google/protobuf/stubs/atomicops_internals_macosx.h            \
   google/protobuf/stubs/atomicops_internals_mips_gcc.h          \
   google/protobuf/stubs/atomicops_internals_pnacl.h             \
+  google/protobuf/stubs/atomicops_internals_sunos.h             \
   google/protobuf/stubs/atomicops_internals_x86_gcc.h           \
   google/protobuf/stubs/atomicops_internals_x86_msvc.h          \
   google/protobuf/stubs/common.h                                \
Index: src/google/protobuf/compiler/cpp/cpp_unittest.cc
===================================================================
--- src/google/protobuf/compiler/cpp/cpp_unittest.cc	(revision 514)
+++ src/google/protobuf/compiler/cpp/cpp_unittest.cc	(working copy)
@@ -227,7 +227,7 @@
   // that we can delete after it's been set.
   unittest::TestAllTypes message;
 
-  EXPECT_EQ(NULL, message.release_default_string());
+  EXPECT_EQ((void*)NULL, message.release_default_string());
   EXPECT_FALSE(message.has_default_string());
   EXPECT_EQ("hello", message.default_string());
 
@@ -239,7 +239,7 @@
   EXPECT_EQ("blah", *str);
   delete str;
 
-  EXPECT_EQ(NULL, message.release_default_string());
+  EXPECT_EQ((void*)NULL, message.release_default_string());
   EXPECT_FALSE(message.has_default_string());
   EXPECT_EQ("hello", message.default_string());
 }
@@ -249,7 +249,7 @@
   // that we can delete after it's been set.
   unittest::TestAllTypes message;
 
-  EXPECT_EQ(NULL, message.release_optional_nested_message());
+  EXPECT_EQ((void*)NULL, message.release_optional_nested_message());
   EXPECT_FALSE(message.has_optional_nested_message());
 
   message.mutable_optional_nested_message()->set_bb(1);
@@ -260,7 +260,7 @@
   EXPECT_EQ(1, nest->bb());
   delete nest;
 
-  EXPECT_EQ(NULL, message.release_optional_nested_message());
+  EXPECT_EQ((void*)NULL, message.release_optional_nested_message());
   EXPECT_FALSE(message.has_optional_nested_message());
 }
 
Index: src/google/protobuf/io/tokenizer_unittest.cc
===================================================================
--- src/google/protobuf/io/tokenizer_unittest.cc	(revision 514)
+++ src/google/protobuf/io/tokenizer_unittest.cc	(working copy)
@@ -717,7 +717,7 @@
   }
 
   // Verify that we matched all the detached comments.
-  EXPECT_EQ(NULL,
+  EXPECT_EQ((void*)NULL,
       kDocCommentCases_case.detached_comments[detached_comments.size()]);
 
   EXPECT_EQ(kDocCommentCases_case.next_leading_comments,
Index: src/google/protobuf/repeated_field_unittest.cc
===================================================================
--- src/google/protobuf/repeated_field_unittest.cc	(revision 514)
+++ src/google/protobuf/repeated_field_unittest.cc	(working copy)
@@ -774,7 +774,7 @@
           // Were the removed elements extracted into the catcher array?
           for (int i = 0; i < num; ++i)
             EXPECT_EQ(catcher[i], subject[start + i]);
-          EXPECT_EQ(NULL, catcher[num]);
+          EXPECT_EQ((void*)NULL, catcher[num]);
 
           // Does the resulting array contain the right values?
           for (int i = 0; i < start; ++i)
Index: src/google/protobuf/stubs/atomicops.h
===================================================================
--- src/google/protobuf/stubs/atomicops.h	(revision 514)
+++ src/google/protobuf/stubs/atomicops.h	(working copy)
@@ -175,6 +175,10 @@
 #elif defined(GOOGLE_PROTOBUF_OS_APPLE)
 #include <google/protobuf/stubs/atomicops_internals_macosx.h>
 
+// SunOS.
+#elif defined(GOOGLE_PROTOBUF_OS_SUNOS)
+#include <google/protobuf/stubs/atomicops_internals_sunos.h>
+
 // GCC.
 #elif defined(__GNUC__)
 #if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64)
Index: src/google/protobuf/stubs/atomicops_internals_sunos.h
===================================================================
--- src/google/protobuf/stubs/atomicops_internals_sunos.h	(revision 0)
+++ src/google/protobuf/stubs/atomicops_internals_sunos.h	(working copy)
@@ -0,0 +1,211 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2012 Google Inc.  All rights reserved.
+// http://code.google.com/p/protobuf/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//     * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// This file is an internal atomic implementation, use atomicops.h instead.
+
+#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SUNOS_H_
+#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SUNOS_H_
+
+#include <atomic.h>
+
+namespace google {
+namespace protobuf {
+namespace internal {
+
+// Atomically execute:
+//      result = *ptr;
+//      if (*ptr == old_value)
+//        *ptr = new_value;
+//      return result;
+//
+// I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value".
+// Always return the old value of "*ptr"
+//
+// This routine implies no memory barriers.
+inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr,
+                                         Atomic32 old_value,
+                                         Atomic32 new_value) {
+  return atomic_cas_32((volatile uint32_t*)ptr, old_value, new_value);
+}
+
+// Atomically store new_value into *ptr, returning the previous value held in
+// *ptr.  This routine implies no memory barriers.
+inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr,
+                                         Atomic32 new_value) {
+  return atomic_swap_32((volatile uint32_t*)ptr, new_value);
+}
+
+// Atomically increment *ptr by "increment".  Returns the new value of
+// *ptr with the increment applied.  This routine implies no memory barriers.
+inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr,
+                                          Atomic32 increment) {
+  return atomic_add_32_nv((volatile uint32_t*)ptr, increment);
+}
+
+inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr,
+                                        Atomic32 increment) {
+  membar_exit();
+  Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment);
+  membar_enter();
+  return res;
+}
+
+// "Acquire" operations
+// ensure that no later memory access can be reordered ahead of the operation.
+// "Release" operations ensure that no previous memory access can be reordered
+// after the operation.  "Barrier" operations have both "Acquire" and "Release"
+// semantics.   A MemoryBarrier() has "Barrier" semantics, but does no memory
+// access.
+inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr,
+                                       Atomic32 old_value,
+                                       Atomic32 new_value) {
+  Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+  membar_enter();
+  return res;
+}
+
+inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr,
+                                       Atomic32 old_value,
+                                       Atomic32 new_value) {
+  membar_exit();
+  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+}
+
+inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) {
+  *ptr = value;
+}
+
+inline void MemoryBarrier() {
+  membar_exit();
+  membar_enter();
+}
+
+inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) {
+  *ptr = value;
+  membar_enter();
+}
+
+inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) {
+  membar_exit();
+  *ptr = value;
+}
+
+inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) {
+  return *ptr;
+}
+
+inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) {
+  Atomic32 value = *ptr;
+  membar_enter();
+  return value;
+}
+
+inline Atomic32 Release_Load(volatile const Atomic32* ptr) {
+  membar_exit();
+  return *ptr;
+}
+
+#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT
+
+inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr,
+                                         Atomic64 old_value,
+                                         Atomic64 new_value) {
+  return atomic_cas_64((volatile uint64_t*)ptr, old_value, new_value);
+}
+
+inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr,
+                                         Atomic64 new_value) {
+  return atomic_swap_64((volatile uint64_t*)ptr, new_value);
+}
+
+inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr,
+                                          Atomic64 increment) {
+  return atomic_add_64_nv((volatile uint64_t*)ptr, increment);
+}
+
+inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr,
+                                        Atomic64 increment) {
+  membar_exit();
+  Atomic64 res = NoBarrier_AtomicIncrement(ptr, increment);
+  membar_enter();
+  return res;
+}
+
+inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr,
+                                       Atomic64 old_value,
+                                       Atomic64 new_value) {
+  Atomic64 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+  membar_enter();
+  return res;
+}
+
+inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr,
+                                       Atomic64 old_value,
+                                       Atomic64 new_value) {
+  membar_exit();
+  return NoBarrier_CompareAndSwap(ptr, old_value, new_value);
+}
+
+inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) {
+  *ptr = value;
+}
+
+inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) {
+  *ptr = value;
+  membar_enter();
+}
+
+inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) {
+  membar_exit();
+  *ptr = value;
+}
+
+inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) {
+  return *ptr;
+}
+
+inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) {
+  Atomic64 value = *ptr;
+  membar_enter();
+  return value;
+}
+
+inline Atomic64 Release_Load(volatile const Atomic64* ptr) {
+  membar_exit();
+  return *ptr;
+}
+
+#endif // GOOGLE_PROTOBUF_ARCH_64_BIT
+
+}  // namespace internal
+}  // namespace protobuf
+}  // namespace google
+
+#endif  // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SUNOS_H_
Index: src/google/protobuf/stubs/platform_macros.h
===================================================================
--- src/google/protobuf/stubs/platform_macros.h	(revision 514)
+++ src/google/protobuf/stubs/platform_macros.h	(working copy)
@@ -57,7 +57,22 @@
 #elif defined(__ppc__)
 #define GOOGLE_PROTOBUF_ARCH_PPC 1
 #define GOOGLE_PROTOBUF_ARCH_32_BIT 1
+#elif defined(__sun)
+#if defined(__sparc)
+#define GOOGLE_PROTOBUF_ARCH_SPARC 1
+#if defined(__sparcv9)
+#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
 #else
+#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
+#endif
+#elif defined(__x86_64)
+#define GOOGLE_PROTOBUF_ARCH_X64 1
+#define GOOGLE_PROTOBUF_ARCH_64_BIT 1
+#else
+#define GOOGLE_PROTOBUF_ARCH_IA32 1
+#define GOOGLE_PROTOBUF_ARCH_32_BIT 1
+#endif
+#else
 #error Host architecture was not detected as supported by protobuf
 #endif
 
@@ -65,6 +80,8 @@
 #define GOOGLE_PROTOBUF_OS_APPLE
 #elif defined(__native_client__)
 #define GOOGLE_PROTOBUF_OS_NACL
+#elif defined(__sun)
+#define GOOGLE_PROTOBUF_OS_SUNOS
 #endif
 
 #endif  // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_
Index: src/google/protobuf/stubs/stringprintf_unittest.cc
===================================================================
--- src/google/protobuf/stubs/stringprintf_unittest.cc	(revision 514)
+++ src/google/protobuf/stubs/stringprintf_unittest.cc	(working copy)
@@ -32,6 +32,7 @@
 
 #include <google/protobuf/stubs/stringprintf.h>
 
+#include <clocale>
 #include <cerrno>
 #include <string>
 
Index: src/google/protobuf/text_format_unittest.cc
===================================================================
--- src/google/protobuf/text_format_unittest.cc	(revision 514)
+++ src/google/protobuf/text_format_unittest.cc	(working copy)
@@ -845,7 +845,7 @@
   TextFormat::ParseInfoTree* unknown_nested_tree =
       tree.GetTreeForNested(nested_field, 2);
 
-  EXPECT_EQ(NULL, unknown_nested_tree);
+  EXPECT_EQ((void*)NULL, unknown_nested_tree);
 }
 
 TEST_F(TextFormatParserTest, ParseFieldValueFromString) {

Reply via email to