Allow re-use of ensure_space_for macro

This commit is contained in:
Kovid Goyal 2017-11-13 15:29:52 +05:30
parent a97ba08cbb
commit aef8b4ae67
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 9 deletions

View File

@ -232,6 +232,16 @@ typedef struct {
clear_sprite_position((line)->cells[(at)]); \
}
#define ensure_space_for(base, array, type, num, capacity, initial_cap, zero_mem) \
if ((base)->capacity < num) { \
size_t _newcap = MAX(initial_cap, MAX(2 * (base)->capacity, num)); \
(base)->array = realloc((base)->array, sizeof(type) * _newcap); \
if ((base)->array == NULL) fatal("Out of memory while ensuring space in array"); \
if (zero_mem) memset((base)->array + (base)->capacity, 0, sizeof(type) * (_newcap - (base)->capacity)); \
(base)->capacity = _newcap; \
}
// Global functions
const char* base64_decode(const uint32_t *src, size_t src_sz, uint8_t *dest, size_t dest_capacity, size_t *dest_sz);
Line* alloc_line();

View File

@ -23,15 +23,6 @@ PyTypeObject GraphicsManager_Type;
#define REPORT_ERROR(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); }
#define ensure_space_for(base, array, type, num, capacity, initial_cap, zero_mem) \
if (base->capacity < num) { \
size_t _newcap = MAX(initial_cap, MAX(2 * base->capacity, num)); \
base->array = realloc(base->array, sizeof(type) * _newcap); \
if (base->array == NULL) fatal("Out of memory while ensuring space in array"); \
if (zero_mem) memset(base->array + base->capacity, 0, sizeof(type) * (_newcap - base->capacity)); \
base->capacity = _newcap; \
}
static bool send_to_gpu = true;