diff options
21 files changed, 118 insertions, 77 deletions
diff --git a/.travis.yml b/.travis.yml index d49e0a71..e7853ebe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ language: cpp os: - osx # The Objective C build needs Xcode 7.0 or later. -osx_image: xcode8.1 +osx_image: xcode8.3 script: - ./tests.sh $CONFIG env: diff --git a/conformance/failure_list_csharp.txt b/conformance/failure_list_csharp.txt index a938e5bd..2a20aa78 100644 --- a/conformance/failure_list_csharp.txt +++ b/conformance/failure_list_csharp.txt @@ -1,7 +1,2 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput -Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0 -Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1 -Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2 -Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3 - diff --git a/conformance/update_failure_list.py b/conformance/update_failure_list.py index 63f453df..ad42ed3c 100755 --- a/conformance/update_failure_list.py +++ b/conformance/update_failure_list.py @@ -35,7 +35,6 @@ This is sort of like comm(1), except it recognizes comments and ignores them. """ import argparse -import fileinput parser = argparse.ArgumentParser( description='Adds/removes failures from the failure list.') @@ -62,7 +61,8 @@ for remove_file in (args.remove_list or []): add_list = sorted(add_set, reverse=True) -existing_list = file(args.filename).read() +with open(args.filename) as in_file: + existing_list = in_file.read() with open(args.filename, "w") as f: for line in existing_list.splitlines(True): diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index e719d2a0..e7c6b805 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -284,6 +284,20 @@ namespace Google.Protobuf Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
}
+ // Representations of a tag for field 0 with various wire types
+ [Test]
+ [TestCase(0)]
+ [TestCase(1)]
+ [TestCase(2)]
+ [TestCase(3)]
+ [TestCase(4)]
+ [TestCase(5)]
+ public void ReadTag_ZeroFieldRejected(byte tag)
+ {
+ CodedInputStream cis = new CodedInputStream(new byte[] { tag });
+ Assert.Throws<InvalidProtocolBufferException>(() => cis.ReadTag());
+ }
+
internal static TestRecursiveMessage MakeRecursiveMessage(int depth)
{
if (depth == 0)
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs index 84f90a25..abd352b9 100644 --- a/csharp/src/Google.Protobuf/CodedInputStream.cs +++ b/csharp/src/Google.Protobuf/CodedInputStream.cs @@ -373,9 +373,9 @@ namespace Google.Protobuf lastTag = ReadRawVarint32();
}
- if (lastTag == 0)
+ if (WireFormat.GetTagFieldNumber(lastTag) == 0)
{
- // If we actually read zero, that's not a valid tag.
+ // If we actually read a tag with a field of 0, that's not a valid tag.
throw InvalidProtocolBufferException.InvalidTag();
}
return lastTag;
diff --git a/docs/third_party.md b/docs/third_party.md index 385650df..5d2695d8 100644 --- a/docs/third_party.md +++ b/docs/third_party.md @@ -32,6 +32,7 @@ These are projects we know about implementing Protocol Buffers for other program * Delphi: http://sourceforge.net/projects/protobuf-delphi/ * Delphi: http://fundementals.sourceforge.net/dl.html * Elixir: https://github.com/jeremyong/exprotoc +* Elixir: https://github.com/tony612/protobuf-elixir * Elm: https://github.com/tiziano88/elm-protobuf * Erlang: http://github.com/ngerakines/erlang_protobuffs/tree/master * Erlang: http://piqi.org/ @@ -117,6 +118,7 @@ GRPC (http://www.grpc.io/) is Google's RPC implementation for Protocol Buffers. * https://github.com/w359405949/libmaid (C++, Python) * https://github.com/madwyn/libpbrpc (C++) * https://github.com/SeriousMa/grpc-protobuf-validation (Java) +* https://github.com/tony612/grpc-elixir (Elixir) ## Other Utilities diff --git a/examples/add_person.py b/examples/add_person.py index 0b698579..aa0fbca7 100755 --- a/examples/add_person.py +++ b/examples/add_person.py @@ -5,6 +5,12 @@ import addressbook_pb2 import sys +try: + raw_input # Python 2 +except NameError: + raw_input = input # Python 3 + + # This function fills in a Person message based on user input. def PromptForAddress(person): person.id = int(raw_input("Enter person ID number: ")) @@ -30,13 +36,14 @@ def PromptForAddress(person): elif type == "work": phone_number.type = addressbook_pb2.Person.WORK else: - print "Unknown phone type; leaving as default value." + print("Unknown phone type; leaving as default value.") + # Main procedure: Reads the entire address book from a file, # adds one person based on user input, then writes it back out to the same # file. if len(sys.argv) != 2: - print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE" + print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE") sys.exit(-1) address_book = addressbook_pb2.AddressBook() @@ -46,7 +53,7 @@ try: with open(sys.argv[1], "rb") as f: address_book.ParseFromString(f.read()) except IOError: - print sys.argv[1] + ": File not found. Creating a new file." + print(sys.argv[1] + ": File not found. Creating a new file.") # Add an address. PromptForAddress(address_book.people.add()) diff --git a/examples/list_people.py b/examples/list_people.py index f131872d..d2c294c6 100755 --- a/examples/list_people.py +++ b/examples/list_people.py @@ -2,30 +2,33 @@ # See README.txt for information and build instructions. +from __future__ import print_function import addressbook_pb2 import sys + # Iterates though all people in the AddressBook and prints info about them. def ListPeople(address_book): for person in address_book.people: - print "Person ID:", person.id - print " Name:", person.name + print("Person ID:", person.id) + print(" Name:", person.name) if person.email != "": - print " E-mail address:", person.email + print(" E-mail address:", person.email) for phone_number in person.phones: if phone_number.type == addressbook_pb2.Person.MOBILE: - print " Mobile phone #:", + print(" Mobile phone #:", end=" ") elif phone_number.type == addressbook_pb2.Person.HOME: - print " Home phone #:", + print(" Home phone #:", end=" ") elif phone_number.type == addressbook_pb2.Person.WORK: - print " Work phone #:", - print phone_number.number + print(" Work phone #:", end=" ") + print(phone_number.number) + # Main procedure: Reads the entire address book from a file and prints all # the information inside. if len(sys.argv) != 2: - print "Usage:", sys.argv[0], "ADDRESS_BOOK_FILE" + print("Usage:", sys.argv[0], "ADDRESS_BOOK_FILE") sys.exit(-1) address_book = addressbook_pb2.AddressBook() 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 4cf79d7b..1b136144 100644 --- a/java/core/src/main/java/com/google/protobuf/Utf8.java +++ b/java/core/src/main/java/com/google/protobuf/Utf8.java @@ -1347,7 +1347,7 @@ final class Utf8 { // Read bytes until 8-byte aligned so that we can read longs in the loop below. // We do this by ANDing the address with 7 to determine the number of bytes that need to // be read before we're 8-byte aligned. - final int unaligned = (int) address & 7; + final int unaligned = 8 - ((int) address & 7); for (int j = unaligned; j > 0; j--) { if (UnsafeUtil.getByte(address++) < 0) { return unaligned - j; diff --git a/jenkins/make_test_output.py b/jenkins/make_test_output.py index b1f2e2c0..98536853 100644 --- a/jenkins/make_test_output.py +++ b/jenkins/make_test_output.py @@ -17,11 +17,12 @@ detailed test results. It runs as the last step before the Jenkins build finishes. """ -import os; -import sys; +import os +import sys from yattag import Doc from collections import defaultdict + def readtests(basedir): tests = defaultdict(dict) @@ -68,6 +69,7 @@ def readtests(basedir): return ret + def genxml(tests): doc, tag, text = Doc().tagtext() @@ -86,6 +88,7 @@ def genxml(tests): return doc.getvalue() + sys.stderr.write("make_test_output.py: writing XML from directory: " + - sys.argv[1] + "\n"); -print genxml(readtests(sys.argv[1])) + sys.argv[1] + "\n") +print(genxml(readtests(sys.argv[1]))) diff --git a/objectivec/DevTools/full_mac_build.sh b/objectivec/DevTools/full_mac_build.sh index c3cc8e68..9ac24bb3 100755 --- a/objectivec/DevTools/full_mac_build.sh +++ b/objectivec/DevTools/full_mac_build.sh @@ -276,9 +276,7 @@ if [[ "${DO_XCODE_IOS_TESTS}" == "yes" ]] ; then 8.3* ) XCODEBUILD_TEST_BASE_IOS+=( -destination "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit - -destination "platform=iOS Simulator,name=iPhone 7,OS=10.3" # 64bit - -destination "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit - -destination "platform=iOS Simulator,name=iPad Pro (9.7 inch),OS=10.3" # 64bit + -destination "platform=iOS Simulator,name=iPhone 7,OS=latest" # 64bit ) ;; * ) diff --git a/objectivec/DevTools/pddm.py b/objectivec/DevTools/pddm.py index 9a11fec4..0b5b7b40 100755 --- a/objectivec/DevTools/pddm.py +++ b/objectivec/DevTools/pddm.py @@ -124,6 +124,7 @@ def _MacroRefRe(macro_names): return re.compile(r'\b(?P<macro_ref>(?P<name>(%s))\((?P<args>.*?)\))' % '|'.join(macro_names)) + def _MacroArgRefRe(macro_arg_names): # Takes in a list of macro arg names and makes a regex that will match # uses of those args. @@ -318,25 +319,26 @@ class MacroCollection(object): return macro.body assert len(arg_values) == len(macro.args) args = dict(zip(macro.args, arg_values)) + def _lookupArg(match): val = args[match.group('name')] opt = match.group('option') if opt: - if opt == 'S': # Spaces for the length + if opt == 'S': # Spaces for the length return ' ' * len(val) - elif opt == 'l': # Lowercase first character + elif opt == 'l': # Lowercase first character if val: return val[0].lower() + val[1:] else: return val - elif opt == 'L': # All Lowercase + elif opt == 'L': # All Lowercase return val.lower() - elif opt == 'u': # Uppercase first character + elif opt == 'u': # Uppercase first character if val: return val[0].upper() + val[1:] else: return val - elif opt == 'U': # All Uppercase + elif opt == 'U': # All Uppercase return val.upper() else: raise PDDMError('Unknown arg option "%s$%s" while expanding "%s".%s' @@ -350,6 +352,7 @@ class MacroCollection(object): def _EvalMacrosRefs(self, text, macro_stack): macro_ref_re = _MacroRefRe(self._macros.keys()) + def _resolveMacro(match): return self._Expand(match, macro_stack) return macro_ref_re.sub(_resolveMacro, text) @@ -496,9 +499,10 @@ class SourceFile(object): # Add the ending marker. if len(captured_lines) == 1: result.append('//%%PDDM-EXPAND-END %s' % - captured_lines[0][directive_len:].strip()) + captured_lines[0][directive_len:].strip()) else: - result.append('//%%PDDM-EXPAND-END (%s expansions)' % len(captured_lines)) + result.append('//%%PDDM-EXPAND-END (%s expansions)' % + len(captured_lines)) return result @@ -669,15 +673,15 @@ def main(args): if src_file.processed_content != src_file.original_content: if not opts.dry_run: - print 'Updating for "%s".' % a_path + print('Updating for "%s".' % a_path) with open(a_path, 'w') as f: f.write(src_file.processed_content) else: # Special result to indicate things need updating. - print 'Update needed for "%s".' % a_path + print('Update needed for "%s".' % a_path) result = 1 elif opts.verbose: - print 'No update for "%s".' % a_path + print('No update for "%s".' % a_path) return result diff --git a/protoc-artifacts/Dockerfile b/protoc-artifacts/Dockerfile index 36b547a2..43e6863c 100644 --- a/protoc-artifacts/Dockerfile +++ b/protoc-artifacts/Dockerfile @@ -15,9 +15,10 @@ RUN yum install -y git \ # Install Java 8 RUN wget -q --no-cookies --no-check-certificate \ - --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz" \ + --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" \ + "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz" \ -O - | tar xz -C /var/local -ENV JAVA_HOME /var/local/jdk1.8.0_45 +ENV JAVA_HOME /var/local/jdk1.8.0_131 ENV PATH $JAVA_HOME/bin:$PATH # Install Maven diff --git a/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py b/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py index 53e9d507..e71b295b 100755 --- a/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py +++ b/python/compatibility_tests/v2.5.0/tests/google/protobuf/internal/message_test.py @@ -55,6 +55,11 @@ from google.protobuf.internal import api_implementation from google.protobuf.internal import test_util from google.protobuf import message +try: + cmp # Python 2 +except NameError: + cmp = lambda x, y: (x > y) - (x < y) # Python 3 + # Python pre-2.6 does not have isinf() or isnan() functions, so we have # to provide our own. def isnan(val): diff --git a/python/google/protobuf/internal/message_factory_test.py b/python/google/protobuf/internal/message_factory_test.py index 4caa2443..aa7af2d0 100644 --- a/python/google/protobuf/internal/message_factory_test.py +++ b/python/google/protobuf/internal/message_factory_test.py @@ -183,7 +183,14 @@ class MessageFactoryTest(unittest.TestCase): with self.assertRaises(Exception) as cm: factory.GetMessages([f.name]) - self.assertIsInstance(cm.exception, (AssertionError, ValueError)) + self.assertIn(str(cm.exception), + ['Extensions ' + '"google.protobuf.python.internal.Duplicate.extension_field" and' + ' "google.protobuf.python.internal.Extension.extension_field"' + ' both try to extend message type' + ' "google.protobuf.python.internal.Container"' + ' with field number 2.', + 'Double registration of Extensions']) if __name__ == '__main__': diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index 29a515b2..dda72cdd 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -53,9 +53,13 @@ import six import sys try: - import unittest2 as unittest #PY26 + import unittest2 as unittest # PY26 except ImportError: import unittest +try: + cmp # Python 2 +except NameError: + cmp = lambda x, y: (x > y) - (x < y) # Python 3 from google.protobuf import map_unittest_pb2 from google.protobuf import unittest_pb2 @@ -1927,8 +1931,9 @@ class PackedFieldTest(BaseTestCase): self.assertEqual(golden_data, message.SerializeToString()) -@unittest.skipIf(api_implementation.Type() != 'cpp', - 'explicit tests of the C++ implementation') +@unittest.skipIf(api_implementation.Type() != 'cpp' or + sys.version_info < (2, 7), + 'explicit tests of the C++ implementation for PY27 and above') class OversizeProtosTest(BaseTestCase): @classmethod diff --git a/python/google/protobuf/internal/reflection_test.py b/python/google/protobuf/internal/reflection_test.py index 55b0d72e..5ab5225e 100755 --- a/python/google/protobuf/internal/reflection_test.py +++ b/python/google/protobuf/internal/reflection_test.py @@ -40,6 +40,7 @@ import gc import operator import six import struct +import sys try: import unittest2 as unittest #PY26 @@ -686,8 +687,8 @@ class ReflectionTest(BaseTestCase): self.assertEqual(expected_min, getattr(pb, field_name)) setattr(pb, field_name, expected_max) self.assertEqual(expected_max, getattr(pb, field_name)) - self.assertRaises(ValueError, setattr, pb, field_name, expected_min - 1) - self.assertRaises(ValueError, setattr, pb, field_name, expected_max + 1) + self.assertRaises(Exception, setattr, pb, field_name, expected_min - 1) + self.assertRaises(Exception, setattr, pb, field_name, expected_max + 1) TestMinAndMaxIntegers('optional_int32', -(1 << 31), (1 << 31) - 1) TestMinAndMaxIntegers('optional_uint32', 0, 0xffffffff) @@ -696,7 +697,7 @@ class ReflectionTest(BaseTestCase): # A bit of white-box testing since -1 is an int and not a long in C++ and # so goes down a different path. pb = unittest_pb2.TestAllTypes() - with self.assertRaises(ValueError): + with self.assertRaises(Exception): pb.optional_uint64 = integer_fn(-(1 << 63)) pb = unittest_pb2.TestAllTypes() diff --git a/python/google/protobuf/internal/test_util.py b/python/google/protobuf/internal/test_util.py index 269d0e2d..9434b7b1 100755 --- a/python/google/protobuf/internal/test_util.py +++ b/python/google/protobuf/internal/test_util.py @@ -39,11 +39,15 @@ __author__ = 'robinson@google.com (Will Robinson)' import numbers import operator import os.path -import sys from google.protobuf import unittest_import_pb2 from google.protobuf import unittest_pb2 -from google.protobuf import descriptor_pb2 + +try: + long # Python 2 +except NameError: + long = int # Python 3 + # Tests whether the given TestAllTypes message is proto2 or not. # This is used to gate several fields/features that only exist @@ -51,6 +55,7 @@ from google.protobuf import descriptor_pb2 def IsProto2(message): return message.DESCRIPTOR.syntax == "proto2" + def SetAllNonLazyFields(message): """Sets every non-lazy field in the message to a unique value. @@ -707,8 +712,8 @@ class NonStandardInteger(numbers.Integral): NonStandardInteger is the minimal legal specification for a custom Integral. As such, it does not support 0 < x < 5 and it is not hashable. - Note: This is added here instead of relying on numpy or a similar library with - custom integers to limit dependencies. + Note: This is added here instead of relying on numpy or a similar library + with custom integers to limit dependencies. """ def __init__(self, val, error_string_on_conversion=None): @@ -845,4 +850,3 @@ class NonStandardInteger(numbers.Integral): def __repr__(self): return 'NonStandardInteger(%s)' % self.val - diff --git a/python/mox.py b/python/mox.py index 257468e5..43db0219 100755 --- a/python/mox.py +++ b/python/mox.py @@ -778,7 +778,7 @@ class Comparator: rhs: any python object """ - raise NotImplementedError, 'method must be implemented by a subclass.' + raise NotImplementedError('method must be implemented by a subclass.') def __eq__(self, rhs): return self.equals(rhs) diff --git a/src/google/protobuf/stubs/atomicops.h b/src/google/protobuf/stubs/atomicops.h index 75aee306..64c838fb 100644 --- a/src/google/protobuf/stubs/atomicops.h +++ b/src/google/protobuf/stubs/atomicops.h @@ -63,28 +63,21 @@ namespace google { namespace protobuf { namespace internal { -#if defined(GOOGLE_PROTOBUF_ARCH_POWER) -#if defined(_LP64) || defined(__LP64__) -typedef int32 Atomic32; -typedef intptr_t Atomic64; +#ifdef GOOGLE_PROTOBUF_ARCH_32_BIT + typedef intptr_t Atomic32; + typedef int64 Atomic64; #else -typedef intptr_t Atomic32; -typedef int64 Atomic64; -#endif -#else -typedef int32 Atomic32; -#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT -// We need to be able to go between Atomic64 and AtomicWord implicitly. This -// means Atomic64 and AtomicWord should be the same type on 64-bit. -#if defined(__ILP32__) || defined(GOOGLE_PROTOBUF_OS_NACL) -// NaCl's intptr_t is not actually 64-bits on 64-bit! -// http://code.google.com/p/nativeclient/issues/detail?id=1162 -// sparcv9's pointer type is 32bits -typedef int64 Atomic64; -#else -typedef intptr_t Atomic64; -#endif -#endif + typedef int32 Atomic32; + // We need to be able to go between Atomic64 and AtomicWord implicitly. This + // means Atomic64 and AtomicWord should be the same type on 64-bit. + #if defined(__ILP32__) || defined(GOOGLE_PROTOBUF_OS_NACL) + // NaCl's intptr_t is not actually 64-bits on 64-bit! + // http://code.google.com/p/nativeclient/issues/detail?id=1162 + // sparcv9's pointer type is 32bits + typedef int64 Atomic64; + #else + typedef intptr_t Atomic64; + #endif #endif // Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or @@ -294,8 +294,7 @@ build_python_cpp() { cd python # Only test Python 2.6/3.x on Linux if [ $(uname -s) == "Linux" ]; then - # py26 is currently disabled due to json_format - envlist=py\{27,33,34\}-cpp + envlist=py\{26,27,33,34\}-cpp else envlist=py27-cpp fi |