This patch adds support for atomic operations on Solaris, on any platform.
It makes use of the atomic functions made available in Solaris' atomic.h
header.
__atomic_store_n() cannot take a memory model argument of
__ATOMIC_ACQUIRE, and __atomic_load_n() cannot take a memory model
argument of __ATOMIC_RELEASE, per the GCC documentation:
https://gcc.gnu.org/onlinedocs/gcc-4.9.1/gcc/_005f_005fatomic-Builtins.html
On Clang this generates a -Watomic-memory-ordering warning.
Promote the fences in Acquire_Store() and Release_Load() to the stronger
__ATOMIC_SEQ_CST memory model, which ought to be safe.
Note that there are no actual uses of Acquire_Store() or Release_Load()
in protobuf, though.
This follows the TSAN atomicops implementation, which also uses SEQ_CST
fences for these functions.
(Fixes #25.)
We cannot use Clang's __has_extension macro unless we really are
compiling on Clang, which means we cannot use this expression:
#if (defined(__clang__) && __has_extension(c_atomic)))
// ...
#endif
On GCC, this generates the following errors:
In file included from ./google/protobuf/stubs/atomicops.h:59:0,
from google/protobuf/stubs/atomicops_internals_x86_gcc.cc:36:
./google/protobuf/stubs/platform_macros.h:67:41: error: missing binary operator before token "("
(defined(__clang__) && __has_extension(c_atomic)))
^
In file included from google/protobuf/stubs/atomicops_internals_x86_gcc.cc:36:0:
./google/protobuf/stubs/atomicops.h:196:40: error: missing binary operator before token "("
(defined(__clang__) && __has_extension(c_atomic))
^
Instead, we have to protect the __has_extension expression by only
executing it when __clang__ is defined:
#if defined(__clang__)
# if __has_extension(c_atomic)
// ...
# endif
#endif
In the current implementation, a message with the same amount of null or
equal-valued fields as a different message type will have the same
hashCode. This adds more variety by including the hashCode of the
class's name in the hashCode calculations.
Change-Id: I284e3e6d198ad8037815948d1f65686465ffd623
Signed-off-by: Jason Neufeld <jneufeld@google.com>
The generic atomicops implementation is only exposed if GCC >= 4.7 is
available, but Clang, where the underlying __atomic built-ins are also
available, typically only claims to be GCC 4.2. This causes build
failures when compiling protobuf or the output of protoc's C++ code
generator on an architecture that needs the generic atomicops
implementation with Clang.
Clang has a "c_atomic" extension which can be tested for which almost
does what we want:
C11 atomic operations
Use __has_feature(c_atomic) or __has_extension(c_atomic) to
determine if support for atomic types using _Atomic is enabled.
Clang also provides a set of builtins which can be used to implement
the <stdatomic.h> operations on _Atomic types.
I'm not sure if this guarantees that the GNU atomic builtins (the ones
with the __atomic prefix) are also available, but in practice this
should guarantee that Clang is new enough.
With this change in place, Clang generates several diagnostics when
compiling the generic atomicops implementation. These appear to be bugs
in the generic atomicops implementation and are not Clang-specific.
The macro GOOGLE_PROTOBUF_ARCH_PPC is not used anywhere in the protobuf
source; there is no Power-specific atomics implementation, etc.
Funnily enough, the macro __ppc__ is not actually defined on 32-bit
Power on GCC/Linux, according to the following webpage:
http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros#POWER
and verified on a 32-bit Debian sid 'powerpc' chroot:
(sid_powerpc-dchroot)edmonds@partch:~$ gcc -dM -E - < /dev/null | grep -c __ppc__
0
(sid_powerpc-dchroot)edmonds@partch:~$ gcc -dM -E - < /dev/null | grep -c __LP64__
0
The behavior of the string ctor is undefined when you pass NULL. This
is checked strictly in C++11, so fails to compile.
Change-Id: Id5e0984ad1d37f2d504f7c42ac23e52ed4a58903
Instead of publishing its class I chose to encapsulate the troublesome
references in equals()/hashCode() in the generated code into superclass
methods in ExtendableMessageNano.
Changed a couple of java packages in the test suite to catch this issue
easier in the future.
Change-Id: I43f88411f63bb6f3ffc8d63361f2f77bebf6220a
This CL adds the "parcelable_messages" option. When enabled, all
generated message classes will conform to the Android Parcelable
contract. This is achieved by introducing a new parent class for
generated classes which implements the required functionality.
Since the store_unknown_fields option also makes use of a superclass,
ExtendableMessageNano, we have two versions of the new Parcelable
superclass: one extending MessageNano, and one extending
ExtendableMessageNano. These classes are otherwise identical.
As these classes depend on Android framework jars, they are not
included in the host .jar build of the nanoproto library.
Finally, add a test suite for running tests of Android-specific
functionality, as this cannot be done on a desktop JVM.
Change-Id: Icc2a257f03317e947f7078dbb9857c3286857497
Nano proto compiler normally throws an error if any service is
defined. If --ignore-services=true is set, no error is thrown and the
service is simply skipped.
Change-Id: Id82583555085cc55550d03a485d3f0189885240b
This avoids a race-condition when cachedSize is momentarily set to 0
for non-empty messages if multiple threads call getSerializedSize
(e.g. during serialization).
This is a retry of https://android-review.googlesource.com/#/c/88570/.
getSerializedSize() has been kept non-final so that messages generated
with a previous version of the compiler will not break.
Change-Id: I8d8154a10938cde579ae19c55eae55b1e70e0bda