Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 3 additions & 12 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,16 @@ 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
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
Expand Down
78 changes: 60 additions & 18 deletions m4/php-embed.m4
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
])



9 changes: 9 additions & 0 deletions runtime/methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions runtime/templates/templates_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
@@@

Expand Down Expand Up @@ -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" @@@@@@
Expand Down
62 changes: 42 additions & 20 deletions src/codegen/Compile_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<stringstream*> 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<stringstream*> 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)
Expand All @@ -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;
}


Expand Down
1 change: 1 addition & 0 deletions src/codegen/Compile_C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/codegen/Generate_C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
//
// So that means casts are pure.

// Needed for PHP_VERSION_ID
#include <php_version.h>

#include <fstream>
#include <boost/format.hpp>

Expand Down Expand Up @@ -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)
{
Expand Down
13 changes: 13 additions & 0 deletions src/embed/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down