From: Wolfgang (Blub) Bumiller Date: Wed, 27 Jun 2012 12:50:52 +0000 (+0200) Subject: moved mem_resize and mem_append vector function macros into gmqcc.h X-Git-Tag: 0.1-rc1~371^2~14 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2fd3ddcb1a23ca0e5f5e2a7499b1f73b32ba3955;p=xonotic%2Fgmqcc.git moved mem_resize and mem_append vector function macros into gmqcc.h --- diff --git a/exec.c b/exec.c index bb4b59c..297a4f3 100644 --- a/exec.c +++ b/exec.c @@ -2,56 +2,6 @@ #define QCVM_EXECUTOR -#define _MEM_VEC_FUN_APPEND(Tself, Twhat, mem) \ -bool GMQCC_WARN Tself##_##mem##_append(Tself *s, Twhat *p, size_t c) \ -{ \ - Twhat *reall; \ - if (s->mem##_count+c >= s->mem##_alloc) { \ - if (!s->mem##_alloc) { \ - s->mem##_alloc = c < 16 ? 16 : c; \ - } else { \ - s->mem##_alloc *= 2; \ - if (s->mem##_count+c >= s->mem##_alloc) { \ - s->mem##_alloc = s->mem##_count+c; \ - } \ - } \ - reall = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \ - if (!reall) { \ - return false; \ - } \ - memcpy(reall, s->mem, sizeof(Twhat) * s->mem##_count); \ - mem_d(s->mem); \ - s->mem = reall; \ - } \ - memcpy(&s->mem[s->mem##_count], p, c*sizeof(*p)); \ - s->mem##_count += c; \ - return true; \ -} - -#define _MEM_VEC_FUN_RESIZE(Tself, Twhat, mem) \ -bool GMQCC_WARN Tself##_##mem##_resize(Tself *s, size_t c) \ -{ \ - Twhat *reall; \ - if (c > s->mem##_alloc) { \ - reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ - if (!reall) { return false; } \ - memcpy(reall, s->mem, sizeof(Twhat) * s->mem##_count); \ - s->mem##_alloc = c; \ - mem_d(s->mem); \ - s->mem = reall; \ - return true; \ - } \ - s->mem##_count = c; \ - if (c < (s->mem##_alloc / 2)) { \ - reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ - if (!reall) { return false; } \ - memcpy(reall, s->mem, sizeof(Twhat) * c); \ - mem_d(s->mem); \ - s->mem = reall; \ - } \ - return true; \ -} - /* darkplaces has (or will have) a 64 bit prog loader * where the 32 bit qc program is autoconverted on load. * Since we may want to support that as well, let's redefine diff --git a/gmqcc.h b/gmqcc.h index 035079f..47c145c 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -737,6 +737,56 @@ bool GMQCC_WARN Tself##_##mem##_find(Tself *self, Twhat obj, size_t *idx) \ return false; \ } +#define _MEM_VEC_FUN_APPEND(Tself, Twhat, mem) \ +bool GMQCC_WARN Tself##_##mem##_append(Tself *s, Twhat *p, size_t c) \ +{ \ + Twhat *reall; \ + if (s->mem##_count+c >= s->mem##_alloc) { \ + if (!s->mem##_alloc) { \ + s->mem##_alloc = c < 16 ? 16 : c; \ + } else { \ + s->mem##_alloc *= 2; \ + if (s->mem##_count+c >= s->mem##_alloc) { \ + s->mem##_alloc = s->mem##_count+c; \ + } \ + } \ + reall = (Twhat*)mem_a(sizeof(Twhat) * s->mem##_alloc); \ + if (!reall) { \ + return false; \ + } \ + memcpy(reall, s->mem, sizeof(Twhat) * s->mem##_count); \ + mem_d(s->mem); \ + s->mem = reall; \ + } \ + memcpy(&s->mem[s->mem##_count], p, c*sizeof(*p)); \ + s->mem##_count += c; \ + return true; \ +} + +#define _MEM_VEC_FUN_RESIZE(Tself, Twhat, mem) \ +bool GMQCC_WARN Tself##_##mem##_resize(Tself *s, size_t c) \ +{ \ + Twhat *reall; \ + if (c > s->mem##_alloc) { \ + reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ + if (!reall) { return false; } \ + memcpy(reall, s->mem, sizeof(Twhat) * s->mem##_count); \ + s->mem##_alloc = c; \ + mem_d(s->mem); \ + s->mem = reall; \ + return true; \ + } \ + s->mem##_count = c; \ + if (c < (s->mem##_alloc / 2)) { \ + reall = (Twhat*)mem_a(sizeof(Twhat) * c); \ + if (!reall) { return false; } \ + memcpy(reall, s->mem, sizeof(Twhat) * c); \ + mem_d(s->mem); \ + s->mem = reall; \ + } \ + return true; \ +} + #define _MEM_VEC_FUN_CLEAR(Tself, mem) \ void Tself##_##mem##_clear(Tself *self) \ { \