Skip to content

Commit

Permalink
#4 fix for PHP 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
longxinH committed Dec 28, 2017
1 parent a862c02 commit 8773583
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This version supports PHP7
# PHP Version
- 7.0
- 7.1
- 7.2

# Installation
```
Expand Down
10 changes: 10 additions & 0 deletions extension/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ PHP_ARG_ENABLE(xhprof, whether to enable xhprof support,
[ --enable-xhprof Enable xhprof support])

if test "$PHP_XHPROF" != "no"; then

AC_MSG_CHECKING([for PCRE includes])

if test -f $phpincludedir/ext/pcre/php_pcre.h; then
AC_DEFINE([HAVE_PCRE], 1, [have pcre headers])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi

PHP_NEW_EXTENSION(xhprof, xhprof.c, $ext_shared)
fi
25 changes: 18 additions & 7 deletions extension/xhprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include <stdlib.h>
#include <unistd.h>

#if HAVE_PCRE
#include "ext/pcre/php_pcre.h"
#endif

#ifdef __FreeBSD__
# if __FreeBSD_version >= 700110
Expand Down Expand Up @@ -79,7 +81,7 @@
*/

/* XHProf version */
#define XHPROF_VERSION "1.0.0"
#define XHPROF_VERSION "1.1.0"

/* Fictitious function name to represent top of the call tree. The paranthesis
* in the name is to ensure we don't conflict with user function names. */
Expand Down Expand Up @@ -831,8 +833,7 @@ static char *hp_get_function_argument_summary(char *ret, zend_execute_data *data
if (strcmp(ret, "PDO::exec") == 0 ||
strcmp(ret, "PDO::query") == 0 ||
strcmp(ret, "mysqli::query") == 0) {
zval *arg;
arg = ZEND_CALL_ARG(data, 1);
zval *arg = ZEND_CALL_ARG(data, 1);
spprintf(&result, 0, "%s#%s", ret, Z_STRVAL_P(arg));
} else if (strcmp(ret, "mysqli_query") == 0) {
zval *arg = ZEND_CALL_ARG(data, 2);
Expand All @@ -848,6 +849,13 @@ static char *hp_get_function_argument_summary(char *ret, zend_execute_data *data
convert_to_array(&tmp_obj);

if ((value = zend_hash_str_find(Z_ARRVAL(tmp_obj), ZEND_STRL("queryString"))) != NULL) {
#ifndef HAVE_PCRE
spprintf(&result, 0, "%s#%s", ret, Z_STRVAL_P(value));
zval_ptr_dtor(&tmp_obj);
efree(ret);
return result;
#endif

zval *arg, tmp_zv;
pcre_cache_entry *pce_regexp;
zend_string *pattern_str = NULL;
Expand Down Expand Up @@ -884,18 +892,21 @@ static char *hp_get_function_argument_summary(char *ret, zend_execute_data *data

ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(arg), num_key, key, val)
{
#if PHP_VERSION_ID < 70200
zval repl;
ZVAL_STR(&repl, zval_get_string(val));

zend_string *res = php_pcre_replace_impl(pce_regexp, NULL, Z_STRVAL(tmp_zv), Z_STRLEN(tmp_zv), &repl, 0, 1, 0);

zval_ptr_dtor(&repl);
#elif PHP_VERSION_ID >= 70200
zend_string *repl = zval_get_string(val);
zend_string *res = php_pcre_replace_impl(pce_regexp, NULL, Z_STRVAL(tmp_zv), Z_STRLEN(tmp_zv), repl, 1, 0);
zend_string_release(repl);
#endif
if (res != NULL) {
zval_ptr_dtor(&tmp_zv);
ZVAL_STR(&tmp_zv, res);
}

zval_ptr_dtor(&repl);

}ZEND_HASH_FOREACH_END();

zend_string_release(pattern_str);
Expand Down

0 comments on commit 8773583

Please sign in to comment.