Data Structures | Macros | Typedefs
garray.h File Reference
#include <stddef.h>
#include "nvim/types.h"
#include "nvim/log.h"

Go to the source code of this file.

Data Structures

struct  growarray
 

Macros

#define GA_EMPTY_INIT_VALUE   { 0, 0, 0, 1, NULL }
 
#define GA_INIT(itemsize, growsize)   { 0, 0, (itemsize), (growsize), NULL }
 
#define GA_EMPTY(ga_ptr)   ((ga_ptr)->ga_len <= 0)
 
#define GA_APPEND(item_type, gap, item)
 
#define GA_APPEND_VIA_PTR(item_type, gap)   ga_append_via_ptr(gap, sizeof(item_type))
 
#define GA_DEEP_CLEAR(gap, item_type, free_item_fn)
 
#define FREE_PTR_PTR(ptr)   xfree(*(ptr))
 
#define GA_DEEP_CLEAR_PTR(gap)   GA_DEEP_CLEAR(gap, void*, FREE_PTR_PTR)
 

Typedefs

typedef struct growarray garray_T
 

Macro Definition Documentation

#define FREE_PTR_PTR (   ptr)    xfree(*(ptr))
#define GA_APPEND (   item_type,
  gap,
  item 
)
Value:
do { \
ga_grow(gap, 1); \
((item_type *)(gap)->ga_data)[(gap)->ga_len++] = (item); \
} while (0)
void ga_grow(garray_T *gap, int n)
Definition: garray.c:77
int item
Definition: edit.c:216
#define GA_APPEND_VIA_PTR (   item_type,
  gap 
)    ga_append_via_ptr(gap, sizeof(item_type))
#define GA_DEEP_CLEAR (   gap,
  item_type,
  free_item_fn 
)
Value:
do { \
garray_T *_gap = (gap); \
if (_gap->ga_data != NULL) { \
for (int i = 0; i < _gap->ga_len; i++) { \
item_type *_item = &(((item_type *)_gap->ga_data)[i]); \
free_item_fn(_item); \
} \
} \
ga_clear(_gap); \
} while (false)
void ga_clear(garray_T *gap)
Clear an allocated growing array.
Definition: garray.c:27
if(len)
Definition: encode.c:222
return NULL
Definition: eval.c:23987
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1217
int i
Definition: typval.c:868
struct growarray garray_T

Deep free a garray of specific type using a custom free function. Items in the array as well as the array itself are freed.

Parameters
gapthe garray to be freed
item_typetype of the item in the garray
free_item_fnfree function that takes (*item_type) as parameter
#define GA_DEEP_CLEAR_PTR (   gap)    GA_DEEP_CLEAR(gap, void*, FREE_PTR_PTR)

Call free for every pointer stored in the garray and then frees the garray.

Parameters
gapthe garray to be freed
#define GA_EMPTY (   ga_ptr)    ((ga_ptr)->ga_len <= 0)
#define GA_EMPTY_INIT_VALUE   { 0, 0, 0, 1, NULL }
#define GA_INIT (   itemsize,
  growsize 
)    { 0, 0, (itemsize), (growsize), NULL }

Typedef Documentation

typedef struct growarray garray_T

Structure used for growing arrays. This is used to store information that only grows, is deleted all at once, and needs to be accessed by index. See ga_clear() and ga_grow().