소스 검색

Fixed PHP to support field numbers >=2**28. (#8235)

Joshua Haberman 4 년 전
부모
커밋
d5079ed7db
5개의 변경된 파일2158개의 추가작업 그리고 367개의 파일을 삭제
  1. 1554 310
      php/ext/google/protobuf/php-upb.c
  2. 588 55
      php/ext/google/protobuf/php-upb.h
  3. 2 2
      php/src/Google/Protobuf/Internal/GPBWire.php
  4. 10 0
      php/tests/EncodeDecodeTest.php
  5. 4 0
      php/tests/proto/test.proto

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 1554 - 310
php/ext/google/protobuf/php-upb.c


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 588 - 55
php/ext/google/protobuf/php-upb.h


+ 2 - 2
php/src/Google/Protobuf/Internal/GPBWire.php

@@ -50,8 +50,8 @@ class GPBWire
 
     public static function getTagFieldNumber($tag)
     {
-        return ($tag >> self::TAG_TYPE_BITS) &
-            (1 << ((PHP_INT_SIZE * 8) - self::TAG_TYPE_BITS)) - 1;
+        // We have to mask because PHP has no arithmetic shift.
+        return ($tag >> self::TAG_TYPE_BITS) & 0x1fffffff;
     }
 
     public static function getTagWireType($tag)

+ 10 - 0
php/tests/EncodeDecodeTest.php

@@ -14,6 +14,7 @@ use Foo\TestStringValue;
 use Foo\TestBytesValue;
 use Foo\TestAny;
 use Foo\TestEnum;
+use Foo\TestLargeFieldNumber;
 use Foo\TestMessage;
 use Foo\TestMessage\Sub;
 use Foo\TestPackedMessage;
@@ -529,6 +530,15 @@ class EncodeDecodeTest extends TestBase
         $this->assertSame("", $data);
     }
 
+    public function testLargeFieldNumber()
+    {
+        $m = new TestLargeFieldNumber(['large_field_number' => 5]);
+        $data = $m->serializeToString();
+        $m2 = new TestLargeFieldNumber();
+        $m2->mergeFromString($data);
+        $this->assertSame(5, $m2->getLargeFieldNumber());
+    }
+
     public function testDecodeInvalidInt32()
     {
         $this->expectException(Exception::class);

+ 4 - 0
php/tests/proto/test.proto

@@ -220,6 +220,10 @@ message TestRandomFieldOrder {
   string tag14 = 160;
 }
 
+message TestLargeFieldNumber {
+  int32 large_field_number = 536870911;
+}
+
 message TestReverseFieldOrder {
   repeated int32 a = 2;
   string b = 1;

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.