XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
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.

72 lines
2.6 KiB

  1. #ifdef ZEND_ENGINE_2
  2. static void xc_var_collect_object(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
  3. {
  4. size_t next_index = xc_vector_size(&processor->objects);
  5. if (!xc_vector_initialized(&processor->objects)) {
  6. xc_vector_init(zend_object, &processor->objects, 0);
  7. zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
  8. }
  9. if (_zend_hash_index_update_or_next_insert(&processor->handle_to_index, handle, (void *) &next_index, sizeof(next_index), NULL, HASH_ADD ZEND_FILE_LINE_CC) == SUCCESS) {
  10. zend_object *object = zend_object_store_get_object_by_handle(handle TSRMLS_CC);
  11. xc_vector_push_back(&processor->objects, object);
  12. }
  13. }
  14. /* }}} */
  15. static size_t xc_var_store_handle(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
  16. {
  17. size_t *index;
  18. if (zend_hash_index_find(&processor->handle_to_index, handle, (void **) &index) != SUCCESS) {
  19. php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle not found in objects");
  20. return (size_t) -1;
  21. }
  22. return *index;
  23. }
  24. /* }}} */
  25. static zend_object_handle xc_var_restore_handle(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
  26. {
  27. zend_object_handle handle = processor->object_handles[index];
  28. zend_objects_store_add_ref_by_handle(handle TSRMLS_CC);
  29. return handle;
  30. }
  31. /* }}} */
  32. #endif
  33. static void xc_var_collect_class(xc_processor_t *processor, zend_class_entry *ce TSRMLS_DC) /* {{{ */
  34. {
  35. size_t next_index = xc_vector_size(&processor->class_names);
  36. if (zend_hash_add(&processor->class_name_to_index, ce->name, ce->name_length, (void *) &next_index, sizeof(next_index), NULL) == SUCCESS) {
  37. xc_constant_string_t class_name = { ce->name, ce->name_length };
  38. xc_vector_push_back(&processor->class_names, &class_name);
  39. }
  40. }
  41. /* }}} */
  42. /* on store */
  43. static size_t xc_var_ce_to_index(xc_processor_t *processor, zend_class_entry *ce TSRMLS_DC) /* {{{ */
  44. {
  45. size_t *index;
  46. if (zend_hash_find(&processor->class_name_to_index, ce->name, ce->name_length, (void **) &index) != SUCCESS) {
  47. php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: class name not found in class names");
  48. return (size_t) -1;
  49. }
  50. return *index;
  51. }
  52. /* }}} */
  53. /* on restore */
  54. static zend_class_entry *xc_var_index_to_ec(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
  55. {
  56. xc_constant_string_t *name = &processor->entry_var_src->class_names[index];
  57. zend_class_entry *ce;
  58. if (!(ce = xc_lookup_class(name->str, name->len+1 TSRMLS_CC))) {
  59. ce = zend_standard_class_def;
  60. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s not found when restroing variable", name->str);
  61. }
  62. return ce;
  63. }
  64. /* }}} */