From 132457932cfee5f1eb1f7468c9045f4fe2516b07 Mon Sep 17 00:00:00 2001 From: Joseph Griego Date: Tue, 11 Sep 2018 07:43:49 -0700 Subject: [PATCH] Suppress Hack arr notices in thrift binary deserialization Summary: binary_serialize constructs a PHP array temporarily when it serializes a thrift map--for Hack `Map`s with intish keys, this raises a notice Reviewed By: ricklavoie Differential Revision: D9759729 fbshipit-source-id: f289f5870930b34349f2f60332453bb6df4a0df0 --- hphp/runtime/ext/thrift/binary.cpp | 2 + hphp/test/slow/hack_arr_compat/thrift_map.php | 93 ++++++++++++++++++++++ .../slow/hack_arr_compat/thrift_map.php.expect | 15 ++++ .../slow/hack_arr_compat/thrift_map.php.hphp_opts | 2 + hphp/test/slow/hack_arr_compat/thrift_map.php.opts | 2 + 5 files changed, 114 insertions(+) create mode 100644 hphp/test/slow/hack_arr_compat/thrift_map.php create mode 100644 hphp/test/slow/hack_arr_compat/thrift_map.php.expect create mode 100644 hphp/test/slow/hack_arr_compat/thrift_map.php.hphp_opts create mode 100644 hphp/test/slow/hack_arr_compat/thrift_map.php.opts diff --git a/hphp/runtime/ext/thrift/binary.cpp b/hphp/runtime/ext/thrift/binary.cpp index 4f079aa0704..686c608e16f 100644 --- a/hphp/runtime/ext/thrift/binary.cpp +++ b/hphp/runtime/ext/thrift/binary.cpp @@ -696,6 +696,8 @@ void HHVM_FUNCTION(thrift_protocol_write_binary, const Object& obj_request_struct = request_struct; + SuppressHackArrCompatNotices suppressNotices; + Variant spec(get_tspec(obj_request_struct->getVMClass())); binary_serialize_spec(obj_request_struct, transport, spec.toArray()); diff --git a/hphp/test/slow/hack_arr_compat/thrift_map.php b/hphp/test/slow/hack_arr_compat/thrift_map.php new file mode 100644 index 00000000000..22d0cd13d41 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/thrift_map.php @@ -0,0 +1,93 @@ +t = new DummyTransport(); + } + function getTransport() { + return $this->t; + } +} + +class DummyTransport { + public $buff = ''; + public $pos = 0; + function flush() { + } + function onewayFlush() {} + function write($buff) { + $this->buff .= $buff; + } + function read($n) { + $r = substr($this->buff, $this->pos, $n); + $this->pos += $n; + return $r; + } +} + +class Mappish { + public static darray> $_TSPEC = darray[ + 1 => darray[ + 'var' => 'extraData', + 'type' => TType::MAP, + 'ktype' => TType::STRING, + 'vtype' => TType::STRING, + 'key' => darray[ + 'type' => TType::STRING, + ], + 'val' => darray[ + 'type' => TType::STRING, + ], + 'format' => 'collection', + ], + ]; +} + +class TestStruct { + public static $_TSPEC = darray[ + 0 => darray[ + 'var' => 'success', + 'type' => TType::STRUCT, + 'class' => 'Config' + ], + ]; + + const int STRUCTURAL_ID = 957977401221134810; +} + +function test() { + //var_dump(TestStruct::$_TSPEC); + $p = new DummyProtocol(); + $v1 = new Mappish(); + $v1->extraData = Map {"1" => 2}; + var_dump($v1); + thrift_protocol_write_binary($p, 'foomethod', 2, $v1, 20, true); + var_dump(md5($p->getTransport()->buff)); + var_dump(thrift_protocol_read_binary($p, 'Mappish', true)); +} + +<<__EntryPoint>> +function main_1556() { +test(); +} diff --git a/hphp/test/slow/hack_arr_compat/thrift_map.php.expect b/hphp/test/slow/hack_arr_compat/thrift_map.php.expect new file mode 100644 index 00000000000..c092033b8b2 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/thrift_map.php.expect @@ -0,0 +1,15 @@ +object(Mappish)#3 (1) { + ["extraData"]=> + object(HH\Map)#4 (1) { + ["1"]=> + int(2) + } +} +string(32) "d1fc008b81d8074505914973cbab7120" +object(Mappish)#5 (1) { + ["extraData"]=> + object(HH\Map)#6 (1) { + ["1"]=> + string(1) "2" + } +} diff --git a/hphp/test/slow/hack_arr_compat/thrift_map.php.hphp_opts b/hphp/test/slow/hack_arr_compat/thrift_map.php.hphp_opts new file mode 100644 index 00000000000..4a3ad2d4a02 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/thrift_map.php.hphp_opts @@ -0,0 +1,2 @@ +-vRuntime.Eval.HackArrCompatCheckIntishCast=1 +-vRuntime.Eval.HackArrCompatNotices=true -d hhvm.php7.all=0 diff --git a/hphp/test/slow/hack_arr_compat/thrift_map.php.opts b/hphp/test/slow/hack_arr_compat/thrift_map.php.opts new file mode 100644 index 00000000000..b299cda9208 --- /dev/null +++ b/hphp/test/slow/hack_arr_compat/thrift_map.php.opts @@ -0,0 +1,2 @@ +-vEval.HackArrCompatNotices=true +-vEval.HackArrCompatCheckIntishCast=1 -- 2.11.4.GIT