source: trunk/xcache/xc_extension.c @ 1045

Last change on this file since 1045 was 1045, checked in by moo, 2 years ago

refactor: bring back compatibility with Zend Optimizer

  • Property svn:eol-style set to native
File size: 2.8 KB
RevLine 
[1026]1
2#include "xc_extension.h"
3#include "xcache.h"
4#include "util/xc_trace.h"
5
6
[1045]7int xcache_zend_extension_prepend(zend_extension *new_extension) /* {{{ */
[1026]8{
9    zend_extension extension;
10
11    extension = *new_extension;
12    extension.handle = 0;
13
14    zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension);
15
[1045]16    zend_llist_prepend_element(&zend_extensions, &extension);
17    TRACE("%s", "prepended");
[1026]18    return SUCCESS;
19}
20/* }}} */
21static int xc_ptr_compare_func(void *p1, void *p2) /* {{{ */
22{
23    return p1 == p2;
24}
25/* }}} */
26static int xc_zend_extension_remove(zend_extension *extension) /* {{{ */
27{
28    llist_dtor_func_t dtor;
29
30    assert(extension);
31    dtor = zend_extensions.dtor; /* avoid dtor */
32    zend_extensions.dtor = NULL;
33    zend_llist_del_element(&zend_extensions, extension, xc_ptr_compare_func);
34    zend_extensions.dtor = dtor;
35    return SUCCESS;
36}
37/* }}} */
[1045]38int xcache_zend_extension_remove(zend_extension *extension) /* {{{ */
[1026]39{
40    zend_extension *ext = zend_get_extension(extension->name);
41    if (!ext) {
42        return FAILURE;
43    }
44
45    if (ext->shutdown) {
46        ext->shutdown(ext);
47    }
48    xc_zend_extension_remove(ext);
49    return SUCCESS;
50}
51/* }}} */
52
[1045]53int xcache_zend_extension_count_by_prefix(zend_llist *l, const char *extension_name_prefix) /* {{{ */
[1026]54{
55    zend_llist_element *element;
[1045]56    size_t n = strlen(extension_name_prefix);
57    int count = 0;
[1026]58
59    for (element = zend_extensions.head; element; element = element->next) {
60        zend_extension *extension = (zend_extension *) element->data;
61
[1045]62        if (strncmp(extension->name, extension_name_prefix, n) == 0) {
63            ++count;
[1026]64        }
65    }
[1045]66    return count;
[1026]67}
68/* }}} */
[1045]69void xcache_zend_extension_unlink_by_prefix(xc_stack_t *linked, zend_llist *l, const char *extension_name_prefix) /* {{{ */
70{
71    size_t n = strlen(extension_name_prefix);
72    zend_llist_element *unlinked = NULL;
73    zend_llist_element *element, *next;
74
75    for (element = zend_extensions.head; element; element = next) {
76        zend_extension *extension = (zend_extension *) element->data;
77        next = element->next;
78
79        if (strncmp(extension->name, extension_name_prefix, n) == 0) {
80            xcache_llist_unlink(l, element);
81            xc_stack_push(linked, element);
82        }
83    }
84
85    for (element = zend_extensions.head; element; element = next) {
86        zend_extension *extension = (zend_extension *) element->data;
87        next = element->next;
88    }
89}
90/* }}} */
[1026]91void xcache_llist_prepend(zend_llist *l, zend_llist_element *element) /* {{{ */
92{
93    element->next = l->head;
94    element->prev = NULL;
95    if (l->head) {
96        l->head->prev = element;
97    }
98    else {
99        l->tail = element;
100    }
101    l->head = element;
102    ++l->count;
103}
104/* }}} */
105void xcache_llist_unlink(zend_llist *l, zend_llist_element *element) /* {{{ */
106{
107    if ((element)->prev) {
108        (element)->prev->next = (element)->next;
109    }
110    else {
111        (l)->head = (element)->next;
112    }
113
114    if ((element)->next) {
115        (element)->next->prev = (element)->prev;
116    }
117    else {
118        (l)->tail = (element)->prev;
119    }
120
121    --l->count;
122}
123/* }}} */
Note: See TracBrowser for help on using the repository browser.