You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1701 lines
48 KiB

27 years ago
27 years ago
24 years ago
24 years ago
27 years ago
27 years ago
27 years ago
27 years ago
17 years ago
25 years ago
26 years ago
27 years ago
27 years ago
23 years ago
23 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
20 years ago
27 years ago
27 years ago
27 years ago
23 years ago
25 years ago
25 years ago
24 years ago
23 years ago
27 years ago
27 years ago
27 years ago
24 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
18 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
19 years ago
25 years ago
19 years ago
27 years ago
25 years ago
27 years ago
25 years ago
17 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
17 years ago
25 years ago
24 years ago
25 years ago
25 years ago
25 years ago
25 years ago
24 years ago
25 years ago
27 years ago
27 years ago
27 years ago
21 years ago
27 years ago
27 years ago
22 years ago
27 years ago
27 years ago
27 years ago
19 years ago
27 years ago
27 years ago
22 years ago
27 years ago
27 years ago
27 years ago
23 years ago
18 years ago
27 years ago
27 years ago
27 years ago
27 years ago
19 years ago
22 years ago
22 years ago
19 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
22 years ago
27 years ago
27 years ago
22 years ago
22 years ago
22 years ago
22 years ago
27 years ago
27 years ago
26 years ago
25 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
22 years ago
22 years ago
21 years ago
21 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Zend Engine |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1998-2009 Zend Technologies Ltd. (http://www.zend.com) |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.00 of the Zend license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.zend.com/license/2_00.txt. |
  11. | If you did not receive a copy of the Zend license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@zend.com so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andi Gutmans <andi@zend.com> |
  16. | Zeev Suraski <zeev@zend.com> |
  17. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #include <stdio.h>
  21. #include <signal.h>
  22. #include "zend.h"
  23. #include "zend_compile.h"
  24. #include "zend_execute.h"
  25. #include "zend_API.h"
  26. #include "zend_ptr_stack.h"
  27. #include "zend_constants.h"
  28. #include "zend_extensions.h"
  29. #include "zend_exceptions.h"
  30. #include "zend_closures.h"
  31. #include "zend_vm.h"
  32. #include "zend_float.h"
  33. #ifdef HAVE_SYS_TIME_H
  34. #include <sys/time.h>
  35. #endif
  36. ZEND_API void (*zend_execute)(zend_op_array *op_array TSRMLS_DC);
  37. ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
  38. /* true globals */
  39. ZEND_API const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 };
  40. ZEND_API const zend_fcall_info_cache empty_fcall_info_cache = { 0, NULL, NULL, NULL, NULL };
  41. #ifdef ZEND_WIN32
  42. #include <process.h>
  43. static WNDCLASS wc;
  44. static HWND timeout_window;
  45. static HANDLE timeout_thread_event;
  46. static HANDLE timeout_thread_handle;
  47. static DWORD timeout_thread_id;
  48. static int timeout_thread_initialized=0;
  49. #endif
  50. #if 0&&ZEND_DEBUG
  51. static void (*original_sigsegv_handler)(int);
  52. static void zend_handle_sigsegv(int dummy) /* {{{ */
  53. {
  54. fflush(stdout);
  55. fflush(stderr);
  56. if (original_sigsegv_handler == zend_handle_sigsegv) {
  57. signal(SIGSEGV, original_sigsegv_handler);
  58. } else {
  59. signal(SIGSEGV, SIG_DFL);
  60. }
  61. {
  62. TSRMLS_FETCH();
  63. fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n",
  64. active_opline->opcode,
  65. active_opline-EG(active_op_array)->opcodes,
  66. get_active_function_name(TSRMLS_C),
  67. zend_get_executed_filename(TSRMLS_C),
  68. zend_get_executed_lineno(TSRMLS_C));
  69. }
  70. if (original_sigsegv_handler!=zend_handle_sigsegv) {
  71. original_sigsegv_handler(dummy);
  72. }
  73. }
  74. /* }}} */
  75. #endif
  76. static void zend_extension_activator(zend_extension *extension TSRMLS_DC) /* {{{ */
  77. {
  78. if (extension->activate) {
  79. extension->activate();
  80. }
  81. }
  82. /* }}} */
  83. static void zend_extension_deactivator(zend_extension *extension TSRMLS_DC) /* {{{ */
  84. {
  85. if (extension->deactivate) {
  86. extension->deactivate();
  87. }
  88. }
  89. /* }}} */
  90. static int clean_non_persistent_function(zend_function *function TSRMLS_DC) /* {{{ */
  91. {
  92. return (function->type == ZEND_INTERNAL_FUNCTION) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
  93. }
  94. /* }}} */
  95. static int clean_non_persistent_function_full(zend_function *function TSRMLS_DC) /* {{{ */
  96. {
  97. return (function->type != ZEND_INTERNAL_FUNCTION);
  98. }
  99. /* }}} */
  100. static int clean_non_persistent_class(zend_class_entry **ce TSRMLS_DC) /* {{{ */
  101. {
  102. return ((*ce)->type == ZEND_INTERNAL_CLASS) ? ZEND_HASH_APPLY_STOP : ZEND_HASH_APPLY_REMOVE;
  103. }
  104. /* }}} */
  105. static int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC) /* {{{ */
  106. {
  107. return ((*ce)->type != ZEND_INTERNAL_CLASS);
  108. }
  109. /* }}} */
  110. void init_executor(TSRMLS_D) /* {{{ */
  111. {
  112. zend_init_fpu(TSRMLS_C);
  113. INIT_ZVAL(EG(uninitialized_zval));
  114. /* trick to make uninitialized_zval never be modified, passed by ref, etc. */
  115. Z_ADDREF(EG(uninitialized_zval));
  116. INIT_ZVAL(EG(error_zval));
  117. EG(uninitialized_zval_ptr)=&EG(uninitialized_zval);
  118. EG(error_zval_ptr)=&EG(error_zval);
  119. zend_ptr_stack_init(&EG(arg_types_stack));
  120. /* destroys stack frame, therefore makes core dumps worthless */
  121. #if 0&&ZEND_DEBUG
  122. original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
  123. #endif
  124. EG(return_value_ptr_ptr) = NULL;
  125. EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
  126. EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
  127. EG(no_extensions) = 0;
  128. EG(function_table) = CG(function_table);
  129. EG(class_table) = CG(class_table);
  130. EG(in_execution) = 0;
  131. EG(in_autoload) = NULL;
  132. EG(autoload_func) = NULL;
  133. EG(error_handling) = EH_NORMAL;
  134. zend_vm_stack_init(TSRMLS_C);
  135. zend_vm_stack_push((void *) NULL TSRMLS_CC);
  136. zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0);
  137. {
  138. zval *globals;
  139. ALLOC_ZVAL(globals);
  140. Z_SET_REFCOUNT_P(globals, 1);
  141. Z_SET_ISREF_P(globals);
  142. Z_TYPE_P(globals) = IS_ARRAY;
  143. Z_ARRVAL_P(globals) = &EG(symbol_table);
  144. zend_hash_update(&EG(symbol_table), "GLOBALS", sizeof("GLOBALS"), &globals, sizeof(zval *), NULL);
  145. }
  146. EG(active_symbol_table) = &EG(symbol_table);
  147. zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_activator TSRMLS_CC);
  148. EG(opline_ptr) = NULL;
  149. zend_hash_init(&EG(included_files), 5, NULL, NULL, 0);
  150. EG(ticks_count) = 0;
  151. EG(user_error_handler) = NULL;
  152. EG(current_execute_data) = NULL;
  153. zend_stack_init(&EG(user_error_handlers_error_reporting));
  154. zend_ptr_stack_init(&EG(user_error_handlers));
  155. zend_ptr_stack_init(&EG(user_exception_handlers));
  156. zend_objects_store_init(&EG(objects_store), 1024);
  157. EG(full_tables_cleanup) = 0;
  158. #ifdef ZEND_WIN32
  159. EG(timed_out) = 0;
  160. #endif
  161. EG(exception) = NULL;
  162. EG(prev_exception) = NULL;
  163. EG(scope) = NULL;
  164. EG(called_scope) = NULL;
  165. EG(This) = NULL;
  166. EG(active_op_array) = NULL;
  167. EG(active) = 1;
  168. }
  169. /* }}} */
  170. static int zval_call_destructor(zval **zv TSRMLS_DC) /* {{{ */
  171. {
  172. if (Z_TYPE_PP(zv) == IS_OBJECT && Z_REFCOUNT_PP(zv) == 1) {
  173. return ZEND_HASH_APPLY_REMOVE;
  174. } else {
  175. return ZEND_HASH_APPLY_KEEP;
  176. }
  177. }
  178. /* }}} */
  179. void shutdown_destructors(TSRMLS_D) /* {{{ */
  180. {
  181. zend_try {
  182. int symbols;
  183. do {
  184. symbols = zend_hash_num_elements(&EG(symbol_table));
  185. zend_hash_reverse_apply(&EG(symbol_table), (apply_func_t) zval_call_destructor TSRMLS_CC);
  186. } while (symbols != zend_hash_num_elements(&EG(symbol_table)));
  187. zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC);
  188. } zend_catch {
  189. /* if we couldn't destruct cleanly, mark all objects as destructed anyway */
  190. zend_objects_store_mark_destructed(&EG(objects_store) TSRMLS_CC);
  191. } zend_end_try();
  192. }
  193. /* }}} */
  194. void shutdown_executor(TSRMLS_D) /* {{{ */
  195. {
  196. zend_try {
  197. /* Removed because this can not be safely done, e.g. in this situation:
  198. Object 1 creates object 2
  199. Object 3 holds reference to object 2.
  200. Now when 1 and 2 are destroyed, 3 can still access 2 in its destructor, with
  201. very problematic results */
  202. /* zend_objects_store_call_destructors(&EG(objects_store) TSRMLS_CC); */
  203. /* Moved after symbol table cleaners, because some of the cleaners can call
  204. destructors, which would use EG(symtable_cache_ptr) and thus leave leaks */
  205. /* while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
  206. zend_hash_destroy(*EG(symtable_cache_ptr));
  207. efree(*EG(symtable_cache_ptr));
  208. EG(symtable_cache_ptr)--;
  209. }
  210. */
  211. zend_llist_apply(&zend_extensions, (llist_apply_func_t) zend_extension_deactivator TSRMLS_CC);
  212. zend_hash_graceful_reverse_destroy(&EG(symbol_table));
  213. } zend_end_try();
  214. zend_try {
  215. zval *zeh;
  216. /* remove error handlers before destroying classes and functions,
  217. * so that if handler used some class, crash would not happen */
  218. if (EG(user_error_handler)) {
  219. zeh = EG(user_error_handler);
  220. EG(user_error_handler) = NULL;
  221. zval_dtor(zeh);
  222. FREE_ZVAL(zeh);
  223. }
  224. if (EG(user_exception_handler)) {
  225. zeh = EG(user_exception_handler);
  226. EG(user_exception_handler) = NULL;
  227. zval_dtor(zeh);
  228. FREE_ZVAL(zeh);
  229. }
  230. zend_stack_destroy(&EG(user_error_handlers_error_reporting));
  231. zend_stack_init(&EG(user_error_handlers_error_reporting));
  232. zend_ptr_stack_clean(&EG(user_error_handlers), ZVAL_DESTRUCTOR, 1);
  233. zend_ptr_stack_clean(&EG(user_exception_handlers), ZVAL_DESTRUCTOR, 1);
  234. } zend_end_try();
  235. zend_try {
  236. /* Cleanup static data for functions and arrays.
  237. * We need a separate cleanup stage because of the following problem:
  238. * Suppose we destroy class X, which destroys the class's function table,
  239. * and in the function table we have function foo() that has static $bar.
  240. * Now if an object of class X is assigned to $bar, its destructor will be
  241. * called and will fail since X's function table is in mid-destruction.
  242. * So we want first of all to clean up all data and then move to tables destruction.
  243. * Note that only run-time accessed data need to be cleaned up, pre-defined data can
  244. * not contain objects and thus are not probelmatic */
  245. if (EG(full_tables_cleanup)) {
  246. zend_hash_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
  247. } else {
  248. zend_hash_reverse_apply(EG(function_table), (apply_func_t) zend_cleanup_function_data TSRMLS_CC);
  249. }
  250. zend_hash_apply(EG(class_table), (apply_func_t) zend_cleanup_class_data TSRMLS_CC);
  251. zend_vm_stack_destroy(TSRMLS_C);
  252. zend_objects_store_free_object_storage(&EG(objects_store) TSRMLS_CC);
  253. /* Destroy all op arrays */
  254. if (EG(full_tables_cleanup)) {
  255. zend_hash_apply(EG(function_table), (apply_func_t) clean_non_persistent_function_full TSRMLS_CC);
  256. zend_hash_apply(EG(class_table), (apply_func_t) clean_non_persistent_class_full TSRMLS_CC);
  257. } else {
  258. zend_hash_reverse_apply(EG(function_table), (apply_func_t) clean_non_persistent_function TSRMLS_CC);
  259. zend_hash_reverse_apply(EG(class_table), (apply_func_t) clean_non_persistent_class TSRMLS_CC);
  260. }
  261. while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
  262. zend_hash_destroy(*EG(symtable_cache_ptr));
  263. FREE_HASHTABLE(*EG(symtable_cache_ptr));
  264. EG(symtable_cache_ptr)--;
  265. }
  266. } zend_end_try();
  267. zend_try {
  268. clean_non_persistent_constants(TSRMLS_C);
  269. } zend_end_try();
  270. zend_try {
  271. #if 0&&ZEND_DEBUG
  272. signal(SIGSEGV, original_sigsegv_handler);
  273. #endif
  274. zend_hash_destroy(&EG(included_files));
  275. zend_ptr_stack_destroy(&EG(arg_types_stack));
  276. zend_stack_destroy(&EG(user_error_handlers_error_reporting));
  277. zend_ptr_stack_destroy(&EG(user_error_handlers));
  278. zend_ptr_stack_destroy(&EG(user_exception_handlers));
  279. zend_objects_store_destroy(&EG(objects_store));
  280. if (EG(in_autoload)) {
  281. zend_hash_destroy(EG(in_autoload));
  282. FREE_HASHTABLE(EG(in_autoload));
  283. }
  284. } zend_end_try();
  285. zend_shutdown_fpu(TSRMLS_C);
  286. EG(active) = 0;
  287. }
  288. /* }}} */
  289. /* return class name and "::" or "". */
  290. ZEND_API char *get_active_class_name(char **space TSRMLS_DC) /* {{{ */
  291. {
  292. if (!zend_is_executing(TSRMLS_C)) {
  293. if (space) {
  294. *space = "";
  295. }
  296. return "";
  297. }
  298. switch (EG(current_execute_data)->function_state.function->type) {
  299. case ZEND_USER_FUNCTION:
  300. case ZEND_INTERNAL_FUNCTION:
  301. {
  302. zend_class_entry *ce = EG(current_execute_data)->function_state.function->common.scope;
  303. if (space) {
  304. *space = ce ? "::" : "";
  305. }
  306. return ce ? ce->name : "";
  307. }
  308. default:
  309. if (space) {
  310. *space = "";
  311. }
  312. return "";
  313. }
  314. }
  315. /* }}} */
  316. ZEND_API char *get_active_function_name(TSRMLS_D) /* {{{ */
  317. {
  318. if (!zend_is_executing(TSRMLS_C)) {
  319. return NULL;
  320. }
  321. switch (EG(current_execute_data)->function_state.function->type) {
  322. case ZEND_USER_FUNCTION: {
  323. char *function_name = ((zend_op_array *) EG(current_execute_data)->function_state.function)->function_name;
  324. if (function_name) {
  325. return function_name;
  326. } else {
  327. return "main";
  328. }
  329. }
  330. break;
  331. case ZEND_INTERNAL_FUNCTION:
  332. return ((zend_internal_function *) EG(current_execute_data)->function_state.function)->function_name;
  333. break;
  334. default:
  335. return NULL;
  336. }
  337. }
  338. /* }}} */
  339. ZEND_API char *zend_get_executed_filename(TSRMLS_D) /* {{{ */
  340. {
  341. if (EG(active_op_array)) {
  342. return EG(active_op_array)->filename;
  343. } else {
  344. return "[no active file]";
  345. }
  346. }
  347. /* }}} */
  348. ZEND_API uint zend_get_executed_lineno(TSRMLS_D) /* {{{ */
  349. {
  350. if (EG(opline_ptr)) {
  351. return active_opline->lineno;
  352. } else {
  353. return 0;
  354. }
  355. }
  356. /* }}} */
  357. ZEND_API zend_bool zend_is_executing(TSRMLS_D) /* {{{ */
  358. {
  359. return EG(in_execution);
  360. }
  361. /* }}} */
  362. ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
  363. {
  364. #if DEBUG_ZEND>=2
  365. printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, Z_REFCOUNT_PP(zval_ptr), Z_REFCOUNT_PP(zval_ptr) - 1);
  366. #endif
  367. Z_DELREF_PP(zval_ptr);
  368. if (Z_REFCOUNT_PP(zval_ptr) == 0) {
  369. TSRMLS_FETCH();
  370. if (*zval_ptr != &EG(uninitialized_zval)) {
  371. GC_REMOVE_ZVAL_FROM_BUFFER(*zval_ptr);
  372. zval_dtor(*zval_ptr);
  373. efree_rel(*zval_ptr);
  374. }
  375. } else {
  376. TSRMLS_FETCH();
  377. if (Z_REFCOUNT_PP(zval_ptr) == 1) {
  378. Z_UNSET_ISREF_PP(zval_ptr);
  379. }
  380. GC_ZVAL_CHECK_POSSIBLE_ROOT(*zval_ptr);
  381. }
  382. }
  383. /* }}} */
  384. ZEND_API void _zval_internal_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
  385. {
  386. #if DEBUG_ZEND>=2
  387. printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, Z_REFCOUNT_PP(zval_ptr), Z_REFCOUNT_PP(zval_ptr) - 1);
  388. #endif
  389. Z_DELREF_PP(zval_ptr);
  390. if (Z_REFCOUNT_PP(zval_ptr) == 0) {
  391. zval_internal_dtor(*zval_ptr);
  392. free(*zval_ptr);
  393. } else if (Z_REFCOUNT_PP(zval_ptr) == 1) {
  394. Z_UNSET_ISREF_PP(zval_ptr);
  395. }
  396. }
  397. /* }}} */
  398. ZEND_API int zend_is_true(zval *op) /* {{{ */
  399. {
  400. return i_zend_is_true(op);
  401. }
  402. /* }}} */
  403. #include "../TSRM/tsrm_strtok_r.h"
  404. #define IS_VISITED_CONSTANT IS_CONSTANT_INDEX
  405. #define IS_CONSTANT_VISITED(p) (Z_TYPE_P(p) & IS_VISITED_CONSTANT)
  406. #define Z_REAL_TYPE_P(p) (Z_TYPE_P(p) & ~IS_VISITED_CONSTANT)
  407. #define MARK_CONSTANT_VISITED(p) Z_TYPE_P(p) |= IS_VISITED_CONSTANT
  408. static void zval_deep_copy(zval **p)
  409. {
  410. zval *value;
  411. ALLOC_ZVAL(value);
  412. *value = **p;
  413. Z_TYPE_P(value) &= ~IS_CONSTANT_INDEX;
  414. zval_copy_ctor(value);
  415. Z_TYPE_P(value) = Z_TYPE_PP(p);
  416. INIT_PZVAL(value);
  417. *p = value;
  418. }
  419. ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *scope TSRMLS_DC) /* {{{ */
  420. {
  421. zval *p = *pp;
  422. zend_bool inline_change = (zend_bool) (zend_uintptr_t) arg;
  423. zval const_value;
  424. char *colon;
  425. if (IS_CONSTANT_VISITED(p)) {
  426. zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
  427. } else if ((Z_TYPE_P(p) & IS_CONSTANT_TYPE_MASK) == IS_CONSTANT) {
  428. int refcount;
  429. zend_uchar is_ref;
  430. SEPARATE_ZVAL_IF_NOT_REF(pp);
  431. p = *pp;
  432. MARK_CONSTANT_VISITED(p);
  433. refcount = Z_REFCOUNT_P(p);
  434. is_ref = Z_ISREF_P(p);
  435. if (!zend_get_constant_ex(p->value.str.val, p->value.str.len, &const_value, scope, Z_REAL_TYPE_P(p) TSRMLS_CC)) {
  436. char *actual = Z_STRVAL_P(p);
  437. if ((colon = zend_memrchr(Z_STRVAL_P(p), ':', Z_STRLEN_P(p)))) {
  438. zend_error(E_ERROR, "Undefined class constant '%s'", Z_STRVAL_P(p));
  439. Z_STRLEN_P(p) -= ((colon - Z_STRVAL_P(p)) + 1);
  440. if (inline_change) {
  441. colon = estrndup(colon, Z_STRLEN_P(p));
  442. efree(Z_STRVAL_P(p));
  443. Z_STRVAL_P(p) = colon;
  444. } else {
  445. Z_STRVAL_P(p) = colon + 1;
  446. }
  447. } else {
  448. char *save = actual, *slash;
  449. int actual_len = Z_STRLEN_P(p);
  450. if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) && (slash = (char *)zend_memrchr(actual, '\\', actual_len))) {
  451. actual = slash + 1;
  452. actual_len -= (actual - Z_STRVAL_P(p));
  453. if (inline_change) {
  454. actual = estrndup(actual, actual_len);
  455. Z_STRVAL_P(p) = actual;
  456. Z_STRLEN_P(p) = actual_len;
  457. }
  458. }
  459. if (actual[0] == '\\') {
  460. if (inline_change) {
  461. memmove(Z_STRVAL_P(p), Z_STRVAL_P(p)+1, Z_STRLEN_P(p));
  462. --Z_STRLEN_P(p);
  463. } else {
  464. ++actual;
  465. }
  466. --actual_len;
  467. }
  468. if ((Z_TYPE_P(p) & IS_CONSTANT_UNQUALIFIED) == 0) {
  469. int fix_save = 0;
  470. if (save[0] == '\\') {
  471. save++;
  472. fix_save = 1;
  473. }
  474. zend_error(E_ERROR, "Undefined constant '%s'", save);
  475. if (fix_save) {
  476. save--;
  477. }
  478. if (inline_change) {
  479. efree(save);
  480. }
  481. save = NULL;
  482. }
  483. if (inline_change && save && save != actual) {
  484. efree(save);
  485. }
  486. zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", actual, actual);
  487. p->type = IS_STRING;
  488. if (!inline_change) {
  489. Z_STRVAL_P(p) = actual;
  490. Z_STRLEN_P(p) = actual_len;
  491. zval_copy_ctor(p);
  492. }
  493. }
  494. } else {
  495. if (inline_change) {
  496. STR_FREE(Z_STRVAL_P(p));
  497. }
  498. *p = const_value;
  499. }
  500. Z_SET_REFCOUNT_P(p, refcount);
  501. Z_SET_ISREF_TO_P(p, is_ref);
  502. } else if (Z_TYPE_P(p) == IS_CONSTANT_ARRAY) {
  503. zval **element, *new_val;
  504. char *str_index;
  505. uint str_index_len;
  506. ulong num_index;
  507. int ret;
  508. SEPARATE_ZVAL_IF_NOT_REF(pp);
  509. p = *pp;
  510. Z_TYPE_P(p) = IS_ARRAY;
  511. if (!inline_change) {
  512. zval *tmp;
  513. HashTable *tmp_ht = NULL;
  514. ALLOC_HASHTABLE(tmp_ht);
  515. zend_hash_init(tmp_ht, zend_hash_num_elements(Z_ARRVAL_P(p)), NULL, ZVAL_PTR_DTOR, 0);
  516. zend_hash_copy(tmp_ht, Z_ARRVAL_P(p), (copy_ctor_func_t) zval_deep_copy, (void *) &tmp, sizeof(zval *));
  517. Z_ARRVAL_P(p) = tmp_ht;
  518. }
  519. /* First go over the array and see if there are any constant indices */
  520. zend_hash_internal_pointer_reset(Z_ARRVAL_P(p));
  521. while (zend_hash_get_current_data(Z_ARRVAL_P(p), (void **) &element) == SUCCESS) {
  522. if (!(Z_TYPE_PP(element) & IS_CONSTANT_INDEX)) {
  523. zend_hash_move_forward(Z_ARRVAL_P(p));
  524. continue;
  525. }
  526. Z_TYPE_PP(element) &= ~IS_CONSTANT_INDEX;
  527. if (zend_hash_get_current_key_ex(Z_ARRVAL_P(p), &str_index, &str_index_len, &num_index, 0, NULL) != HASH_KEY_IS_STRING) {
  528. zend_hash_move_forward(Z_ARRVAL_P(p));
  529. continue;
  530. }
  531. if (!zend_get_constant_ex(str_index, str_index_len - 3, &const_value, scope, str_index[str_index_len - 2] TSRMLS_CC)) {
  532. char *actual, *save = str_index;
  533. if ((colon = zend_memrchr(str_index, ':', str_index_len - 3))) {
  534. zend_error(E_ERROR, "Undefined class constant '%s'", str_index);
  535. str_index_len -= ((colon - str_index) + 1);
  536. str_index = colon;
  537. } else {
  538. if (str_index[str_index_len - 2] & IS_CONSTANT_UNQUALIFIED) {
  539. if ((actual = (char *)zend_memrchr(str_index, '\\', str_index_len - 3))) {
  540. actual++;
  541. str_index_len -= (actual - str_index);
  542. str_index = actual;
  543. }
  544. }
  545. if (str_index[0] == '\\') {
  546. ++str_index;
  547. --str_index_len;
  548. }
  549. if (save[0] == '\\') {
  550. ++save;
  551. }
  552. if ((str_index[str_index_len - 2] & IS_CONSTANT_UNQUALIFIED) == 0) {
  553. zend_error(E_ERROR, "Undefined constant '%s'", save);
  554. }
  555. zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", str_index, str_index);
  556. }
  557. ZVAL_STRINGL(&const_value, str_index, str_index_len-3, 1);
  558. }
  559. if (Z_REFCOUNT_PP(element) > 1) {
  560. ALLOC_ZVAL(new_val);
  561. *new_val = **element;
  562. zval_copy_ctor(new_val);
  563. Z_SET_REFCOUNT_P(new_val, 1);
  564. Z_UNSET_ISREF_P(new_val);
  565. /* preserve this bit for inheritance */
  566. Z_TYPE_PP(element) |= IS_CONSTANT_INDEX;
  567. zval_ptr_dtor(element);
  568. *element = new_val;
  569. }
  570. switch (Z_TYPE(const_value)) {
  571. case IS_STRING:
  572. ret = zend_symtable_update_current_key(Z_ARRVAL_P(p), Z_STRVAL(const_value), Z_STRLEN(const_value) + 1, HASH_UPDATE_KEY_IF_BEFORE);
  573. break;
  574. case IS_BOOL:
  575. case IS_LONG:
  576. ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, Z_LVAL(const_value), HASH_UPDATE_KEY_IF_BEFORE, NULL);
  577. break;
  578. case IS_DOUBLE:
  579. ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_LONG, NULL, 0, zend_dval_to_lval(Z_DVAL(const_value)), HASH_UPDATE_KEY_IF_BEFORE, NULL);
  580. break;
  581. case IS_NULL:
  582. ret = zend_hash_update_current_key_ex(Z_ARRVAL_P(p), HASH_KEY_IS_STRING, "", 1, 0, HASH_UPDATE_KEY_IF_BEFORE, NULL);
  583. break;
  584. default:
  585. ret = SUCCESS;
  586. break;
  587. }
  588. if (ret == SUCCESS) {
  589. zend_hash_move_forward(Z_ARRVAL_P(p));
  590. }
  591. zval_dtor(&const_value);
  592. }
  593. zend_hash_apply_with_argument(Z_ARRVAL_P(p), (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC);
  594. zend_hash_internal_pointer_reset(Z_ARRVAL_P(p));
  595. }
  596. return 0;
  597. }
  598. /* }}} */
  599. ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC) /* {{{ */
  600. {
  601. return zval_update_constant_ex(pp, arg, NULL TSRMLS_CC);
  602. }
  603. /* }}} */
  604. int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC) /* {{{ */
  605. {
  606. zval ***params_array;
  607. zend_uint i;
  608. int ex_retval;
  609. zval *local_retval_ptr = NULL;
  610. if (param_count) {
  611. params_array = (zval ***) emalloc(sizeof(zval **)*param_count);
  612. for (i=0; i<param_count; i++) {
  613. params_array[i] = &params[i];
  614. }
  615. } else {
  616. params_array = NULL;
  617. }
  618. ex_retval = call_user_function_ex(function_table, object_pp, function_name, &local_retval_ptr, param_count, params_array, 1, NULL TSRMLS_CC);
  619. if (local_retval_ptr) {
  620. COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
  621. } else {
  622. INIT_ZVAL(*retval_ptr);
  623. }
  624. if (params_array) {
  625. efree(params_array);
  626. }
  627. return ex_retval;
  628. }
  629. /* }}} */
  630. int call_user_function_ex(HashTable *function_table, zval **object_pp, zval *function_name, zval **retval_ptr_ptr, zend_uint param_count, zval **params[], int no_separation, HashTable *symbol_table TSRMLS_DC) /* {{{ */
  631. {
  632. zend_fcall_info fci;
  633. fci.size = sizeof(fci);
  634. fci.function_table = function_table;
  635. fci.object_ptr = object_pp ? *object_pp : NULL;
  636. fci.function_name = function_name;
  637. fci.retval_ptr_ptr = retval_ptr_ptr;
  638. fci.param_count = param_count;
  639. fci.params = params;
  640. fci.no_separation = (zend_bool) no_separation;
  641. fci.symbol_table = symbol_table;
  642. return zend_call_function(&fci, NULL TSRMLS_CC);
  643. }
  644. /* }}} */
  645. int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TSRMLS_DC) /* {{{ */
  646. {
  647. zend_uint i;
  648. zval **original_return_value;
  649. HashTable *calling_symbol_table;
  650. zend_op_array *original_op_array;
  651. zend_op **original_opline_ptr;
  652. zend_class_entry *current_scope;
  653. zend_class_entry *current_called_scope;
  654. zend_class_entry *calling_scope = NULL;
  655. zend_class_entry *called_scope = NULL;
  656. zval *current_this;
  657. zend_execute_data execute_data;
  658. *fci->retval_ptr_ptr = NULL;
  659. if (!EG(active)) {
  660. return FAILURE; /* executor is already inactive */
  661. }
  662. if (EG(exception)) {
  663. return FAILURE; /* we would result in an instable executor otherwise */
  664. }
  665. switch (fci->size) {
  666. case sizeof(zend_fcall_info):
  667. break; /* nothing to do currently */
  668. default:
  669. zend_error(E_ERROR, "Corrupted fcall_info provided to zend_call_function()");
  670. break;
  671. }
  672. /* Initialize execute_data */
  673. if (EG(current_execute_data)) {
  674. execute_data = *EG(current_execute_data);
  675. EX(op_array) = NULL;
  676. EX(opline) = NULL;
  677. EX(object) = NULL;
  678. } else {
  679. /* This only happens when we're called outside any execute()'s
  680. * It shouldn't be strictly necessary to NULL execute_data out,
  681. * but it may make bugs easier to spot
  682. */
  683. memset(&execute_data, 0, sizeof(zend_execute_data));
  684. }
  685. if (!fci_cache || !fci_cache->initialized) {
  686. zend_fcall_info_cache fci_cache_local;
  687. char *callable_name;
  688. char *error = NULL;
  689. if (!fci_cache) {
  690. fci_cache = &fci_cache_local;
  691. }
  692. if (!zend_is_callable_ex(fci->function_name, fci->object_ptr, IS_CALLABLE_CHECK_SILENT, &callable_name, NULL, fci_cache, &error TSRMLS_CC)) {
  693. if (error) {
  694. zend_error(E_WARNING, "Invalid callback %s, %s", callable_name, error);
  695. efree(error);
  696. }
  697. if (callable_name) {
  698. efree(callable_name);
  699. }
  700. return FAILURE;
  701. } else if (error) {
  702. /* Capitalize the first latter of the error message */
  703. if (error[0] >= 'a' && error[0] <= 'z') {
  704. error[0] += ('A' - 'a');
  705. }
  706. zend_error(E_STRICT, "%s", error);
  707. efree(error);
  708. }
  709. efree(callable_name);
  710. }
  711. EX(function_state).function = fci_cache->function_handler;
  712. calling_scope = fci_cache->calling_scope;
  713. called_scope = fci_cache->called_scope;
  714. fci->object_ptr = fci_cache->object_ptr;
  715. EX(object) = fci->object_ptr;
  716. if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
  717. (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
  718. return FAILURE;
  719. }
  720. if (EX(function_state).function->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
  721. if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
  722. zend_error_noreturn(E_ERROR, "Cannot call abstract method %s::%s()", EX(function_state).function->common.scope->name, EX(function_state).function->common.function_name);
  723. }
  724. if (EX(function_state).function->common.fn_flags & ZEND_ACC_DEPRECATED) {
  725. zend_error(E_DEPRECATED, "Function %s%s%s() is deprecated",
  726. EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
  727. EX(function_state).function->common.scope ? "::" : "",
  728. EX(function_state).function->common.function_name);
  729. }
  730. }
  731. ZEND_VM_STACK_GROW_IF_NEEDED(fci->param_count + 1);
  732. for (i=0; i<fci->param_count; i++) {
  733. zval *param;
  734. if (ARG_SHOULD_BE_SENT_BY_REF(EX(function_state).function, i + 1)
  735. && !PZVAL_IS_REF(*fci->params[i])) {
  736. if (Z_REFCOUNT_PP(fci->params[i]) > 1) {
  737. zval *new_zval;
  738. if (fci->no_separation) {
  739. if(i) {
  740. /* hack to clean up the stack */
  741. zend_vm_stack_push_nocheck((void *) (zend_uintptr_t)i TSRMLS_CC);
  742. zend_vm_stack_clear_multiple(TSRMLS_C);
  743. }
  744. zend_error(E_WARNING, "Parameter %d to %s%s%s() expected to be a reference, value given",
  745. i+1,
  746. EX(function_state).function->common.scope ? EX(function_state).function->common.scope->name : "",
  747. EX(function_state).function->common.scope ? "::" : "",
  748. EX(function_state).function->common.function_name);
  749. return FAILURE;
  750. }
  751. ALLOC_ZVAL(new_zval);
  752. *new_zval = **fci->params[i];
  753. zval_copy_ctor(new_zval);
  754. Z_SET_REFCOUNT_P(new_zval, 1);
  755. Z_DELREF_PP(fci->params[i]);
  756. *fci->params[i] = new_zval;
  757. }
  758. Z_ADDREF_PP(fci->params[i]);
  759. Z_SET_ISREF_PP(fci->params[i]);
  760. param = *fci->params[i];
  761. } else if (*fci->params[i] != &EG(uninitialized_zval)) {
  762. Z_ADDREF_PP(fci->params[i]);
  763. param = *fci->params[i];
  764. } else {
  765. ALLOC_ZVAL(param);
  766. *param = **(fci->params[i]);
  767. INIT_PZVAL(param);
  768. }
  769. zend_vm_stack_push_nocheck(param TSRMLS_CC);
  770. }
  771. EX(function_state).arguments = zend_vm_stack_top(TSRMLS_C);
  772. zend_vm_stack_push_nocheck((void*)(zend_uintptr_t)fci->param_count TSRMLS_CC);
  773. current_scope = EG(scope);
  774. EG(scope) = calling_scope;
  775. current_this = EG(This);
  776. current_called_scope = EG(called_scope);
  777. if (called_scope) {
  778. EG(called_scope) = called_scope;
  779. } else if (EX(function_state).function->type != ZEND_INTERNAL_FUNCTION) {
  780. EG(called_scope) = NULL;
  781. }
  782. if (fci->object_ptr) {
  783. if ((EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC)) {
  784. EG(This) = NULL;
  785. } else {
  786. EG(This) = fci->object_ptr;
  787. if (!PZVAL_IS_REF(EG(This))) {
  788. Z_ADDREF_P(EG(This)); /* For $this pointer */
  789. } else {
  790. zval *this_ptr;
  791. ALLOC_ZVAL(this_ptr);
  792. *this_ptr = *EG(This);
  793. INIT_PZVAL(this_ptr);
  794. zval_copy_ctor(this_ptr);
  795. EG(This) = this_ptr;
  796. }
  797. }
  798. } else {
  799. EG(This) = NULL;
  800. }
  801. EX(prev_execute_data) = EG(current_execute_data);
  802. EG(current_execute_data) = &execute_data;
  803. if (EX(function_state).function->type == ZEND_USER_FUNCTION) {
  804. calling_symbol_table = EG(active_symbol_table);
  805. EG(scope) = EX(function_state).function->common.scope;
  806. if (fci->symbol_table) {
  807. EG(active_symbol_table) = fci->symbol_table;
  808. } else {
  809. EG(active_symbol_table) = NULL;
  810. }
  811. original_return_value = EG(return_value_ptr_ptr);
  812. original_op_array = EG(active_op_array);
  813. EG(return_value_ptr_ptr) = fci->retval_ptr_ptr;
  814. EG(active_op_array) = (zend_op_array *) EX(function_state).function;
  815. original_opline_ptr = EG(opline_ptr);
  816. zend_execute(EG(active_op_array) TSRMLS_CC);
  817. if (!fci->symbol_table && EG(active_symbol_table)) {
  818. if (EG(symtable_cache_ptr)>=EG(symtable_cache_limit)) {
  819. zend_hash_destroy(EG(active_symbol_table));
  820. FREE_HASHTABLE(EG(active_symbol_table));
  821. } else {
  822. /* clean before putting into the cache, since clean
  823. could call dtors, which could use cached hash */
  824. zend_hash_clean(EG(active_symbol_table));
  825. *(++EG(symtable_cache_ptr)) = EG(active_symbol_table);
  826. }
  827. }
  828. EG(active_symbol_table) = calling_symbol_table;
  829. EG(active_op_array) = original_op_array;
  830. EG(return_value_ptr_ptr)=original_return_value;
  831. EG(opline_ptr) = original_opline_ptr;
  832. } else if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {
  833. int call_via_handler = (EX(function_state).function->common.fn_flags & ZEND_ACC_CALL_VIA_HANDLER) != 0;
  834. ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
  835. if (EX(function_state).function->common.scope) {
  836. EG(scope) = EX(function_state).function->common.scope;
  837. }
  838. ((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
  839. /* We shouldn't fix bad extensions here,
  840. because it can break proper ones (Bug #34045)
  841. if (!EX(function_state).function->common.return_reference)
  842. {
  843. INIT_PZVAL(*fci->retval_ptr_ptr);
  844. }*/
  845. if (EG(exception) && fci->retval_ptr_ptr) {
  846. zval_ptr_dtor(fci->retval_ptr_ptr);
  847. *fci->retval_ptr_ptr = NULL;
  848. }
  849. if (call_via_handler) {
  850. /* We must re-initialize function again */
  851. fci_cache->initialized = 0;
  852. }
  853. } else { /* ZEND_OVERLOADED_FUNCTION */
  854. ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
  855. /* Not sure what should be done here if it's a static method */
  856. if (fci->object_ptr) {
  857. Z_OBJ_HT_P(fci->object_ptr)->call_method(EX(function_state).function->common.function_name, fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
  858. } else {
  859. zend_error_noreturn(E_ERROR, "Cannot call overloaded function for non-object");
  860. }
  861. if (EX(function_state).function->type == ZEND_OVERLOADED_FUNCTION_TEMPORARY) {
  862. efree(EX(function_state).function->common.function_name);
  863. }
  864. efree(EX(function_state).function);
  865. if (EG(exception) && fci->retval_ptr_ptr) {
  866. zval_ptr_dtor(fci->retval_ptr_ptr);
  867. *fci->retval_ptr_ptr = NULL;
  868. }
  869. }
  870. zend_vm_stack_clear_multiple(TSRMLS_C);
  871. if (EG(This)) {
  872. zval_ptr_dtor(&EG(This));
  873. }
  874. EG(called_scope) = current_called_scope;
  875. EG(scope) = current_scope;
  876. EG(This) = current_this;
  877. EG(current_execute_data) = EX(prev_execute_data);
  878. if (EG(exception)) {
  879. zend_throw_exception_internal(NULL TSRMLS_CC);
  880. }
  881. return SUCCESS;
  882. }
  883. /* }}} */
  884. ZEND_API int zend_lookup_class_ex(const char *name, int name_length, int use_autoload, zend_class_entry ***ce TSRMLS_DC) /* {{{ */
  885. {
  886. zval **args[1];
  887. zval autoload_function;
  888. zval *class_name_ptr;
  889. zval *retval_ptr = NULL;
  890. int retval, lc_length;
  891. char *lc_name;
  892. char *lc_free;
  893. zend_fcall_info fcall_info;
  894. zend_fcall_info_cache fcall_cache;
  895. char dummy = 1;
  896. ulong hash;
  897. ALLOCA_FLAG(use_heap)
  898. if (name == NULL || !name_length) {
  899. return FAILURE;
  900. }
  901. lc_free = lc_name = do_alloca(name_length + 1, use_heap);
  902. zend_str_tolower_copy(lc_name, name, name_length);
  903. lc_length = name_length + 1;
  904. if (lc_name[0] == '\\') {
  905. lc_name += 1;
  906. lc_length -= 1;
  907. }
  908. hash = zend_inline_hash_func(lc_name, lc_length);
  909. if (zend_hash_quick_find(EG(class_table), lc_name, lc_length, hash, (void **) ce) == SUCCESS) {
  910. free_alloca(lc_free, use_heap);
  911. return SUCCESS;
  912. }
  913. /* The compiler is not-reentrant. Make sure we __autoload() only during run-time
  914. * (doesn't impact fuctionality of __autoload()
  915. */
  916. if (!use_autoload || zend_is_compiling(TSRMLS_C)) {
  917. free_alloca(lc_free, use_heap);
  918. return FAILURE;
  919. }
  920. if (EG(in_autoload) == NULL) {
  921. ALLOC_HASHTABLE(EG(in_autoload));
  922. zend_hash_init(EG(in_autoload), 0, NULL, NULL, 0);
  923. }
  924. if (zend_hash_quick_add(EG(in_autoload), lc_name, lc_length, hash, (void**)&dummy, sizeof(char), NULL) == FAILURE) {
  925. free_alloca(lc_free, use_heap);
  926. return FAILURE;
  927. }
  928. ZVAL_STRINGL(&autoload_function, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1, 0);
  929. ALLOC_ZVAL(class_name_ptr);
  930. INIT_PZVAL(class_name_ptr);
  931. ZVAL_STRINGL(class_name_ptr, name, name_length, 1);
  932. args[0] = &class_name_ptr;
  933. fcall_info.size = sizeof(fcall_info);
  934. fcall_info.function_table = EG(function_table);
  935. fcall_info.function_name = &autoload_function;
  936. fcall_info.symbol_table = NULL;
  937. fcall_info.retval_ptr_ptr = &retval_ptr;
  938. fcall_info.param_count = 1;
  939. fcall_info.params = args;
  940. fcall_info.object_ptr = NULL;
  941. fcall_info.no_separation = 1;
  942. fcall_cache.initialized = EG(autoload_func) ? 1 : 0;
  943. fcall_cache.function_handler = EG(autoload_func);
  944. fcall_cache.calling_scope = NULL;
  945. fcall_cache.called_scope = NULL;
  946. fcall_cache.object_ptr = NULL;
  947. zend_exception_save(TSRMLS_C);
  948. retval = zend_call_function(&fcall_info, &fcall_cache TSRMLS_CC);
  949. zend_exception_restore(TSRMLS_C);
  950. EG(autoload_func) = fcall_cache.function_handler;
  951. zval_ptr_dtor(&class_name_ptr);
  952. zend_hash_quick_del(EG(in_autoload), lc_name, lc_length, hash);
  953. if (retval_ptr) {
  954. zval_ptr_dtor(&retval_ptr);
  955. }
  956. if (retval == FAILURE) {
  957. free_alloca(lc_free, use_heap);
  958. return FAILURE;
  959. }
  960. retval = zend_hash_quick_find(EG(class_table), lc_name, lc_length, hash, (void **) ce);
  961. free_alloca(lc_free, use_heap);
  962. return retval;
  963. }
  964. /* }}} */
  965. ZEND_API int zend_lookup_class(const char *name, int name_length, zend_class_entry ***ce TSRMLS_DC) /* {{{ */
  966. {
  967. return zend_lookup_class_ex(name, name_length, 1, ce TSRMLS_CC);
  968. }
  969. /* }}} */
  970. ZEND_API int zend_eval_stringl(char *str, int str_len, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
  971. {
  972. zval pv;
  973. zend_op_array *new_op_array;
  974. zend_op_array *original_active_op_array = EG(active_op_array);
  975. zend_uint original_compiler_options;
  976. int retval;
  977. if (retval_ptr) {
  978. Z_STRLEN(pv) = str_len + sizeof("return ;") - 1;
  979. Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1);
  980. memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
  981. memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, str, str_len);
  982. Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
  983. Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
  984. } else {
  985. Z_STRLEN(pv) = str_len;
  986. Z_STRVAL(pv) = str;
  987. }
  988. Z_TYPE(pv) = IS_STRING;
  989. /*printf("Evaluating '%s'\n", pv.value.str.val);*/
  990. original_compiler_options = CG(compiler_options);
  991. CG(compiler_options) = ZEND_COMPILE_DEFAULT_FOR_EVAL;
  992. new_op_array = zend_compile_string(&pv, string_name TSRMLS_CC);
  993. CG(compiler_options) = original_compiler_options;
  994. if (new_op_array) {
  995. zval *local_retval_ptr=NULL;
  996. zval **original_return_value_ptr_ptr = EG(return_value_ptr_ptr);
  997. zend_op **original_opline_ptr = EG(opline_ptr);
  998. int orig_interactive = CG(interactive);
  999. EG(return_value_ptr_ptr) = &local_retval_ptr;
  1000. EG(active_op_array) = new_op_array;
  1001. EG(no_extensions)=1;
  1002. if (!EG(active_symbol_table)) {
  1003. zend_rebuild_symbol_table(TSRMLS_C);
  1004. }
  1005. CG(interactive) = 0;
  1006. zend_execute(new_op_array TSRMLS_CC);
  1007. CG(interactive) = orig_interactive;
  1008. if (local_retval_ptr) {
  1009. if (retval_ptr) {
  1010. COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr);
  1011. } else {
  1012. zval_ptr_dtor(&local_retval_ptr);
  1013. }
  1014. } else {
  1015. if (retval_ptr) {
  1016. INIT_ZVAL(*retval_ptr);
  1017. }
  1018. }
  1019. EG(no_extensions)=0;
  1020. EG(opline_ptr) = original_opline_ptr;
  1021. EG(active_op_array) = original_active_op_array;
  1022. destroy_op_array(new_op_array TSRMLS_CC);
  1023. efree(new_op_array);
  1024. EG(return_value_ptr_ptr) = original_return_value_ptr_ptr;
  1025. retval = SUCCESS;
  1026. } else {
  1027. retval = FAILURE;
  1028. }
  1029. if (retval_ptr) {
  1030. zval_dtor(&pv);
  1031. }
  1032. return retval;
  1033. }
  1034. /* }}} */
  1035. ZEND_API int zend_eval_string(char *str, zval *retval_ptr, char *string_name TSRMLS_DC) /* {{{ */
  1036. {
  1037. return zend_eval_stringl(str, strlen(str), retval_ptr, string_name TSRMLS_CC);
  1038. }
  1039. /* }}} */
  1040. ZEND_API int zend_eval_stringl_ex(char *str, int str_len, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
  1041. {
  1042. int result;
  1043. result = zend_eval_stringl(str, str_len, retval_ptr, string_name TSRMLS_CC);
  1044. if (handle_exceptions && EG(exception)) {
  1045. zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
  1046. result = FAILURE;
  1047. }
  1048. return result;
  1049. }
  1050. /* }}} */
  1051. ZEND_API int zend_eval_string_ex(char *str, zval *retval_ptr, char *string_name, int handle_exceptions TSRMLS_DC) /* {{{ */
  1052. {
  1053. return zend_eval_stringl_ex(str, strlen(str), retval_ptr, string_name, handle_exceptions TSRMLS_CC);
  1054. }
  1055. /* }}} */
  1056. void execute_new_code(TSRMLS_D) /* {{{ */
  1057. {
  1058. zend_op *opline, *end;
  1059. zend_op *ret_opline;
  1060. int orig_interactive;
  1061. if (!(CG(active_op_array)->fn_flags & ZEND_ACC_INTERACTIVE)
  1062. || CG(active_op_array)->backpatch_count>0
  1063. || CG(active_op_array)->function_name
  1064. || CG(active_op_array)->type!=ZEND_USER_FUNCTION) {
  1065. return;
  1066. }
  1067. ret_opline = get_next_op(CG(active_op_array) TSRMLS_CC);
  1068. ret_opline->opcode = ZEND_RETURN;
  1069. ret_opline->op1.op_type = IS_CONST;
  1070. INIT_ZVAL(ret_opline->op1.u.constant);
  1071. SET_UNUSED(ret_opline->op2);
  1072. if (!CG(active_op_array)->start_op) {
  1073. CG(active_op_array)->start_op = CG(active_op_array)->opcodes;
  1074. }
  1075. opline=CG(active_op_array)->start_op;
  1076. end=CG(active_op_array)->opcodes+CG(active_op_array)->last;
  1077. while (opline<end) {
  1078. if (opline->op1.op_type == IS_CONST) {
  1079. Z_SET_ISREF(opline->op1.u.constant);
  1080. Z_SET_REFCOUNT(opline->op1.u.constant, 2); /* Make sure is_ref won't be reset */
  1081. }
  1082. if (opline->op2.op_type == IS_CONST) {
  1083. Z_SET_ISREF(opline->op2.u.constant);
  1084. Z_SET_REFCOUNT(opline->op2.u.constant, 2);
  1085. }
  1086. switch (opline->opcode) {
  1087. case ZEND_GOTO:
  1088. if (Z_TYPE(opline->op2.u.constant) != IS_LONG) {
  1089. zend_resolve_goto_label(CG(active_op_array), opline, 1 TSRMLS_CC);
  1090. }
  1091. /* break omitted intentionally */
  1092. case ZEND_JMP:
  1093. opline->op1.u.jmp_addr = &CG(active_op_array)->opcodes[opline->op1.u.opline_num];
  1094. break;
  1095. case ZEND_JMPZ:
  1096. case ZEND_JMPNZ:
  1097. case ZEND_JMPZ_EX:
  1098. case ZEND_JMPNZ_EX:
  1099. case ZEND_JMP_SET:
  1100. opline->op2.u.jmp_addr = &CG(active_op_array)->opcodes[opline->op2.u.opline_num];
  1101. break;
  1102. }
  1103. ZEND_VM_SET_OPCODE_HANDLER(opline);
  1104. opline++;
  1105. }
  1106. zend_release_labels(TSRMLS_C);
  1107. EG(return_value_ptr_ptr) = NULL;
  1108. EG(active_op_array) = CG(active_op_array);
  1109. orig_interactive = CG(interactive);
  1110. CG(interactive) = 0;
  1111. zend_execute(CG(active_op_array) TSRMLS_CC);
  1112. CG(interactive) = orig_interactive;
  1113. if (EG(exception)) {
  1114. zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
  1115. }
  1116. CG(active_op_array)->last -= 1; /* get rid of that ZEND_RETURN */
  1117. CG(active_op_array)->start_op = CG(active_op_array)->opcodes+CG(active_op_array)->last;
  1118. }
  1119. /* }}} */
  1120. ZEND_API void zend_timeout(int dummy) /* {{{ */
  1121. {
  1122. TSRMLS_FETCH();
  1123. if (zend_on_timeout) {
  1124. zend_on_timeout(EG(timeout_seconds) TSRMLS_CC);
  1125. }
  1126. zend_error(E_ERROR, "Maximum execution time of %d second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s");
  1127. }
  1128. /* }}} */
  1129. #ifdef ZEND_WIN32
  1130. static LRESULT CALLBACK zend_timeout_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) /* {{{ */
  1131. {
  1132. switch (message) {
  1133. case WM_DESTROY:
  1134. PostQuitMessage(0);
  1135. break;
  1136. case WM_REGISTER_ZEND_TIMEOUT:
  1137. /* wParam is the thread id pointer, lParam is the timeout amount in seconds */
  1138. if (lParam == 0) {
  1139. KillTimer(timeout_window, wParam);
  1140. } else {
  1141. #ifdef ZTS
  1142. void ***tsrm_ls;
  1143. #endif
  1144. SetTimer(timeout_window, wParam, lParam*1000, NULL);
  1145. #ifdef ZTS
  1146. tsrm_ls = ts_resource_ex(0, &wParam);
  1147. if (!tsrm_ls) {
  1148. /* shouldn't normally happen */
  1149. break;
  1150. }
  1151. #endif
  1152. EG(timed_out) = 0;
  1153. }
  1154. break;
  1155. case WM_UNREGISTER_ZEND_TIMEOUT:
  1156. /* wParam is the thread id pointer */
  1157. KillTimer(timeout_window, wParam);
  1158. break;
  1159. case WM_TIMER: {
  1160. #ifdef ZTS
  1161. void ***tsrm_ls;
  1162. tsrm_ls = ts_resource_ex(0, &wParam);
  1163. if (!tsrm_ls) {
  1164. /* Thread died before receiving its timeout? */
  1165. break;
  1166. }
  1167. #endif
  1168. KillTimer(timeout_window, wParam);
  1169. EG(timed_out) = 1;
  1170. }
  1171. break;
  1172. default:
  1173. return DefWindowProc(hWnd, message, wParam, lParam);
  1174. }
  1175. return 0;
  1176. }
  1177. /* }}} */
  1178. static unsigned __stdcall timeout_thread_proc(void *pArgs) /* {{{ */
  1179. {
  1180. MSG message;
  1181. wc.style=0;
  1182. wc.lpfnWndProc = zend_timeout_WndProc;
  1183. wc.cbClsExtra=0;
  1184. wc.cbWndExtra=0;
  1185. wc.hInstance=NULL;
  1186. wc.hIcon=NULL;
  1187. wc.hCursor=NULL;
  1188. wc.hbrBackground=(HBRUSH)(COLOR_BACKGROUND + 5);
  1189. wc.lpszMenuName=NULL;
  1190. wc.lpszClassName = "Zend Timeout Window";
  1191. if (!RegisterClass(&wc)) {
  1192. return -1;
  1193. }
  1194. timeout_window = CreateWindow(wc.lpszClassName, wc.lpszClassName, 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
  1195. SetEvent(timeout_thread_event);
  1196. while (GetMessage(&message, NULL, 0, 0)) {
  1197. SendMessage(timeout_window, message.message, message.wParam, message.lParam);
  1198. if (message.message == WM_QUIT) {
  1199. break;
  1200. }
  1201. }
  1202. DestroyWindow(timeout_window);
  1203. UnregisterClass(wc.lpszClassName, NULL);
  1204. SetEvent(timeout_thread_handle);
  1205. return 0;
  1206. }
  1207. /* }}} */
  1208. void zend_init_timeout_thread(void) /* {{{ */
  1209. {
  1210. timeout_thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
  1211. timeout_thread_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
  1212. _beginthreadex(NULL, 0, timeout_thread_proc, NULL, 0, &timeout_thread_id);
  1213. WaitForSingleObject(timeout_thread_event, INFINITE);
  1214. }
  1215. /* }}} */
  1216. void zend_shutdown_timeout_thread(void) /* {{{ */
  1217. {
  1218. if (!timeout_thread_initialized) {
  1219. return;
  1220. }
  1221. PostThreadMessage(timeout_thread_id, WM_QUIT, 0, 0);
  1222. /* Wait for thread termination */
  1223. WaitForSingleObject(timeout_thread_handle, 5000);
  1224. CloseHandle(timeout_thread_handle);
  1225. timeout_thread_initialized = 0;
  1226. }
  1227. /* }}} */
  1228. #endif
  1229. /* This one doesn't exists on QNX */
  1230. #ifndef SIGPROF
  1231. #define SIGPROF 27
  1232. #endif
  1233. void zend_set_timeout(long seconds, int reset_signals) /* {{{ */
  1234. {
  1235. TSRMLS_FETCH();
  1236. EG(timeout_seconds) = seconds;
  1237. #ifdef ZEND_WIN32
  1238. if(!seconds) {
  1239. return;
  1240. }
  1241. if (timeout_thread_initialized == 0 && InterlockedIncrement(&timeout_thread_initialized) == 1) {
  1242. /* We start up this process-wide thread here and not in zend_startup(), because if Zend
  1243. * is initialized inside a DllMain(), you're not supposed to start threads from it.
  1244. */
  1245. zend_init_timeout_thread();
  1246. }
  1247. PostThreadMessage(timeout_thread_id, WM_REGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) seconds);
  1248. #else
  1249. # ifdef HAVE_SETITIMER
  1250. {
  1251. struct itimerval t_r; /* timeout requested */
  1252. sigset_t sigset;
  1253. if(seconds) {
  1254. t_r.it_value.tv_sec = seconds;
  1255. t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
  1256. # ifdef __CYGWIN__
  1257. setitimer(ITIMER_REAL, &t_r, NULL);
  1258. }
  1259. if(reset_signals) {
  1260. signal(SIGALRM, zend_timeout);
  1261. sigemptyset(&sigset);
  1262. sigaddset(&sigset, SIGALRM);
  1263. }
  1264. # else
  1265. setitimer(ITIMER_PROF, &t_r, NULL);
  1266. }
  1267. if(reset_signals) {
  1268. signal(SIGPROF, zend_timeout);
  1269. sigemptyset(&sigset);
  1270. sigaddset(&sigset, SIGPROF);
  1271. }
  1272. # endif
  1273. if(reset_signals) {
  1274. sigprocmask(SIG_UNBLOCK, &sigset, NULL);
  1275. }
  1276. }
  1277. # endif
  1278. #endif
  1279. }
  1280. /* }}} */
  1281. void zend_unset_timeout(TSRMLS_D) /* {{{ */
  1282. {
  1283. #ifdef ZEND_WIN32
  1284. if(timeout_thread_initialized) {
  1285. PostThreadMessage(timeout_thread_id, WM_UNREGISTER_ZEND_TIMEOUT, (WPARAM) GetCurrentThreadId(), (LPARAM) 0);
  1286. }
  1287. #else
  1288. # ifdef HAVE_SETITIMER
  1289. {
  1290. struct itimerval no_timeout;
  1291. no_timeout.it_value.tv_sec = no_timeout.it_value.tv_usec = no_timeout.it_interval.tv_sec = no_timeout.it_interval.tv_usec = 0;
  1292. #ifdef __CYGWIN__
  1293. setitimer(ITIMER_REAL, &no_timeout, NULL);
  1294. #else
  1295. setitimer(ITIMER_PROF, &no_timeout, NULL);
  1296. #endif
  1297. }
  1298. # endif
  1299. #endif
  1300. }
  1301. /* }}} */
  1302. zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len, int fetch_type TSRMLS_DC) /* {{{ */
  1303. {
  1304. zend_class_entry **pce;
  1305. int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
  1306. int silent = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
  1307. fetch_type &= ZEND_FETCH_CLASS_MASK;
  1308. check_fetch_type:
  1309. switch (fetch_type) {
  1310. case ZEND_FETCH_CLASS_SELF:
  1311. if (!EG(scope)) {
  1312. zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
  1313. }
  1314. return EG(scope);
  1315. case ZEND_FETCH_CLASS_PARENT:
  1316. if (!EG(scope)) {
  1317. zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
  1318. }
  1319. if (!EG(scope)->parent) {
  1320. zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
  1321. }
  1322. return EG(scope)->parent;
  1323. case ZEND_FETCH_CLASS_STATIC:
  1324. if (!EG(called_scope)) {
  1325. zend_error(E_ERROR, "Cannot access static:: when no class scope is active");
  1326. }
  1327. return EG(called_scope);
  1328. case ZEND_FETCH_CLASS_AUTO: {
  1329. fetch_type = zend_get_class_fetch_type(class_name, class_name_len);
  1330. if (fetch_type!=ZEND_FETCH_CLASS_DEFAULT) {
  1331. goto check_fetch_type;
  1332. }
  1333. }
  1334. break;
  1335. }
  1336. if (zend_lookup_class_ex(class_name, class_name_len, use_autoload, &pce TSRMLS_CC) == FAILURE) {
  1337. if (use_autoload) {
  1338. if (!silent && !EG(exception)) {
  1339. if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
  1340. zend_error(E_ERROR, "Interface '%s' not found", class_name);
  1341. } else {
  1342. zend_error(E_ERROR, "Class '%s' not found", class_name);
  1343. }
  1344. }
  1345. }
  1346. return NULL;
  1347. }
  1348. return *pce;
  1349. }
  1350. /* }}} */
  1351. #define MAX_ABSTRACT_INFO_CNT 3
  1352. #define MAX_ABSTRACT_INFO_FMT "%s%s%s%s"
  1353. #define DISPLAY_ABSTRACT_FN(idx) \
  1354. ai.afn[idx] ? ZEND_FN_SCOPE_NAME(ai.afn[idx]) : "", \
  1355. ai.afn[idx] ? "::" : "", \
  1356. ai.afn[idx] ? ai.afn[idx]->common.function_name : "", \
  1357. ai.afn[idx] && ai.afn[idx + 1] ? ", " : (ai.afn[idx] && ai.cnt > MAX_ABSTRACT_INFO_CNT ? ", ..." : "")
  1358. typedef struct _zend_abstract_info {
  1359. zend_function *afn[MAX_ABSTRACT_INFO_CNT + 1];
  1360. int cnt;
  1361. int ctor;
  1362. } zend_abstract_info;
  1363. static int zend_verify_abstract_class_function(zend_function *fn, zend_abstract_info *ai TSRMLS_DC) /* {{{ */
  1364. {
  1365. if (fn->common.fn_flags & ZEND_ACC_ABSTRACT) {
  1366. if (ai->cnt < MAX_ABSTRACT_INFO_CNT) {
  1367. ai->afn[ai->cnt] = fn;
  1368. }
  1369. if (fn->common.fn_flags & ZEND_ACC_CTOR) {
  1370. if (!ai->ctor) {
  1371. ai->cnt++;
  1372. ai->ctor = 1;
  1373. } else {
  1374. ai->afn[ai->cnt] = NULL;
  1375. }
  1376. } else {
  1377. ai->cnt++;
  1378. }
  1379. }
  1380. return 0;
  1381. }
  1382. /* }}} */
  1383. void zend_verify_abstract_class(zend_class_entry *ce TSRMLS_DC) /* {{{ */
  1384. {
  1385. zend_abstract_info ai;
  1386. if ((ce->ce_flags & ZEND_ACC_IMPLICIT_ABSTRACT_CLASS) && !(ce->ce_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
  1387. memset(&ai, 0, sizeof(ai));
  1388. zend_hash_apply_with_argument(&ce->function_table, (apply_func_arg_t) zend_verify_abstract_class_function, &ai TSRMLS_CC);
  1389. if (ai.cnt) {
  1390. zend_error(E_ERROR, "Class %s contains %d abstract method%s and must therefore be declared abstract or implement the remaining methods (" MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT MAX_ABSTRACT_INFO_FMT ")",
  1391. ce->name, ai.cnt,
  1392. ai.cnt > 1 ? "s" : "",
  1393. DISPLAY_ABSTRACT_FN(0),
  1394. DISPLAY_ABSTRACT_FN(1),
  1395. DISPLAY_ABSTRACT_FN(2)
  1396. );
  1397. }
  1398. }
  1399. }
  1400. /* }}} */
  1401. ZEND_API void zend_reset_all_cv(HashTable *symbol_table TSRMLS_DC) /* {{{ */
  1402. {
  1403. zend_execute_data *ex;
  1404. int i;
  1405. for (ex = EG(current_execute_data); ex; ex = ex->prev_execute_data) {
  1406. if (ex->op_array && ex->symbol_table == symbol_table) {
  1407. for (i = 0; i < ex->op_array->last_var; i++) {
  1408. ex->CVs[i] = NULL;
  1409. }
  1410. }
  1411. }
  1412. }
  1413. /* }}} */
  1414. ZEND_API int zend_delete_global_variable(char *name, int name_len TSRMLS_DC) /* {{{ */
  1415. {
  1416. zend_execute_data *ex;
  1417. ulong hash_value = zend_inline_hash_func(name, name_len + 1);
  1418. if (zend_hash_quick_exists(&EG(symbol_table), name, name_len + 1, hash_value)) {
  1419. for (ex = EG(current_execute_data); ex; ex = ex->prev_execute_data) {
  1420. if (ex->op_array && ex->symbol_table == &EG(symbol_table)) {
  1421. int i;
  1422. for (i = 0; i < ex->op_array->last_var; i++) {
  1423. if (ex->op_array->vars[i].hash_value == hash_value &&
  1424. ex->op_array->vars[i].name_len == name_len &&
  1425. !memcmp(ex->op_array->vars[i].name, name, name_len)
  1426. ) {
  1427. ex->CVs[i] = NULL;
  1428. break;
  1429. }
  1430. }
  1431. }
  1432. }
  1433. return zend_hash_quick_del(&EG(symbol_table), name, name_len + 1, hash_value);
  1434. }
  1435. return FAILURE;
  1436. }
  1437. /* }}} */
  1438. ZEND_API void zend_rebuild_symbol_table(TSRMLS_D) /* {{{ */
  1439. {
  1440. zend_uint i;
  1441. zend_execute_data *ex;
  1442. if (!EG(active_symbol_table)) {
  1443. /* Search for last called user function */
  1444. ex = EG(current_execute_data);
  1445. while (ex && !ex->op_array) {
  1446. ex = ex->prev_execute_data;
  1447. }
  1448. if (ex && ex->symbol_table) {
  1449. EG(active_symbol_table) = ex->symbol_table;
  1450. return;
  1451. }
  1452. if (ex && ex->op_array) {
  1453. if (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
  1454. /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
  1455. EG(active_symbol_table) = *(EG(symtable_cache_ptr)--);
  1456. } else {
  1457. ALLOC_HASHTABLE(EG(active_symbol_table));
  1458. zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0);
  1459. /*printf("Cache miss! Initialized %x\n", EG(active_symbol_table));*/
  1460. }
  1461. ex->symbol_table = EG(active_symbol_table);
  1462. if (ex->op_array->this_var != -1 &&
  1463. !ex->CVs[ex->op_array->this_var] &&
  1464. EG(This)) {
  1465. ex->CVs[ex->op_array->this_var] = (zval**)ex->CVs + ex->op_array->last_var + ex->op_array->this_var;
  1466. *ex->CVs[ex->op_array->this_var] = EG(This);
  1467. }
  1468. for (i = 0; i < ex->op_array->last_var; i++) {
  1469. if (ex->CVs[i]) {
  1470. zend_hash_quick_update(EG(active_symbol_table),
  1471. ex->op_array->vars[i].name,
  1472. ex->op_array->vars[i].name_len + 1,
  1473. ex->op_array->vars[i].hash_value,
  1474. (void**)ex->CVs[i],
  1475. sizeof(zval*),
  1476. (void**)&ex->CVs[i]);
  1477. }
  1478. }
  1479. }
  1480. }
  1481. }
  1482. /* }}} */
  1483. /*
  1484. * Local variables:
  1485. * tab-width: 4
  1486. * c-basic-offset: 4
  1487. * indent-tabs-mode: t
  1488. * End:
  1489. */