Skip to content

Commit 14739d9

Browse files
committed
Merge remote-tracking branch 'hnw/pr/45' into fixes
hnw#45 * hnw/pr/45: fix for ZTS
2 parents cc251ee + 53d9729 commit 14739d9

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

timecop_php7.c

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,17 @@ static inline void _call_php_function_with_2_params(const char *function_name, z
311311
static void _call_php_function_with_3_params(const char *function_name, zval *retval_ptr, zval *arg1, zval *arg2, zval *arg3);
312312
static inline void _call_php_function_with_params(const char *function_name, zval *retval_ptr, uint32_t param_count, zval params[]);
313313

314+
static const zend_module_dep timecop_module_deps[] = {
315+
ZEND_MOD_REQUIRED("Date")
316+
ZEND_MOD_END
317+
};
318+
314319
/* {{{ timecop_module_entry
315320
*/
316321
zend_module_entry timecop_module_entry = {
317-
#if ZEND_MODULE_API_NO >= 20010901
318-
STANDARD_MODULE_HEADER,
319-
#endif
322+
STANDARD_MODULE_HEADER_EX,
323+
NULL,
324+
timecop_module_deps,
320325
"timecop",
321326
timecop_functions,
322327
PHP_MINIT(timecop),
@@ -355,6 +360,14 @@ PHP_MINIT_FUNCTION(timecop)
355360
ZEND_INIT_MODULE_GLOBALS(timecop, timecop_globals_ctor, NULL);
356361
REGISTER_INI_ENTRIES();
357362
register_timecop_classes();
363+
364+
if (TIMECOP_G(func_override)) {
365+
if (SUCCESS != timecop_func_override() ||
366+
SUCCESS != timecop_class_override()) {
367+
return FAILURE;
368+
}
369+
}
370+
358371
return SUCCESS;
359372
}
360373
/* }}} */
@@ -364,6 +377,12 @@ PHP_MINIT_FUNCTION(timecop)
364377
PHP_MSHUTDOWN_FUNCTION(timecop)
365378
{
366379
UNREGISTER_INI_ENTRIES();
380+
381+
if (TIMECOP_G(func_override)) {
382+
timecop_func_override_clear();
383+
timecop_class_override_clear();
384+
}
385+
367386
return SUCCESS;
368387
}
369388
/* }}} */
@@ -375,25 +394,13 @@ PHP_RINIT_FUNCTION(timecop)
375394
ZEND_TSRMLS_CACHE_UPDATE();
376395
#endif
377396

378-
if (TIMECOP_G(func_override)) {
379-
if (SUCCESS != timecop_func_override() ||
380-
SUCCESS != timecop_class_override()) {
381-
return FAILURE;
382-
}
383-
}
384-
385397
return SUCCESS;
386398
}
387399
/* }}} */
388400

389401
/* {{{ PHP_RSHUTDOWN_FUNCTION(timecop) */
390402
PHP_RSHUTDOWN_FUNCTION(timecop)
391403
{
392-
if (TIMECOP_G(func_override)) {
393-
timecop_func_override_clear();
394-
timecop_class_override_clear();
395-
}
396-
397404
if (Z_TYPE(TIMECOP_G(orig_request_time)) == IS_NULL) {
398405
restore_request_time();
399406
}
@@ -496,22 +503,22 @@ static int timecop_func_override()
496503

497504
p = &(timecop_override_func_table[0]);
498505
while (p->orig_func != NULL) {
499-
zf_orig = zend_hash_str_find_ptr(EG(function_table), p->orig_func, strlen(p->orig_func));
506+
zf_orig = zend_hash_str_find_ptr(CG(function_table), p->orig_func, strlen(p->orig_func));
500507
if (zf_orig == NULL) {
501508
/* Do nothing. Because some functions are introduced by optional extensions. */
502509
p++;
503510
continue;
504511
}
505512

506-
zf_ovrd = zend_hash_str_find_ptr(EG(function_table), p->ovrd_func, strlen(p->ovrd_func));
513+
zf_ovrd = zend_hash_str_find_ptr(CG(function_table), p->ovrd_func, strlen(p->ovrd_func));
507514
if (zf_ovrd == NULL) {
508515
php_error_docref("https://github.com/hnw/php-timecop", E_WARNING,
509516
"timecop couldn't find function %s.", p->ovrd_func);
510517
p++;
511518
continue;
512519
}
513520

514-
zf_save = zend_hash_str_find_ptr(EG(function_table), p->save_func, strlen(p->save_func));
521+
zf_save = zend_hash_str_find_ptr(CG(function_table), p->save_func, strlen(p->save_func));
515522
if (zf_save != NULL) {
516523
php_error_docref("https://github.com/hnw/php-timecop", E_WARNING,
517524
"timecop couldn't create function %s because already exists.",
@@ -523,12 +530,12 @@ static int timecop_func_override()
523530
TIMECOP_ASSERT(zf_orig->type == ZEND_INTERNAL_FUNCTION);
524531
TIMECOP_ASSERT(zf_ovrd->type == ZEND_INTERNAL_FUNCTION);
525532

526-
zend_hash_str_add_mem(EG(function_table), p->save_func, strlen(p->save_func),
533+
zend_hash_str_add_mem(CG(function_table), p->save_func, strlen(p->save_func),
527534
zf_orig, sizeof(zend_internal_function));
528535
function_add_ref(zf_orig);
529536

530537
GUARD_FUNCTION_ARG_INFO_BEGIN(zf_orig);
531-
zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func),
538+
zend_hash_str_update_mem(CG(function_table), p->orig_func, strlen(p->orig_func),
532539
zf_ovrd, sizeof(zend_internal_function));
533540
GUARD_FUNCTION_ARG_INFO_END();
534541
function_add_ref(zf_ovrd);
@@ -546,15 +553,15 @@ static int timecop_class_override()
546553

547554
p = &(timecop_override_class_table[0]);
548555
while (p->orig_class != NULL) {
549-
ce_orig = zend_hash_str_find_ptr(EG(class_table), p->orig_class, strlen(p->orig_class));
556+
ce_orig = zend_hash_str_find_ptr(CG(class_table), p->orig_class, strlen(p->orig_class));
550557
if (ce_orig == NULL) {
551558
php_error_docref("https://github.com/hnw/php-timecop", E_WARNING,
552559
"timecop couldn't find class %s.", p->orig_class);
553560
p++;
554561
continue;
555562
}
556563

557-
ce_ovrd = zend_hash_str_find_ptr(EG(class_table), p->ovrd_class, strlen(p->ovrd_class));
564+
ce_ovrd = zend_hash_str_find_ptr(CG(class_table), p->ovrd_class, strlen(p->ovrd_class));
558565
if (ce_ovrd == NULL) {
559566
php_error_docref("https://github.com/hnw/php-timecop", E_WARNING,
560567
"timecop couldn't find class %s.", p->ovrd_class);
@@ -626,23 +633,23 @@ static int timecop_func_override_clear()
626633

627634
p = &(timecop_override_func_table[0]);
628635
while (p->orig_func != NULL) {
629-
zf_orig = zend_hash_str_find_ptr(EG(function_table),
636+
zf_orig = zend_hash_str_find_ptr(CG(function_table),
630637
p->save_func, strlen(p->save_func));
631-
zf_ovld = zend_hash_str_find_ptr(EG(function_table),
638+
zf_ovld = zend_hash_str_find_ptr(CG(function_table),
632639
p->orig_func, strlen(p->orig_func));
633640
if (zf_orig == NULL || zf_ovld == NULL) {
634641
p++;
635642
continue;
636643
}
637644

638645
GUARD_FUNCTION_ARG_INFO_BEGIN(zf_ovld);
639-
zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func),
646+
zend_hash_str_update_mem(CG(function_table), p->orig_func, strlen(p->orig_func),
640647
zf_orig, sizeof(zend_internal_function));
641648
GUARD_FUNCTION_ARG_INFO_END();
642649
function_add_ref(zf_orig);
643650

644651
GUARD_FUNCTION_ARG_INFO_BEGIN(zf_orig);
645-
zend_hash_str_del(EG(function_table), p->save_func, strlen(p->save_func));
652+
zend_hash_str_del(CG(function_table), p->save_func, strlen(p->save_func));
646653
GUARD_FUNCTION_ARG_INFO_END();
647654

648655
p++;
@@ -658,7 +665,7 @@ static int timecop_class_override_clear()
658665

659666
p = &(timecop_override_class_table[0]);
660667
while (p->orig_class != NULL) {
661-
ce_orig = zend_hash_str_find_ptr(EG(class_table),
668+
ce_orig = zend_hash_str_find_ptr(CG(class_table),
662669
p->orig_class, strlen(p->orig_class));
663670
if (ce_orig == NULL) {
664671
php_error_docref("https://github.com/hnw/php-timecop", E_WARNING,

0 commit comments

Comments
 (0)