PageRenderTime 231ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 1ms

/Zend/zend_execute_API.c

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