Allow the Sandbox to work in FastCGI mode

Passing through the FastCGI DOCUMENT_ROOT unmolested, in particular
allowing it to be empty(), is what the Sandbox requires.
Closes #2099
Github Author: Jim Radford <radfordblackbean.org>

Reviewed By: @fredemmott

Differential Revision: D1229971
actually set the session save path

Instead of just setting the Ini value, also set
s_session->m_session_path.

This prevents HHVM from always picking /tmp.

Closes #2075
Github Author: Daniel Sloof <goapsychadelicgmail.com>

Reviewed By: @fredemmott

Differential Revision: D1224022
Bug fix for guard relaxation when refcount opts are disabled

If we relax {SetL, PopC} pairs to not guard on countedness,
then we must run refcount opts to clean up the IncRef/DecRef pair --
or else we might try to access the count field when it's invalid.

Reviewed By: @swtaarrs

Differential Revision: D1229447
Set up control flow options for contbuild control

Reviewed By: @ottoni

Differential Revision: D1229608
PHAR optional parameters

Closes #2055
Closes #2094
Github Author: Marco Pivetta <ocramiusgmail.com>

Reviewed By: @fredemmott

Differential Revision: D1229939
Fix compilation on FreeBSD and OSX from f15d52f

HOST_NAME_MAX is recommended by POSIX, but not required to be defined. 255
is generally a safe number to assume in that case and matches upstream's
behavior.
Closes #2089
Github Author: Chad Horohoe <chadhwikimedia.org>

Reviewed By: @fredemmott

Differential Revision: D1230067
fix (de)serialization incompatibility with multiple sessions

When using named sessions (see session_name), multiple sessions are
stored in a single session file. The serialized data in these sessions
may refer to previous objects, using "r:<reference_id>".

HHVM stores these reference IDs on a session_name basis. Zend PHP
however, keeps using the same reference counter for all sessions it
encounters in a single file. This works fine when either of two systems
is being used, but this may causes session data to be read improperly or
corrupt it when sharing sessions.

This change works in several ways:
- Allow us to dynamically set start/end buffers in VariableUnserializer
  so we can keep using the unserializer while keeping m_refs.
- Implement a keepCount option in VariableSerializer that does nothing
  other than keep the existing reference count, this option is disabled
  by default.
- Move serializer/unserializer out of session iteration scope so that
  we don't lose reference information.

Additionally there is a test demonstration the issue.

Closes #2078.
Closes #2092
Github Author: Daniel Sloof <goapsychadelicgmail.com>

Reviewed By: @fredemmott

Differential Revision: D1230054
Fix precedence for == with DateTimeInterface implementations

Reviewed By: @alexmalyshev

Differential Revision: D1230275
Fix simplifier rules for ConvStrTo{Dbl,Int}

The simplifier was using isNumericWithVal, and then casting the
result to {Int,Dbl}.

PHP5 has functions convert_to_{double,long} and they just call
strtod and strtoll respectively.

Reviewed By: @ottoni

Differential Revision: D1229976
Test type suggestions with namespaces

Just realized I must have never really tried this before.
Thankfully it works. Add a unit test for it.

Reviewed By: @gabelevi

Differential Revision: D1230237
Improve exception support in ext_zend_compat

Exceptions in Zend work by setting EG(exception) and adjusting the
VM opline pointer, and then returning to the C caller as usual.
C code is not exception-safe, and will leak memory or worse if C++
exceptions are allowed to propagate into it.

So:

* Set up try/catch blocks around C++ function calls. When an exception
  occurs, set EG(exception) to something sensible and save the exception
  object for rethrowing after the extension function returns.

* In zend_throw_exception(), just save the object for throwing later and
  return, don't actually throw it.

* Add a separate extension for testing aspects of ext_zend_compat, called
  ezc_test. It is based on ext_skel, and its tests are confirmed to work
  under Zend. The features I want to provide in ext_zend_compat were not
  properly tested by the existing extensions.

* Fix the JIT unwinder to properly interpret exception objects whether
  they are normal exceptions or "dependent" exceptions, i.e. thrown by
  std::rethrow_exception(). Document the GCC code I followed in doing
  this. This allows std::rethrow_exception() to be used in hhvm.

Also:

* Fix the use of default_exception_ce. It wasn't reliably initialised,
  but even if it were, it stores a pointer to request-local memory, so
  a static variable with no __thread was never going to work.

* Fix assertion from zend_call_function() when fcc->object_ptr is not
  initialised. With calling code such is found in Zend's
  call_user_func(), it will just point to uninitialised stack memory.
  Set it to NULL in fcc and fci, like what the Zend code does for
  global functions. Also document some pre-existing incompatibilities
  with the Zend interface.

* Pop the ZendExecutionStack even if an exception was thrown, otherwise
  memory will leak.

Fixes facebook/hhvm#1986

Reviewed By: @ptarjan

Differential Revision: D1220351
Convert IntlError::throwException into IntlError::getException

Rather than have the helper throw the exception for us,
just return an exception Object which we can throw ourselves.

@ptarjan complained about my anti-pattern at the
time and I promised to fix things after intl landed.

This is me making good on that promise.

Reviewed By: @ptarjan

Differential Revision: D1229744
Allow calling mixed-mode native functions with up to 7 args

Now that the rCgGp bug is fixed, we can re-enable
using more than 5 args for mixed mode natives (using doubles),
and using up to a full 15 args with FCallBuiltin for
int-only mode natives.

Reviewed By: @edwinsmith

Differential Revision: D1228599
Use Either in APCObject instead of an ad hoc class

Reviewed By: @dariorussi

Differential Revision: D1227404
include <sys/time.h>

ubuntu 10.04 won't compile without this saying

    /home/ptarjan/dev/hhvm/hphp/runtime/base/ssl-socket.cpp: In member function ‘bool HPHP::SSLSocket::enableCrypto(bool)’:
    /home/ptarjan/dev/hhvm/hphp/runtime/base/ssl-socket.cpp:574:25: error: aggregate ‘HPHP::SSLSocket::enableCrypto(bool)::timezone tz’ has incomplete type and cannot be defined
             struct timezone tz;
                             ^
    /home/ptarjan/dev/hhvm/hphp/runtime/base/ssl-socket.cpp:576:31: error: ‘gettimeofday’ was not declared in this scope
             gettimeofday(&tvs, &tz);
                                   ^
    make[2]: *** [hphp/runtime/CMakeFiles/hphp_runtime_static.dir/base/ssl-socket.cpp.o] Error 1

Reviewed By: @fredemmott

Differential Revision: D1232313
Add JCacheStorageTest to the clown test list.

Memcache tests fail on both Zend and HHVM. (Both with/without memcache installed in the system)
Closes #2115
Github Author: Witchakorn Kamolpornwijit <witchakkmit.edu>

Reviewed By: @fredemmott

Differential Revision: D1231653
kill ClassInfo from reflection

We've gotten the VM's reflection stuff to the point that it totally supports everything ClassInfo does! Yay! The only change is that `Iterator` comes back as `HH\Iterator` which seems more right anyways.

We also get a bit back, yay again!

Reviewed By: @elgenie

Differential Revision: D1227773
Fix warnings caused by violation of one-definition-rule when using PCH

This is to be merged together with #1932 -- after the headers have been aggregated to be compiled together, some macros might #define over each other causing warnings. This is harmless because definitions will just supersede each other.
Closes #2046
Github Author: Joel Low <joeljoelsplace.sg>

Reviewed By: @fredemmott

Differential Revision: D1231221
Set SEVER_SOFTWARE to the value provided over FastCGI

Closes #2106
Github Author: Simon Welsh <simonsimon.geek.nz>

Reviewed By: @fredemmott

Differential Revision: D1229962
Set stream type for sockets

Fixes a test case in ReactPHP.

Closes #2080
Closes #2081
Github Author: Camillus Gerard Cai <cgcaiqxcg.net>

Reviewed By: @fredemmott

Differential Revision: D1230072