Changeset 212 for trunk/utils.c
- Timestamp:
- 2006-10-04T02:38:45+02:00 (7 years ago)
- File:
-
- 1 edited
-
trunk/utils.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/utils.c
r210 r212 1 #include "php.h" 1 2 2 #include "xcache.h" 3 3 #include "utils.h" … … 9 9 #include "assert.h" 10 10 11 #ifndef ZEND_VM_SET_OPCODE_HANDLER 12 # define ZEND_VM_SET_OPCODE_HANDLER(opline) do { } while (0) 13 #endif 14 15 #define OP_ZVAL_DTOR(op) do { \ 16 (op).u.constant.is_ref = 0; \ 17 zval_dtor(&(op).u.constant); \ 18 } while(0) 11 19 xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, /* {{{ */ 12 20 zend_op_array *op_array, … … 264 272 /* }}} */ 265 273 #endif 274 275 int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zend_op *opline, int oplineno, void *data TSRMLS_DC), void *data TSRMLS_DC) /* {{{ */ 276 { 277 zend_op *opline, *begin, *end, *next = NULL; 278 xc_cest_t cest; 279 280 opline = begin = op_array->opcodes; 281 end = opline + op_array->last; 282 while (opline < end) { 283 switch (opline->opcode) { 284 case ZEND_JMP: 285 next = begin + opline->op1.u.opline_num; 286 break; 287 288 case ZEND_JMPZNZ: 289 next = begin + max(opline->op2.u.opline_num, opline->extended_value); 290 break; 291 292 case ZEND_JMPZ: 293 case ZEND_JMPNZ: 294 case ZEND_JMPZ_EX: 295 case ZEND_JMPNZ_EX: 296 next = begin + opline->op2.u.opline_num; 297 break; 298 299 case ZEND_RETURN: 300 opline = end; 301 break; 302 303 case ZEND_DECLARE_INHERITED_CLASS: 304 callback(opline, opline - begin, data TSRMLS_CC); 305 break; 306 } 307 308 if (opline < next) { 309 opline = next; 310 } 311 else { 312 opline ++; 313 } 314 } 315 } 316 /* }}} */ 317 int xc_do_early_binding(zend_op_array *op_array, HashTable *class_table, int oplineno TSRMLS_DC) /* {{{ */ 318 { 319 zend_op *opline, *opcodes; 320 321 #ifdef DEBUG 322 fprintf(stderr, "binding %d\n", oplineno); 323 #endif 324 assert(oplineno >= 0); 325 326 /* do early binding */ 327 opline = &(op_array->opcodes[oplineno]); 328 329 switch (opline->opcode) { 330 case ZEND_DECLARE_INHERITED_CLASS: 331 #ifdef ZEND_ENGINE_2 332 { 333 zval *parent_name; 334 zend_class_entry **pce; 335 parent_name = &(opline - 1)->op2.u.constant; 336 #ifdef DEBUG 337 fprintf(stderr, "binding with parent %s\n", Z_STRVAL_P(parent_name)); 338 #endif 339 if (zend_lookup_class(Z_STRVAL_P(parent_name), Z_STRLEN_P(parent_name), &pce TSRMLS_CC) == FAILURE) { 340 return FAILURE; 341 } 342 343 if (do_bind_inherited_class(opline, class_table, *pce, 1 TSRMLS_CC) == NULL) { 344 return FAILURE; 345 } 346 } 347 #else 348 if (do_bind_function_or_class(opline, NULL, class_table, 1) == FAILURE) { 349 return FAILURE; 350 } 351 #endif 352 353 #ifdef ZEND_FETCH_CLASS 354 /* clear unnecessary ZEND_FETCH_CLASS opcode */ 355 if (opline > op_array->opcodes 356 && (opline - 1)->opcode == ZEND_FETCH_CLASS) { 357 zend_op *fetch_class_opline = opline - 1; 358 359 #ifdef DEBUG 360 fprintf(stderr, "%s %p\n", Z_STRVAL(fetch_class_opline->op2.u.constant), Z_STRVAL(fetch_class_opline->op2.u.constant)); 361 #endif 362 OP_ZVAL_DTOR(fetch_class_opline->op2); 363 fetch_class_opline->opcode = ZEND_NOP; 364 ZEND_VM_SET_OPCODE_HANDLER(fetch_class_opline); 365 memset(&fetch_class_opline->op1, 0, sizeof(znode)); 366 memset(&fetch_class_opline->op2, 0, sizeof(znode)); 367 SET_UNUSED(fetch_class_opline->op1); 368 SET_UNUSED(fetch_class_opline->op2); 369 SET_UNUSED(fetch_class_opline->result); 370 } 371 #endif 372 break; 373 374 default: 375 return FAILURE; 376 } 377 378 zend_hash_del(class_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len); 379 OP_ZVAL_DTOR(opline->op1); 380 OP_ZVAL_DTOR(opline->op2); 381 opline->opcode = ZEND_NOP; 382 ZEND_VM_SET_OPCODE_HANDLER(opline); 383 memset(&opline->op1, 0, sizeof(znode)); 384 memset(&opline->op2, 0, sizeof(znode)); 385 SET_UNUSED(opline->op1); 386 SET_UNUSED(opline->op2); 387 return SUCCESS; 388 } 389 /* }}} */ 266 390 267 391 #ifdef HAVE_XCACHE_CONSTANT … … 320 444 } 321 445 /* }}} */ 322 ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, zend_uchar type, zstr key, uint len TSRMLS_DC) /* {{{ */446 ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, zstr key, uint len TSRMLS_DC) /* {{{ */ 323 447 { 324 448 zend_bool istmpkey; … … 336 460 ZESW(&stored_ce_ptr, NULL) 337 461 ); 462 if (oplineno != -1) { 463 xc_do_early_binding(CG(active_op_array), CG(class_table), oplineno TSRMLS_CC); 464 } 338 465 } 339 466 else if (zend_u_hash_add(CG(class_table), type, key, len, … … 349 476 zend_error(E_ERROR, "Cannot redeclare class %s", cep->name); 350 477 #endif 478 assert(oplineno == -1); 351 479 } 352 480 ZESW(return (xc_cest_t *) stored_ce_ptr, NOTHING); … … 403 531 404 532 return sandbox; 533 } 534 /* }}} */ 535 static void xc_early_binding_cb(zend_op *opline, int oplineno, void *data TSRMLS_DC) /* {{{ */ 536 { 537 xc_sandbox_t *sandbox = (xc_sandbox_t *) data; 538 xc_do_early_binding(CG(active_op_array), OG(class_table), oplineno TSRMLS_CC); 405 539 } 406 540 /* }}} */ … … 433 567 /* install class */ 434 568 while (b != NULL) { 435 xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, 569 xc_install_class(sandbox->filename, (xc_cest_t*) b->pData, -1, 436 570 BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength TSRMLS_CC); 437 571 b = b->pListNext; 438 572 } 573 xc_undo_pass_two(CG(active_op_array) TSRMLS_CC); 574 xc_foreach_early_binding_class(CG(active_op_array), xc_early_binding_cb, (void *) sandbox TSRMLS_CC); 575 xc_redo_pass_two(CG(active_op_array) TSRMLS_CC); 439 576 440 577 i = 1;
Note: See TracChangeset
for help on using the changeset viewer.

