Skip to content

Commit 5bf4560

Browse files
committed
added PHP 7.2 fix
1 parent 9855df1 commit 5bf4560

File tree

3 files changed

+13
-1641
lines changed

3 files changed

+13
-1641
lines changed

timecop.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,10 @@ static int timecop_func_override(TSRMLS_D)
603603
function_add_ref(zf_orig);
604604

605605
#if PHP_MAJOR_VERSION >= 7
606+
GUARD_FUNCTION_ARG_INFO_BEGIN(zf_orig);
606607
zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func),
607608
zf_ovrd, sizeof(zend_internal_function));
609+
GUARD_FUNCTION_ARG_INFO_END();
608610
#else
609611
zend_hash_update(EG(function_table), p->orig_func, strlen(p->orig_func)+1,
610612
zf_ovrd, sizeof(zend_function), NULL);
@@ -764,23 +766,29 @@ static int timecop_class_override(TSRMLS_D)
764766
static int timecop_func_override_clear(TSRMLS_D)
765767
{
766768
const struct timecop_override_func_entry *p;
767-
zend_function *zf_orig;
769+
zend_function *zf_orig, *zf_ovld;
768770

769771
p = &(timecop_override_func_table[0]);
770772
while (p->orig_func != NULL) {
771773
#if PHP_MAJOR_VERSION >= 7
772774
zf_orig = zend_hash_str_find_ptr(EG(function_table),
773775
p->save_func, strlen(p->save_func));
774-
if (zf_orig == NULL) {
776+
zf_ovld = zend_hash_str_find_ptr(EG(function_table),
777+
p->orig_func, strlen(p->orig_func));
778+
779+
if (zf_orig == NULL || zf_ovld == NULL) {
775780
p++;
776781
continue;
777782
}
778783

784+
GUARD_FUNCTION_ARG_INFO_BEGIN(zf_ovld);
779785
zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func),
780786
zf_orig, sizeof(zend_internal_function));
787+
GUARD_FUNCTION_ARG_INFO_END();
781788
function_add_ref(zf_orig);
782-
789+
GUARD_FUNCTION_ARG_INFO_BEGIN(zf_orig);
783790
zend_hash_str_del(EG(function_table), p->save_func, strlen(p->save_func));
791+
GUARD_FUNCTION_ARG_INFO_END();
784792
#else
785793
if (zend_hash_find(EG(function_table), p->save_func, strlen(p->save_func)+1,
786794
(void **)&zf_orig) != SUCCESS) {

timecop.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ ZEND_END_MODULE_GLOBALS(timecop)
153153
#define TIMECOP_OCE(cname, mname) \
154154
{cname, mname, OVRD_CLASS_PREFIX cname, SAVE_FUNC_PREFIX mname}
155155

156+
#if PHP_MAJOR_VERSION >= 7
156157
/*
157158
* Trick for guarding the multi-referenced internal function from function destructor on PHP 7.2.0+
158159
* See: https://github.com/hnw/php-timecop/issues/29#issuecomment-332171527
@@ -170,6 +171,7 @@ ZEND_END_MODULE_GLOBALS(timecop)
170171
zf->common.arg_info = orig_arg_info; \
171172
} \
172173
}
174+
#endif
173175

174176
struct timecop_override_func_entry {
175177
char *orig_func;

0 commit comments

Comments
 (0)