Last change
on this file since 1164 was
1044,
checked in by Xuefer, 8 years ago

refactor: fix c89 compatibility


Property svn:eolstyle set to
native

File size:
1.3 KB

Line  

1  #ifndef XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B 

2  #define XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B 

3  

4  #if _MSC_VER > 1000 

5  #pragma once 

6  #endif /* _MSC_VER > 1000 */ 

7  

8  typedef struct { 

9  zend_uint size; 

10  zend_uint cnt; 

11  void *data; 

12  } xc_vector_t; 

13  

14  #define xc_vector_init(type, vector) do { \ 

15  (vector)>cnt = 0; \ 

16  (vector)>size = 0; \ 

17  (vector)>data = NULL; \ 

18  } while (0) 

19  

20  #define xc_vector_add(type, vector, value) do { \ 

21  if ((vector)>cnt == (vector)>size) { \ 

22  if ((vector)>size) { \ 

23  (vector)>size <<= 1; \ 

24  (vector)>data = erealloc((vector)>data, sizeof(type) * (vector)>size); \ 

25  } \ 

26  else { \ 

27  (vector)>size = 8; \ 

28  (vector)>data = emalloc(sizeof(type) * (vector)>size); \ 

29  } \ 

30  } \ 

31  ((type *) (vector)>data)[(vector)>cnt++] = value; \ 

32  } while (0) 

33  

34  static inline void *xc_vector_detach_impl(xc_vector_t *vector) 

35  { 

36  void *data = vector>data; 

37  vector>data = NULL; 

38  vector>size = 0; 

39  vector>cnt = 0; 

40  return data; 

41  } 

42  

43  #define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector)) 

44  

45  static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC) 

46  { 

47  if (vector>data) { 

48  efree(vector>data); 

49  } 

50  vector>size = 0; 

51  vector>cnt = 0; 

52  } 

53  

54  #define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC) 

55  

56  #endif /* XC_VECTOR_H_0957AC4E1A44E838C7B8DBECFF9C4B3B */ 

Note: See
TracBrowser
for help on using the repository browser.