source: svn/trunk/processor/var-helper.h @ 1567

Last change on this file since 1567 was 1567, checked in by Xuefer, 5 years ago

use vector for objects/object_handles

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1#ifdef ZEND_ENGINE_2
2static void xc_var_collect_object(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
3{
4    size_t next_index;
5
6    if (!xc_vector_initialized(&processor->object_handles)) {
7        xc_vector_init(zend_object, &processor->object_handles);
8        zend_hash_init(&processor->handle_to_index, 0, NULL, NULL, 0);
9    }
10
11    next_index = xc_vector_size(&processor->object_handles);
12    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) {
13        zend_object *object = zend_object_store_get_object_by_handle(handle TSRMLS_CC);
14        xc_vector_push_back(&processor->object_handles, object);
15    }
16}
17/* }}} */
18static size_t xc_var_store_handle(xc_processor_t *processor, zend_object_handle handle TSRMLS_DC) /* {{{ */
19{
20    size_t *index;
21
22    if (zend_hash_index_find(&processor->handle_to_index, handle, (void **) &index) != SUCCESS) {
23        php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: handle %d not found on store", handle);
24        return (size_t) -1;
25    }
26
27    return *index;
28}
29/* }}} */
30static zend_object_handle xc_var_restore_handle(xc_processor_t *processor, size_t index TSRMLS_DC) /* {{{ */
31{
32    zend_object_handle handle = xc_vector_data(zend_object_handle, &processor->object_handles)[index];
33    zend_objects_store_add_ref_by_handle(handle TSRMLS_CC);
34    return handle;
35}
36/* }}} */
37#endif
38static void xc_var_collect_class(xc_processor_t *processor, zend_class_entry *ce TSRMLS_DC) /* {{{ */
39{
40    size_t next_index;
41
42    if (!xc_vector_initialized(&processor->class_names)) {
43        xc_vector_init(xc_constant_string_t, &processor->class_names);
44        zend_hash_init(&processor->class_name_to_index, 0, NULL, NULL, 0);
45    }
46
47    /* HashTable <=PHP_4 cannot handle NULL pointers, +1 needed */
48    next_index = xc_vector_size(&processor->class_names) + 1;
49    if (zend_hash_add(&processor->class_name_to_index, ce->name, ce->name_length, (void *) &next_index, sizeof(next_index), NULL) == SUCCESS) {
50        xc_constant_string_t class_name;
51        class_name.str = (char *) ce->name;
52        class_name.len = ce->name_length;
53        xc_vector_push_back(&processor->class_names, &class_name);
54    }
55}
56/* }}} */
57static size_t xc_var_store_ce(xc_processor_t *processor, zend_class_entry *ce TSRMLS_DC) /* {{{ */
58{
59    size_t *index;
60
61    if (zend_hash_find(&processor->class_name_to_index, ce->name, ce->name_length, (void **) &index) != SUCCESS) {
62        php_error_docref(NULL TSRMLS_CC, E_CORE_ERROR, "Internal error: class name not found in class names");
63        return (size_t) - 1;
64    }
65
66    return *index - 1;
67}
68/* }}} */
69/* on restore */
Note: See TracBrowser for help on using the repository browser.