Commit 8ecae34a authored by Paul Yang's avatar Paul Yang Committed by GitHub

Merge pull request #3255 from TeBoring/3.3.x-3

Cherry-pick bug fixes for php
parents bf04c832 3b1a8751
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "protobuf.h" #include "protobuf.h"
const char* const kReservedNames[] = {"Empty"}; const char* const kReservedNames[] = {"Empty", "ECHO", "ARRAY"};
const int kReservedNamesSize = 1; const int kReservedNamesSize = 3;
// Forward declare. // Forward declare.
static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC); static void descriptor_init_c_instance(Descriptor* intern TSRMLS_DC);
......
...@@ -1167,6 +1167,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, ...@@ -1167,6 +1167,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
upb_msg_field_next(&i)) { upb_msg_field_next(&i)) {
upb_fielddef* f = upb_msg_iter_field(&i); upb_fielddef* f = upb_msg_iter_field(&i);
uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset; uint32_t offset = desc->layout->fields[upb_fielddef_index(f)].offset;
bool containing_oneof = false;
if (upb_fielddef_containingoneof(f)) { if (upb_fielddef_containingoneof(f)) {
uint32_t oneof_case_offset = uint32_t oneof_case_offset =
...@@ -1179,6 +1180,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, ...@@ -1179,6 +1180,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
} }
// Otherwise, fall through to the appropriate singular-field handler // Otherwise, fall through to the appropriate singular-field handler
// below. // below.
containing_oneof = true;
} }
if (is_map_field(f)) { if (is_map_field(f)) {
...@@ -1209,7 +1211,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc, ...@@ -1209,7 +1211,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
#define T(upbtypeconst, upbtype, ctype, default_value) \ #define T(upbtypeconst, upbtype, ctype, default_value) \
case upbtypeconst: { \ case upbtypeconst: { \
ctype value = DEREF(message_data(msg), offset, ctype); \ ctype value = DEREF(message_data(msg), offset, ctype); \
if (value != default_value) { \ if (containing_oneof || value != default_value) { \
upb_sink_put##upbtype(sink, sel, value); \ upb_sink_put##upbtype(sink, sel, value); \
} \ } \
} break; } break;
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <php.h> #include <php.h>
#include <stdlib.h> #include <stdlib.h>
#include <ext/json/php_json.h>
#include "protobuf.h" #include "protobuf.h"
......
...@@ -739,6 +739,13 @@ class Message ...@@ -739,6 +739,13 @@ class Message
*/ */
private function existField($field) private function existField($field)
{ {
$oneof_index = $field->getOneofIndex();
if ($oneof_index !== -1) {
$oneof = $this->desc->getOneofDecl()[$oneof_index];
$oneof_name = $oneof->getName();
return $this->$oneof_name->getNumber() === $field->getNumber();
}
$getter = $field->getGetter(); $getter = $field->getGetter();
$value = $this->$getter(); $value = $this->$getter();
return $value !== $this->defaultValue($field); return $value !== $this->defaultValue($field);
......
...@@ -236,7 +236,7 @@ function getClassNamePrefix( ...@@ -236,7 +236,7 @@ function getClassNamePrefix(
return $prefix; return $prefix;
} }
$reserved_words = array("Empty"); $reserved_words = array("Empty", "ECHO", "ARRAY");
foreach ($reserved_words as $reserved_word) { foreach ($reserved_words as $reserved_word) {
if ($classname === $reserved_word) { if ($classname === $reserved_word) {
if ($file_proto->getPackage() === "google.protobuf") { if ($file_proto->getPackage() === "google.protobuf") {
......
...@@ -88,6 +88,13 @@ class EncodeDecodeTest extends TestBase ...@@ -88,6 +88,13 @@ class EncodeDecodeTest extends TestBase
$n = new TestMessage(); $n = new TestMessage();
$n->mergeFromString($data); $n->mergeFromString($data);
$this->assertSame(1, $n->getOneofMessage()->getA()); $this->assertSame(1, $n->getOneofMessage()->getA());
// Encode default value
$m->setOneofEnum(TestEnum::ZERO);
$data = $m->serializeToString();
$n = new TestMessage();
$n->mergeFromString($data);
$this->assertSame("oneof_enum", $n->getMyOneof());
} }
public function testPackedEncode() public function testPackedEncode()
......
...@@ -876,5 +876,6 @@ class GeneratedClassTest extends TestBase ...@@ -876,5 +876,6 @@ class GeneratedClassTest extends TestBase
$m = new \Foo\TestMessage_Empty(); $m = new \Foo\TestMessage_Empty();
$m = new \Foo\PBEmpty(); $m = new \Foo\PBEmpty();
$m = new \PrefixEmpty(); $m = new \PrefixEmpty();
$m = new \Foo\PBARRAY();
} }
} }
...@@ -8,6 +8,7 @@ require_once('generated/NoNamespaceMessage_NestedEnum.php'); ...@@ -8,6 +8,7 @@ require_once('generated/NoNamespaceMessage_NestedEnum.php');
require_once('generated/PrefixEmpty.php'); require_once('generated/PrefixEmpty.php');
require_once('generated/PrefixTestPrefix.php'); require_once('generated/PrefixTestPrefix.php');
require_once('generated/Bar/TestInclude.php'); require_once('generated/Bar/TestInclude.php');
require_once('generated/Foo/PBARRAY.php');
require_once('generated/Foo/PBEmpty.php'); require_once('generated/Foo/PBEmpty.php');
require_once('generated/Foo/TestEnum.php'); require_once('generated/Foo/TestEnum.php');
require_once('generated/Foo/TestIncludePrefixMessage.php'); require_once('generated/Foo/TestIncludePrefixMessage.php');
......
...@@ -127,6 +127,10 @@ message Empty { ...@@ -127,6 +127,10 @@ message Empty {
int32 a = 1; int32 a = 1;
} }
message ARRAY {
int32 a = 1;
}
message TestPackedMessage { message TestPackedMessage {
repeated int32 repeated_int32 = 90 [packed = true]; repeated int32 repeated_int32 = 90 [packed = true];
repeated int64 repeated_int64 = 91 [packed = true]; repeated int64 repeated_int64 = 91 [packed = true];
......
...@@ -49,8 +49,8 @@ const std::string kDescriptorMetadataFile = ...@@ -49,8 +49,8 @@ const std::string kDescriptorMetadataFile =
"GPBMetadata/Google/Protobuf/Internal/Descriptor.php"; "GPBMetadata/Google/Protobuf/Internal/Descriptor.php";
const std::string kDescriptorDirName = "Google/Protobuf/Internal"; const std::string kDescriptorDirName = "Google/Protobuf/Internal";
const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal"; const std::string kDescriptorPackageName = "Google\\Protobuf\\Internal";
const char* const kReservedNames[] = {"Empty", "ECHO"}; const char* const kReservedNames[] = {"ARRAY", "Empty", "ECHO"};
const int kReservedNamesSize = 2; const int kReservedNamesSize = 3;
namespace google { namespace google {
namespace protobuf { namespace protobuf {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment