Make converting constructors from raw ref-counted objects be explicit
commitb544d903ea646aae6c5066748643c3d3fdbbeee2
authorRick Lavoie <rlavoie@fb.com>
Wed, 29 Jul 2015 23:15:45 +0000 (29 16:15 -0700)
committerhhvm-bot <hhvm-bot@fb.com>
Thu, 30 Jul 2015 00:02:25 +0000 (29 17:02 -0700)
tree6ddb42413f3d3655862b86ecb42cbfdfc28c0367
parent96f9edd881982cef260368bc4f2c72bc66ddb6c9
Make converting constructors from raw ref-counted objects be explicit

Summary: The constructors for Variant, String, Object, and Resource which take a raw
[String,Object,Resource]Data pointer manipulate the reference count as part of
the conversion. Since these constructors are implicit, that means you might be
undergoing reference count manipulations without realizing it. This is
especially problematic now that the ref-counts of all objects begin at 1, and
its important not to inc-ref again when wrapping the object. IE: its very easy
to make a mistake like this:

String func() {
  return StringData::Make(...);
}

and end-up with a String with a ref-count of 2 instead of 1.

Therefore, its safer to make these constructors explicit. They still have the
same behavior, but at least you won't have such conversions happening unless you
explicitly ask for it.

Reviewed By: @edwinsmith

Differential Revision: D2230166
75 files changed:
hphp/compiler/analysis/emitter.cpp
hphp/runtime/base/apc-array.cpp
hphp/runtime/base/apc-handle.cpp
hphp/runtime/base/apc-string.h
hphp/runtime/base/array-init.h
hphp/runtime/base/autoload-handler.cpp
hphp/runtime/base/backtrace.cpp
hphp/runtime/base/builtin-functions.cpp
hphp/runtime/base/class-info.cpp
hphp/runtime/base/file-await.cpp
hphp/runtime/base/file.cpp
hphp/runtime/base/file.h
hphp/runtime/base/mixed-array.cpp
hphp/runtime/base/object-data.cpp
hphp/runtime/base/sort-helpers.h
hphp/runtime/base/tv-helpers.h
hphp/runtime/base/type-array.h
hphp/runtime/base/type-conversions.h
hphp/runtime/base/type-object.h
hphp/runtime/base/type-resource.h
hphp/runtime/base/type-string.h
hphp/runtime/base/type-variant.cpp
hphp/runtime/base/type-variant.h
hphp/runtime/base/unit-cache.cpp
hphp/runtime/base/variable-serializer.cpp
hphp/runtime/debugger/debugger_hook_handler.h
hphp/runtime/ext/asio/asio-blockable.cpp
hphp/runtime/ext/asio/asio-session.cpp
hphp/runtime/ext/asio/ext_asio.cpp
hphp/runtime/ext/asio/ext_async-function-wait-handle.cpp
hphp/runtime/ext/asio/ext_async-generator-wait-handle.cpp
hphp/runtime/ext/asio/ext_await-all-wait-handle.cpp
hphp/runtime/ext/asio/ext_external-thread-event-wait-handle.cpp
hphp/runtime/ext/asio/ext_gen-array-wait-handle.cpp
hphp/runtime/ext/asio/ext_gen-map-wait-handle.cpp
hphp/runtime/ext/asio/ext_gen-vector-wait-handle.cpp
hphp/runtime/ext/asio/ext_waitable-wait-handle.cpp
hphp/runtime/ext/async_mysql/ext_async_mysql.cpp
hphp/runtime/ext/collections/ext_collections-idl.cpp
hphp/runtime/ext/collections/ext_collections-idl.h
hphp/runtime/ext/curl/ext_curl.cpp
hphp/runtime/ext/datetime/ext_datetime.cpp
hphp/runtime/ext/domdocument/ext_domdocument.cpp
hphp/runtime/ext/ext_closure.cpp
hphp/runtime/ext/fileinfo/ext_fileinfo.cpp
hphp/runtime/ext/fribidi/ext_fribidi.cpp
hphp/runtime/ext/icu/ext_icu_calendar.cpp
hphp/runtime/ext/icu/ext_icu_uconverter.cpp
hphp/runtime/ext/imagick/imagick.cpp
hphp/runtime/ext/imagick/imagickdraw.cpp
hphp/runtime/ext/imagick/imagickpixel.cpp
hphp/runtime/ext/imagick/imagickpixeliterator.cpp
hphp/runtime/ext/mailparse/mime.cpp
hphp/runtime/ext/mcrouter/ext_mcrouter.cpp
hphp/runtime/ext/memcached/ext_memcached.cpp
hphp/runtime/ext/mysql/ext_mysqli.cpp
hphp/runtime/ext/reflection/ext_reflection.cpp
hphp/runtime/ext/session/ext_session.cpp
hphp/runtime/ext/session/ext_session.h
hphp/runtime/ext/simplexml/ext_simplexml.cpp
hphp/runtime/ext/spl/ext_spl.cpp
hphp/runtime/ext/sqlite3/ext_sqlite3.cpp
hphp/runtime/ext/std/ext_std_file.cpp
hphp/runtime/ext/std/ext_std_options.cpp
hphp/runtime/ext/stream/ext_stream-user-filters.cpp
hphp/runtime/ext/string/ext_string.cpp
hphp/runtime/ext/wddx/ext_wddx.cpp
hphp/runtime/ext/xdebug/ext_xdebug.cpp
hphp/runtime/ext/zip/ext_zip.cpp
hphp/runtime/ext_zend_compat/php-src/Zend/zend_object_handlers.cpp
hphp/runtime/server/pagelet-server.h
hphp/runtime/vm/event-hook.cpp
hphp/runtime/vm/hh-utils.cpp
hphp/runtime/vm/jit/ssa-tmp.cpp
hphp/runtime/vm/jit/translator-runtime.cpp