Advertisement
Guest User

Untitled

a guest
Apr 7th, 2015
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.88 KB | None | 0 0
  1. diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
  2. index 4842e1a..0e026e8 100644
  3. --- a/ext/pcntl/pcntl.c
  4. +++ b/ext/pcntl/pcntl.c
  5. @@ -511,7 +511,7 @@ PHP_MINIT_FUNCTION(pcntl)
  6.  {
  7.     php_register_signal_constants(INIT_FUNC_ARGS_PASSTHRU);
  8.     php_pcntl_register_errno_constants(INIT_FUNC_ARGS_PASSTHRU);
  9. -   php_add_tick_function(pcntl_signal_dispatch);
  10. +   php_add_tick_function(pcntl_signal_dispatch, NULL);
  11.  
  12.     return SUCCESS;
  13.  }
  14. diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
  15. index 36d530d..07314ec 100644
  16. --- a/ext/standard/basic_functions.c
  17. +++ b/ext/standard/basic_functions.c
  18. @@ -4942,9 +4942,8 @@ static void user_tick_function_call(user_tick_function_entry *tick_fe) /* {{{ */
  19.  }
  20.  /* }}} */
  21.  
  22. -static void run_user_tick_functions(int tick_count) /* {{{ */
  23. +static void run_user_tick_functions(int tick_count, void *arg) /* {{{ */
  24.  {
  25. -
  26.     zend_llist_apply(BG(user_tick_functions), (llist_apply_func_t) user_tick_function_call);
  27.  }
  28.  /* }}} */
  29. @@ -5654,7 +5653,7 @@ PHP_FUNCTION(register_tick_function)
  30.         zend_llist_init(BG(user_tick_functions),
  31.                         sizeof(user_tick_function_entry),
  32.                         (llist_dtor_func_t) user_tick_function_dtor, 0);
  33. -       php_add_tick_function(run_user_tick_functions);
  34. +       php_add_tick_function(run_user_tick_functions, NULL);
  35.     }
  36.  
  37.     for (i = 0; i < tick_fe.arg_count; i++) {
  38. diff --git a/main/php_ticks.c b/main/php_ticks.c
  39. index b776652..bb6bd1a 100644
  40. --- a/main/php_ticks.c
  41. +++ b/main/php_ticks.c
  42. @@ -21,9 +21,15 @@
  43.  #include "php.h"
  44.  #include "php_ticks.h"
  45.  
  46. +struct st_tick_function
  47. +{
  48. +   void (*func)(int, void *);
  49. +   void *arg;
  50. +};
  51. +
  52.  int php_startup_ticks(void)
  53.  {
  54. -   zend_llist_init(&PG(tick_functions), sizeof(void(*)(int)), NULL, 1);
  55. +   zend_llist_init(&PG(tick_functions), sizeof(struct st_tick_function), NULL, 1);
  56.     return SUCCESS;
  57.  }
  58.  
  59. @@ -39,30 +45,27 @@ void php_shutdown_ticks(void)
  60.  
  61.  static int php_compare_tick_functions(void *elem1, void *elem2)
  62.  {
  63. -   void(*func1)(int);
  64. -   void(*func2)(int);
  65. -   memcpy(&func1, elem1, sizeof(void(*)(int)));
  66. -   memcpy(&func2, elem2, sizeof(void(*)(int)));
  67. -   return (func1 == func2);
  68. +  struct st_tick_function *e1 = (struct st_tick_function *)elem1;
  69. +  struct st_tick_function *e2 = (struct st_tick_function *)elem2;
  70. +  return e1->func == e2->func && e1->arg == e2->arg;
  71.  }
  72.  
  73. -PHPAPI void php_add_tick_function(void (*func)(int))
  74. +PHPAPI void php_add_tick_function(void (*func)(int, void*), void * arg)
  75.  {
  76. -   zend_llist_add_element(&PG(tick_functions), (void *)&func);
  77. +   struct st_tick_function tmp = {func, arg};
  78. +   zend_llist_add_element(&PG(tick_functions), (void *)&tmp);
  79.  }
  80.  
  81. -PHPAPI void php_remove_tick_function(void (*func)(int))
  82. +PHPAPI void php_remove_tick_function(void (*func)(int, void *), void * arg)
  83.  {
  84. -   zend_llist_del_element(&PG(tick_functions), (void *)func,
  85. -                          (int(*)(void*, void*))php_compare_tick_functions);
  86. +   struct st_tick_function tmp = {func, arg};
  87. +   zend_llist_del_element(&PG(tick_functions), (void *)&tmp, (int(*)(void*, void*))php_compare_tick_functions);
  88.  }
  89.  
  90. -static void php_tick_iterator(void *data, void *arg)
  91. +static void php_tick_iterator(void *d, void *arg)
  92.  {
  93. -   void (*func)(int);
  94. -
  95. -   memcpy(&func, data, sizeof(void(*)(int)));
  96. -   func(*((int *)arg));
  97. +   struct st_tick_function *data = (struct st_tick_function *)d;
  98. +   data->func(*((int *)arg), data->arg);
  99.  }
  100.  
  101.  void php_run_ticks(int count)
  102. diff --git a/main/php_ticks.h b/main/php_ticks.h
  103. index b6ae0e7..4f42239 100644
  104. --- a/main/php_ticks.h
  105. +++ b/main/php_ticks.h
  106. @@ -27,8 +27,8 @@ void php_shutdown_ticks(void);
  107.  void php_run_ticks(int count);
  108.  
  109.  BEGIN_EXTERN_C()
  110. -PHPAPI void php_add_tick_function(void (*func)(int));
  111. -PHPAPI void php_remove_tick_function(void (*func)(int));
  112. +PHPAPI void php_add_tick_function(void (*func)(int, void *), void *arg);
  113. +PHPAPI void php_remove_tick_function(void (*func)(int, void *), void * arg);
  114.  END_EXTERN_C()
  115.  
  116.  #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement