moved mem_resize and mem_append vector function macros into gmqcc.h

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-06-27 14:50:52 +02:00
parent 0dae2898e3
commit 2fd3ddcb1a
2 changed files with 50 additions and 50 deletions

50
exec.c
View file

@ -2,56 +2,6 @@
#define QCVM_EXECUTOR #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 /* darkplaces has (or will have) a 64 bit prog loader
* where the 32 bit qc program is autoconverted on load. * where the 32 bit qc program is autoconverted on load.
* Since we may want to support that as well, let's redefine * Since we may want to support that as well, let's redefine

50
gmqcc.h
View file

@ -737,6 +737,56 @@ bool GMQCC_WARN Tself##_##mem##_find(Tself *self, Twhat obj, size_t *idx) \
return false; \ 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) \ #define _MEM_VEC_FUN_CLEAR(Tself, mem) \
void Tself##_##mem##_clear(Tself *self) \ void Tself##_##mem##_clear(Tself *self) \
{ \ { \