Changeset 662 for trunk/utils.h


Ignore:
Timestamp:
2009-08-03T10:15:53+02:00 (6 years ago)
Author:
moo
Message:

back patch __FILE and __DIR on cache restore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils.h

    r640 r662  
    3838
    3939#   define IFDEBUG(x) do { } while (0)
    40 #   ifndef NDEBUG
    41 #       define NDEBUG
    42 #   endif
    4340#endif /* XCACHE_DEBUG */
    4441#include <assert.h>
     
    132129void xc_copy_internal_zend_constants(HashTable *target, HashTable *source);
    133130#endif
     131
     132typedef struct {
     133    zend_uint size;
     134    zend_uint cnt;
     135    void *data;
     136} xc_vector_t;
     137
     138#define xc_vector_init(type, vector) do { \
     139    (vector)->cnt = 0;     \
     140    (vector)->size = 0;    \
     141    (vector)->data = NULL; \
     142} while (0)
     143
     144#define xc_vector_add(type, vector, value) do { \
     145    if ((vector)->cnt == (vector)->size) { \
     146        if ((vector)->size) { \
     147            (vector)->size <<= 1; \
     148            (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
     149        } \
     150        else { \
     151            (vector)->size = 8; \
     152            (vector)->data = emalloc(sizeof(type) * (vector)->size); \
     153        } \
     154    } \
     155    ((type *) (vector)->data)[(vector)->cnt++] = value; \
     156} while (0)
     157
     158static inline void *xc_vector_detach_impl(xc_vector_t *vector)
     159{
     160    void *data = vector->data;
     161    vector->data = NULL;
     162    vector->size = 0;
     163    vector->cnt = 0;
     164    return data;
     165}
     166
     167#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))
     168
     169static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
     170{
     171    if (vector->data) {
     172        efree(vector->data);
     173    }
     174    vector->size = 0;
     175    vector->cnt = 0;
     176}
     177
     178#define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)
     179
Note: See TracChangeset for help on using the changeset viewer.