From 98835fb8f8a8f144f2a1eac0b833ff83f4a05f54 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 19 Sep 2016 13:45:07 -0700 Subject: Integrate internal changes --- php/tests/test.pb.php | 1385 +++++++++++++++++++++++++++++++++++++++++ php/tests/test_include.pb.php | 36 ++ 2 files changed, 1421 insertions(+) create mode 100644 php/tests/test.pb.php create mode 100644 php/tests/test_include.pb.php (limited to 'php') diff --git a/php/tests/test.pb.php b/php/tests/test.pb.php new file mode 100644 index 00000000..ed316b6e --- /dev/null +++ b/php/tests/test.pb.php @@ -0,0 +1,1385 @@ +optional_int32; + } + + public function setOptionalInt32($var) + { + GPBUtil::checkInt32($var); + $this->optional_int32 = $var; + } + + public function getOptionalInt64() + { + return $this->optional_int64; + } + + public function setOptionalInt64($var) + { + GPBUtil::checkInt64($var); + $this->optional_int64 = $var; + } + + public function getOptionalUint32() + { + return $this->optional_uint32; + } + + public function setOptionalUint32($var) + { + GPBUtil::checkUint32($var); + $this->optional_uint32 = $var; + } + + public function getOptionalUint64() + { + return $this->optional_uint64; + } + + public function setOptionalUint64($var) + { + GPBUtil::checkUint64($var); + $this->optional_uint64 = $var; + } + + public function getOptionalSint32() + { + return $this->optional_sint32; + } + + public function setOptionalSint32($var) + { + GPBUtil::checkInt32($var); + $this->optional_sint32 = $var; + } + + public function getOptionalSint64() + { + return $this->optional_sint64; + } + + public function setOptionalSint64($var) + { + GPBUtil::checkInt64($var); + $this->optional_sint64 = $var; + } + + public function getOptionalFixed32() + { + return $this->optional_fixed32; + } + + public function setOptionalFixed32($var) + { + GPBUtil::checkUint32($var); + $this->optional_fixed32 = $var; + } + + public function getOptionalFixed64() + { + return $this->optional_fixed64; + } + + public function setOptionalFixed64($var) + { + GPBUtil::checkUint64($var); + $this->optional_fixed64 = $var; + } + + public function getOptionalSfixed32() + { + return $this->optional_sfixed32; + } + + public function setOptionalSfixed32($var) + { + GPBUtil::checkInt32($var); + $this->optional_sfixed32 = $var; + } + + public function getOptionalSfixed64() + { + return $this->optional_sfixed64; + } + + public function setOptionalSfixed64($var) + { + GPBUtil::checkInt64($var); + $this->optional_sfixed64 = $var; + } + + public function getOptionalFloat() + { + return $this->optional_float; + } + + public function setOptionalFloat($var) + { + GPBUtil::checkFloat($var); + $this->optional_float = $var; + } + + public function getOptionalDouble() + { + return $this->optional_double; + } + + public function setOptionalDouble($var) + { + GPBUtil::checkDouble($var); + $this->optional_double = $var; + } + + public function getOptionalBool() + { + return $this->optional_bool; + } + + public function setOptionalBool($var) + { + GPBUtil::checkBool($var); + $this->optional_bool = $var; + } + + public function getOptionalString() + { + return $this->optional_string; + } + + public function setOptionalString($var) + { + GPBUtil::checkString($var, True); + $this->optional_string = $var; + } + + public function getOptionalBytes() + { + return $this->optional_bytes; + } + + public function setOptionalBytes($var) + { + GPBUtil::checkString($var, False); + $this->optional_bytes = $var; + } + + public function getOptionalEnum() + { + return $this->optional_enum; + } + + public function setOptionalEnum($var) + { + GPBUtil::checkEnum($var, \Foo\TestEnum::class); + $this->optional_enum = $var; + } + + public function getOptionalMessage() + { + return $this->optional_message; + } + + public function setOptionalMessage(&$var) + { + GPBUtil::checkMessage($var, \Foo\TestMessage_Sub::class); + $this->optional_message = $var; + } + + public function getOptionalIncludedMessage() + { + return $this->optional_included_message; + } + + public function setOptionalIncludedMessage(&$var) + { + GPBUtil::checkMessage($var, \Bar\TestInclude::class); + $this->optional_included_message = $var; + } + + public function getRecursive() + { + return $this->recursive; + } + + public function setRecursive(&$var) + { + GPBUtil::checkMessage($var, \Foo\TestMessage::class); + $this->recursive = $var; + } + + public function getRepeatedInt32() + { + return $this->repeated_int32; + } + + public function setRepeatedInt32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT32); + $this->repeated_int32 = $var; + } + + public function getRepeatedInt64() + { + return $this->repeated_int64; + } + + public function setRepeatedInt64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT64); + $this->repeated_int64 = $var; + } + + public function getRepeatedUint32() + { + return $this->repeated_uint32; + } + + public function setRepeatedUint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT32); + $this->repeated_uint32 = $var; + } + + public function getRepeatedUint64() + { + return $this->repeated_uint64; + } + + public function setRepeatedUint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT64); + $this->repeated_uint64 = $var; + } + + public function getRepeatedSint32() + { + return $this->repeated_sint32; + } + + public function setRepeatedSint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT32); + $this->repeated_sint32 = $var; + } + + public function getRepeatedSint64() + { + return $this->repeated_sint64; + } + + public function setRepeatedSint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT64); + $this->repeated_sint64 = $var; + } + + public function getRepeatedFixed32() + { + return $this->repeated_fixed32; + } + + public function setRepeatedFixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED32); + $this->repeated_fixed32 = $var; + } + + public function getRepeatedFixed64() + { + return $this->repeated_fixed64; + } + + public function setRepeatedFixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED64); + $this->repeated_fixed64 = $var; + } + + public function getRepeatedSfixed32() + { + return $this->repeated_sfixed32; + } + + public function setRepeatedSfixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED32); + $this->repeated_sfixed32 = $var; + } + + public function getRepeatedSfixed64() + { + return $this->repeated_sfixed64; + } + + public function setRepeatedSfixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED64); + $this->repeated_sfixed64 = $var; + } + + public function getRepeatedFloat() + { + return $this->repeated_float; + } + + public function setRepeatedFloat(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FLOAT); + $this->repeated_float = $var; + } + + public function getRepeatedDouble() + { + return $this->repeated_double; + } + + public function setRepeatedDouble(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::DOUBLE); + $this->repeated_double = $var; + } + + public function getRepeatedBool() + { + return $this->repeated_bool; + } + + public function setRepeatedBool(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BOOL); + $this->repeated_bool = $var; + } + + public function getRepeatedString() + { + return $this->repeated_string; + } + + public function setRepeatedString(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::STRING); + $this->repeated_string = $var; + } + + public function getRepeatedBytes() + { + return $this->repeated_bytes; + } + + public function setRepeatedBytes(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BYTES); + $this->repeated_bytes = $var; + } + + public function getRepeatedEnum() + { + return $this->repeated_enum; + } + + public function setRepeatedEnum(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); + $this->repeated_enum = $var; + } + + public function getRepeatedMessage() + { + return $this->repeated_message; + } + + public function setRepeatedMessage(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::MESSAGE, \Foo\TestMessage_Sub::class); + $this->repeated_message = $var; + } + + public function getRepeatedRecursive() + { + return $this->repeated_recursive; + } + + public function setRepeatedRecursive(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::MESSAGE, \Foo\TestMessage::class); + $this->repeated_recursive = $var; + } + + public function getOneofInt32() + { + return $this->readOneof(51); + } + + public function setOneofInt32($var) + { + GPBUtil::checkInt32($var); + $this->writeOneof(51, $var); + } + + public function getOneofInt64() + { + return $this->readOneof(52); + } + + public function setOneofInt64($var) + { + GPBUtil::checkInt64($var); + $this->writeOneof(52, $var); + } + + public function getOneofUint32() + { + return $this->readOneof(53); + } + + public function setOneofUint32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(53, $var); + } + + public function getOneofUint64() + { + return $this->readOneof(54); + } + + public function setOneofUint64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(54, $var); + } + + public function getOneofSint32() + { + return $this->readOneof(55); + } + + public function setOneofSint32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(55, $var); + } + + public function getOneofSint64() + { + return $this->readOneof(56); + } + + public function setOneofSint64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(56, $var); + } + + public function getOneofFixed32() + { + return $this->readOneof(57); + } + + public function setOneofFixed32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(57, $var); + } + + public function getOneofFixed64() + { + return $this->readOneof(58); + } + + public function setOneofFixed64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(58, $var); + } + + public function getOneofSfixed32() + { + return $this->readOneof(59); + } + + public function setOneofSfixed32($var) + { + GPBUtil::checkUint32($var); + $this->writeOneof(59, $var); + } + + public function getOneofSfixed64() + { + return $this->readOneof(60); + } + + public function setOneofSfixed64($var) + { + GPBUtil::checkUint64($var); + $this->writeOneof(60, $var); + } + + public function getOneofDouble() + { + return $this->readOneof(61); + } + + public function setOneofDouble($var) + { + GPBUtil::checkDouble($var); + $this->writeOneof(61, $var); + } + + public function getOneofFloat() + { + return $this->readOneof(62); + } + + public function setOneofFloat($var) + { + GPBUtil::checkFloat($var); + $this->writeOneof(62, $var); + } + + public function getOneofBool() + { + return $this->readOneof(63); + } + + public function setOneofBool($var) + { + GPBUtil::checkBool($var); + $this->writeOneof(63, $var); + } + + public function getOneofString() + { + return $this->readOneof(64); + } + + public function setOneofString($var) + { + GPBUtil::checkString($var, True); + $this->writeOneof(64, $var); + } + + public function getOneofBytes() + { + return $this->readOneof(65); + } + + public function setOneofBytes($var) + { + GPBUtil::checkString($var, False); + $this->writeOneof(65, $var); + } + + public function getOneofEnum() + { + return $this->readOneof(66); + } + + public function setOneofEnum($var) + { + GPBUtil::checkEnum($var, \Foo\TestEnum::class); + $this->writeOneof(66, $var); + } + + public function getOneofMessage() + { + return $this->readOneof(67); + } + + public function setOneofMessage(&$var) + { + GPBUtil::checkMessage($var, \Foo\TestMessage_Sub::class); + $this->writeOneof(67, $var); + } + + public function getMapInt32Int32() + { + return $this->map_int32_int32; + } + + public function setMapInt32Int32(&$var) + { + $this->map_int32_int32 = $var; + } + + public function getMapInt64Int64() + { + return $this->map_int64_int64; + } + + public function setMapInt64Int64(&$var) + { + $this->map_int64_int64 = $var; + } + + public function getMapUint32Uint32() + { + return $this->map_uint32_uint32; + } + + public function setMapUint32Uint32(&$var) + { + $this->map_uint32_uint32 = $var; + } + + public function getMapUint64Uint64() + { + return $this->map_uint64_uint64; + } + + public function setMapUint64Uint64(&$var) + { + $this->map_uint64_uint64 = $var; + } + + public function getMapSint32Sint32() + { + return $this->map_sint32_sint32; + } + + public function setMapSint32Sint32(&$var) + { + $this->map_sint32_sint32 = $var; + } + + public function getMapSint64Sint64() + { + return $this->map_sint64_sint64; + } + + public function setMapSint64Sint64(&$var) + { + $this->map_sint64_sint64 = $var; + } + + public function getMapFixed32Fixed32() + { + return $this->map_fixed32_fixed32; + } + + public function setMapFixed32Fixed32(&$var) + { + $this->map_fixed32_fixed32 = $var; + } + + public function getMapFixed64Fixed64() + { + return $this->map_fixed64_fixed64; + } + + public function setMapFixed64Fixed64(&$var) + { + $this->map_fixed64_fixed64 = $var; + } + + public function getMapSfixed32Sfixed32() + { + return $this->map_sfixed32_sfixed32; + } + + public function setMapSfixed32Sfixed32(&$var) + { + $this->map_sfixed32_sfixed32 = $var; + } + + public function getMapSfixed64Sfixed64() + { + return $this->map_sfixed64_sfixed64; + } + + public function setMapSfixed64Sfixed64(&$var) + { + $this->map_sfixed64_sfixed64 = $var; + } + + public function getMapInt32Float() + { + return $this->map_int32_float; + } + + public function setMapInt32Float(&$var) + { + $this->map_int32_float = $var; + } + + public function getMapInt32Double() + { + return $this->map_int32_double; + } + + public function setMapInt32Double(&$var) + { + $this->map_int32_double = $var; + } + + public function getMapBoolBool() + { + return $this->map_bool_bool; + } + + public function setMapBoolBool(&$var) + { + $this->map_bool_bool = $var; + } + + public function getMapStringString() + { + return $this->map_string_string; + } + + public function setMapStringString(&$var) + { + $this->map_string_string = $var; + } + + public function getMapInt32Bytes() + { + return $this->map_int32_bytes; + } + + public function setMapInt32Bytes(&$var) + { + $this->map_int32_bytes = $var; + } + + public function getMapInt32Enum() + { + return $this->map_int32_enum; + } + + public function setMapInt32Enum(&$var) + { + $this->map_int32_enum = $var; + } + + public function getMapInt32Message() + { + return $this->map_int32_message; + } + + public function setMapInt32Message(&$var) + { + $this->map_int32_message = $var; + } + + public function getMapRecursive() + { + return $this->map_recursive; + } + + public function setMapRecursive(&$var) + { + $this->map_recursive = $var; + } + + public function getMyOneof() + { + return $this->my_oneof; + } + +} + +class TestMessage_Sub extends \Google\Protobuf\Internal\Message +{ + private $a = 0; + + public function getA() + { + return $this->a; + } + + public function setA($var) + { + GPBUtil::checkInt32($var); + $this->a = $var; + } + +} + +class TestPackedMessage extends \Google\Protobuf\Internal\Message +{ + private $repeated_int32; + private $repeated_int64; + private $repeated_uint32; + private $repeated_uint64; + private $repeated_sint32; + private $repeated_sint64; + private $repeated_fixed32; + private $repeated_fixed64; + private $repeated_sfixed32; + private $repeated_sfixed64; + private $repeated_float; + private $repeated_double; + private $repeated_bool; + private $repeated_enum; + + public function getRepeatedInt32() + { + return $this->repeated_int32; + } + + public function setRepeatedInt32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT32); + $this->repeated_int32 = $var; + } + + public function getRepeatedInt64() + { + return $this->repeated_int64; + } + + public function setRepeatedInt64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT64); + $this->repeated_int64 = $var; + } + + public function getRepeatedUint32() + { + return $this->repeated_uint32; + } + + public function setRepeatedUint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT32); + $this->repeated_uint32 = $var; + } + + public function getRepeatedUint64() + { + return $this->repeated_uint64; + } + + public function setRepeatedUint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT64); + $this->repeated_uint64 = $var; + } + + public function getRepeatedSint32() + { + return $this->repeated_sint32; + } + + public function setRepeatedSint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT32); + $this->repeated_sint32 = $var; + } + + public function getRepeatedSint64() + { + return $this->repeated_sint64; + } + + public function setRepeatedSint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT64); + $this->repeated_sint64 = $var; + } + + public function getRepeatedFixed32() + { + return $this->repeated_fixed32; + } + + public function setRepeatedFixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED32); + $this->repeated_fixed32 = $var; + } + + public function getRepeatedFixed64() + { + return $this->repeated_fixed64; + } + + public function setRepeatedFixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED64); + $this->repeated_fixed64 = $var; + } + + public function getRepeatedSfixed32() + { + return $this->repeated_sfixed32; + } + + public function setRepeatedSfixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED32); + $this->repeated_sfixed32 = $var; + } + + public function getRepeatedSfixed64() + { + return $this->repeated_sfixed64; + } + + public function setRepeatedSfixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED64); + $this->repeated_sfixed64 = $var; + } + + public function getRepeatedFloat() + { + return $this->repeated_float; + } + + public function setRepeatedFloat(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FLOAT); + $this->repeated_float = $var; + } + + public function getRepeatedDouble() + { + return $this->repeated_double; + } + + public function setRepeatedDouble(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::DOUBLE); + $this->repeated_double = $var; + } + + public function getRepeatedBool() + { + return $this->repeated_bool; + } + + public function setRepeatedBool(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BOOL); + $this->repeated_bool = $var; + } + + public function getRepeatedEnum() + { + return $this->repeated_enum; + } + + public function setRepeatedEnum(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); + $this->repeated_enum = $var; + } + +} + +class TestUnpackedMessage extends \Google\Protobuf\Internal\Message +{ + private $repeated_int32; + private $repeated_int64; + private $repeated_uint32; + private $repeated_uint64; + private $repeated_sint32; + private $repeated_sint64; + private $repeated_fixed32; + private $repeated_fixed64; + private $repeated_sfixed32; + private $repeated_sfixed64; + private $repeated_float; + private $repeated_double; + private $repeated_bool; + private $repeated_enum; + + public function getRepeatedInt32() + { + return $this->repeated_int32; + } + + public function setRepeatedInt32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT32); + $this->repeated_int32 = $var; + } + + public function getRepeatedInt64() + { + return $this->repeated_int64; + } + + public function setRepeatedInt64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::INT64); + $this->repeated_int64 = $var; + } + + public function getRepeatedUint32() + { + return $this->repeated_uint32; + } + + public function setRepeatedUint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT32); + $this->repeated_uint32 = $var; + } + + public function getRepeatedUint64() + { + return $this->repeated_uint64; + } + + public function setRepeatedUint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::UINT64); + $this->repeated_uint64 = $var; + } + + public function getRepeatedSint32() + { + return $this->repeated_sint32; + } + + public function setRepeatedSint32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT32); + $this->repeated_sint32 = $var; + } + + public function getRepeatedSint64() + { + return $this->repeated_sint64; + } + + public function setRepeatedSint64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SINT64); + $this->repeated_sint64 = $var; + } + + public function getRepeatedFixed32() + { + return $this->repeated_fixed32; + } + + public function setRepeatedFixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED32); + $this->repeated_fixed32 = $var; + } + + public function getRepeatedFixed64() + { + return $this->repeated_fixed64; + } + + public function setRepeatedFixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FIXED64); + $this->repeated_fixed64 = $var; + } + + public function getRepeatedSfixed32() + { + return $this->repeated_sfixed32; + } + + public function setRepeatedSfixed32(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED32); + $this->repeated_sfixed32 = $var; + } + + public function getRepeatedSfixed64() + { + return $this->repeated_sfixed64; + } + + public function setRepeatedSfixed64(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::SFIXED64); + $this->repeated_sfixed64 = $var; + } + + public function getRepeatedFloat() + { + return $this->repeated_float; + } + + public function setRepeatedFloat(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::FLOAT); + $this->repeated_float = $var; + } + + public function getRepeatedDouble() + { + return $this->repeated_double; + } + + public function setRepeatedDouble(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::DOUBLE); + $this->repeated_double = $var; + } + + public function getRepeatedBool() + { + return $this->repeated_bool; + } + + public function setRepeatedBool(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::BOOL); + $this->repeated_bool = $var; + } + + public function getRepeatedEnum() + { + return $this->repeated_enum; + } + + public function setRepeatedEnum(&$var) + { + GPBUtil::checkRepeatedField($var, GPBType::ENUM, Foo\TestEnum::class); + $this->repeated_enum = $var; + } + +} + +class TestEnum +{ + const ZERO = 0; + const ONE = 1; +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0a83250a0a746573742e70726f746f1203666f6f1a12746573745f696e63" . + "6c7564652e70726f746f22be1d0a0b546573744d65737361676512160a0e" . + "6f7074696f6e616c5f696e74333218012001280512160a0e6f7074696f6e" . + "616c5f696e74363418022001280312170a0f6f7074696f6e616c5f75696e" . + "74333218032001280d12170a0f6f7074696f6e616c5f75696e7436341804" . + "2001280412170a0f6f7074696f6e616c5f73696e74333218052001281112" . + "170a0f6f7074696f6e616c5f73696e74363418062001281212180a106f70" . + "74696f6e616c5f6669786564333218072001280712180a106f7074696f6e" . + "616c5f6669786564363418082001280612190a116f7074696f6e616c5f73" . + "6669786564333218092001280f12190a116f7074696f6e616c5f73666978" . + "65643634180a2001281012160a0e6f7074696f6e616c5f666c6f6174180b" . + "2001280212170a0f6f7074696f6e616c5f646f75626c65180c2001280112" . + "150a0d6f7074696f6e616c5f626f6f6c180d2001280812170a0f6f707469" . + "6f6e616c5f737472696e67180e2001280912160a0e6f7074696f6e616c5f" . + "6279746573180f2001280c12240a0d6f7074696f6e616c5f656e756d1810" . + "2001280e320d2e666f6f2e54657374456e756d122e0a106f7074696f6e61" . + "6c5f6d65737361676518112001280b32142e666f6f2e546573744d657373" . + "6167652e53756212330a196f7074696f6e616c5f696e636c756465645f6d" . + "65737361676518122001280b32102e6261722e54657374496e636c756465" . + "12230a0972656375727369766518132001280b32102e666f6f2e54657374" . + "4d65737361676512160a0e72657065617465645f696e743332181f200328" . + "0512160a0e72657065617465645f696e74363418202003280312170a0f72" . + "657065617465645f75696e74333218212003280d12170a0f726570656174" . + "65645f75696e74363418222003280412170a0f72657065617465645f7369" . + "6e74333218232003281112170a0f72657065617465645f73696e74363418" . + "242003281212180a1072657065617465645f666978656433321825200328" . + "0712180a1072657065617465645f6669786564363418262003280612190a" . + "1172657065617465645f736669786564333218272003280f12190a117265" . + "7065617465645f736669786564363418282003281012160a0e7265706561" . + "7465645f666c6f617418292003280212170a0f72657065617465645f646f" . + "75626c65182a2003280112150a0d72657065617465645f626f6f6c182b20" . + "03280812170a0f72657065617465645f737472696e67182c200328091216" . + "0a0e72657065617465645f6279746573182d2003280c12240a0d72657065" . + "617465645f656e756d182e2003280e320d2e666f6f2e54657374456e756d" . + "122e0a1072657065617465645f6d657373616765182f2003280b32142e66" . + "6f6f2e546573744d6573736167652e537562122c0a127265706561746564" . + "5f72656375727369766518302003280b32102e666f6f2e546573744d6573" . + "7361676512150a0b6f6e656f665f696e743332183320012805480012150a" . + "0b6f6e656f665f696e743634183420012803480012160a0c6f6e656f665f" . + "75696e74333218352001280d480012160a0c6f6e656f665f75696e743634" . + "183620012804480012160a0c6f6e656f665f73696e74333218372001280d" . + "480012160a0c6f6e656f665f73696e743634183820012804480012170a0d" . + "6f6e656f665f6669786564333218392001280d480012170a0d6f6e656f66" . + "5f66697865643634183a20012804480012180a0e6f6e656f665f73666978" . + "65643332183b2001280d480012180a0e6f6e656f665f7366697865643634" . + "183c20012804480012160a0c6f6e656f665f646f75626c65183d20012801" . + "480012150a0b6f6e656f665f666c6f6174183e20012802480012140a0a6f" . + "6e656f665f626f6f6c183f20012808480012160a0c6f6e656f665f737472" . + "696e67184020012809480012150a0b6f6e656f665f627974657318412001" . + "280c480012230a0a6f6e656f665f656e756d18422001280e320d2e666f6f" . + "2e54657374456e756d4800122d0a0d6f6e656f665f6d6573736167651843" . + "2001280b32142e666f6f2e546573744d6573736167652e5375624800123c" . + "0a0f6d61705f696e7433325f696e74333218472003280b32232e666f6f2e" . + "546573744d6573736167652e4d6170496e743332496e743332456e747279" . + "123c0a0f6d61705f696e7436345f696e74363418482003280b32232e666f" . + "6f2e546573744d6573736167652e4d6170496e743634496e743634456e74" . + "727912400a116d61705f75696e7433325f75696e74333218492003280b32" . + "252e666f6f2e546573744d6573736167652e4d617055696e74333255696e" . + "743332456e74727912400a116d61705f75696e7436345f75696e74363418" . + "4a2003280b32252e666f6f2e546573744d6573736167652e4d617055696e" . + "74363455696e743634456e74727912400a116d61705f73696e7433325f73" . + "696e743332184b2003280b32252e666f6f2e546573744d6573736167652e" . + "4d617053696e74333253696e743332456e74727912400a116d61705f7369" . + "6e7436345f73696e743634184c2003280b32252e666f6f2e546573744d65" . + "73736167652e4d617053696e74363453696e743634456e74727912440a13" . + "6d61705f666978656433325f66697865643332184d2003280b32272e666f" . + "6f2e546573744d6573736167652e4d617046697865643332466978656433" . + "32456e74727912440a136d61705f666978656436345f6669786564363418" . + "4e2003280b32272e666f6f2e546573744d6573736167652e4d6170466978" . + "6564363446697865643634456e74727912480a156d61705f736669786564" . + "33325f7366697865643332184f2003280b32292e666f6f2e546573744d65" . + "73736167652e4d617053666978656433325366697865643332456e747279" . + "12480a156d61705f73666978656436345f73666978656436341850200328" . + "0b32292e666f6f2e546573744d6573736167652e4d617053666978656436" . + "345366697865643634456e747279123c0a0f6d61705f696e7433325f666c" . + "6f617418512003280b32232e666f6f2e546573744d6573736167652e4d61" . + "70496e743332466c6f6174456e747279123e0a106d61705f696e7433325f" . + "646f75626c6518522003280b32242e666f6f2e546573744d657373616765" . + "2e4d6170496e743332446f75626c65456e74727912380a0d6d61705f626f" . + "6f6c5f626f6f6c18532003280b32212e666f6f2e546573744d6573736167" . + "652e4d6170426f6f6c426f6f6c456e74727912400a116d61705f73747269" . + "6e675f737472696e6718542003280b32252e666f6f2e546573744d657373" . + "6167652e4d6170537472696e67537472696e67456e747279123c0a0f6d61" . + "705f696e7433325f627974657318552003280b32232e666f6f2e54657374" . + "4d6573736167652e4d6170496e7433324279746573456e747279123a0a0e" . + "6d61705f696e7433325f656e756d18562003280b32222e666f6f2e546573" . + "744d6573736167652e4d6170496e743332456e756d456e74727912400a11" . + "6d61705f696e7433325f6d65737361676518572003280b32252e666f6f2e" . + "546573744d6573736167652e4d6170496e7433324d657373616765456e74" . + "727912390a0d6d61705f72656375727369766518582003280b32222e666f" . + "6f2e546573744d6573736167652e4d6170526563757273697665456e7472" . + "791a340a124d6170496e743332496e743332456e747279120b0a036b6579" . + "180120012805120d0a0576616c75651802200128053a0238011a340a124d" . + "6170496e743634496e743634456e747279120b0a036b6579180120012803" . + "120d0a0576616c75651802200128033a0238011a360a144d617055696e74" . + "333255696e743332456e747279120b0a036b657918012001280d120d0a05" . + "76616c756518022001280d3a0238011a360a144d617055696e7436345569" . + "6e743634456e747279120b0a036b6579180120012804120d0a0576616c75" . + "651802200128043a0238011a360a144d617053696e74333253696e743332" . + "456e747279120b0a036b6579180120012811120d0a0576616c7565180220" . + "0128113a0238011a360a144d617053696e74363453696e743634456e7472" . + "79120b0a036b6579180120012812120d0a0576616c75651802200128123a" . + "0238011a380a164d61704669786564333246697865643332456e74727912" . + "0b0a036b6579180120012807120d0a0576616c75651802200128073a0238" . + "011a380a164d61704669786564363446697865643634456e747279120b0a" . + "036b6579180120012806120d0a0576616c75651802200128063a0238011a" . + "3a0a184d617053666978656433325366697865643332456e747279120b0a" . + "036b657918012001280f120d0a0576616c756518022001280f3a0238011a" . + "3a0a184d617053666978656436345366697865643634456e747279120b0a" . + "036b6579180120012810120d0a0576616c75651802200128103a0238011a" . + "340a124d6170496e743332466c6f6174456e747279120b0a036b65791801" . + "20012805120d0a0576616c75651802200128023a0238011a350a134d6170" . + "496e743332446f75626c65456e747279120b0a036b657918012001280512" . + "0d0a0576616c75651802200128013a0238011a320a104d6170426f6f6c42" . + "6f6f6c456e747279120b0a036b6579180120012808120d0a0576616c7565" . + "1802200128083a0238011a360a144d6170537472696e67537472696e6745" . + "6e747279120b0a036b6579180120012809120d0a0576616c756518022001" . + "28093a0238011a340a124d6170496e7433324279746573456e747279120b" . + "0a036b6579180120012805120d0a0576616c756518022001280c3a023801" . + "1a420a114d6170496e743332456e756d456e747279120b0a036b65791801" . + "20012805121c0a0576616c756518022001280e320d2e666f6f2e54657374" . + "456e756d3a0238011a4c0a144d6170496e7433324d657373616765456e74" . + "7279120b0a036b657918012001280512230a0576616c756518022001280b" . + "32142e666f6f2e546573744d6573736167652e5375623a0238011a450a11" . + "4d6170526563757273697665456e747279120b0a036b6579180120012805" . + "121f0a0576616c756518022001280b32102e666f6f2e546573744d657373" . + "6167653a0238011a100a0353756212090a0161180120012805420a0a086d" . + "795f6f6e656f6622b7030a11546573745061636b65644d65737361676512" . + "1a0a0e72657065617465645f696e743332185a2003280542021001121a0a" . + "0e72657065617465645f696e743634185b2003280342021001121b0a0f72" . + "657065617465645f75696e743332185c2003280d42021001121b0a0f7265" . + "7065617465645f75696e743634185d2003280442021001121b0a0f726570" . + "65617465645f73696e743332185e2003281142021001121b0a0f72657065" . + "617465645f73696e743634185f2003281242021001121c0a107265706561" . + "7465645f6669786564333218602003280742021001121c0a107265706561" . + "7465645f6669786564363418612003280642021001121d0a117265706561" . + "7465645f736669786564333218622003280f42021001121d0a1172657065" . + "617465645f736669786564363418632003281042021001121a0a0e726570" . + "65617465645f666c6f617418642003280242021001121b0a0f7265706561" . + "7465645f646f75626c651865200328014202100112190a0d726570656174" . + "65645f626f6f6c1866200328084202100112280a0d72657065617465645f" . + "656e756d18672003280e320d2e666f6f2e54657374456e756d4202100122" . + "b9030a1354657374556e7061636b65644d657373616765121a0a0e726570" . + "65617465645f696e743332185a2003280542021000121a0a0e7265706561" . + "7465645f696e743634185b2003280342021000121b0a0f72657065617465" . + "645f75696e743332185c2003280d42021000121b0a0f7265706561746564" . + "5f75696e743634185d2003280442021000121b0a0f72657065617465645f" . + "73696e743332185e2003281142021000121b0a0f72657065617465645f73" . + "696e743634185f2003281242021000121c0a1072657065617465645f6669" . + "786564333218602003280742021000121c0a1072657065617465645f6669" . + "786564363418612003280642021000121d0a1172657065617465645f7366" . + "69786564333218622003280f42021000121d0a1172657065617465645f73" . + "6669786564363418632003281042021000121a0a0e72657065617465645f" . + "666c6f617418642003280242021000121b0a0f72657065617465645f646f" . + "75626c651865200328014202100012190a0d72657065617465645f626f6f" . + "6c1866200328084202100012280a0d72657065617465645f656e756d1867" . + "2003280e320d2e666f6f2e54657374456e756d420210002a1d0a08546573" . + "74456e756d12080a045a45524f100012070a034f4e451001620670726f74" . + "6f33" +)); + diff --git a/php/tests/test_include.pb.php b/php/tests/test_include.pb.php new file mode 100644 index 00000000..2c43cc41 --- /dev/null +++ b/php/tests/test_include.pb.php @@ -0,0 +1,36 @@ +a; + } + + public function setA($var) + { + GPBUtil::checkInt32($var); + $this->a = $var; + } + +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0a3b0a12746573745f696e636c7564652e70726f746f120362617222180a" . + "0b54657374496e636c75646512090a0161180120012805620670726f746f" . + "33" +)); + -- cgit v1.2.3 From ebcda12102f2beaa630a81f5675854abb44746c1 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 20 Sep 2016 21:29:02 +0000 Subject: Bump version number to 3.1.0-alpha-1. --- Protobuf.podspec | 2 +- configure.ac | 2 +- csharp/Google.Protobuf.Tools.nuspec | 2 +- csharp/src/Google.Protobuf/project.json | 2 +- java/core/pom.xml | 2 +- java/lite/pom.xml | 2 +- java/pom.xml | 2 +- java/util/pom.xml | 2 +- javanano/pom.xml | 2 +- js/package.json | 2 +- php/ext/google/protobuf/package.xml | 2 +- protoc-artifacts/pom.xml | 2 +- python/google/protobuf/__init__.py | 2 +- ruby/Gemfile.lock | 2 +- ruby/google-protobuf.gemspec | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) (limited to 'php') diff --git a/Protobuf.podspec b/Protobuf.podspec index 8d1ab357..2aebdda4 100644 --- a/Protobuf.podspec +++ b/Protobuf.podspec @@ -5,7 +5,7 @@ # dependent projects use the :git notation to refer to the library. Pod::Spec.new do |s| s.name = 'Protobuf' - s.version = '3.0.2' + s.version = '3.1.0-alpha-1' s.summary = 'Protocol Buffers v.3 runtime library for Objective-C.' s.homepage = 'https://github.com/google/protobuf' s.license = 'New BSD' diff --git a/configure.ac b/configure.ac index 757f55c9..c21990b5 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PREREQ(2.59) # In the SVN trunk, the version should always be the next anticipated release # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed # the size of one file name in the dist tarfile over the 99-char limit.) -AC_INIT([Protocol Buffers],[3.0.2],[protobuf@googlegroups.com],[protobuf]) +AC_INIT([Protocol Buffers],[3.1.0-alpha-1],[protobuf@googlegroups.com],[protobuf]) AM_MAINTAINER_MODE([enable]) diff --git a/csharp/Google.Protobuf.Tools.nuspec b/csharp/Google.Protobuf.Tools.nuspec index ce7514b4..79f32bab 100644 --- a/csharp/Google.Protobuf.Tools.nuspec +++ b/csharp/Google.Protobuf.Tools.nuspec @@ -5,7 +5,7 @@ Google Protocol Buffers tools Tools for Protocol Buffers - Google's data interchange format. See project site for more info. - 3.0.2 + 3.1.0-alpha1 Google Inc. protobuf-packages https://github.com/google/protobuf/blob/master/LICENSE diff --git a/csharp/src/Google.Protobuf/project.json b/csharp/src/Google.Protobuf/project.json index 607b65ef..dd958c98 100644 --- a/csharp/src/Google.Protobuf/project.json +++ b/csharp/src/Google.Protobuf/project.json @@ -1,5 +1,5 @@ { - "version": "3.0.2", + "version": "3.1.0-alpha-1", "title": "Google Protocol Buffers", "description": "See project site for more info.", "authors": [ "Google Inc." ], diff --git a/java/core/pom.xml b/java/core/pom.xml index 28bc99a0..790f0af3 100644 --- a/java/core/pom.xml +++ b/java/core/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.0.2 + 3.1.0-alpha-1 protobuf-java diff --git a/java/lite/pom.xml b/java/lite/pom.xml index 9862cd94..d6490247 100644 --- a/java/lite/pom.xml +++ b/java/lite/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.0.0 + 3.1.0-alpha-1 protobuf-lite diff --git a/java/pom.xml b/java/pom.xml index ccfb229e..3fa0a85b 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -11,7 +11,7 @@ com.google.protobuf protobuf-parent - 3.0.2 + 3.1.0-alpha-1 pom Protocol Buffers [Parent] diff --git a/java/util/pom.xml b/java/util/pom.xml index 58cc4b30..4d6ad7fa 100644 --- a/java/util/pom.xml +++ b/java/util/pom.xml @@ -6,7 +6,7 @@ com.google.protobuf protobuf-parent - 3.0.2 + 3.1.0-alpha-1 protobuf-java-util diff --git a/javanano/pom.xml b/javanano/pom.xml index 6ebba3cf..291ed27a 100644 --- a/javanano/pom.xml +++ b/javanano/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf.nano protobuf-javanano - 3.0.0-alpha-7 + 3.1.0-alpha-1 bundle Protocol Buffer JavaNano API diff --git a/js/package.json b/js/package.json index 5df7283c..cc0db47b 100644 --- a/js/package.json +++ b/js/package.json @@ -1,6 +1,6 @@ { "name": "google-protobuf", - "version": "3.0.2", + "version": "3.1.0-alpha.1", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", "files": [ diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 83719091..cfb33acb 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -13,7 +13,7 @@ 2016-09-02 - 3.1.0 + 3.1.0a1 3.1.0 diff --git a/protoc-artifacts/pom.xml b/protoc-artifacts/pom.xml index c4f0a73d..b8581da1 100644 --- a/protoc-artifacts/pom.xml +++ b/protoc-artifacts/pom.xml @@ -10,7 +10,7 @@ com.google.protobuf protoc - 3.0.2 + 3.1.0-alpha-1 pom Protobuf Compiler diff --git a/python/google/protobuf/__init__.py b/python/google/protobuf/__init__.py index 30ee6e81..f52137c4 100755 --- a/python/google/protobuf/__init__.py +++ b/python/google/protobuf/__init__.py @@ -30,7 +30,7 @@ # Copyright 2007 Google Inc. All Rights Reserved. -__version__ = '3.0.2' +__version__ = '3.1.0a1' if __name__ != '__main__': try: diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index d0eb9cc4..7a89c866 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - google-protobuf (3.0.0.alpha.5.0.5) + google-protobuf (3.1.0.alpha.1.0) GEM remote: https://rubygems.org/ diff --git a/ruby/google-protobuf.gemspec b/ruby/google-protobuf.gemspec index 67b15c33..26d9b20d 100644 --- a/ruby/google-protobuf.gemspec +++ b/ruby/google-protobuf.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "google-protobuf" - s.version = "3.0.2" + s.version = "3.1.0.alpha.1.0" s.licenses = ["BSD"] s.summary = "Protocol Buffers" s.description = "Protocol Buffers are Google's data interchange format." -- cgit v1.2.3 From 11433f78a72daf5d547547ab132de25ac79b9b0b Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 22 Sep 2016 17:09:32 -0700 Subject: PHP: support 7.0 on PHP implementation (#2162) * PHP: support 7.0 * Also fix in test_util.php --- php/src/Google/Protobuf/Internal/Message.php | 45 +++++++++++++++------------- php/tests/test_util.php | 4 ++- 2 files changed, 27 insertions(+), 22 deletions(-) (limited to 'php') diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index a8de6a11..7bdc6a8c 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -81,41 +81,44 @@ class Message switch ($value_field->getType()) { case GPBType::MESSAGE: case GPBType::GROUP: - $this->$setter( - new MapField( - $key_field->getType(), - $value_field->getType(), - $value_field->getMessageType()->getClass())); + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getMessageType()->getClass()); + $this->$setter($map_field); break; case GPBType::ENUM: - $this->$setter( - new MapField( - $key_field->getType(), - $value_field->getType(), - $value_field->getEnumType()->getClass())); + $map_field = new MapField( + $key_field->getType(), + $value_field->getType(), + $value_field->getEnumType()->getClass()); + $this->$setter($map_field); break; default: - $this->$setter(new MapField($key_field->getType(), - $value_field->getType())); + $map_field = new MapField( + $key_field->getType(), + $value_field->getType()); + $this->$setter($map_field); break; } } else if ($field->getLabel() === GPBLabel::REPEATED) { switch ($field->getType()) { case GPBType::MESSAGE: case GPBType::GROUP: - $this->$setter( - new RepeatedField( - $field->getType(), - $field->getMessageType()->getClass())); + $repeated_field = new RepeatedField( + $field->getType(), + $field->getMessageType()->getClass()); + $this->$setter($repeated_field); break; case GPBType::ENUM: - $this->$setter( - new RepeatedField( - $field->getType(), - $field->getEnumType()->getClass())); + $repeated_field = new RepeatedField( + $field->getType(), + $field->getEnumType()->getClass()); + $this->$setter($repeated_field); break; default: - $this->$setter(new RepeatedField($field->getType())); + $repeated_field = new RepeatedField($field->getType()); + $this->$setter($repeated_field); break; } } else if ($field->getOneofIndex() !== -1) { diff --git a/php/tests/test_util.php b/php/tests/test_util.php index decd1a78..2f6e4dd8 100644 --- a/php/tests/test_util.php +++ b/php/tests/test_util.php @@ -50,6 +50,8 @@ class TestUtil public static function setTestMessage(TestMessage $m) { + $sub = new TestMessage_Sub(); + $m->setOptionalInt32(-42); $m->setOptionalInt64(-43); $m->setOptionalUint32(42); @@ -66,7 +68,7 @@ class TestUtil $m->setOptionalString('a'); $m->setOptionalBytes('b'); $m->setOptionalEnum(TestEnum::ONE); - $m->setOptionalMessage(new TestMessage_Sub()); + $m->setOptionalMessage($sub); $m->getOptionalMessage()->SetA(33); $m->getRepeatedInt32() []= -42; -- cgit v1.2.3 From 9cb812fab5631fe1958c6bae465a4f86202b6db2 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Thu, 22 Sep 2016 17:17:01 -0700 Subject: Modify php api version and minimum supported php version. --- php/ext/google/protobuf/package.xml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index cfb33acb..14d46c43 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2016-09-02 + 2016-09-23 3.1.0a1 - 3.1.0 + 3.1.0a1 alpha @@ -45,7 +45,7 @@ First alpha release. - 5.6.0 + 5.5.37 1.4.0 @@ -57,14 +57,15 @@ First alpha release. - 3.1.0 - 3.1.0 + 3.1.0a1 + 3.1.0a1 alpha alpha - 2016-09-02 + 2016-09-23 + New BSD License First alpha release -- cgit v1.2.3 From 18f336b98aa21e7f735cff9186c6c1fc347ad7a6 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Fri, 23 Sep 2016 22:22:18 +0000 Subject: Update php supported version. --- php/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'php') diff --git a/php/README.md b/php/README.md index 2f5380f5..ec92d329 100644 --- a/php/README.md +++ b/php/README.md @@ -16,7 +16,8 @@ generation functionality. To use PHP runtime library requires: -- PHP 5.5 or above. +- C extension: PHP 5.5.x or 5.6.x. +- PHP package: PHP 5.5, 5.6 or 7. ## Installation @@ -94,6 +95,5 @@ Known Issues * Map fields may not be garbage-collected if there is cycle reference. * No debug information for messages in c extension. * HHVM not tested. -* PHP 7.0 not tested. -* C extension not tested on windows. +* C extension not tested on windows, mac, php 7.0. * Message name cannot be Empty. -- cgit v1.2.3 From 907a075d7eb83ddfa49c51c77b0292fe4fcafff6 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Fri, 23 Sep 2016 17:05:45 -0700 Subject: php: support 5.5.9 for pecl extension (#2174) --- php/ext/google/protobuf/package.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'php') diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 14d46c43..e1064b37 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -45,7 +45,7 @@ First alpha release. - 5.5.37 + 5.5.9 1.4.0 -- cgit v1.2.3 From 787f3fb16380a403c99716a23ed09cd7b9ea5b67 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 26 Sep 2016 12:48:28 -0700 Subject: Fixing inconsistent php version number. --- php/ext/google/protobuf/package.xml | 2 +- php/ext/google/protobuf/protobuf.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index e1064b37..01aad411 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -6,7 +6,7 @@ https://developers.google.com/protocol-buffers/ Bo Yang - teboring + stanleycheung protobuf-opensource@google.com yes diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 0330f36f..b3ad20dd 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "0.01" +#define PHP_PROTOBUF_VERSION "3.1.0a1" // ----------------------------------------------------------------------------- // Forward Declaration -- cgit v1.2.3 From bcb32c0b8692774634cb9de10be921d11d7fbf8a Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Fri, 30 Sep 2016 19:07:33 +0000 Subject: Test php5.5_c test on jenkins --- jenkins/pull_request_in_docker.sh | 7 +----- php/tests/test.sh | 10 ++++---- tests.sh | 49 ++++++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 30 deletions(-) (limited to 'php') diff --git a/jenkins/pull_request_in_docker.sh b/jenkins/pull_request_in_docker.sh index 66f3bb23..b843a355 100755 --- a/jenkins/pull_request_in_docker.sh +++ b/jenkins/pull_request_in_docker.sh @@ -58,12 +58,7 @@ parallel --results $LOG_OUTPUT_DIR --joblog $OUTPUT_DIR/joblog $TEST_SCRIPT ::: ruby_all \ javascript \ golang \ - php5.5 \ - php5.6 \ - php7.0 \ - php5.5_c \ - php5.6_c \ - php7.0_c \ + php_all \ || true # Process test results even if tests fail. cat $OUTPUT_DIR/joblog diff --git a/php/tests/test.sh b/php/tests/test.sh index f3f04a47..15df768c 100755 --- a/php/tests/test.sh +++ b/php/tests/test.sh @@ -1,10 +1,5 @@ #!/bin/bash -# Compile protoc -pushd ../../ -./autogen.sh && ./configure && make -popd - # Generate test file ../../src/protoc --php_out=. test.proto test_include.proto @@ -29,4 +24,9 @@ done # Make sure to run the memory test in debug mode. php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php +php --version +which php +pwd +ls +ls -l `which php` USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php diff --git a/tests.sh b/tests.sh index e6595044..f0d2abc9 100755 --- a/tests.sh +++ b/tests.sh @@ -334,54 +334,64 @@ build_javascript() { cd js && npm install && npm test && cd .. } +use_php() { + VERSION=$1 + PHP=`which php` + PHP_CONFIG=`which php-config` + PHPIZE=`which phpize` + rm $PHP + rm $PHP_CONFIG + rm $PHPIZE + cp "/usr/bin/php$VERSION" $PHP + cp "/usr/bin/php-config$VERSION" $PHP_CONFIG + cp "/usr/bin/phpize$VERSION" $PHPIZE +} + build_php5.5_c() { - ln -sfn /usr/bin/php5.5 /usr/bin/php - ln -sfn /usr/bin/php-config5.5 /usr/bin/php-config - ln -sfn /usr/bin/phpize5.5 /usr/bin/phpize + use_php 5.5 cd php/tests && /bin/bash ./test.sh && cd ../.. } build_php5.5() { - ln -sfn /usr/bin/php5.5 /usr/bin/php - ln -sfn /usr/bin/php-config5.5 /usr/bin/php-config - ln -sfn /usr/bin/phpize5.5 /usr/bin/phpize + use_php 5.5 rm -rf vendor cp -r /usr/local/vendor-5.5 vendor ./vendor/bin/phpunit } build_php5.6_c() { - ln -sfn /usr/bin/php5.6 /usr/bin/php - ln -sfn /usr/bin/php-config5.6 /usr/bin/php-config - ln -sfn /usr/bin/phpize5.6 /usr/bin/phpize + use_php 5.6 cd php/tests && /bin/bash ./test.sh && cd ../.. } build_php5.6() { - ln -sfn /usr/bin/php5.6 /usr/bin/php - ln -sfn /usr/bin/php-config5.6 /usr/bin/php-config - ln -sfn /usr/bin/phpize5.6 /usr/bin/phpize + use_php 5.6 rm -rf vendor cp -r /usr/local/vendor-5.6 vendor ./vendor/bin/phpunit } build_php7.0_c() { - ln -sfn /usr/bin/php7.0 /usr/bin/php - ln -sfn /usr/bin/php-config7.0 /usr/bin/php-config - ln -sfn /usr/bin/phpize7.0 /usr/bin/phpize + use_php 7.0 cd php/tests && /bin/bash ./test.sh && cd ../.. } build_php7.0() { - ln -sfn /usr/bin/php7.0 /usr/bin/php - ln -sfn /usr/bin/php-config7.0 /usr/bin/php-config - ln -sfn /usr/bin/phpize7.0 /usr/bin/phpize + use_php 7.0 rm -rf vendor cp -r /usr/local/vendor-7.0 vendor ./vendor/bin/phpunit } +build_php_all() { + build_php5.5 + build_php5.6 + build_php7.0 + build_php5.5_c + build_php5.6_c + # build_php7.0_c +} + # Note: travis currently does not support testing more than one language so the # .travis.yml cheats and claims to only be cpp. If they add multiple language # support, this should probably get updated to install steps and/or @@ -418,7 +428,8 @@ Usage: $0 { cpp | php5.6 | php5.6_c | php7.0 | - php7.0_c) + php7.0_c | + php_all) " exit 1 fi -- cgit v1.2.3 From 52ab3b07ac9a6889ed0ac9bf21afd8dab8ef0014 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Tue, 4 Oct 2016 13:39:51 -0700 Subject: PHP: fix ZTS tsrm_ls errors (#2189) * PHP: fix ZTS tsrm_ls errors * Fix a few more macros --- php/ext/google/protobuf/array.c | 5 +-- php/ext/google/protobuf/encode_decode.c | 64 +++++++++++++++++---------------- php/ext/google/protobuf/map.c | 19 +++++----- php/ext/google/protobuf/message.c | 5 +-- php/ext/google/protobuf/protobuf.h | 15 ++++---- php/ext/google/protobuf/storage.c | 20 ++++++----- 6 files changed, 69 insertions(+), 59 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index fde4f726..f96e95ec 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -160,7 +160,8 @@ static void repeated_field_write_dimension(zval *object, zval *offset, unsigned char memory[NATIVE_SLOT_MAX_SIZE]; memset(memory, 0, NATIVE_SLOT_MAX_SIZE); - if (!native_slot_set(intern->type, intern->msg_ce, memory, value)) { + if (!native_slot_set(intern->type, intern->msg_ce, memory, value + TSRMLS_CC)) { return; } @@ -192,7 +193,7 @@ static HashTable *repeated_field_get_gc(zval *object, zval ***table, // C RepeatedField Utilities // ----------------------------------------------------------------------------- -void *repeated_field_index_native(RepeatedField *intern, int index) { +void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC) { HashTable *ht = HASH_OF(intern->array); void *value; diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index 4b51dabe..af90ff33 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -199,11 +199,11 @@ static void *startseq_handler(void* closure, const void* hd) { // Handlers that append primitive values to a repeated field. #define DEFINE_APPEND_HANDLER(type, ctype) \ static bool append##type##_handler(void* closure, const void* hd, \ - ctype val) { \ + ctype val TSRMLS_DC) { \ zval* array = (zval*)closure; \ RepeatedField* intern = \ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \ - repeated_field_push_native(intern, &val); \ + repeated_field_push_native(intern, &val TSRMLS_CC); \ return true; \ } @@ -218,7 +218,7 @@ DEFINE_APPEND_HANDLER(double, double) // Appends a string to a repeated field. static void* appendstr_handler(void *closure, const void *hd, - size_t size_hint) { + size_t size_hint TSRMLS_DC) { zval* array = (zval*)closure; RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -234,7 +234,7 @@ static void* appendstr_handler(void *closure, // Appends a 'bytes' string to a repeated field. static void* appendbytes_handler(void *closure, const void *hd, - size_t size_hint) { + size_t size_hint TSRMLS_DC) { zval* array = (zval*)closure; RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -296,7 +296,7 @@ static size_t stringdata_handler(void* closure, const void* hd, } // Appends a submessage to a repeated field. -static void *appendsubmsg_handler(void *closure, const void *hd) { +static void *appendsubmsg_handler(void *closure, const void *hd TSRMLS_DC) { zval* array = (zval*)closure; RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -319,7 +319,7 @@ static void *appendsubmsg_handler(void *closure, const void *hd) { } // Sets a non-repeated submessage field in a message. -static void *submsg_handler(void *closure, const void *hd) { +static void *submsg_handler(void *closure, const void *hd TSRMLS_DC) { MessageHeader* msg = closure; const submsg_handlerdata_t* submsgdata = hd; zval* subdesc_php = get_def_obj((void*)submsgdata->md); @@ -423,7 +423,8 @@ static void map_slot_key(upb_fieldtype_t type, const void* from, char** keyval, } } -static void map_slot_value(upb_fieldtype_t type, const void* from, upb_value* v) { +static void map_slot_value(upb_fieldtype_t type, const void* from, + upb_value* v) { size_t len; void* to = upb_value_memory(v); #ifndef NDEBUG @@ -464,7 +465,8 @@ static void *startmapentry_handler(void *closure, const void *hd) { // Handler to end a map entry: inserts the value defined during the message into // the map. This is the 'endmsg' handler on the map entry msgdef. -static bool endmap_handler(void *closure, const void *hd, upb_status* s) { +static bool endmap_handler(void *closure, const void *hd, upb_status* s + TSRMLS_DC) { map_parse_frame_t* frame = closure; const map_handlerdata_t* mapdata = hd; @@ -574,7 +576,7 @@ static void *oneofbytes_handler(void *closure, // Handler for a submessage field in a oneof. static void *oneofsubmsg_handler(void *closure, - const void *hd) { + const void *hd TSRMLS_DC) { MessageHeader* msg = closure; const oneof_handlerdata_t *oneofdata = hd; uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t); @@ -771,7 +773,8 @@ static void add_handlers_for_oneof_field(upb_handlers *h, upb_handlerattr_uninit(&attr); } -static void add_handlers_for_message(const void *closure, upb_handlers *h) { +static void add_handlers_for_message(const void *closure, upb_handlers *h + TSRMLS_DC) { const upb_msgdef* msgdef = upb_handlers_msgdef(h); Descriptor* desc = (Descriptor*)zend_object_store_get_object( get_def_obj((void*)msgdef) TSRMLS_CC); @@ -860,7 +863,7 @@ static const upb_pbdecodermethod *msgdef_decodermethod(Descriptor* desc) { // ----------------------------------------------------------------------------- static void putmsg(zval* msg, const Descriptor* desc, upb_sink* sink, - int depth); + int depth TSRMLS_DC); static void putstr(zval* str, const upb_fielddef* f, upb_sink* sink); @@ -868,11 +871,12 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, upb_sink* sink); static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, - int depth); + int depth TSRMLS_DC); static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, - int depth); -static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, int depth); + int depth TSRMLS_DC); +static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, int depth + TSRMLS_DC); static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { upb_selector_t ret; @@ -882,7 +886,7 @@ static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { } static void put_optional_value(void* memory, int len, const upb_fielddef* f, - int depth, upb_sink* sink) { + int depth, upb_sink* sink TSRMLS_DC) { assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL); switch (upb_fielddef_type(f)) { @@ -911,7 +915,7 @@ static void put_optional_value(void* memory, int len, const upb_fielddef* f, break; case UPB_TYPE_MESSAGE: { zval* submsg = *(zval**)memory; - putsubmsg(submsg, f, sink, depth); + putsubmsg(submsg, f, sink, depth TSRMLS_CC); break; } default: @@ -943,7 +947,7 @@ static int raw_value_len(void* memory, int len, const upb_fielddef* f) { } static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { Map* self; upb_sink subsink; const upb_fielddef* key_field; @@ -960,7 +964,7 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, key_field = map_field_key(f); value_field = map_field_value(f); - for (map_begin(map, &it); !map_done(&it); map_next(&it)) { + for (map_begin(map, &it TSRMLS_CC); !map_done(&it); map_next(&it)) { upb_status status; upb_sink entry_sink; @@ -970,13 +974,13 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, // Serialize key. const char *key = map_iter_key(&it, &len); - put_optional_value(key, len, key_field, depth + 1, &entry_sink); + put_optional_value(key, len, key_field, depth + 1, &entry_sink TSRMLS_CC); // Serialize value. upb_value value = map_iter_value(&it, &len); put_optional_value(raw_value(upb_value_memory(&value), value_field), raw_value_len(upb_value_memory(&value), len, value_field), - value_field, depth + 1, &entry_sink); + value_field, depth + 1, &entry_sink TSRMLS_CC); upb_sink_endmsg(&entry_sink, &status); upb_sink_endsubmsg(&subsink, getsel(f, UPB_HANDLER_ENDSUBMSG)); @@ -986,7 +990,7 @@ static void putmap(zval* map, const upb_fielddef* f, upb_sink* sink, } static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { upb_msg_field_iter i; upb_status status; @@ -1023,12 +1027,12 @@ static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, if (is_map_field(f)) { zval* map = *DEREF(msg, offset, zval**); if (map != NULL) { - putmap(map, f, sink, depth); + putmap(map, f, sink, depth TSRMLS_CC); } } else if (upb_fielddef_isseq(f)) { zval* array = *DEREF(msg, offset, zval**); if (array != NULL) { - putarray(array, f, sink, depth); + putarray(array, f, sink, depth TSRMLS_CC); } } else if (upb_fielddef_isstring(f)) { zval* str = *DEREF(msg, offset, zval**); @@ -1036,7 +1040,7 @@ static void putmsg(zval* msg_php, const Descriptor* desc, upb_sink* sink, putstr(str, f, sink); } } else if (upb_fielddef_issubmsg(f)) { - putsubmsg(*DEREF(msg, offset, zval**), f, sink, depth); + putsubmsg(*DEREF(msg, offset, zval**), f, sink, depth TSRMLS_CC); } else { upb_selector_t sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); @@ -1113,7 +1117,7 @@ static void putrawstr(const char* str, int len, const upb_fielddef* f, } static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { upb_sink subsink; if (Z_TYPE_P(submsg) == IS_NULL) return; @@ -1123,12 +1127,12 @@ static void putsubmsg(zval* submsg, const upb_fielddef* f, upb_sink* sink, (Descriptor*)zend_object_store_get_object(php_descriptor TSRMLS_CC); upb_sink_startsubmsg(sink, getsel(f, UPB_HANDLER_STARTSUBMSG), &subsink); - putmsg(submsg, subdesc, &subsink, depth + 1); + putmsg(submsg, subdesc, &subsink, depth + 1 TSRMLS_CC); upb_sink_endsubmsg(sink, getsel(f, UPB_HANDLER_ENDSUBMSG)); } static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, - int depth) { + int depth TSRMLS_DC) { upb_sink subsink; upb_fieldtype_t type = upb_fielddef_type(f); upb_selector_t sel = 0; @@ -1147,7 +1151,7 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, } for (i = 0; i < size; i++) { - void* memory = repeated_field_index_native(intern, i); + void* memory = repeated_field_index_native(intern, i TSRMLS_CC); switch (type) { #define T(upbtypeconst, upbtype, ctype) \ case upbtypeconst: \ @@ -1168,7 +1172,7 @@ static void putarray(zval* array, const upb_fielddef* f, upb_sink* sink, putstr(*((zval**)memory), f, &subsink); break; case UPB_TYPE_MESSAGE: - putsubmsg(*((zval**)memory), f, &subsink, depth); + putsubmsg(*((zval**)memory), f, &subsink, depth TSRMLS_CC); break; #undef T @@ -1206,7 +1210,7 @@ PHP_METHOD(Message, encode) { stackenv_init(&se, "Error occurred during encoding: %s"); encoder = upb_pb_encoder_create(&se.env, serialize_handlers, &sink.sink); - putmsg(getThis(), desc, upb_pb_encoder_input(encoder), 0); + putmsg(getThis(), desc, upb_pb_encoder_input(encoder), 0 TSRMLS_CC); RETVAL_STRINGL(sink.ptr, sink.len, 1); diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 6d822fff..6a80d978 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -88,7 +88,7 @@ void* upb_value_memory(upb_value* v) { static bool table_key(Map* self, zval* key, char* buf, const char** out_key, - size_t* out_length) { + size_t* out_length TSRMLS_DC) { switch (self->key_type) { case UPB_TYPE_STRING: if (!protobuf_convert_to_string(key)) { @@ -108,7 +108,7 @@ static bool table_key(Map* self, zval* key, if (!protobuf_convert_to_##type(key, &type##_value)) { \ return false; \ } \ - native_slot_set(self->key_type, NULL, buf, key); \ + native_slot_set(self->key_type, NULL, buf, key TSRMLS_CC); \ *out_key = buf; \ *out_length = native_slot_size(self->key_type); \ break; \ @@ -248,7 +248,7 @@ void map_field_create_with_type(zend_class_entry *ce, const upb_fielddef *field, const upb_fielddef *value_field = map_field_value(field); intern->key_type = upb_fielddef_type(key_field); intern->value_type = upb_fielddef_type(value_field); - intern->msg_ce = field_type_class(value_field); + intern->msg_ce = field_type_class(value_field TSRMLS_CC); } static void map_field_free_element(void *object) { @@ -270,7 +270,7 @@ static bool *map_field_read_dimension(zval *object, zval *key, int type, #ifndef NDEBUG v.ctype = UPB_CTYPE_UINT64; #endif - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } @@ -303,13 +303,14 @@ static bool map_field_write_dimension(zval *object, zval *key, size_t length = 0; upb_value v; void* mem; - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } mem = upb_value_memory(&v); memset(mem, 0, native_slot_size(intern->value_type)); - if(!native_slot_set(intern->value_type, intern->msg_ce, mem, value)) { + if (!native_slot_set(intern->value_type, intern->msg_ce, mem, value + TSRMLS_CC)) { return false; } #ifndef NDEBUG @@ -333,7 +334,7 @@ static bool map_field_unset_dimension(zval *object, zval *key TSRMLS_DC) { const char* keyval = NULL; size_t length = 0; upb_value v; - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } #ifndef NDEBUG @@ -396,7 +397,7 @@ PHP_METHOD(MapField, offsetExists) { #ifndef NDEBUG v.ctype = UPB_CTYPE_UINT64; #endif - if (!table_key(intern, key, keybuf, &keyval, &length)) { + if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { return false; } @@ -446,7 +447,7 @@ PHP_METHOD(MapField, count) { // Map Iterator // ----------------------------------------------------------------------------- -void map_begin(zval *map_php, MapIter *iter) { +void map_begin(zval *map_php, MapIter *iter TSRMLS_DC) { Map *self = UNBOX(Map, map_php); map_begin_internal(self, iter); } diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 0cae6dba..cb46031e 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -96,7 +96,7 @@ static void message_set_property(zval* object, zval* member, zval* value, zend_error(E_USER_ERROR, "Unknown field: %s", Z_STRVAL_P(member)); } - layout_set(self->descriptor->layout, self, field, value); + layout_set(self->descriptor->layout, self, field, value TSRMLS_CC); } static zval* message_get_property(zval* object, zval* member, int type, @@ -177,7 +177,8 @@ static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC) { zend_object_std_init(&msg->std, ce TSRMLS_CC); object_properties_init(&msg->std, ce); - layout_init(desc->layout, message_data(msg), msg->std.properties_table); + layout_init(desc->layout, message_data(msg), msg->std.properties_table + TSRMLS_CC); return_value.handle = zend_objects_store_put( msg, (zend_objects_store_dtor_t)zend_objects_destroy_object, message_free, diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index b3ad20dd..5edb15db 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -233,11 +233,12 @@ struct MessageHeader { }; MessageLayout* create_layout(const upb_msgdef* msgdef); -void layout_init(MessageLayout* layout, void* storage, zval** properties_table); +void layout_init(MessageLayout* layout, void* storage, zval** properties_table + TSRMLS_DC); zval* layout_get(MessageLayout* layout, const void* storage, const upb_fielddef* field, zval** cache TSRMLS_DC); void layout_set(MessageLayout* layout, MessageHeader* header, - const upb_fielddef* field, zval* val); + const upb_fielddef* field, zval* val TSRMLS_DC); void free_layout(MessageLayout* layout); PHP_METHOD(Message, readOneof); @@ -293,7 +294,7 @@ PHP_METHOD(Util, checkRepeatedField); size_t native_slot_size(upb_fieldtype_t type); bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, - void* memory, zval* value); + void* memory, zval* value TSRMLS_DC); void native_slot_init(upb_fieldtype_t type, void* memory, zval** cache); // For each property, in order to avoid conversion between the zval object and // the actual data type during parsing/serialization, the containing message @@ -325,7 +326,7 @@ typedef struct { upb_strtable_iter it; } MapIter; -void map_begin(zval* self, MapIter* iter); +void map_begin(zval* self, MapIter* iter TSRMLS_DC); void map_next(MapIter* iter); bool map_done(MapIter* iter); const char* map_iter_key(MapIter* iter, int* len); @@ -377,10 +378,10 @@ void repeated_field_create_with_type(zend_class_entry* ce, zval** repeated_field TSRMLS_DC); // Return the element at the index position from the repeated field. There is // not restriction on the type of stored elements. -void *repeated_field_index_native(RepeatedField *intern, int index); +void *repeated_field_index_native(RepeatedField *intern, int index TSRMLS_DC); // Add the element to the end of the repeated field. There is not restriction on // the type of stored elements. -void repeated_field_push_native(RepeatedField *intern, void *value); +void repeated_field_push_native(RepeatedField *intern, void *value TSRMLS_DC); PHP_METHOD(RepeatedField, __construct); PHP_METHOD(RepeatedField, append); @@ -411,7 +412,7 @@ typedef struct { // ----------------------------------------------------------------------------- upb_fieldtype_t to_fieldtype(upb_descriptortype_t type); -const zend_class_entry *field_type_class(const upb_fielddef *field); +const zend_class_entry *field_type_class(const upb_fielddef *field TSRMLS_DC); // ----------------------------------------------------------------------------- // Utilities. diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index 7423552b..56497f62 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -56,7 +56,7 @@ size_t native_slot_size(upb_fieldtype_t type) { } bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, - void* memory, zval* value) { + void* memory, zval* value TSRMLS_DC) { switch (type) { case UPB_TYPE_STRING: case UPB_TYPE_BYTES: { @@ -295,7 +295,7 @@ const upb_fielddef* map_entry_value(const upb_msgdef* msgdef) { return value_field; } -const zend_class_entry* field_type_class(const upb_fielddef* field) { +const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) { if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) { zval* desc_php = get_def_obj(upb_fielddef_subdef(field)); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); @@ -435,7 +435,8 @@ void free_layout(MessageLayout* layout) { FREE(layout); } -void layout_init(MessageLayout* layout, void* storage, zval** properties_table) { +void layout_init(MessageLayout* layout, void* storage, zval** properties_table + TSRMLS_DC) { int i; upb_msg_field_iter it; for (upb_msg_field_begin(&it, layout->msgdef), i = 0; !upb_msg_field_done(&it); @@ -451,11 +452,12 @@ void layout_init(MessageLayout* layout, void* storage, zval** properties_table) *oneof_case = ONEOF_CASE_NONE; } else if (is_map_field(field)) { zval_ptr_dtor(property_ptr); - map_field_create_with_type(map_field_type, field, property_ptr); + map_field_create_with_type(map_field_type, field, property_ptr TSRMLS_CC); DEREF(memory, zval**) = property_ptr; } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { zval_ptr_dtor(property_ptr); - repeated_field_create_with_type(repeated_field_type, field, property_ptr); + repeated_field_create_with_type(repeated_field_type, field, property_ptr + TSRMLS_CC); DEREF(memory, zval**) = property_ptr; } else { native_slot_init(upb_fielddef_type(field), memory, property_ptr); @@ -501,8 +503,8 @@ zval* layout_get(MessageLayout* layout, const void* storage, } } -void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef* field, - zval* val) { +void layout_set(MessageLayout* layout, MessageHeader* header, + const upb_fielddef* field, zval* val TSRMLS_DC) { void* storage = message_data(header); void* memory = slot_memory(layout, storage, field); uint32_t* oneof_case = slot_oneof_case(layout, storage, field); @@ -535,7 +537,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef break; } - native_slot_set(type, ce, memory, val); + native_slot_set(type, ce, memory, val TSRMLS_CC); *oneof_case = upb_fielddef_number(field); } else if (upb_fielddef_label(field) == UPB_LABEL_REPEATED) { // Works for both repeated and map fields @@ -554,6 +556,6 @@ void layout_set(MessageLayout* layout, MessageHeader* header, const upb_fielddef Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); ce = desc->klass; } - native_slot_set(type, ce, value_memory(field, memory), val); + native_slot_set(type, ce, value_memory(field, memory), val TSRMLS_CC); } } -- cgit v1.2.3 From 75b69887aa446aeb7f1b6325ec826f2b5ddfa972 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 5 Oct 2016 10:54:39 -0700 Subject: Fix segmentation fault when ZTS is defined. --- php/ext/google/protobuf/array.c | 3 +-- php/ext/google/protobuf/encode_decode.c | 28 ++++++++++++++--------- php/ext/google/protobuf/type_check.c | 1 - php/tests/array_test.php | 40 ++++++++++++++++----------------- tests.sh | 1 + 5 files changed, 39 insertions(+), 34 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index f96e95ec..c24ede81 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -160,8 +160,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset, unsigned char memory[NATIVE_SLOT_MAX_SIZE]; memset(memory, 0, NATIVE_SLOT_MAX_SIZE); - if (!native_slot_set(intern->type, intern->msg_ce, memory, value - TSRMLS_CC)) { + if (!native_slot_set(intern->type, intern->msg_ce, memory, value TSRMLS_CC)) { return; } diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index af90ff33..b45d1b2a 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -199,8 +199,9 @@ static void *startseq_handler(void* closure, const void* hd) { // Handlers that append primitive values to a repeated field. #define DEFINE_APPEND_HANDLER(type, ctype) \ static bool append##type##_handler(void* closure, const void* hd, \ - ctype val TSRMLS_DC) { \ + ctype val) { \ zval* array = (zval*)closure; \ + TSRMLS_FETCH(); \ RepeatedField* intern = \ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \ repeated_field_push_native(intern, &val TSRMLS_CC); \ @@ -218,8 +219,9 @@ DEFINE_APPEND_HANDLER(double, double) // Appends a string to a repeated field. static void* appendstr_handler(void *closure, const void *hd, - size_t size_hint TSRMLS_DC) { + size_t size_hint) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -234,8 +236,9 @@ static void* appendstr_handler(void *closure, // Appends a 'bytes' string to a repeated field. static void* appendbytes_handler(void *closure, const void *hd, - size_t size_hint TSRMLS_DC) { + size_t size_hint) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -296,8 +299,9 @@ static size_t stringdata_handler(void* closure, const void* hd, } // Appends a submessage to a repeated field. -static void *appendsubmsg_handler(void *closure, const void *hd TSRMLS_DC) { +static void *appendsubmsg_handler(void *closure, const void *hd) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -319,10 +323,11 @@ static void *appendsubmsg_handler(void *closure, const void *hd TSRMLS_DC) { } // Sets a non-repeated submessage field in a message. -static void *submsg_handler(void *closure, const void *hd TSRMLS_DC) { +static void *submsg_handler(void *closure, const void *hd) { MessageHeader* msg = closure; const submsg_handlerdata_t* submsgdata = hd; zval* subdesc_php = get_def_obj((void*)submsgdata->md); + TSRMLS_FETCH(); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; @@ -465,11 +470,11 @@ static void *startmapentry_handler(void *closure, const void *hd) { // Handler to end a map entry: inserts the value defined during the message into // the map. This is the 'endmsg' handler on the map entry msgdef. -static bool endmap_handler(void *closure, const void *hd, upb_status* s - TSRMLS_DC) { +static bool endmap_handler(void* closure, const void* hd, upb_status* s) { map_parse_frame_t* frame = closure; const map_handlerdata_t* mapdata = hd; + TSRMLS_FETCH(); Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC); const char* keyval = NULL; @@ -575,12 +580,12 @@ static void *oneofbytes_handler(void *closure, } // Handler for a submessage field in a oneof. -static void *oneofsubmsg_handler(void *closure, - const void *hd TSRMLS_DC) { +static void* oneofsubmsg_handler(void* closure, const void* hd) { MessageHeader* msg = closure; const oneof_handlerdata_t *oneofdata = hd; uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t); zval* subdesc_php = get_def_obj((void*)oneofdata->md); + TSRMLS_FETCH(); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; @@ -773,9 +778,10 @@ static void add_handlers_for_oneof_field(upb_handlers *h, upb_handlerattr_uninit(&attr); } -static void add_handlers_for_message(const void *closure, upb_handlers *h - TSRMLS_DC) { +static void add_handlers_for_message(const void* closure, + upb_handlers* h) { const upb_msgdef* msgdef = upb_handlers_msgdef(h); + TSRMLS_FETCH(); Descriptor* desc = (Descriptor*)zend_object_store_get_object( get_def_obj((void*)msgdef) TSRMLS_CC); upb_msg_field_iter i; diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index fe9359fc..c215d72e 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -214,7 +214,6 @@ bool protobuf_convert_to_bool(zval* from, int8_t* to) { } else { *to = 1; } - STR_FREE(strval); } break; default: { zend_error(E_USER_ERROR, "Given value cannot be converted to bool."); diff --git a/php/tests/array_test.php b/php/tests/array_test.php index d683add5..09d4dc82 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -789,26 +789,26 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $this->assertSame(1, count($arr)); } - public function testInsertRemoval() - { - $arr = new RepeatedField(GPBType::INT32); - - $arr []= 0; - $arr []= 1; - $arr []= 2; - $this->assertSame(3, count($arr)); - - unset($arr[2]); - $this->assertSame(2, count($arr)); - $this->assertSame(0, $arr[0]); - $this->assertSame(1, $arr[1]); - - $arr [] = 3; - $this->assertSame(3, count($arr)); - $this->assertSame(0, $arr[0]); - $this->assertSame(1, $arr[1]); - $this->assertSame(3, $arr[2]); - } + public function testInsertRemoval() + { + $arr = new RepeatedField(GPBType::INT32); + + $arr []= 0; + $arr []= 1; + $arr []= 2; + $this->assertSame(3, count($arr)); + + unset($arr[2]); + $this->assertSame(2, count($arr)); + $this->assertSame(0, $arr[0]); + $this->assertSame(1, $arr[1]); + + $arr [] = 3; + $this->assertSame(3, count($arr)); + $this->assertSame(0, $arr[0]); + $this->assertSame(1, $arr[1]); + $this->assertSame(3, $arr[2]); + } /** * @expectedException PHPUnit_Framework_Error diff --git a/tests.sh b/tests.sh index ccf49f00..5823bff5 100755 --- a/tests.sh +++ b/tests.sh @@ -377,6 +377,7 @@ build_php5.5_mac() { build_php5.5_zts_c() { use_php_zts 5.5 + wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit cd php/tests && /bin/bash ./test.sh && cd ../.. } -- cgit v1.2.3 From 96e2d76491f7ea8aa33b524e7b0a2194b05c473a Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 5 Oct 2016 18:28:13 -0700 Subject: Fix compile error for php on Mac. --- .travis.yml | 2 +- php/ext/google/protobuf/array.c | 8 ++++---- php/ext/google/protobuf/def.c | 3 ++- php/ext/google/protobuf/encode_decode.c | 6 ++++-- php/ext/google/protobuf/map.c | 11 ++++++----- php/ext/google/protobuf/protobuf.c | 12 ++++++++++-- php/ext/google/protobuf/protobuf.h | 9 +-------- php/ext/google/protobuf/storage.c | 11 +++++++---- php/ext/google/protobuf/utf8.c | 2 +- php/tests/test.sh | 5 ----- tests.sh | 25 +++++++++++++++++++------ 11 files changed, 55 insertions(+), 39 deletions(-) (limited to 'php') diff --git a/.travis.yml b/.travis.yml index d331a26e..fd54ed1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ env: - CONFIG=ruby21 - CONFIG=ruby22 - CONFIG=jruby - - CONFIG=php5.5_mac + - CONFIG=php5.6_mac matrix: exclude: # It's nontrivial to programmatically install a new JDK from the command diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index c24ede81..215dcd46 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -169,7 +169,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset, } else { if (protobuf_convert_to_uint64(offset, &index)) { if (!zend_hash_index_exists(ht, index)) { - zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); + zend_error(E_USER_ERROR, "Element at %llu doesn't exist.\n", index); return; } } else { @@ -222,7 +222,7 @@ void repeated_field_create_with_type(zend_class_entry *ce, zend_object_store_get_object(*repeated_field TSRMLS_CC); intern->type = upb_fielddef_type(field); if (intern->type == UPB_TYPE_MESSAGE) { - upb_msgdef *msg = upb_fielddef_msgsubdef(field); + const upb_msgdef *msg = upb_fielddef_msgsubdef(field); zval *desc_php = get_def_obj(msg); Descriptor *desc = zend_object_store_get_object(desc_php TSRMLS_CC); intern->msg_ce = desc->klass; @@ -321,7 +321,7 @@ PHP_METHOD(RepeatedField, offsetGet) { HashTable *table = HASH_OF(intern->array); if (zend_hash_index_find(table, index, (void **)&memory) == FAILURE) { - zend_error(E_USER_ERROR, "Element at %d doesn't exist.\n", index); + zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index); return; } @@ -365,7 +365,7 @@ PHP_METHOD(RepeatedField, offsetUnset) { // Only the element at the end of the array can be removed. if (index == -1 || index != (zend_hash_num_elements(HASH_OF(intern->array)) - 1)) { - zend_error(E_USER_ERROR, "Cannot remove element at %d.\n", index); + zend_error(E_USER_ERROR, "Cannot remove element at %ld.\n", index); return; } diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index cbd0ec62..156eca07 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -318,7 +318,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { add_def_obj(desc->def_type_lower, desc_php); \ /* Unlike other messages, MapEntry is shared by all map fields and doesn't \ * have generated PHP class.*/ \ - if (upb_def_type(def) == UPB_DEF_MSG && upb_msgdef_mapentry(def)) { \ + if (upb_def_type(def) == UPB_DEF_MSG && \ + upb_msgdef_mapentry(upb_downcast_msgdef(def))) { \ break; \ } \ /* Prepend '.' to package name to make it absolute. */ \ diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index b45d1b2a..eafe1ae8 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -29,6 +29,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "protobuf.h" +#include "utf8.h" /* stringsink *****************************************************************/ @@ -416,7 +417,8 @@ static void map_slot_uninit(void* memory, upb_fieldtype_t type) { } } -static void map_slot_key(upb_fieldtype_t type, const void* from, char** keyval, +static void map_slot_key(upb_fieldtype_t type, const void* from, + const char** keyval, size_t* length) { if (type == UPB_TYPE_STRING) { zval* key_php = **(zval***)from; @@ -891,7 +893,7 @@ static upb_selector_t getsel(const upb_fielddef* f, upb_handlertype_t type) { return ret; } -static void put_optional_value(void* memory, int len, const upb_fielddef* f, +static void put_optional_value(const void* memory, int len, const upb_fielddef* f, int depth, upb_sink* sink TSRMLS_DC) { assert(upb_fielddef_label(f) == UPB_LABEL_OPTIONAL); diff --git a/php/ext/google/protobuf/map.c b/php/ext/google/protobuf/map.c index 6a80d978..35747b05 100644 --- a/php/ext/google/protobuf/map.c +++ b/php/ext/google/protobuf/map.c @@ -33,6 +33,7 @@ #include #include "protobuf.h" +#include "utf8.h" ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1) ZEND_ARG_INFO(0, index) @@ -152,7 +153,7 @@ static zend_function_entry map_field_methods[] = { zend_class_entry* map_field_type; zend_object_handlers* map_field_handlers; -static map_begin_internal(Map *map, MapIter *iter) { +static void map_begin_internal(Map *map, MapIter *iter) { iter->self = map; upb_strtable_begin(&iter->it, &map->table); } @@ -258,8 +259,8 @@ static void map_field_free_element(void *object) { // MapField Handlers // ----------------------------------------------------------------------------- -static bool *map_field_read_dimension(zval *object, zval *key, int type, - zval **retval TSRMLS_DC) { +static bool map_field_read_dimension(zval *object, zval *key, int type, + zval **retval TSRMLS_DC) { Map *intern = (Map *)zend_object_store_get_object(object TSRMLS_CC); @@ -398,7 +399,7 @@ PHP_METHOD(MapField, offsetExists) { v.ctype = UPB_CTYPE_UINT64; #endif if (!table_key(intern, key, keybuf, &keyval, &length TSRMLS_CC)) { - return false; + RETURN_BOOL(false); } RETURN_BOOL(upb_strtable_lookup2(&intern->table, keyval, length, &v)); @@ -434,7 +435,7 @@ PHP_METHOD(MapField, offsetUnset) { PHP_METHOD(MapField, count) { Map *intern = - (MapField *)zend_object_store_get_object(getThis() TSRMLS_CC); + (Map *)zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_parse_parameters_none() == FAILURE) { return; diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index d8ad3c88..019bca29 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -55,7 +55,7 @@ static void add_to_table(HashTable* t, const void* def, void* value) { uint nIndex = (ulong)def & t->nTableMask; zval* pDest = NULL; - zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), &pDest); + zend_hash_index_update(t, (zend_ulong)def, &value, sizeof(zval*), (void**)&pDest); } static void* get_from_table(const HashTable* t, const void* def) { @@ -69,7 +69,7 @@ static void* get_from_table(const HashTable* t, const void* def) { static void add_to_list(HashTable* t, void* value) { zval* pDest = NULL; - zend_hash_next_index_insert(t, &value, sizeof(void*), &pDest); + zend_hash_next_index_insert(t, &value, sizeof(void*), (void**)&pDest); } void add_def_obj(const void* def, zval* value) { @@ -134,6 +134,8 @@ static PHP_RINIT_FUNCTION(protobuf) { generated_pool = NULL; generated_pool_php = NULL; + + return 0; } static PHP_RSHUTDOWN_FUNCTION(protobuf) { @@ -147,6 +149,8 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { zval_dtor(generated_pool_php); FREE_ZVAL(generated_pool_php); } + + return 0; } static PHP_MINIT_FUNCTION(protobuf) { @@ -158,10 +162,14 @@ static PHP_MINIT_FUNCTION(protobuf) { descriptor_init(TSRMLS_C); enum_descriptor_init(TSRMLS_C); util_init(TSRMLS_C); + + return 0; } static PHP_MSHUTDOWN_FUNCTION(protobuf) { PEFREE(message_handlers); PEFREE(repeated_field_handlers); PEFREE(map_field_handlers); + + return 0; } diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 5edb15db..8a1d9261 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -70,14 +70,6 @@ typedef struct MapField MapField; ZEND_BEGIN_MODULE_GLOBALS(protobuf) ZEND_END_MODULE_GLOBALS(protobuf) -ZEND_DECLARE_MODULE_GLOBALS(protobuf) - -#ifdef ZTS -#define PROTOBUF_G(v) TSRMG(protobuf_globals_id, zend_protobuf_globals*, v) -#else -#define PROTOBUF_G(v) (protobuf_globals.v) -#endif - // Init module and PHP classes. void descriptor_init(TSRMLS_D); void enum_descriptor_init(TSRMLS_D); @@ -347,6 +339,7 @@ void* upb_value_memory(upb_value* v); // These operate on a map field (i.e., a repeated field of submessages whose // submessage type is a map-entry msgdef). +bool is_map_field(const upb_fielddef* field); const upb_fielddef* map_field_key(const upb_fielddef* field); const upb_fielddef* map_field_value(const upb_fielddef* field); diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index 56497f62..e94aa319 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -32,6 +32,8 @@ #include #include +#include "utf8.h" + // ----------------------------------------------------------------------------- // Native slot storage. // ----------------------------------------------------------------------------- @@ -210,7 +212,7 @@ CASE(ENUM, LONG, uint32_t) return; } default: - return EG(uninitialized_zval_ptr); + return; } } @@ -245,7 +247,7 @@ void native_slot_get_default(upb_fieldtype_t type, zval** cache TSRMLS_DC) { return; } default: - return EG(uninitialized_zval_ptr); + return; } } @@ -305,6 +307,7 @@ const zend_class_entry* field_type_class(const upb_fielddef* field TSRMLS_DC) { EnumDescriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); return desc->klass; } + return NULL; } // ----------------------------------------------------------------------------- @@ -517,7 +520,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, // zval in properties table first. switch (type) { case UPB_TYPE_MESSAGE: { - upb_msgdef* msg = upb_fielddef_msgsubdef(field); + const upb_msgdef* msg = upb_fielddef_msgsubdef(field); zval* desc_php = get_def_obj(msg); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); ce = desc->klass; @@ -551,7 +554,7 @@ void layout_set(MessageLayout* layout, MessageHeader* header, upb_fieldtype_t type = upb_fielddef_type(field); zend_class_entry *ce = NULL; if (type == UPB_TYPE_MESSAGE) { - upb_msgdef* msg = upb_fielddef_msgsubdef(field); + const upb_msgdef* msg = upb_fielddef_msgsubdef(field); zval* desc_php = get_def_obj(msg); Descriptor* desc = zend_object_store_get_object(desc_php TSRMLS_CC); ce = desc->klass; diff --git a/php/ext/google/protobuf/utf8.c b/php/ext/google/protobuf/utf8.c index a1541636..2752a08b 100644 --- a/php/ext/google/protobuf/utf8.c +++ b/php/ext/google/protobuf/utf8.c @@ -58,7 +58,7 @@ bool is_structurally_valid_utf8(const char* buf, int len) { return false; } for (j = i + 1; j < i + offset; j++) { - if (buf[j] & 0xc0 != 0x80) { + if ((buf[j] & 0xc0) != 0x80) { return false; } } diff --git a/php/tests/test.sh b/php/tests/test.sh index 15df768c..888e93eb 100755 --- a/php/tests/test.sh +++ b/php/tests/test.sh @@ -24,9 +24,4 @@ done # Make sure to run the memory test in debug mode. php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php -php --version -which php -pwd -ls -ls -l `which php` USE_ZEND_ALLOC=0 valgrind --leak-check=yes php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php diff --git a/tests.sh b/tests.sh index 5823bff5..a497f1d2 100755 --- a/tests.sh +++ b/tests.sh @@ -369,12 +369,6 @@ build_php5.5_c() { cd php/tests && /bin/bash ./test.sh && cd ../.. } -build_php5.5_mac() { - curl -s https://php-osx.liip.ch/install.sh | bash -s 5.5 - export PATH="/usr/local/php5-5.5.38-20160831-100002/bin:$PATH" - cd php/tests && /bin/bash ./test.sh && cd ../.. -} - build_php5.5_zts_c() { use_php_zts 5.5 wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit @@ -393,6 +387,25 @@ build_php5.6_c() { cd php/tests && /bin/bash ./test.sh && cd ../.. } +build_php5.6_mac() { + # Install PHP + curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6 + export PATH="/usr/local/php5-5.6.25-20160831-101628/bin:$PATH" + + # Install phpunit + curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar + chmod +x phpunit.phar + sudo mv phpunit.phar /usr/local/bin/phpunit + + # Install valgrind + echo "#! /bin/bash" > valgrind + chmod ug+x valgrind + sudo mv valgrind /usr/local/bin/valgrind + + # Test + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + build_php7.0() { use_php 7.0 rm -rf vendor -- cgit v1.2.3 From 60d95f36c0081a03b947c2b625c10841bb19736c Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 11 Oct 2016 10:36:25 -0700 Subject: Fix the bug that message without namespace is not found in the descriptor pool. (#2240) --- Makefile.am | 2 ++ php/ext/google/protobuf/def.c | 46 +++++++++++++++++++--------------- php/src/Google/Protobuf/descriptor.php | 10 +++++--- php/tests/generated_class_test.php | 9 +++++++ php/tests/test_no_namespace.pb.php | 34 +++++++++++++++++++++++++ php/tests/test_no_namespace.proto | 5 ++++ 6 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 php/tests/test_no_namespace.pb.php create mode 100644 php/tests/test_no_namespace.proto (limited to 'php') diff --git a/Makefile.am b/Makefile.am index 69d162e1..de197088 100644 --- a/Makefile.am +++ b/Makefile.am @@ -600,6 +600,8 @@ php_EXTRA_DIST= \ php/tests/test_include.pb.php \ php/tests/map_field_test.php \ php/tests/test_base.php \ + php/tests/test_no_namespace.proto \ + php/tests/test_no_namespace.pb.php \ php/tests/test_util.php \ php/tests/test.proto \ php/tests/test.pb.php \ diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 156eca07..5a8c3c25 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -250,28 +250,36 @@ PHP_METHOD(DescriptorPool, getGeneratedPool) { RETURN_ZVAL(generated_pool_php, 1, 0); } -static void convert_to_class_name_inplace(char *proto_name, - size_t pkg_name_len) { +static void convert_to_class_name_inplace(char *class_name, + const char* fullname, + const char* package_name) { size_t i; bool first_char = false; - - for (i = 0; i <= pkg_name_len + 1; i++) { - // PHP package uses camel case. - if (!first_char && proto_name[i] != '.') { - first_char = true; - proto_name[i] += 'A' - 'a'; - } - // php packages are divided by '\'. - if (proto_name[i] == '.') { - first_char = false; - proto_name[i] = '\\'; + size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name); + + if (pkg_name_len == 0) { + strcpy(class_name, fullname); + } else { + class_name[0] = '.'; + strcpy(&class_name[1], fullname); + for (i = 0; i <= pkg_name_len + 1; i++) { + // PHP package uses camel case. + if (!first_char && class_name[i] != '.') { + first_char = true; + class_name[i] += 'A' - 'a'; + } + // php packages are divided by '\'. + if (class_name[i] == '.') { + first_char = false; + class_name[i] = '\\'; + } } } // Submessage is concatenated with its containing messages by '_'. - for (i = pkg_name_len; i < strlen(proto_name); i++) { - if (proto_name[i] == '.') { - proto_name[i] = '_'; + for (i = pkg_name_len; i < strlen(class_name); i++) { + if (class_name[i] == '.') { + class_name[i] = '_'; } } } @@ -325,10 +333,8 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { /* Prepend '.' to package name to make it absolute. */ \ const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \ char *klass_name = ecalloc(sizeof(char), 2 + strlen(fullname)); \ - klass_name[0] = '.'; \ - strcpy(&klass_name[1], fullname); \ - size_t pkg_name_len = strlen(upb_filedef_package(files[0])); \ - convert_to_class_name_inplace(klass_name, pkg_name_len); \ + convert_to_class_name_inplace(klass_name, fullname, \ + upb_filedef_package(files[0])); \ zend_class_entry **pce; \ if (zend_lookup_class(klass_name, strlen(klass_name), &pce TSRMLS_CC) == \ FAILURE) { \ diff --git a/php/src/Google/Protobuf/descriptor.php b/php/src/Google/Protobuf/descriptor.php index afe08227..e5cff0ba 100644 --- a/php/src/Google/Protobuf/descriptor.php +++ b/php/src/Google/Protobuf/descriptor.php @@ -240,9 +240,13 @@ function getFullClassName( $class_name_without_package = implode('_', array_map('ucwords', explode('.', $message_name_without_package))); - $classname = - implode('\\', array_map('ucwords', explode('.', $package))). - "\\".$class_name_without_package; + if ($package === "") { + $classname = $class_name_without_package; + } else { + $classname = + implode('\\', array_map('ucwords', explode('.', $package))). + "\\".$class_name_without_package; + } } class OneofDescriptor diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index 56466cae..d1a0bd51 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -1,6 +1,7 @@ assertSame('', $m->getOneofString()); $this->assertSame(1, $m->getOneofMessage()->getA()); } + + ######################################################### + # Test oneof field. + ######################################################### + + public function testMessageWithoutNamespace() { + $m = new NoNameSpace(); + } } diff --git a/php/tests/test_no_namespace.pb.php b/php/tests/test_no_namespace.pb.php new file mode 100644 index 00000000..2f92c955 --- /dev/null +++ b/php/tests/test_no_namespace.pb.php @@ -0,0 +1,34 @@ +a; + } + + public function setA($var) + { + GPBUtil::checkInt32($var); + $this->a = $var; + } + +} + +$pool = DescriptorPool::getGeneratedPool(); + +$pool->internalAddGeneratedFile(hex2bin( + "0a3b0a17746573745f6e6f5f6e616d6573706163652e70726f746f22180a" . + "0b4e6f4e616d65537061636512090a0161180120012805620670726f746f" . + "33" +)); + diff --git a/php/tests/test_no_namespace.proto b/php/tests/test_no_namespace.proto new file mode 100644 index 00000000..4331aeab --- /dev/null +++ b/php/tests/test_no_namespace.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +message NoNameSpace { + int32 a = 1; +} -- cgit v1.2.3 From 51c5ff889ccd3836c25f40baafb350f92c9ee103 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 25 Oct 2016 17:27:05 -0700 Subject: Fix pure php implementation for 32-bit machine. (#2282) --- Makefile.am | 1 - composer.json | 3 +- jenkins/buildcmds/pull_request_32.sh | 2 +- jenkins/docker32/Dockerfile | 4 +- php/src/Google/Protobuf/Internal/GPBUtil.php | 41 ++++- php/src/Google/Protobuf/Internal/GPBWire.php | 47 +++--- php/src/Google/Protobuf/Internal/InputStream.php | 66 +++++++- php/src/Google/Protobuf/Internal/Message.php | 5 - php/src/Google/Protobuf/Internal/OutputStream.php | 51 +++++-- php/src/Google/Protobuf/Internal/Type.php | 175 ---------------------- php/tests/array_test.php | 111 +++++++++----- php/tests/generated_class_test.php | 65 ++++++-- php/tests/map_field_test.php | 56 +++++-- php/tests/php_implementation_test.php | 148 +++++++++++------- php/tests/test_base.php | 20 ++- php/tests/test_util.php | 121 ++++++++++----- tests.sh | 21 +++ 17 files changed, 545 insertions(+), 392 deletions(-) delete mode 100644 php/src/Google/Protobuf/Internal/Type.php (limited to 'php') diff --git a/Makefile.am b/Makefile.am index 7e47a119..4763d949 100644 --- a/Makefile.am +++ b/Makefile.am @@ -577,7 +577,6 @@ php_EXTRA_DIST= \ php/src/Google/Protobuf/Internal/DescriptorPool.php \ php/src/Google/Protobuf/Internal/OneofField.php \ php/src/Google/Protobuf/Internal/MapEntry.php \ - php/src/Google/Protobuf/Internal/Type.php \ php/src/Google/Protobuf/Internal/InputStream.php \ php/src/Google/Protobuf/Internal/OutputStream.php \ php/src/Google/Protobuf/Internal/MessageBuilderContext.php \ diff --git a/composer.json b/composer.json index 8b73a2b9..6afe71ce 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ }, "files": [ "php/src/Google/Protobuf/descriptor.php", - "php/src/Google/Protobuf/descriptor_internal.pb.php", - "php/src/Google/Protobuf/Internal/Type.php" + "php/src/Google/Protobuf/descriptor_internal.pb.php" ] } } diff --git a/jenkins/buildcmds/pull_request_32.sh b/jenkins/buildcmds/pull_request_32.sh index 99df2971..bf0fb7ff 100755 --- a/jenkins/buildcmds/pull_request_32.sh +++ b/jenkins/buildcmds/pull_request_32.sh @@ -12,5 +12,5 @@ export DOCKERFILE_DIR=jenkins/docker32 export DOCKER_RUN_SCRIPT=jenkins/pull_request_in_docker.sh export OUTPUT_DIR=testoutput -export TEST_SET="php_all" +export TEST_SET="php_all_32" ./jenkins/build_and_run_docker.sh diff --git a/jenkins/docker32/Dockerfile b/jenkins/docker32/Dockerfile index 73dfd8d5..015d273c 100644 --- a/jenkins/docker32/Dockerfile +++ b/jenkins/docker32/Dockerfile @@ -83,7 +83,9 @@ RUN wget http://am1.php.net/get/php-5.5.38.tar.bz2/from/this/mirror RUN mv mirror php-5.5.38.tar.bz2 RUN tar -xvf php-5.5.38.tar.bz2 RUN cd php-5.5.38 && ./configure --enable-maintainer-zts --prefix=/usr/local/php-5.5-zts && \ - make && make install + make && make install && make clean && cd .. +RUN cd php-5.5.38 && ./configure --enable-bcmath --prefix=/usr/local/php-5.5-bc && \ + make && make install && make clean && cd .. ################## # Python dependencies diff --git a/php/src/Google/Protobuf/Internal/GPBUtil.php b/php/src/Google/Protobuf/Internal/GPBUtil.php index 417a9729..30d7350f 100644 --- a/php/src/Google/Protobuf/Internal/GPBUtil.php +++ b/php/src/Google/Protobuf/Internal/GPBUtil.php @@ -37,6 +37,28 @@ use Google\Protobuf\Internal\RepeatedField; class GPBUtil { + public function divideInt64ToInt32($value, &$high, &$low, $trim = false) + { + $isNeg = (bccomp($value, 0) < 0); + if ($isNeg) { + $value = bcsub(0, $value); + } + $high = (int) bcdiv(bcadd($value, 1), 4294967296); + $low = (int) bcmod($value, 4294967296); + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high++; + } + } + + if ($trim) { + $high = 0; + } + } + public static function checkString(&$var, $check_utf8) { @@ -70,9 +92,14 @@ class GPBUtil public static function checkUint32(&$var) { if (is_numeric($var)) { - $var = intval($var); if (PHP_INT_SIZE === 8) { + $var = intval($var); $var |= ((-(($var >> 31) & 0x1)) & ~0xFFFFFFFF); + } else { + if (bccomp($var, 0x7FFFFFFF) > 0) { + $var = bcsub($var, "4294967296"); + } + $var = (int) $var; } } else { trigger_error("Expect integer.", E_USER_ERROR); @@ -82,7 +109,11 @@ class GPBUtil public static function checkInt64(&$var) { if (is_numeric($var)) { - $var = intval($var); + if (PHP_INT_SIZE == 8) { + $var = intval($var); + } else { + $var = bcdiv($var, 1, 0); + } } else { trigger_error("Expect integer.", E_USER_ERROR); } @@ -91,7 +122,11 @@ class GPBUtil public static function checkUint64(&$var) { if (is_numeric($var)) { - $var = intval($var); + if (PHP_INT_SIZE == 8) { + $var = intval($var); + } else { + $var = bcdiv($var, 1, 0); + } } else { trigger_error("Expect integer.", E_USER_ERROR); } diff --git a/php/src/Google/Protobuf/Internal/GPBWire.php b/php/src/Google/Protobuf/Internal/GPBWire.php index 0e741e15..7e2c124f 100644 --- a/php/src/Google/Protobuf/Internal/GPBWire.php +++ b/php/src/Google/Protobuf/Internal/GPBWire.php @@ -32,10 +32,6 @@ namespace Google\Protobuf\Internal; -use Google\Protobuf\Internal\GPBUtil; -use Google\Protobuf\Internal\Int64; -use Google\Protobuf\Internal\Uint64; - class GPBWire { @@ -150,20 +146,28 @@ class GPBWire public static function zigZagEncode64($int64) { - $a = $int64->copy()->leftShift(1); - $b = $int64->copy()->rightShift(63); - $result = $a->bitXor($b); - $uint64 = Uint64::newValue($result->high, $result->low); - return $uint64; + if (PHP_INT_SIZE == 4) { + if (bccomp($int64, 0) >= 0) { + return bcmul($int64, 2); + } else { + return bcsub(bcmul(bcsub(0, $int64), 2), 1); + } + } else { + return ($int64 << 1) ^ ($int64 >> 63); + } } public static function zigZagDecode64($uint64) { - $a = $uint64->copy()->rightShift(1); - $b = $uint64->oddMask(); - $result = $a->bitXor($b); - $int64 = Int64::newValue($result->high, $result->low); - return $int64; + if (PHP_INT_SIZE == 4) { + if (bcmod($uint64, 2) == 0) { + return bcdiv($uint64, 2, 0); + } else { + return bcsub(0, bcdiv(bcadd($uint64, 1), 2, 0)); + } + } else { + return (($uint64 >> 1) & 0x7FFFFFFFFFFFFFFF) ^ (-($uint64 & 1)); + } } public static function readInt32(&$input, &$value) @@ -227,11 +231,7 @@ class GPBWire public static function readSfixed64(&$input, &$value) { - if (!self::readFixed64($input, $value)) { - return false; - } - $value = Int64::newValue($value->high, $value->low); - return true; + return $input->readLittleEndian64($value); } public static function readFloat(&$input, &$value) @@ -259,7 +259,7 @@ class GPBWire if (!$input->readVarint64($value)) { return false; } - if ($value->high === 0 && $value->low === 0) { + if ($value == 0) { $value = false; } else { $value = true; @@ -324,8 +324,8 @@ class GPBWire public static function writeSint64(&$output, $value) { - $value = GPBWire::zigZagEncode64(GPBUtil::Int64($value)); - return $output->writeVarint64($value->toInteger()); + $value = GPBWire::zigZagEncode64($value); + return $output->writeVarint64($value); } public static function writeFixed32(&$output, $value) @@ -431,9 +431,8 @@ class GPBWire public static function sint64Size($value) { - $value = GPBUtil::Int64($value); $value = self::zigZagEncode64($value); - return self::varint64Size($value->toInteger()); + return self::varint64Size($value); } public static function varint64Size($value) diff --git a/php/src/Google/Protobuf/Internal/InputStream.php b/php/src/Google/Protobuf/Internal/InputStream.php index 18d07075..6d6c74e9 100644 --- a/php/src/Google/Protobuf/Internal/InputStream.php +++ b/php/src/Google/Protobuf/Internal/InputStream.php @@ -34,6 +34,24 @@ namespace Google\Protobuf\Internal; use Google\Protobuf\Internal\Uint64; +function combineInt32ToInt64($high, $low) +{ + $isNeg = $high < 0; + if ($isNeg) { + $high = ~$high; + $low = ~$low; + $low++; + if (!$low) { + $high++; + } + } + $result = bcadd(bcmul($high, 4294967296), $low); + if ($isNeg) { + $result = bcsub(0, $result); + } + return $result; +} + class InputStream { @@ -116,11 +134,23 @@ class InputStream if (!$this->readVarint64($var)) { return false; } - $var = $var->toInteger() & 0xFFFFFFFF; + + if (PHP_INT_SIZE == 4) { + $var = bcmod($var, 4294967296); + } else { + $var &= 0xFFFFFFFF; + } + // Convert large uint32 to int32. - if (PHP_INT_SIZE === 8 && ($var > 0x7FFFFFFF)) { - $var = $var | (0xFFFFFFFF << 32); + if ($var > 0x7FFFFFFF) { + if (PHP_INT_SIZE === 8) { + $var = $var | (0xFFFFFFFF << 32); + } else { + $var = bcsub($var, 4294967296); + } } + + $var = intval($var); return true; } @@ -130,7 +160,8 @@ class InputStream */ public function readVarint64(&$var) { - $result = new Uint64(0); + $high = 0; + $low = 0; $count = 0; $b = 0; @@ -142,12 +173,27 @@ class InputStream return false; } $b = ord($this->buffer[$this->current]); - $result->bitOr((new Uint64($b & 0x7F))->leftShift(7 * $count)); + $bits = 7 * $count; + if ($bits >= 32) { + $high |= (($b & 0x7F) << ($bits - 32)); + } else if ($bits > 25){ + $high_bits = $bits - 25; + $low = ($low | (($b & 0x7F) << $bits)) & (int) 0xFFFFFFFF; + $high = $b & ((0x1 << $high_bits) -1); + } else { + $low |= (($b & 0x7F) << $bits); + } + $this->advance(1); $count += 1; } while ($b & 0x80); - $var = $result; + if (PHP_INT_SIZE == 4) { + $var = combineInt32ToInt64($high, $low); + } else { + $var = ($high & 0xFFFFFFFF) << 32 | + ($low & 0xFFFFFFFF); + } return true; } @@ -161,7 +207,7 @@ class InputStream if (!$this->readVarint64($var)) { return false; } - $var = $var->toInteger(); + $var = (int)$var; return true; } @@ -197,7 +243,11 @@ class InputStream return false; } $high = unpack('V', $data)[1]; - $var = Uint64::newValue($high, $low); + if (PHP_INT_SIZE == 4) { + $var = combineInt32ToInt64($high, $low); + } else { + $var = ($high << 32) | $low; + } return true; } diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 7bdc6a8c..38513e91 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -210,13 +210,11 @@ class Message if (!GPBWire::readInt64($input, $value)) { return false; } - $value = $value->toInteger(); break; case GPBType::UINT64: if (!GPBWire::readUint64($input, $value)) { return false; } - $value = $value->toInteger(); break; case GPBType::INT32: if (!GPBWire::readInt32($input, $value)) { @@ -227,7 +225,6 @@ class Message if (!GPBWire::readFixed64($input, $value)) { return false; } - $value = $value->toInteger(); break; case GPBType::FIXED32: if (!GPBWire::readFixed32($input, $value)) { @@ -285,7 +282,6 @@ class Message if (!GPBWire::readSfixed64($input, $value)) { return false; } - $value = $value->toInteger(); break; case GPBType::SINT32: if (!GPBWire::readSint32($input, $value)) { @@ -296,7 +292,6 @@ class Message if (!GPBWire::readSint64($input, $value)) { return false; } - $value = $value->toInteger(); break; default: user_error("Unsupported type."); diff --git a/php/src/Google/Protobuf/Internal/OutputStream.php b/php/src/Google/Protobuf/Internal/OutputStream.php index fcc5ce6d..587ac352 100644 --- a/php/src/Google/Protobuf/Internal/OutputStream.php +++ b/php/src/Google/Protobuf/Internal/OutputStream.php @@ -90,8 +90,6 @@ class OutputStream public function writeRaw($data, $size) { if ($this->buffer_size < $size) { - var_dump($this->buffer_size); - var_dump($size); trigger_error("Output stream doesn't have enough buffer."); return false; } @@ -107,15 +105,28 @@ class OutputStream private static function writeVarintToArray($value, &$buffer, $trim = false) { $current = 0; - if ($trim) { - $value &= 0xFFFFFFFF; + + $high = 0; + $low = 0; + if (PHP_INT_SIZE == 4) { + GPBUtil::divideInt64ToInt32($value, $high, $low, $trim); + } else { + if ($trim) { + $low = $value & 0xFFFFFFFF; + } else { + $low = $value; + } } - while ($value >= 0x80 || $value < 0) { - $buffer[$current] = chr($value | 0x80); + + while ($low >= 0x80 || $low < 0) { + $buffer[$current] = chr($low | 0x80); $value = ($value >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7)); + $carry = ($high & 0x7F) << ((PHP_INT_SIZE << 3) - 7); + $high = ($high >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7)); + $low = (($low >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7)) | $carry); $current++; } - $buffer[$current] = chr($value); + $buffer[$current] = chr($low); return $current + 1; } @@ -130,14 +141,24 @@ class OutputStream private static function writeLittleEndian64ToArray($value, &$buffer) { - $buffer[0] = chr($value & 0x000000FF); - $buffer[1] = chr(($value >> 8) & 0x000000FF); - $buffer[2] = chr(($value >> 16) & 0x000000FF); - $buffer[3] = chr(($value >> 24) & 0x000000FF); - $buffer[4] = chr(($value >> 32) & 0x000000FF); - $buffer[5] = chr(($value >> 40) & 0x000000FF); - $buffer[6] = chr(($value >> 48) & 0x000000FF); - $buffer[7] = chr(($value >> 56) & 0x000000FF); + $high = 0; + $low = 0; + if (PHP_INT_SIZE == 4) { + GPBUtil::divideInt64ToInt32($value, $high, $low); + } else { + $low = $value & 0xFFFFFFFF; + $high = ($value >> 32) & 0xFFFFFFFF; + } + + $buffer[0] = chr($low & 0x000000FF); + $buffer[1] = chr(($low >> 8) & 0x000000FF); + $buffer[2] = chr(($low >> 16) & 0x000000FF); + $buffer[3] = chr(($low >> 24) & 0x000000FF); + $buffer[4] = chr($high & 0x000000FF); + $buffer[5] = chr(($high >> 8) & 0x000000FF); + $buffer[6] = chr(($high >> 16) & 0x000000FF); + $buffer[7] = chr(($high >> 24) & 0x000000FF); return 8; } + } diff --git a/php/src/Google/Protobuf/Internal/Type.php b/php/src/Google/Protobuf/Internal/Type.php deleted file mode 100644 index 088f0e0c..00000000 --- a/php/src/Google/Protobuf/Internal/Type.php +++ /dev/null @@ -1,175 +0,0 @@ -low = $value & 0xFFFFFFFF; - if (PHP_INT_SIZE === 8) { - $this->high = ($value >> 32) & 0xFFFFFFFF; - } - } - - // Return 0 for unsigned integers and 1 for signed integers. - protected function sign() - { - trigger_error("Not implemented", E_ERROR); - } - - public function leftShift($count) - { - if ($count > 63) { - $this->low = 0; - $this->high = 0; - return; - } - if ($count > 32) { - $this->high = $this->low; - $this->low = 0; - $count -= 32; - } - $mask = (1 << $count) - 1; - $this->high = (($this->high << $count) & 0xFFFFFFFF) | - (($this->low >> (32 - $count)) & $mask); - $this->low = ($this->low << $count) & 0xFFFFFFFF; - - $this->high &= 0xFFFFFFFF; - $this->low &= 0xFFFFFFFF; - return $this; - } - - public function rightShift($count) - { - $sign = (($this->high & 0x80000000) >> 31) & $this->sign(); - if ($count > 63) { - $this->low = -$sign; - $this->high = -$sign; - return; - } - if ($count > 32) { - $this->low = $this->high; - $this->high = -$sign; - $count -= 32; - } - $this->low = (($this->low >> $count) & 0xFFFFFFFF) | - (($this->high << (32 - $count)) & 0xFFFFFFFF); - $this->high = (($this->high >> $count) | (-$sign << $count)); - - $this->high &= 0xFFFFFFFF; - $this->low &= 0xFFFFFFFF; - - return $this; - } - - public function bitOr($var) - { - $this->high |= $var->high; - $this->low |= $var->low; - return $this; - } - - public function bitXor($var) - { - $this->high ^= $var->high; - $this->low ^= $var->low; - return $this; - } - - public function bitAnd($var) - { - $this->high &= $var->high; - $this->low &= $var->low; - return $this; - } - - // Even: all zero; Odd: all one. - public function oddMask() - { - $low = (-($this->low & 1)) & 0xFFFFFFFF; - $high = $low; - return UInt64::newValue($high, $low); - } - - public function toInteger() - { - if (PHP_INT_SIZE === 8) { - return ($this->high << 32) | $this->low; - } else { - return $this->low; - } - } - - public function copy() - { - return static::newValue($this->high, $this->low); - } -} - -class Uint64 extends GPBInteger -{ - - public static function newValue($high, $low) - { - $uint64 = new Uint64(0); - $uint64->high = $high; - $uint64->low = $low; - return $uint64; - } - - protected function sign() - { - return 0; - } -} - -class Int64 extends GPBInteger -{ - - public static function newValue($high, $low) - { - $int64 = new Int64(0); - $int64->high = $high; - $int64->low = $low; - return $int64; - } - - protected function sign() - { - return 1; - } -} diff --git a/php/tests/array_test.php b/php/tests/array_test.php index 09d4dc82..a118b54c 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -225,46 +225,68 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase // Test append. $arr []= MAX_INT64; - $this->assertSame(MAX_INT64, $arr[0]); $arr []= MIN_INT64; - $this->assertEquals(MIN_INT64, $arr[1]); - $arr []= 1.1; - $this->assertSame(1, $arr[2]); - $arr []= '2'; - $this->assertSame(2, $arr[3]); $arr []= '3.1'; - $this->assertSame(3, $arr[4]); $arr []= MAX_INT64_STRING; - $this->assertSame(MAX_INT64, $arr[5]); $arr []= MIN_INT64_STRING; - $this->assertEquals(MIN_INT64, $arr[6]); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_INT64, $arr[0]); + $this->assertSame(MIN_INT64, $arr[1]); + $this->assertSame('1', $arr[2]); + $this->assertSame('2', $arr[3]); + $this->assertSame('3', $arr[4]); + $this->assertSame(MAX_INT64_STRING, $arr[5]); + $this->assertSame(MIN_INT64_STRING, $arr[6]); + } else { + $this->assertSame(MAX_INT64, $arr[0]); + $this->assertSame(MIN_INT64, $arr[1]); + $this->assertSame(1, $arr[2]); + $this->assertSame(2, $arr[3]); + $this->assertSame(3, $arr[4]); + $this->assertSame(MAX_INT64, $arr[5]); + $this->assertSame(MIN_INT64, $arr[6]); + } + $this->assertEquals(7, count($arr)); for ($i = 0; $i < count($arr); $i++) { $arr[$i] = 0; - $this->assertSame(0, $arr[$i]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('0', $arr[$i]); + } else { + $this->assertSame(0, $arr[$i]); + } } // Test set. $arr [0]= MAX_INT64; - $this->assertSame(MAX_INT64, $arr[0]); $arr [1]= MIN_INT64; - $this->assertEquals(MIN_INT64, $arr[1]); - $arr [2]= 1.1; - $this->assertSame(1, $arr[2]); - $arr [3]= '2'; - $this->assertSame(2, $arr[3]); $arr [4]= '3.1'; - $this->assertSame(3, $arr[4]); $arr [5]= MAX_INT64_STRING; - $this->assertSame(MAX_INT64, $arr[5]); $arr [6]= MIN_INT64_STRING; - $this->assertEquals(MIN_INT64, $arr[6]); + + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_INT64_STRING, $arr[0]); + $this->assertSame(MIN_INT64_STRING, $arr[1]); + $this->assertSame('1', $arr[2]); + $this->assertSame('2', $arr[3]); + $this->assertSame('3', $arr[4]); + $this->assertSame(MAX_INT64_STRING, $arr[5]); + $this->assertEquals(MIN_INT64_STRING, $arr[6]); + } else { + $this->assertSame(MAX_INT64, $arr[0]); + $this->assertSame(MIN_INT64, $arr[1]); + $this->assertSame(1, $arr[2]); + $this->assertSame(2, $arr[3]); + $this->assertSame(3, $arr[4]); + $this->assertSame(MAX_INT64, $arr[5]); + $this->assertEquals(MIN_INT64, $arr[6]); + } } /** @@ -315,38 +337,57 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase // Test append. $arr []= MAX_UINT64; - $this->assertEquals(MAX_UINT64, $arr[0]); - $arr []= 1.1; - $this->assertSame(1, $arr[1]); - $arr []= '2'; - $this->assertSame(2, $arr[2]); $arr []= '3.1'; - $this->assertSame(3, $arr[3]); $arr []= MAX_UINT64_STRING; - $this->assertEquals(MAX_UINT64, $arr[4]); - $this->assertEquals(5, count($arr)); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $arr[0]); + $this->assertSame('1', $arr[1]); + $this->assertSame('2', $arr[2]); + $this->assertSame('3', $arr[3]); + $this->assertSame(MAX_UINT64_STRING, $arr[4]); + } else { + $this->assertSame(MAX_UINT64, $arr[0]); + $this->assertSame(1, $arr[1]); + $this->assertSame(2, $arr[2]); + $this->assertSame(3, $arr[3]); + $this->assertSame(MAX_UINT64, $arr[4]); + $this->assertSame(5, count($arr)); + } + + $this->assertSame(5, count($arr)); for ($i = 0; $i < count($arr); $i++) { $arr[$i] = 0; - $this->assertSame(0, $arr[$i]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('0', $arr[$i]); + } else { + $this->assertSame(0, $arr[$i]); + } } // Test set. $arr [0]= MAX_UINT64; - $this->assertEquals(MAX_UINT64, $arr[0]); - $arr [1]= 1.1; - $this->assertSame(1, $arr[1]); - $arr [2]= '2'; - $this->assertSame(2, $arr[2]); $arr [3]= '3.1'; - $this->assertSame(3, $arr[3]); $arr [4]= MAX_UINT64_STRING; - $this->assertEquals(MAX_UINT64, $arr[4]); + + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $arr[0]); + $this->assertSame('1', $arr[1]); + $this->assertSame('2', $arr[2]); + $this->assertSame('3', $arr[3]); + $this->assertSame(MAX_UINT64_STRING, $arr[4]); + } else { + $this->assertSame(MAX_UINT64, $arr[0]); + $this->assertSame(1, $arr[1]); + $this->assertSame(2, $arr[2]); + $this->assertSame(3, $arr[3]); + $this->assertSame(MAX_UINT64, $arr[4]); + } } /** diff --git a/php/tests/generated_class_test.php b/php/tests/generated_class_test.php index d1a0bd51..b3ecd3a1 100644 --- a/php/tests/generated_class_test.php +++ b/php/tests/generated_class_test.php @@ -148,17 +148,40 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase // Set float. $m->setOptionalInt64(1.1); - $this->assertSame(1, $m->getOptionalInt64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('1', $m->getOptionalInt64()); + } else { + $this->assertSame(1, $m->getOptionalInt64()); + } // Set string. $m->setOptionalInt64('2'); - $this->assertSame(2, $m->getOptionalInt64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('2', $m->getOptionalInt64()); + } else { + $this->assertSame(2, $m->getOptionalInt64()); + } + $m->setOptionalInt64('3.1'); - $this->assertSame(3, $m->getOptionalInt64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('3', $m->getOptionalInt64()); + } else { + $this->assertSame(3, $m->getOptionalInt64()); + } + $m->setOptionalInt64(MAX_INT64_STRING); - $this->assertSame(MAX_INT64, $m->getOptionalInt64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_INT64_STRING, $m->getOptionalInt64()); + } else { + $this->assertSame(MAX_INT64, $m->getOptionalInt64()); + } + $m->setOptionalInt64(MIN_INT64_STRING); - $this->assertEquals(MIN_INT64, $m->getOptionalInt64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MIN_INT64_STRING, $m->getOptionalInt64()); + } else { + $this->assertSame(MIN_INT64, $m->getOptionalInt64()); + } } /** @@ -189,19 +212,41 @@ class GeneratedClassTest extends PHPUnit_Framework_TestCase // Set integer. $m->setOptionalUint64(MAX_UINT64); - $this->assertEquals(MAX_UINT64, $m->getOptionalUint64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $m->getOptionalUint64()); + } else { + $this->assertSame(MAX_UINT64, $m->getOptionalUint64()); + } // Set float. $m->setOptionalUint64(1.1); - $this->assertSame(1, $m->getOptionalUint64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('1', $m->getOptionalUint64()); + } else { + $this->assertSame(1, $m->getOptionalUint64()); + } // Set string. $m->setOptionalUint64('2'); - $this->assertSame(2, $m->getOptionalUint64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('2', $m->getOptionalUint64()); + } else { + $this->assertSame(2, $m->getOptionalUint64()); + } + $m->setOptionalUint64('3.1'); - $this->assertSame(3, $m->getOptionalUint64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('3', $m->getOptionalUint64()); + } else { + $this->assertSame(3, $m->getOptionalUint64()); + } + $m->setOptionalUint64(MAX_UINT64_STRING); - $this->assertEquals(MAX_UINT64, $m->getOptionalUint64()); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $m->getOptionalUint64()); + } else { + $this->assertSame(MAX_UINT64, $m->getOptionalUint64()); + } } /** diff --git a/php/tests/map_field_test.php b/php/tests/map_field_test.php index d79d0da3..4e42361d 100644 --- a/php/tests/map_field_test.php +++ b/php/tests/map_field_test.php @@ -205,9 +205,14 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { // Test integer argument. $arr[MAX_INT64] = MAX_INT64; - $this->assertSame(MAX_INT64, $arr[MAX_INT64]); $arr[MIN_INT64] = MIN_INT64; - $this->assertEquals(MIN_INT64, $arr[MIN_INT64]); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]); + $this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]); + } else { + $this->assertSame(MAX_INT64, $arr[MAX_INT64]); + $this->assertSame(MIN_INT64, $arr[MIN_INT64]); + } $this->assertEquals(2, count($arr)); unset($arr[MAX_INT64]); unset($arr[MIN_INT64]); @@ -215,20 +220,31 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { // Test float argument. $arr[1.1] = 1.1; - $this->assertSame(1, $arr[1]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('1', $arr['1']); + } else { + $this->assertSame(1, $arr[1]); + } $this->assertEquals(1, count($arr)); unset($arr[1.1]); $this->assertEquals(0, count($arr)); // Test string argument. $arr['2'] = '2'; - $this->assertSame(2, $arr[2]); $arr['3.1'] = '3.1'; - $this->assertSame(3, $arr[3]); $arr[MAX_INT64_STRING] = MAX_INT64_STRING; - $this->assertSame(MAX_INT64, $arr[MAX_INT64]); $arr[MIN_INT64_STRING] = MIN_INT64_STRING; - $this->assertEquals(MIN_INT64, $arr[MIN_INT64]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('2', $arr['2']); + $this->assertSame('3', $arr['3']); + $this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]); + $this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]); + } else { + $this->assertSame(2, $arr[2]); + $this->assertSame(3, $arr[3]); + $this->assertSame(MAX_INT64, $arr[MAX_INT64]); + $this->assertSame(MIN_INT64, $arr[MIN_INT64]); + } $this->assertEquals(4, count($arr)); unset($arr['2']); unset($arr['3.1']); @@ -282,25 +298,41 @@ class MapFieldTest extends PHPUnit_Framework_TestCase { // Test integer argument. $arr[MAX_UINT64] = MAX_UINT64; - $this->assertEquals(MAX_UINT64, $arr[MAX_UINT64]); + if (PHP_INT_SIZE == 4) { + $this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]); + } else { + $this->assertSame(MAX_UINT64, $arr[MAX_UINT64]); + } $this->assertEquals(1, count($arr)); unset($arr[MAX_UINT64]); $this->assertEquals(0, count($arr)); // Test float argument. $arr[1.1] = 1.1; - $this->assertSame(1, $arr[1]); + if (PHP_INT_SIZE == 4) { + $this->assertSame('1', $arr['1']); + } else { + $this->assertSame(1, $arr[1]); + } $this->assertEquals(1, count($arr)); unset($arr[1.1]); $this->assertEquals(0, count($arr)); // Test string argument. $arr['2'] = '2'; - $this->assertSame(2, $arr[2]); $arr['3.1'] = '3.1'; - $this->assertSame(3, $arr[3]); $arr[MAX_UINT64_STRING] = MAX_UINT64_STRING; - $this->assertEquals(MAX_UINT64, $arr[MAX_UINT64]); + + if (PHP_INT_SIZE == 4) { + $this->assertSame('2', $arr['2']); + $this->assertSame('3', $arr['3']); + $this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]); + } else { + $this->assertSame(2, $arr[2]); + $this->assertSame(3, $arr[3]); + $this->assertSame(MAX_UINT64, $arr[MAX_UINT64]); + } + $this->assertEquals(3, count($arr)); unset($arr['2']); unset($arr['3.1']); diff --git a/php/tests/php_implementation_test.php b/php/tests/php_implementation_test.php index 82941dd2..485956cc 100644 --- a/php/tests/php_implementation_test.php +++ b/php/tests/php_implementation_test.php @@ -9,14 +9,10 @@ use Foo\TestMessage_Sub; use Foo\TestPackedMessage; use Google\Protobuf\Internal\InputStream; use Google\Protobuf\Internal\FileDescriptorSet; -use Google\Protobuf\Internal\GPBUtil; -use Google\Protobuf\Internal\Int64; -use Google\Protobuf\Internal\Uint64; use Google\Protobuf\Internal\GPBLabel; use Google\Protobuf\Internal\GPBType; use Google\Protobuf\Internal\GPBWire; use Google\Protobuf\Internal\OutputStream; -use Google\Protobuf\Internal\RepeatedField; class ImplementationTest extends TestBase { @@ -68,17 +64,17 @@ class ImplementationTest extends TestBase // Positive number. $input = new InputStream(hex2bin("01")); GPBWire::readInt64($input, $value); - $this->assertSame(1, $value->toInteger()); + $this->assertEquals(1, $value); // Negative number. $input = new InputStream(hex2bin("ffffffffffffffffff01")); GPBWire::readInt64($input, $value); - $this->assertSame(-1, $value->toInteger()); + $this->assertEquals(-1, $value); // Discard overflow bits. $input = new InputStream(hex2bin("ffffffffffffffffff0f")); GPBWire::readInt64($input, $value); - $this->assertSame(-1, $value->toInteger()); + $this->assertEquals(-1, $value); } public function testReadUint64() @@ -88,17 +84,17 @@ class ImplementationTest extends TestBase // Positive number. $input = new InputStream(hex2bin("01")); GPBWire::readUint64($input, $value); - $this->assertSame(1, $value->toInteger()); + $this->assertEquals(1, $value); // Negative number. $input = new InputStream(hex2bin("FFFFFFFFFFFFFFFFFF01")); GPBWire::readUint64($input, $value); - $this->assertSame(-1, $value->toInteger()); + $this->assertEquals(-1, $value); // Discard overflow bits. $input = new InputStream(hex2bin("FFFFFFFFFFFFFFFFFF0F")); GPBWire::readUint64($input, $value); - $this->assertSame(-1, $value->toInteger()); + $this->assertEquals(-1, $value); } public function testReadSint32() @@ -124,15 +120,15 @@ class ImplementationTest extends TestBase $input = new InputStream(hex2bin("00")); GPBWire::readSint64($input, $value); - $this->assertEquals(GPBUtil::Int64(0), $value); + $this->assertEquals(0, $value); $input = new InputStream(hex2bin("01")); GPBWire::readSint64($input, $value); - $this->assertEquals(GPBUtil::Int64(-1), $value); + $this->assertEquals(-1, $value); $input = new InputStream(hex2bin("02")); GPBWire::readSint64($input, $value); - $this->assertEquals(GPBUtil::Int64(1), $value); + $this->assertEquals(1, $value); } public function testReadFixed32() @@ -148,7 +144,11 @@ class ImplementationTest extends TestBase $value = null; $input = new InputStream(hex2bin("1234567812345678")); GPBWire::readFixed64($input, $value); - $this->assertEquals(Uint64::newValue(0x78563412, 0x78563412), $value); + if (PHP_INT_SIZE == 4) { + $this->assertSame("8671175386481439762", $value); + } else { + $this->assertSame(0x7856341278563412, $value); + } } public function testReadSfixed32() @@ -193,7 +193,11 @@ class ImplementationTest extends TestBase $value = null; $input = new InputStream(hex2bin("1234567812345678")); GPBWire::readSfixed64($input, $value); - $this->assertEquals(Int64::newValue(0x78563412, 0x78563412), $value); + if (PHP_INT_SIZE == 4) { + $this->assertSame("8671175386481439762", $value); + } else { + $this->assertSame(0x7856341278563412, $value); + } } public function testZigZagEncodeDecode() @@ -214,43 +218,65 @@ class ImplementationTest extends TestBase $this->assertSame(0x3FFFFFFF, GPBWire::zigZagDecode32(0x7FFFFFFE)); $this->assertSame(-1073741824, GPBWire::zigZagDecode32(0x7FFFFFFF)); $this->assertSame(0x7FFFFFFF, GPBWire::zigZagDecode32(0xFFFFFFFE)); - $this->assertSame(-2147483648, GPBWire::zigZagDecode32(0xFFFFFFFF)); - - $this->assertEquals(GPBUtil::Uint64(0), - GPBWire::zigZagEncode64(GPBUtil::Int64(0))); - $this->assertEquals(GPBUtil::Uint64(1), - GPBWire::zigZagEncode64(GPBUtil::Int64(-1))); - $this->assertEquals(GPBUtil::Uint64(2), - GPBWire::zigZagEncode64(GPBUtil::Int64(1))); - $this->assertEquals(GPBUtil::Uint64(3), - GPBWire::zigZagEncode64(GPBUtil::Int64(-2))); - $this->assertEquals( - GPBUtil::Uint64(0x000000007FFFFFFE), - GPBWire::zigZagEncode64(GPBUtil::Int64(0x000000003FFFFFFF))); - $this->assertEquals( - GPBUtil::Uint64(0x000000007FFFFFFF), - GPBWire::zigZagEncode64(GPBUtil::Int64(0xFFFFFFFFC0000000))); - $this->assertEquals( - GPBUtil::Uint64(0x00000000FFFFFFFE), - GPBWire::zigZagEncode64(GPBUtil::Int64(0x000000007FFFFFFF))); - $this->assertEquals( - GPBUtil::Uint64(0x00000000FFFFFFFF), - GPBWire::zigZagEncode64(GPBUtil::Int64(0xFFFFFFFF80000000))); - $this->assertEquals( - Uint64::newValue(4294967295, 4294967294), - GPBWire::zigZagEncode64(GPBUtil::Int64(0x7FFFFFFFFFFFFFFF))); - $this->assertEquals( - Uint64::newValue(4294967295, 4294967295), - GPBWire::zigZagEncode64(GPBUtil::Int64(0x8000000000000000))); - - $this->assertEquals(GPBUtil::Int64(0), - GPBWire::zigZagDecode64(GPBUtil::Uint64(0))); - $this->assertEquals(GPBUtil::Int64(-1), - GPBWire::zigZagDecode64(GPBUtil::Uint64(1))); - $this->assertEquals(GPBUtil::Int64(1), - GPBWire::zigZagDecode64(GPBUtil::Uint64(2))); - $this->assertEquals(GPBUtil::Int64(-2), - GPBWire::zigZagDecode64(GPBUtil::Uint64(3))); + $this->assertSame((int)-2147483648,GPBWire::zigZagDecode32(0xFFFFFFFF)); + + if (PHP_INT_SIZE == 4) { + $this->assertSame('0', GPBWire::zigZagEncode64(0)); + $this->assertSame('1', GPBWire::zigZagEncode64(-1)); + $this->assertSame('2', GPBWire::zigZagEncode64(1)); + $this->assertSame('3', GPBWire::zigZagEncode64(-2)); + $this->assertSame( + '2147483646', // 0x7FFFFFE + GPBWire::zigZagEncode64(0x3FFFFFFF)); + $this->assertSame( + '2147483647', // 0x7FFFFFF + GPBWire::zigZagEncode64(-1073741824)); // 0xFFFFFFFFC0000000 + $this->assertSame( + '4294967294', // 0xFFFFFFFE + GPBWire::zigZagEncode64(2147483647)); // 0x7FFFFFFF + $this->assertSame( + '4294967295', // 0xFFFFFFFF + GPBWire::zigZagEncode64(-2147483648)); // 0xFFFFFFFF80000000 + $this->assertSame( + '18446744073709551614', // 0xFFFFFFFFFFFFFFFE + // 0x7FFFFFFFFFFFFFFF + GPBWire::zigZagEncode64("9223372036854775807")); + $this->assertSame( + '18446744073709551615', // 0xFFFFFFFFFFFFFFFF + // 0x8000000000000000 + GPBWire::zigZagEncode64("-9223372036854775808")); + + $this->assertSame('0', GPBWire::zigZagDecode64(0)); + $this->assertSame('-1', GPBWire::zigZagDecode64(1)); + $this->assertSame('1', GPBWire::zigZagDecode64(2)); + $this->assertSame('-2', GPBWire::zigZagDecode64(3)); + } else { + $this->assertSame(0, GPBWire::zigZagEncode64(0)); + $this->assertSame(1, GPBWire::zigZagEncode64(-1)); + $this->assertSame(2, GPBWire::zigZagEncode64(1)); + $this->assertSame(3, GPBWire::zigZagEncode64(-2)); + $this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode64(0x3FFFFFFF)); + $this->assertSame( + 0x7FFFFFFF, + GPBWire::zigZagEncode64(0xFFFFFFFFC0000000)); + $this->assertSame( + 0xFFFFFFFE, + GPBWire::zigZagEncode64(0x7FFFFFFF)); + $this->assertSame( + 0xFFFFFFFF, + GPBWire::zigZagEncode64(0xFFFFFFFF80000000)); + $this->assertSame( + -2, // 0xFFFFFFFFFFFFFFFE + GPBWire::zigZagEncode64(0x7FFFFFFFFFFFFFFF)); + $this->assertSame( + -1, // 0xFFFFFFFFFFFFFFFF + GPBWire::zigZagEncode64(0x8000000000000000)); + + $this->assertSame(0, GPBWire::zigZagDecode64(0)); + $this->assertSame(-1, GPBWire::zigZagDecode64(1)); + $this->assertSame(1, GPBWire::zigZagDecode64(2)); + $this->assertSame(-2, GPBWire::zigZagDecode64(3)); + } // Round trip $this->assertSame(0, GPBWire::zigZagDecode32(GPBWire::zigZagEncode32(0))); @@ -319,15 +345,27 @@ class ImplementationTest extends TestBase // Normal case. $input = new InputStream(hex2bin('808001')); $this->assertTrue($input->readVarint64($var)); - $this->assertSame(16384, $var->toInteger()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('16384', $var); + } else { + $this->assertSame(16384, $var); + } $this->assertFalse($input->readVarint64($var)); // Read two varint. $input = new InputStream(hex2bin('808001808002')); $this->assertTrue($input->readVarint64($var)); - $this->assertSame(16384, $var->toInteger()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('16384', $var); + } else { + $this->assertSame(16384, $var); + } $this->assertTrue($input->readVarint64($var)); - $this->assertSame(32768, $var->toInteger()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('32768', $var); + } else { + $this->assertSame(32768, $var); + } $this->assertFalse($input->readVarint64($var)); } diff --git a/php/tests/test_base.php b/php/tests/test_base.php index 25f18f74..49886050 100644 --- a/php/tests/test_base.php +++ b/php/tests/test_base.php @@ -13,22 +13,28 @@ class TestBase extends PHPUnit_Framework_TestCase public function expectFields(TestMessage $m) { - $this->assertSame(-42, $m->getOptionalInt32()); - $this->assertSame(42, $m->getOptionalUint32()); - $this->assertSame(-43, $m->getOptionalInt64()); - $this->assertSame(43, $m->getOptionalUint64()); $this->assertSame(-44, $m->getOptionalSint32()); - $this->assertSame(-45, $m->getOptionalSint64()); $this->assertSame(46, $m->getOptionalFixed32()); - $this->assertSame(47, $m->getOptionalFixed64()); $this->assertSame(-46, $m->getOptionalSfixed32()); - $this->assertSame(-47, $m->getOptionalSfixed64()); $this->assertSame(1.5, $m->getOptionalFloat()); $this->assertSame(1.6, $m->getOptionalDouble()); $this->assertSame(true, $m->getOptionalBool()); $this->assertSame('a', $m->getOptionalString()); $this->assertSame('b', $m->getOptionalBytes()); $this->assertSame(33, $m->getOptionalMessage()->getA()); + if (PHP_INT_SIZE == 4) { + $this->assertSame('-43', $m->getOptionalInt64()); + $this->assertSame('43', $m->getOptionalUint64()); + $this->assertSame('-45', $m->getOptionalSint64()); + $this->assertSame('47', $m->getOptionalFixed64()); + $this->assertSame('-47', $m->getOptionalSfixed64()); + } else { + $this->assertSame(-43, $m->getOptionalInt64()); + $this->assertSame(43, $m->getOptionalUint64()); + $this->assertSame(-45, $m->getOptionalSint64()); + $this->assertSame(47, $m->getOptionalFixed64()); + $this->assertSame(-47, $m->getOptionalSfixed64()); + } $this->assertEquals(-42, $m->getRepeatedInt32()[0]); $this->assertEquals(42, $m->getRepeatedUint32()[0]); diff --git a/php/tests/test_util.php b/php/tests/test_util.php index 2f6e4dd8..7f2aae15 100644 --- a/php/tests/test_util.php +++ b/php/tests/test_util.php @@ -20,7 +20,7 @@ define('MAX_INT32', 2147483647); define('MAX_INT32_FLOAT', 2147483647.0); define('MAX_INT32_STRING', '2147483647'); -define('MIN_INT32', -2147483648); +define('MIN_INT32', (int)-2147483648); define('MIN_INT32_FLOAT', -2147483648.0); define('MIN_INT32_STRING', '-2147483648'); @@ -28,23 +28,24 @@ define('MAX_UINT32', 4294967295); define('MAX_UINT32_FLOAT', 4294967295.0); define('MAX_UINT32_STRING', '4294967295'); -define('MIN_UINT32', -2147483648); +define('MIN_UINT32', (int)-2147483648); define('MIN_UINT32_FLOAT', -2147483648.0); define('MIN_UINT32_STRING', '-2147483648'); -define('MAX_INT64', 9223372036854775807); -define('MAX_INT64_STRING', '9223372036854775807'); +define('MAX_INT64_STRING', '9223372036854775807'); +define('MIN_INT64_STRING', '-9223372036854775808'); +define('MAX_UINT64_STRING', '-9223372036854775808'); -define('MIN_INT64_STRING', '-9223372036854775808'); if (PHP_INT_SIZE === 8) { - define('MIN_INT64', -9223372036854775808); + define('MAX_INT64', (int)9223372036854775807); + define('MIN_INT64', (int)-9223372036854775808); + define('MAX_UINT64', (int)-9223372036854775808); } else { + define('MAX_INT64', MAX_INT64_STRING); define('MIN_INT64', MIN_INT64_STRING); + define('MAX_UINT64', MAX_UINT64_STRING); } -define('MAX_UINT64_STRING', '-9223372036854775808'); -define('MAX_UINT64', MAX_UINT64_STRING); - class TestUtil { @@ -129,16 +130,24 @@ class TestUtil public static function assertTestMessage(TestMessage $m) { + if (PHP_INT_SIZE == 4) { + assert('-43' === $m->getOptionalInt64()); + assert('43' === $m->getOptionalUint64()); + assert('-45' === $m->getOptionalSint64()); + assert('47' === $m->getOptionalFixed64()); + assert('-47' === $m->getOptionalSfixed64()); + } else { + assert(-43 === $m->getOptionalInt64()); + assert(43 === $m->getOptionalUint64()); + assert(-45 === $m->getOptionalSint64()); + assert(47 === $m->getOptionalFixed64()); + assert(-47 === $m->getOptionalSfixed64()); + } assert(-42 === $m->getOptionalInt32()); assert(42 === $m->getOptionalUint32()); - assert(-43 === $m->getOptionalInt64()); - assert(43 === $m->getOptionalUint64()); assert(-44 === $m->getOptionalSint32()); - assert(-45 === $m->getOptionalSint64()); assert(46 === $m->getOptionalFixed32()); - assert(47 === $m->getOptionalFixed64()); assert(-46 === $m->getOptionalSfixed32()); - assert(-47 === $m->getOptionalSfixed64()); assert(1.5 === $m->getOptionalFloat()); assert(1.6 === $m->getOptionalDouble()); assert(true=== $m->getOptionalBool()); @@ -147,16 +156,24 @@ class TestUtil assert(TestEnum::ONE === $m->getOptionalEnum()); assert(33 === $m->getOptionalMessage()->getA()); + if (PHP_INT_SIZE == 4) { + assert('-43' === $m->getRepeatedInt64()[0]); + assert('43' === $m->getRepeatedUint64()[0]); + assert('-45' === $m->getRepeatedSint64()[0]); + assert('47' === $m->getRepeatedFixed64()[0]); + assert('-47' === $m->getRepeatedSfixed64()[0]); + } else { + assert(-43 === $m->getRepeatedInt64()[0]); + assert(43 === $m->getRepeatedUint64()[0]); + assert(-45 === $m->getRepeatedSint64()[0]); + assert(47 === $m->getRepeatedFixed64()[0]); + assert(-47 === $m->getRepeatedSfixed64()[0]); + } assert(-42 === $m->getRepeatedInt32()[0]); assert(42 === $m->getRepeatedUint32()[0]); - assert(-43 === $m->getRepeatedInt64()[0]); - assert(43 === $m->getRepeatedUint64()[0]); assert(-44 === $m->getRepeatedSint32()[0]); - assert(-45 === $m->getRepeatedSint64()[0]); assert(46 === $m->getRepeatedFixed32()[0]); - assert(47 === $m->getRepeatedFixed64()[0]); assert(-46 === $m->getRepeatedSfixed32()[0]); - assert(-47 === $m->getRepeatedSfixed64()[0]); assert(1.5 === $m->getRepeatedFloat()[0]); assert(1.6 === $m->getRepeatedDouble()[0]); assert(true=== $m->getRepeatedBool()[0]); @@ -165,16 +182,24 @@ class TestUtil assert(TestEnum::ZERO === $m->getRepeatedEnum()[0]); assert(34 === $m->getRepeatedMessage()[0]->getA()); + if (PHP_INT_SIZE == 4) { + assert('-53' === $m->getRepeatedInt64()[1]); + assert('53' === $m->getRepeatedUint64()[1]); + assert('-55' === $m->getRepeatedSint64()[1]); + assert('57' === $m->getRepeatedFixed64()[1]); + assert('-57' === $m->getRepeatedSfixed64()[1]); + } else { + assert(-53 === $m->getRepeatedInt64()[1]); + assert(53 === $m->getRepeatedUint64()[1]); + assert(-55 === $m->getRepeatedSint64()[1]); + assert(57 === $m->getRepeatedFixed64()[1]); + assert(-57 === $m->getRepeatedSfixed64()[1]); + } assert(-52 === $m->getRepeatedInt32()[1]); assert(52 === $m->getRepeatedUint32()[1]); - assert(-53 === $m->getRepeatedInt64()[1]); - assert(53 === $m->getRepeatedUint64()[1]); assert(-54 === $m->getRepeatedSint32()[1]); - assert(-55 === $m->getRepeatedSint64()[1]); assert(56 === $m->getRepeatedFixed32()[1]); - assert(57 === $m->getRepeatedFixed64()[1]); assert(-56 === $m->getRepeatedSfixed32()[1]); - assert(-57 === $m->getRepeatedSfixed64()[1]); assert(2.5 === $m->getRepeatedFloat()[1]); assert(2.6 === $m->getRepeatedDouble()[1]); assert(false === $m->getRepeatedBool()[1]); @@ -183,14 +208,21 @@ class TestUtil assert(TestEnum::ONE === $m->getRepeatedEnum()[1]); assert(35 === $m->getRepeatedMessage()[1]->getA()); + if (PHP_INT_SIZE == 4) { + assert('-63' === $m->getMapInt64Int64()['-63']); + assert('63' === $m->getMapUint64Uint64()['63']); + assert('-65' === $m->getMapSint64Sint64()['-65']); + assert('67' === $m->getMapFixed64Fixed64()['67']); + } else { + assert(-63 === $m->getMapInt64Int64()[-63]); + assert(63 === $m->getMapUint64Uint64()[63]); + assert(-65 === $m->getMapSint64Sint64()[-65]); + assert(67 === $m->getMapFixed64Fixed64()[67]); + } assert(-62 === $m->getMapInt32Int32()[-62]); - assert(-63 === $m->getMapInt64Int64()[-63]); assert(62 === $m->getMapUint32Uint32()[62]); - assert(63 === $m->getMapUint64Uint64()[63]); assert(-64 === $m->getMapSint32Sint32()[-64]); - assert(-65 === $m->getMapSint64Sint64()[-65]); assert(66 === $m->getMapFixed32Fixed32()[66]); - assert(67 === $m->getMapFixed64Fixed64()[67]); assert(3.5 === $m->getMapInt32Float()[1]); assert(3.6 === $m->getMapInt32Double()[1]); assert(true === $m->getMapBoolBool()[true]); @@ -325,24 +357,14 @@ class TestUtil assert(-42 === $m->getRepeatedInt32()[0]); assert(-52 === $m->getRepeatedInt32()[1]); - assert(-43 === $m->getRepeatedInt64()[0]); - assert(-53 === $m->getRepeatedInt64()[1]); assert(42 === $m->getRepeatedUint32()[0]); assert(52 === $m->getRepeatedUint32()[1]); - assert(43 === $m->getRepeatedUint64()[0]); - assert(53 === $m->getRepeatedUint64()[1]); assert(-44 === $m->getRepeatedSint32()[0]); assert(-54 === $m->getRepeatedSint32()[1]); - assert(-45 === $m->getRepeatedSint64()[0]); - assert(-55 === $m->getRepeatedSint64()[1]); assert(46 === $m->getRepeatedFixed32()[0]); assert(56 === $m->getRepeatedFixed32()[1]); - assert(47 === $m->getRepeatedFixed64()[0]); - assert(57 === $m->getRepeatedFixed64()[1]); assert(-46 === $m->getRepeatedSfixed32()[0]); assert(-56 === $m->getRepeatedSfixed32()[1]); - assert(-47 === $m->getRepeatedSfixed64()[0]); - assert(-57 === $m->getRepeatedSfixed64()[1]); assert(1.5 === $m->getRepeatedFloat()[0]); assert(2.5 === $m->getRepeatedFloat()[1]); assert(1.6 === $m->getRepeatedDouble()[0]); @@ -351,6 +373,29 @@ class TestUtil assert(false === $m->getRepeatedBool()[1]); assert(TestEnum::ONE === $m->getRepeatedEnum()[0]); assert(TestEnum::ZERO === $m->getRepeatedEnum()[1]); + if (PHP_INT_SIZE == 4) { + assert('-43' === $m->getRepeatedInt64()[0]); + assert('-53' === $m->getRepeatedInt64()[1]); + assert('43' === $m->getRepeatedUint64()[0]); + assert('53' === $m->getRepeatedUint64()[1]); + assert('-45' === $m->getRepeatedSint64()[0]); + assert('-55' === $m->getRepeatedSint64()[1]); + assert('47' === $m->getRepeatedFixed64()[0]); + assert('57' === $m->getRepeatedFixed64()[1]); + assert('-47' === $m->getRepeatedSfixed64()[0]); + assert('-57' === $m->getRepeatedSfixed64()[1]); + } else { + assert(-43 === $m->getRepeatedInt64()[0]); + assert(-53 === $m->getRepeatedInt64()[1]); + assert(43 === $m->getRepeatedUint64()[0]); + assert(53 === $m->getRepeatedUint64()[1]); + assert(-45 === $m->getRepeatedSint64()[0]); + assert(-55 === $m->getRepeatedSint64()[1]); + assert(47 === $m->getRepeatedFixed64()[0]); + assert(57 === $m->getRepeatedFixed64()[1]); + assert(-47 === $m->getRepeatedSfixed64()[0]); + assert(-57 === $m->getRepeatedSfixed64()[1]); + } } public static function getGoldenTestPackedMessage() diff --git a/tests.sh b/tests.sh index fb7044f3..1335c06b 100755 --- a/tests.sh +++ b/tests.sh @@ -358,6 +358,16 @@ use_php_zts() { ln -sfn "/usr/local/php-${VERSION}-zts/bin/phpize" $PHPIZE } +use_php_bc() { + VERSION=$1 + PHP=`which php` + PHP_CONFIG=`which php-config` + PHPIZE=`which phpize` + ln -sfn "/usr/local/php-${VERSION}-bc/bin/php" $PHP + ln -sfn "/usr/local/php-${VERSION}-bc/bin/php-config" $PHP_CONFIG + ln -sfn "/usr/local/php-${VERSION}-bc/bin/phpize" $PHPIZE +} + build_php5.5() { use_php 5.5 rm -rf vendor @@ -376,6 +386,13 @@ build_php5.5_zts_c() { cd php/tests && /bin/bash ./test.sh && cd ../.. } +build_php5.5_32() { + use_php_bc 5.5 + rm -rf vendor + cp -r /usr/local/vendor-5.5 vendor + ./vendor/bin/phpunit +} + build_php5.6() { use_php 5.6 rm -rf vendor @@ -429,6 +446,10 @@ build_php_all() { build_php5.5_zts_c } +build_php_all_32() { + build_php5.5_32 +} + # Note: travis currently does not support testing more than one language so the # .travis.yml cheats and claims to only be cpp. If they add multiple language # support, this should probably get updated to install steps and/or -- cgit v1.2.3 From 1f2dbc899b634f3236e1923a90683eebed283d52 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 8 Nov 2016 11:38:34 -0800 Subject: Implement RepeatedFieldIter for c extension. (#2333) --- php/ext/google/protobuf/array.c | 127 ++++++++++++++++++++++++++++++++++++- php/ext/google/protobuf/protobuf.c | 1 + php/ext/google/protobuf/protobuf.h | 16 +++++ php/tests/array_test.php | 11 ++++ tests.sh | 3 +- 5 files changed, 155 insertions(+), 3 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index 215dcd46..e4a88c39 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -54,6 +54,16 @@ static zend_function_entry repeated_field_methods[] = { PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC) PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + +static zend_function_entry repeated_field_iter_methods[] = { + PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC) + PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC) ZEND_FE_END }; @@ -70,11 +80,15 @@ static int repeated_field_has_dimension(zval *object, zval *offset TSRMLS_DC); static HashTable *repeated_field_get_gc(zval *object, zval ***table, int *n TSRMLS_DC); +static zend_object_value repeated_field_iter_create(zend_class_entry *ce TSRMLS_DC); +static void repeated_field_iter_free(void *object TSRMLS_DC); + // ----------------------------------------------------------------------------- // RepeatedField creation/desctruction // ----------------------------------------------------------------------------- zend_class_entry* repeated_field_type; +zend_class_entry* repeated_field_iter_type; zend_object_handlers* repeated_field_handlers; void repeated_field_init(TSRMLS_D) { @@ -86,8 +100,8 @@ void repeated_field_init(TSRMLS_D) { repeated_field_type = zend_register_internal_class(&class_type TSRMLS_CC); repeated_field_type->create_object = repeated_field_create; - zend_class_implements(repeated_field_type TSRMLS_CC, 2, spl_ce_ArrayAccess, - spl_ce_Countable); + zend_class_implements(repeated_field_type TSRMLS_CC, 3, spl_ce_ArrayAccess, + zend_ce_aggregate, spl_ce_Countable); repeated_field_handlers = PEMALLOC(zend_object_handlers); memcpy(repeated_field_handlers, zend_get_std_object_handlers(), @@ -386,3 +400,112 @@ PHP_METHOD(RepeatedField, count) { RETURN_LONG(zend_hash_num_elements(HASH_OF(intern->array))); } + +/** + * Return the beginning iterator. + * This will also be called for: foreach($arr) + * @return object Beginning iterator. + */ +PHP_METHOD(RepeatedField, getIterator) { + zval *iter_php = NULL; + MAKE_STD_ZVAL(iter_php); + Z_TYPE_P(iter_php) = IS_OBJECT; + Z_OBJVAL_P(iter_php) = repeated_field_iter_type->create_object( + repeated_field_iter_type TSRMLS_CC); + + RepeatedField *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedFieldIter *iter = zend_object_store_get_object(iter_php TSRMLS_CC); + iter->repeated_field = intern; + iter->position = 0; + + RETURN_ZVAL(iter_php, 1, 1); +} + +// ----------------------------------------------------------------------------- +// RepeatedFieldIter creation/desctruction +// ----------------------------------------------------------------------------- + +void repeated_field_iter_init(TSRMLS_D) { + zend_class_entry class_type; + const char* class_name = "Google\\Protobuf\\Internal\\RepeatedFieldIter"; + INIT_CLASS_ENTRY_EX(class_type, class_name, strlen(class_name), + repeated_field_iter_methods); + + repeated_field_iter_type = + zend_register_internal_class(&class_type TSRMLS_CC); + repeated_field_iter_type->create_object = repeated_field_iter_create; + + zend_class_implements(repeated_field_iter_type TSRMLS_CC, 1, + zend_ce_iterator); +} + +static zend_object_value repeated_field_iter_create( + zend_class_entry *ce TSRMLS_DC) { + zend_object_value retval = {0}; + RepeatedFieldIter *intern; + + intern = emalloc(sizeof(RepeatedFieldIter)); + memset(intern, 0, sizeof(RepeatedFieldIter)); + + zend_object_std_init(&intern->std, ce TSRMLS_CC); + object_properties_init(&intern->std, ce); + + intern->repeated_field = NULL; + intern->position = 0; + + retval.handle = zend_objects_store_put( + intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, + (zend_objects_free_object_storage_t)repeated_field_iter_free, + NULL TSRMLS_CC); + retval.handlers = zend_get_std_object_handlers(); + + return retval; +} + +static void repeated_field_iter_free(void *object TSRMLS_DC) { + RepeatedFieldIter *intern = object; + zend_object_std_dtor(&intern->std TSRMLS_CC); + efree(object); +} + +// ----------------------------------------------------------------------------- +// PHP RepeatedFieldIter Methods +// ----------------------------------------------------------------------------- + +PHP_METHOD(RepeatedFieldIter, rewind) { + RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + intern->position = 0; +} + +PHP_METHOD(RepeatedFieldIter, current) { + RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RepeatedField *repeated_field = intern->repeated_field; + + long index; + void *memory; + + HashTable *table = HASH_OF(repeated_field->array); + + if (zend_hash_index_find(table, intern->position, (void **)&memory) == + FAILURE) { + zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index); + return; + } + native_slot_get(repeated_field->type, memory, return_value_ptr TSRMLS_CC); +} + +PHP_METHOD(RepeatedFieldIter, key) { + RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RETURN_LONG(intern->position); +} + +PHP_METHOD(RepeatedFieldIter, next) { + RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + ++intern->position; +} + +PHP_METHOD(RepeatedFieldIter, valid) { + RepeatedFieldIter *intern = zend_object_store_get_object(getThis() TSRMLS_CC); + RETURN_BOOL(zend_hash_num_elements(HASH_OF(intern->repeated_field->array)) > + intern->position); +} diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index 019bca29..ea85b999 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -156,6 +156,7 @@ static PHP_RSHUTDOWN_FUNCTION(protobuf) { static PHP_MINIT_FUNCTION(protobuf) { map_field_init(TSRMLS_C); repeated_field_init(TSRMLS_C); + repeated_field_iter_init(TSRMLS_C); gpb_type_init(TSRMLS_C); message_init(TSRMLS_C); descriptor_pool_init(TSRMLS_C); diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 8a1d9261..93027bc1 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -51,6 +51,7 @@ struct MessageField; struct MessageHeader; struct MessageLayout; struct RepeatedField; +struct RepeatedFieldIter; struct MapField; typedef struct DescriptorPool DescriptorPool; @@ -61,6 +62,7 @@ typedef struct MessageField MessageField; typedef struct MessageHeader MessageHeader; typedef struct MessageLayout MessageLayout; typedef struct RepeatedField RepeatedField; +typedef struct RepeatedFieldIter RepeatedFieldIter; typedef struct MapField MapField; // ----------------------------------------------------------------------------- @@ -77,6 +79,7 @@ void descriptor_pool_init(TSRMLS_D); void gpb_type_init(TSRMLS_D); void map_field_init(TSRMLS_D); void repeated_field_init(TSRMLS_D); +void repeated_field_iter_init(TSRMLS_D); void util_init(TSRMLS_D); void message_init(TSRMLS_D); @@ -366,6 +369,12 @@ struct RepeatedField { // (for message field only). }; +struct RepeatedFieldIter { + zend_object std; + RepeatedField* repeated_field; + long position; +}; + void repeated_field_create_with_type(zend_class_entry* ce, const upb_fielddef* field, zval** repeated_field TSRMLS_DC); @@ -383,6 +392,13 @@ PHP_METHOD(RepeatedField, offsetGet); PHP_METHOD(RepeatedField, offsetSet); PHP_METHOD(RepeatedField, offsetUnset); PHP_METHOD(RepeatedField, count); +PHP_METHOD(RepeatedField, getIterator); + +PHP_METHOD(RepeatedFieldIter, rewind); +PHP_METHOD(RepeatedFieldIter, current); +PHP_METHOD(RepeatedFieldIter, key); +PHP_METHOD(RepeatedFieldIter, next); +PHP_METHOD(RepeatedFieldIter, valid); // ----------------------------------------------------------------------------- // Oneof Field. diff --git a/php/tests/array_test.php b/php/tests/array_test.php index a118b54c..a79a08bc 100644 --- a/php/tests/array_test.php +++ b/php/tests/array_test.php @@ -65,6 +65,17 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase $this->assertSame(3, $arr[6]); $arr [7]= MAX_INT32_STRING; $this->assertSame(MAX_INT32, $arr[7]); + + // Test foreach. + $arr = new RepeatedField(GPBType::INT32); + for ($i = 0; $i < 3; $i++) { + $arr []= $i; + } + $i = 0; + foreach ($arr as $val) { + $this->assertSame($i++, $val); + } + $this->assertSame(3, $i); } /** diff --git a/tests.sh b/tests.sh index 1335c06b..7a12f267 100755 --- a/tests.sh +++ b/tests.sh @@ -408,7 +408,8 @@ build_php5.6_c() { build_php5.6_mac() { # Install PHP curl -s https://php-osx.liip.ch/install.sh | bash -s 5.6 - export PATH="/usr/local/php5-5.6.25-20160831-101628/bin:$PATH" + PHP_FOLDER=`find /usr/local -type d -name "php5-5.6*"` # The folder name may change upon time + export PATH="$PHP_FOLDER/bin:$PATH" # Install phpunit curl https://phar.phpunit.de/phpunit.phar -L -o phpunit.phar -- cgit v1.2.3 From df8390790aae6025e95687a37eea81a4757966d0 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 10 Nov 2016 11:20:50 -0800 Subject: Fix php c extension on 32-bit machines. (#2348) --- php/ext/google/protobuf/protobuf.h | 3 + php/ext/google/protobuf/storage.c | 24 ++++- php/ext/google/protobuf/type_check.c | 139 +++++++++++++++++++++++++-- php/src/Google/Protobuf/Internal/Message.php | 10 ++ php/tests/test.sh | 3 +- php/tests/test_base.php | 18 +++- tests.sh | 7 ++ 7 files changed, 187 insertions(+), 17 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 93027bc1..fb5879dc 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -39,6 +39,9 @@ #define PHP_PROTOBUF_EXTNAME "protobuf" #define PHP_PROTOBUF_VERSION "3.1.0a1" +#define MAX_LENGTH_OF_INT64 20 +#define SIZEOF_INT64 8 + // ----------------------------------------------------------------------------- // Forward Declaration // ---------------------------------------------------------------------------- diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index e94aa319..1d25a91b 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -174,11 +174,31 @@ CASE(FLOAT, DOUBLE, float) CASE(DOUBLE, DOUBLE, double) CASE(BOOL, BOOL, int8_t) CASE(INT32, LONG, int32_t) -CASE(INT64, LONG, int64_t) -CASE(UINT64, LONG, uint64_t) CASE(ENUM, LONG, uint32_t) #undef CASE + +#if SIZEOF_LONG == 4 +#define CASE(upb_type, c_type) \ + case UPB_TYPE_##upb_type: { \ + SEPARATE_ZVAL_IF_NOT_REF(cache); \ + char buffer[MAX_LENGTH_OF_INT64]; \ + sprintf(buffer, "%lld", DEREF(memory, c_type)); \ + ZVAL_STRING(*cache, buffer, 1); \ + return; \ + } +#else +#define CASE(upb_type, c_type) \ + case UPB_TYPE_##upb_type: { \ + SEPARATE_ZVAL_IF_NOT_REF(cache); \ + ZVAL_LONG(*cache, DEREF(memory, c_type)); \ + return; \ + } +#endif +CASE(UINT64, uint64_t) +CASE(INT64, int64_t) +#undef CASE + case UPB_TYPE_UINT32: { // Prepend bit-1 for negative numbers, so that uint32 value will be // consistent on both 32-bit and 64-bit architectures. diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index c215d72e..d12d0025 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -34,6 +34,7 @@ #include "utf8.h" static zend_class_entry* util_type; +static const char int64_min_digits[] = "9223372036854775808"; ZEND_BEGIN_ARG_INFO_EX(arg_check_optional, 0, 0, 1) ZEND_ARG_INFO(1, val) @@ -78,8 +79,128 @@ void util_init(TSRMLS_D) { // Type checking/conversion. // ----------------------------------------------------------------------------- +// This is modified from is_numeric_string in zend_operators.h. The behavior of +// this function is the same as is_numeric_string, except that this takes +// int64_t as input instead of long. +static zend_uchar convert_numeric_string( + const char *str, int length, int64_t *lval, double *dval) { + const char *ptr; + int base = 10, digits = 0, dp_or_e = 0; + double local_dval = 0.0; + zend_uchar type; + + if (length == 0) { + return IS_NULL; + } + + while (*str == ' ' || *str == '\t' || *str == '\n' || + *str == '\r' || *str == '\v' || *str == '\f') { + str++; + length--; + } + ptr = str; + + if (*ptr == '-' || *ptr == '+') { + ptr++; + } + + if (ZEND_IS_DIGIT(*ptr)) { + // Handle hex numbers + // str is used instead of ptr to disallow signs and keep old behavior. + if (length > 2 && *str == '0' && (str[1] == 'x' || str[1] == 'X')) { + base = 16; + ptr += 2; + } + + // Skip any leading 0s. + while (*ptr == '0') { + ptr++; + } + + // Count the number of digits. If a decimal point/exponent is found, + // it's a double. Otherwise, if there's a dval or no need to check for + // a full match, stop when there are too many digits for a int64 */ + for (type = IS_LONG; + !(digits >= MAX_LENGTH_OF_INT64 && dval); + digits++, ptr++) { +check_digits: + if (ZEND_IS_DIGIT(*ptr) || (base == 16 && ZEND_IS_XDIGIT(*ptr))) { + continue; + } else if (base == 10) { + if (*ptr == '.' && dp_or_e < 1) { + goto process_double; + } else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) { + const char *e = ptr + 1; + + if (*e == '-' || *e == '+') { + ptr = e++; + } + if (ZEND_IS_DIGIT(*e)) { + goto process_double; + } + } + } + break; + } + + if (base == 10) { + if (digits >= MAX_LENGTH_OF_INT64) { + dp_or_e = -1; + goto process_double; + } + } else if (!(digits < SIZEOF_INT64 * 2 || + (digits == SIZEOF_INT64 * 2 && ptr[-digits] <= '7'))) { + if (dval) { + local_dval = zend_hex_strtod(str, &ptr); + } + type = IS_DOUBLE; + } + } else if (*ptr == '.' && ZEND_IS_DIGIT(ptr[1])) { +process_double: + type = IS_DOUBLE; + + // If there's a dval, do the conversion; else continue checking + // the digits if we need to check for a full match. + if (dval) { + local_dval = zend_strtod(str, &ptr); + } else if (dp_or_e != -1) { + dp_or_e = (*ptr++ == '.') ? 1 : 2; + goto check_digits; + } + } else { + return IS_NULL; + } + if (ptr != str + length) { + zend_error(E_NOTICE, "A non well formed numeric value encountered"); + return 0; + } + + if (type == IS_LONG) { + if (digits == MAX_LENGTH_OF_INT64 - 1) { + int cmp = strcmp(&ptr[-digits], int64_min_digits); + + if (!(cmp < 0 || (cmp == 0 && *str == '-'))) { + if (dval) { + *dval = zend_strtod(str, NULL); + } + + return IS_DOUBLE; + } + } + if (lval) { + *lval = strtoll(str, NULL, base); + } + return IS_LONG; + } else { + if (dval) { + *dval = local_dval; + } + return IS_DOUBLE; + } +} + #define CONVERT_TO_INTEGER(type) \ - static bool convert_long_to_##type(long val, type##_t* type##_value) { \ + static bool convert_int64_to_##type(int64_t val, type##_t* type##_value) { \ *type##_value = (type##_t)val; \ return true; \ } \ @@ -91,15 +212,15 @@ void util_init(TSRMLS_D) { \ static bool convert_string_to_##type(const char* val, int len, \ type##_t* type##_value) { \ - long lval; \ + int64_t lval; \ double dval; \ \ - switch (is_numeric_string(val, len, &lval, &dval, 0)) { \ + switch (convert_numeric_string(val, len, &lval, &dval)) { \ case IS_DOUBLE: { \ return convert_double_to_##type(dval, type##_value); \ } \ case IS_LONG: { \ - return convert_long_to_##type(lval, type##_value); \ + return convert_int64_to_##type(lval, type##_value); \ } \ default: \ zend_error(E_USER_ERROR, \ @@ -111,7 +232,7 @@ void util_init(TSRMLS_D) { bool protobuf_convert_to_##type(zval* from, type##_t* to) { \ switch (Z_TYPE_P(from)) { \ case IS_LONG: { \ - return convert_long_to_##type(Z_LVAL_P(from), to); \ + return convert_int64_to_##type(Z_LVAL_P(from), to); \ } \ case IS_DOUBLE: { \ return convert_double_to_##type(Z_DVAL_P(from), to); \ @@ -137,7 +258,7 @@ CONVERT_TO_INTEGER(uint64); #undef CONVERT_TO_INTEGER #define CONVERT_TO_FLOAT(type) \ - static bool convert_long_to_##type(long val, type* type##_value) { \ + static bool convert_int64_to_##type(int64_t val, type* type##_value) { \ *type##_value = (type)val; \ return true; \ } \ @@ -149,10 +270,10 @@ CONVERT_TO_INTEGER(uint64); \ static bool convert_string_to_##type(const char* val, int len, \ type* type##_value) { \ - long lval; \ + int64_t lval; \ double dval; \ \ - switch (is_numeric_string(val, len, &lval, &dval, 0)) { \ + switch (convert_numeric_string(val, len, &lval, &dval)) { \ case IS_DOUBLE: { \ *type##_value = (type)dval; \ return true; \ @@ -171,7 +292,7 @@ CONVERT_TO_INTEGER(uint64); bool protobuf_convert_to_##type(zval* from, type* to) { \ switch (Z_TYPE_P(from)) { \ case IS_LONG: { \ - return convert_long_to_##type(Z_LVAL_P(from), to); \ + return convert_int64_to_##type(Z_LVAL_P(from), to); \ } \ case IS_DOUBLE: { \ return convert_double_to_##type(Z_DVAL_P(from), to); \ diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index 38513e91..3d1f1598 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -125,6 +125,16 @@ class Message $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()]; $oneof_name = $oneof->getName(); $this->$oneof_name = new OneofField($oneof); + } else if ($field->getLabel() === GPBLabel::OPTIONAL && + PHP_INT_SIZE == 4) { + switch ($field->getType()) { + case GPBType::INT64: + case GPBType::UINT64: + case GPBType::FIXED64: + case GPBType::SFIXED64: + case GPBType::SINT64: + $this->$setter("0"); + } } } } diff --git a/php/tests/test.sh b/php/tests/test.sh index 888e93eb..fe3dc7f6 100755 --- a/php/tests/test.sh +++ b/php/tests/test.sh @@ -7,7 +7,8 @@ pushd ../ext/google/protobuf/ make clean set -e -phpize && ./configure --enable-debug CFLAGS='-g -O0' && make +# Add following in configure for debug: --enable-debug CFLAGS='-g -O0' +phpize && ./configure && make popd tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php ) diff --git a/php/tests/test_base.php b/php/tests/test_base.php index 49886050..d461f0f7 100644 --- a/php/tests/test_base.php +++ b/php/tests/test_base.php @@ -75,20 +75,28 @@ class TestBase extends PHPUnit_Framework_TestCase { $this->assertSame(0, $m->getOptionalInt32()); $this->assertSame(0, $m->getOptionalUint32()); - $this->assertSame(0, $m->getOptionalInt64()); - $this->assertSame(0, $m->getOptionalUint64()); $this->assertSame(0, $m->getOptionalSint32()); - $this->assertSame(0, $m->getOptionalSint64()); $this->assertSame(0, $m->getOptionalFixed32()); - $this->assertSame(0, $m->getOptionalFixed64()); $this->assertSame(0, $m->getOptionalSfixed32()); - $this->assertSame(0, $m->getOptionalSfixed64()); $this->assertSame(0.0, $m->getOptionalFloat()); $this->assertSame(0.0, $m->getOptionalDouble()); $this->assertSame(false, $m->getOptionalBool()); $this->assertSame('', $m->getOptionalString()); $this->assertSame('', $m->getOptionalBytes()); $this->assertNull($m->getOptionalMessage()); + if (PHP_INT_SIZE == 4) { + $this->assertSame("0", $m->getOptionalInt64()); + $this->assertSame("0", $m->getOptionalUint64()); + $this->assertSame("0", $m->getOptionalSint64()); + $this->assertSame("0", $m->getOptionalFixed64()); + $this->assertSame("0", $m->getOptionalSfixed64()); + } else { + $this->assertSame(0, $m->getOptionalInt64()); + $this->assertSame(0, $m->getOptionalUint64()); + $this->assertSame(0, $m->getOptionalSint64()); + $this->assertSame(0, $m->getOptionalFixed64()); + $this->assertSame(0, $m->getOptionalSfixed64()); + } } // This test is to avoid the warning of no test by php unit. diff --git a/tests.sh b/tests.sh index 7a12f267..4ac6b7c6 100755 --- a/tests.sh +++ b/tests.sh @@ -393,6 +393,12 @@ build_php5.5_32() { ./vendor/bin/phpunit } +build_php5.5_c_32() { + use_php_bc 5.5 + wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit + cd php/tests && /bin/bash ./test.sh && cd ../.. +} + build_php5.6() { use_php 5.6 rm -rf vendor @@ -449,6 +455,7 @@ build_php_all() { build_php_all_32() { build_php5.5_32 + build_php5.5_c_32 } # Note: travis currently does not support testing more than one language so the -- cgit v1.2.3 From 99564c3347223b92e49bd40f37b8c0d6fc6a3971 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Wed, 16 Nov 2016 11:07:43 -0800 Subject: Rename Empty to GPBEmpty in php generated file. In php, class name cannot be "Empty". Modified code generator to (#2375) generate GPBEmpty instead (for google.protobuf.Empty only). Also change runtime code to work with the new generated code accordingly. --- php/ext/google/protobuf/def.c | 11 +++++++-- php/ext/google/protobuf/message.c | 4 ++-- php/src/Google/Protobuf/descriptor.php | 15 +++++++++++- php/tests/google/protobuf/empty.pb.php | 28 +++++++++++++++++++++++ php/tests/test.sh | 2 +- php/tests/well_known_test.php | 13 +++++++++++ phpunit.xml | 1 + src/google/protobuf/compiler/php/php_generator.cc | 18 +++++++++++++-- 8 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 php/tests/google/protobuf/empty.pb.php create mode 100644 php/tests/well_known_test.php (limited to 'php') diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 5a8c3c25..6ea2cc93 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -257,6 +257,11 @@ static void convert_to_class_name_inplace(char *class_name, bool first_char = false; size_t pkg_name_len = package_name == NULL ? 0 : strlen(package_name); + // In php, class name cannot be Empty. + if (strcmp("google.protobuf.Empty", fullname) == 0) { + fullname = "google.protobuf.GPBEmpty"; + } + if (pkg_name_len == 0) { strcpy(class_name, fullname); } else { @@ -330,9 +335,11 @@ PHP_METHOD(DescriptorPool, internalAddGeneratedFile) { upb_msgdef_mapentry(upb_downcast_msgdef(def))) { \ break; \ } \ - /* Prepend '.' to package name to make it absolute. */ \ + /* Prepend '.' to package name to make it absolute. In the 5 additional \ + * bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if \ + * given message is google.protobuf.Empty.*/ \ const char *fullname = upb_##def_type_lower##_fullname(def_type_lower); \ - char *klass_name = ecalloc(sizeof(char), 2 + strlen(fullname)); \ + char *klass_name = ecalloc(sizeof(char), 5 + strlen(fullname)); \ convert_to_class_name_inplace(klass_name, fullname, \ upb_filedef_package(files[0])); \ zend_class_entry **pce; \ diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index cb46031e..d8fbbe11 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -177,8 +177,8 @@ static zend_object_value message_create(zend_class_entry* ce TSRMLS_DC) { zend_object_std_init(&msg->std, ce TSRMLS_CC); object_properties_init(&msg->std, ce); - layout_init(desc->layout, message_data(msg), msg->std.properties_table - TSRMLS_CC); + layout_init(desc->layout, message_data(msg), + msg->std.properties_table TSRMLS_CC); return_value.handle = zend_objects_store_put( msg, (zend_objects_store_dtor_t)zend_objects_destroy_object, message_free, diff --git a/php/src/Google/Protobuf/descriptor.php b/php/src/Google/Protobuf/descriptor.php index e5cff0ba..ef6b9dcf 100644 --- a/php/src/Google/Protobuf/descriptor.php +++ b/php/src/Google/Protobuf/descriptor.php @@ -215,6 +215,18 @@ class Descriptor return $desc; } } + +function addPrefixIfSpecial( + $name, + $package) +{ + if ($name === "Empty" && $package === "google.protobuf") { + return "GPBEmpty"; + } else { + return $name; + } +} + function getFullClassName( $proto, $containing, @@ -224,7 +236,8 @@ function getFullClassName( &$fullname) { // Full name needs to start with '.'. - $message_name_without_package = $proto->getName(); + $message_name_without_package = + addPrefixIfSpecial($proto->getName(), $package); if ($containing !== "") { $message_name_without_package = $containing . "." . $message_name_without_package; diff --git a/php/tests/google/protobuf/empty.pb.php b/php/tests/google/protobuf/empty.pb.php new file mode 100644 index 00000000..fdd0fe4f --- /dev/null +++ b/php/tests/google/protobuf/empty.pb.php @@ -0,0 +1,28 @@ +internalAddGeneratedFile(hex2bin( + "0ab7010a1b676f6f676c652f70726f746f6275662f656d7074792e70726f" . + "746f120f676f6f676c652e70726f746f62756622070a05456d7074794276" . + "0a13636f6d2e676f6f676c652e70726f746f627566420a456d7074795072" . + "6f746f50015a276769746875622e636f6d2f676f6c616e672f70726f746f" . + "6275662f7074797065732f656d707479f80101a20203475042aa021e476f" . + "6f676c652e50726f746f6275662e57656c6c4b6e6f776e54797065736206" . + "70726f746f33" +)); + diff --git a/php/tests/test.sh b/php/tests/test.sh index fe3dc7f6..a6ca89b9 100755 --- a/php/tests/test.sh +++ b/php/tests/test.sh @@ -11,7 +11,7 @@ set -e phpize && ./configure && make popd -tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php ) +tests=( array_test.php encode_decode_test.php generated_class_test.php map_field_test.php well_known_test.php ) for t in "${tests[@]}" do diff --git a/php/tests/well_known_test.php b/php/tests/well_known_test.php new file mode 100644 index 00000000..30715ba9 --- /dev/null +++ b/php/tests/well_known_test.php @@ -0,0 +1,13 @@ +php/tests/encode_decode_test.php php/tests/generated_class_test.php php/tests/map_field_test.php + php/tests/well_known_test.php diff --git a/src/google/protobuf/compiler/php/php_generator.cc b/src/google/protobuf/compiler/php/php_generator.cc index 75ddb405..83e629b9 100644 --- a/src/google/protobuf/compiler/php/php_generator.cc +++ b/src/google/protobuf/compiler/php/php_generator.cc @@ -70,6 +70,16 @@ void GenerateEnum(const google::protobuf::EnumDescriptor* en, void Indent(google::protobuf::io::Printer* printer); void Outdent(google::protobuf::io::Printer* printer); +std::string MessagePrefix(const google::protobuf::Descriptor* message) { + // Empty cannot be php class name. + if (message->name() == "Empty" && + message->file()->package() == "google.protobuf") { + return "GPB"; + } else { + return ""; + } +} + std::string MessageName(const google::protobuf::Descriptor* message, bool is_descriptor) { string message_name = message->name(); @@ -78,6 +88,8 @@ std::string MessageName(const google::protobuf::Descriptor* message, message_name = descriptor->name() + '_' + message_name; descriptor = descriptor->containing_type(); } + message_name = MessagePrefix(message) + message_name; + return PhpName(message->file()->package(), is_descriptor) + '\\' + message_name; } @@ -483,8 +495,10 @@ void GenerateMessage(const string& name_prefix, return; } - string message_name = name_prefix.empty()? - message->name() : name_prefix + "_" + message->name(); + string message_name = + name_prefix.empty() + ? message->name() + : name_prefix + "_" + MessagePrefix(message) + message->name(); printer->Print( "class @name@ extends \\Google\\Protobuf\\Internal\\Message\n" -- cgit v1.2.3