diff --git a/config.h.in b/config.h.in index 61afee4db..ce1922669 100644 --- a/config.h.in +++ b/config.h.in @@ -35,3 +35,9 @@ // PHP installation path #undef PHP_INSTALL_PATH + +// PHP installation path +#undef PHP_INCLUDES_PATH + +// PHP embed lib path +#undef PHP_EMBED_PATH diff --git a/configure.ac b/configure.ac index 99af9f58a..6c74555dc 100644 --- a/configure.ac +++ b/configure.ac @@ -46,18 +46,6 @@ AC_ARG_WITH([maketea], [AC_PATH_PROG([maketea], [maketea], [config/phc_missing maketea])] ) -# check PHP path -AC_ARG_WITH([php], - AS_HELP_STRING([--with-php=PATH], [PHP installation path (defaults to /usr/local)]), - [ - AS_IF([test "x$with_php" != xno], - [AC_CHECK_PHP([$withval])], [AS_VAR_SET([found_embed_sapi], [no])]) - ], - [ - AC_CHECK_PHP([/usr/local]) - ]) - - dnl checks for libraries AC_LANG([C++]) AC_CHECK_COVARIANCE @@ -65,6 +53,9 @@ AC_CHECK_LIB_CRUN AX_BOOST_BASE([1.35.0]) AX_BOOST_REGEX +dnl PHP +PHP_EMBED + dnl Xerces AX_LIB_XERCES AC_SUBST([HAVE_XERCES], [$HAVE_XERCES]) # for autovars.php diff --git a/m4/php-embed.m4 b/m4/php-embed.m4 index 7d0891566..786a49a5e 100644 --- a/m4/php-embed.m4 +++ b/m4/php-embed.m4 @@ -1,29 +1,74 @@ -dnl Takes a single parameter - where to look. -AC_DEFUN([AC_CHECK_PHP], [ - AC_PATH_PROG([php], [php], [], ["$1/bin"]) - # For config.h: - AC_DEFINE_UNQUOTED([PHP_INSTALL_PATH], ["$1"]) - # For autovars.php.in: - AC_SUBST([php_install_path], ["$1"]) - # For use below: - PHP_INSTALL_PATH=$1 +AC_DEFUN([PHP_EMBED], +[ + AC_ARG_WITH([php-config], + AS_HELP_STRING([--with-php-config=@<:@ARG@:>@], + [path to php-config (ARG=path)] + ), + [ + if test -f "$withval"; then + php_config="$withval" + elif test -d "$withval"; then + if test -f "$withval/php-config"; then + php_config="$withval/php-config" + fi + else + php_config="php-config" + fi + ], + [ + dnl Default behavior is implicit yes + php_config="php-config" + ] + ) + + if test -z "$php_config"; then + AC_MSG_ERROR([Cannot find php-config. Please use --with-php-config=PATH]) + fi + + dnl For BC + PHP_CONFIG=$php_config + PHP_INSTALL_PATH=`$PHP_CONFIG --prefix 2>/dev/null` + PHP_INCLUDES_PATH=`$PHP_CONFIG --include-dir 2>/dev/null` + PHP_INCLUDES=`$PHP_CONFIG --includes 2>/dev/null` + PHP_EXECUTABLE=`$PHP_CONFIG --php-binary 2>/dev/null` + + for php_embed_path in ${PHP_INSTALL_PATH}/lib ${PHP_INSTALL_PATH}/lib/php ${PHP_INSTALL_PATH}/lib/php5; do + for libext in so dylib a; do + if test -f ${php_embed_path}/libphp5.${libext}; then + PHP_EMBED_PATH=${php_embed_path}; + fi + done + done + + if test -z "$PHP_EMBED_PATH"; then + AC_MSG_ERROR([Cannot find libphp5 embed.]) + fi + + AC_PATH_PROG([php], [php], [${PHP_EXECUTABLE}], [$PATH]) + # For config.h: + AC_DEFINE_UNQUOTED([PHP_INSTALL_PATH], ["${PHP_INSTALL_PATH}"]) + AC_DEFINE_UNQUOTED([PHP_INSTALL_PATH], ["${PHP_INSTALL_PATH}"]) + AC_DEFINE_UNQUOTED([PHP_INCLUDES_PATH], ["${PHP_INCLUDES_PATH}"]) + AC_DEFINE_UNQUOTED([PHP_EMBED_PATH], ["${PHP_EMBED_PATH}"]) + # For autovars.php.in: + AC_SUBST([php_install_path], ["${PHP_INSTALL_PATH}"]) dnl To check if the PHP embed SAPI has been installed, we temporarily add the dnl PHP installation path to LDFLAGS and CFLAGS, and restore it later (since dnl we do not need that path to build phc itself). AS_VAR_SET(found_embed_sapi, yes) OLD_LDFLAGS=$LDFLAGS - OLD_CFLAGS=$CFLAGS - LDFLAGS="-L${PHP_INSTALL_PATH}/lib $LDFLAGS" - CFLAGS="-isystem${PHP_INSTALL_PATH}/include/php -isystem${PHP_INSTALL_PATH}/include/php/main -isystem${PHP_INSTALL_PATH}/include/php/TSRM -isystem${PHP_INSTALL_PATH}/include/php/Zend $CFLAGS" + OLD_CPPFLAGS=$CPPFLAGS + LDFLAGS="-L${PHP_EMBED_PATH} $LDFLAGS" + CPPFLAGS="${PHP_INCLUDES} $CPPFLAGS" AC_CHECK_LIB( [php5], [zend_eval_string], [ AS_VAR_SET(found_embed_sapi, yes) AC_DEFINE(HAVE_EMBED, 1) - AC_SUBST([libphp_headers], ["-isystem${PHP_INSTALL_PATH}/include/php -isystem${PHP_INSTALL_PATH}/include/php/main -isystem${PHP_INSTALL_PATH}/include/php/TSRM -isystem${PHP_INSTALL_PATH}/include/php/Zend"]) - LIBS="-lphp5 -L${PHP_INSTALL_PATH}/lib -R${PHP_INSTALL_PATH}/lib $LIBS" + AC_SUBST([libphp_headers], ["${PHP_INCLUDES}"]) + LIBS="-lphp5 -L${PHP_EMBED_PATH} -R${PHP_EMBED_PATH} $LIBS" ], [ AS_VAR_SET(found_embed_sapi, no) @@ -36,9 +81,6 @@ AC_DEFUN([AC_CHECK_PHP], [ [AS_VAR_SET(found_embed_sapi, no)], [] ) - CFLAGS=$OLD_CFLAGS + CPPFLAGS=$OLD_CPPFLAGS LDFLAGS=$OLD_LDFLAGS ]) - - - diff --git a/runtime/methods.c b/runtime/methods.c index 110bab3c4..76d7df801 100644 --- a/runtime/methods.c +++ b/runtime/methods.c @@ -144,10 +144,19 @@ initialize_method_call (zend_fcall_info * fci, zend_fcall_info_cache * fcic, fcic->initialized = 1; fcic->calling_scope = obj_ce; Z_SET_OBJECT_PTR(fcic, obj); + +#if PHP_VERSION_ID > 50399 + fcic->function_handler + = Z_OBJ_HT_PP (obj)->get_method (obj, + function_name, + strlen (function_name), + NULL TSRMLS_CC); +#else fcic->function_handler = Z_OBJ_HT_PP (obj)->get_method (obj, function_name, strlen (function_name) TSRMLS_CC); +#endif if (fcic->function_handler == NULL) { diff --git a/runtime/templates/templates_new.c b/runtime/templates/templates_new.c index f47dd123b..ffadc4ee5 100644 --- a/runtime/templates/templates_new.c +++ b/runtime/templates/templates_new.c @@ -1057,8 +1057,11 @@ arg_by_ref (node ARG) arg_info++; } else +#if PHP_VERSION_ID > 50399 + by_ref[abr_index] = (signature->common.fn_flags & ZEND_ACC_PASS_REST_BY_REFERENCE); +#else by_ref[abr_index] = signature->common.pass_rest_by_reference; - +#endif abr_index++; @@@ @@ -1203,7 +1206,9 @@ call_function (node ATTRS, string MN, list ARGS, string FILENAME, string LINE, s // We can tell this at compile-time. return_reference_bug (node ATTRS) where ATTRS.return_reference_bug @@@ 1 @@@ return_reference_bug (node ATTRS) where ATTRS.no_return_reference_bug @@@ 0 @@@ -return_reference_bug (node ATTRS) @@@ signature->common.return_reference && signature->type != ZEND_USER_FUNCTION @@@ +return_reference_bug (node ATTRS) @@@ (signature->common.fn_flags |= ZEND_ACC_RETURN_REFERENCE) && signature->type != ZEND_USER_FUNCTION @@@ +//return_reference_bug (node ATTRS) where PHP_VERSION_ID > 50399 @@@ (signature->common.fn_flags |= ZEND_ACC_RETURN_REFERENCE) && signature->type != ZEND_USER_FUNCTION @@@ +//return_reference_bug (node ATTRS) @@@ signature->common.return_reference && signature->type != ZEND_USER_FUNCTION @@@ function_lhs (string USE_LHS, token LHS) where USE_LHS == "NONE" @@@@@@ diff --git a/src/codegen/Compile_C.cpp b/src/codegen/Compile_C.cpp index d9933b5fe..060fa851f 100644 --- a/src/codegen/Compile_C.cpp +++ b/src/codegen/Compile_C.cpp @@ -47,31 +47,53 @@ void Compile_C::run (IR::PHP_script* in, Pass_manager* pm) { // Find PHP installation path const char* php_path; - if(pm->args_info->with_php_given) + const char* php_include_path; + const char* php_embed_path; + Vector args; + new_arg (args) << "gcc"; + if(pm->args_info->with_php_given) { php_path = pm->args_info->with_php_arg; - else + + // Argument array for gcc + new_arg (args) << "-I" << php_path << "/include/php"; + new_arg (args) << "-I" << php_path << "/include/php/main"; + new_arg (args) << "-I" << php_path << "/include/php/TSRM"; + new_arg (args) << "-I" << php_path << "/include/php/Zend"; + new_arg (args) << "-L" << php_path << "/lib"; +#ifndef __APPLE__ + new_arg (args) << "-Wl,-R" << php_path << "/lib"; +#endif + new_arg (args) << "-lphp5"; + new_arg (args) << "-xc"; + new_arg (args) << "-"; + } else { - #ifdef PHP_INSTALL_PATH - php_path = PHP_INSTALL_PATH; + #ifdef PHP_INCLUDES_PATH + php_include_path = PHP_INCLUDES_PATH; #else - phc_error ("PHP_INSTALL_PATH not configured. Please use the --with-php flag to compile"); + phc_error ("PHP_INCLUDES_PATH not configured. Please use the --with-php-config flag to compile"); + assert (0); // in the case of --dont-fail, still fail here. + #endif + #ifdef PHP_EMBED_PATH + php_embed_path = PHP_EMBED_PATH; + #else + phc_error ("PHP_EMBED_PATH not configured. Please use the --with-php-config flag to compile"); assert (0); // in the case of --dont-fail, still fail here. #endif - } - - // Argument array for gcc - Vector args; - new_arg (args) << "gcc"; - new_arg (args) << "-I" << php_path << "/include/php"; - new_arg (args) << "-I" << php_path << "/include/php/main"; - new_arg (args) << "-I" << php_path << "/include/php/TSRM"; - new_arg (args) << "-I" << php_path << "/include/php/Zend"; - new_arg (args) << "-L" << php_path << "/lib"; - new_arg (args) << "-Wl,-R" << php_path << "/lib"; - new_arg (args) << "-lphp5"; - new_arg (args) << "-xc"; - new_arg (args) << "-"; + // Argument array for gcc + new_arg (args) << "-I" << php_include_path; + new_arg (args) << "-I" << php_include_path << "/main"; + new_arg (args) << "-I" << php_include_path << "/TSRM"; + new_arg (args) << "-I" << php_include_path << "/Zend"; + new_arg (args) << "-L" << php_embed_path; +#ifndef __APPLE__ + new_arg (args) << "-Wl,-R" << php_embed_path; +#endif + new_arg (args) << "-lphp5"; + new_arg (args) << "-xc"; + new_arg (args) << "-"; + } // Add (gcc) -g and -o arguments if (strncmp (pm->args_info->optimize_arg, "0", 2) == 0) @@ -95,7 +117,7 @@ void Compile_C::run (IR::PHP_script* in, Pass_manager* pm) // add -o argument if (pm->args_info->output_given) { - new_arg (args) << "-o" << pm->args_info->output_arg; + new_arg (args) << "-o " << pm->args_info->output_arg; } diff --git a/src/codegen/Compile_C.h b/src/codegen/Compile_C.h index cd648a349..da6fd7d80 100644 --- a/src/codegen/Compile_C.h +++ b/src/codegen/Compile_C.h @@ -8,6 +8,7 @@ #ifndef PHC_COMPILE_C #define PHC_COMPILE_C +#include "config.h" #include "pass_manager/Pass.h" class Compile_C : public Pass diff --git a/src/codegen/Generate_C.cpp b/src/codegen/Generate_C.cpp index 8461142ac..7b7a58a6b 100644 --- a/src/codegen/Generate_C.cpp +++ b/src/codegen/Generate_C.cpp @@ -31,6 +31,9 @@ // // So that means casts are pure. +// Needed for PHP_VERSION_ID +#include + #include #include @@ -543,9 +546,11 @@ void function_declaration_block(ostream& buf, Signature_list* methods, String* b buf << "ZEND_END_ARG_INFO()\n\n"; } - buf - << "static function_entry " << *block_name << "_functions[] = {\n" - ; +#if PHP_VERSION_ID > 50399 + buf << "static zend_function_entry " << *block_name << "_functions[] = {\n"; +#else + buf << "static function_entry " << *block_name << "_functions[] = {\n"; +#endif foreach (Signature* s, *methods) { diff --git a/src/embed/optimize.cpp b/src/embed/optimize.cpp index 102c978fc..1f53cbeb9 100644 --- a/src/embed/optimize.cpp +++ b/src/embed/optimize.cpp @@ -220,7 +220,16 @@ PHP::get_method_info (String* name) zend_fcall_info fci; zend_fcall_info_cache fcic; +#if PHP_VERSION_ID > 50399 + uint check_flags=0; + char callable_name[124]; + char error[513]; // , void ***tsrm_ls); + char * cname = &callable_name[0]; + char * err = &error[0]; + int result = zend_fcall_info_init (&fn, check_flags, &fci, &fcic, &cname, &err TSRMLS_CC); +#else int result = zend_fcall_info_init (&fn, &fci, &fcic TSRMLS_CC); +#endif if (result != SUCCESS) return NULL; @@ -245,7 +254,11 @@ Internal_method_info::has_implementation () bool Internal_method_info::return_by_ref () { +#if PHP_VERSION_ID > 50399 + return (func->common.fn_flags & ZEND_ACC_RETURN_REFERENCE); +#else return func->common.return_reference; +#endif } bool