]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
moved mem_resize and mem_append vector function macros into gmqcc.h
authorWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 27 Jun 2012 12:50:52 +0000 (14:50 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 27 Jun 2012 12:50:52 +0000 (14:50 +0200)
exec.c
gmqcc.h

diff --git a/exec.c b/exec.c
index bb4b59cb4d04e77b8d780bd3630df90d6c2c9e26..297a4f3401856406831b14348d88d57b00214c9f 100644 (file)
--- 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 035079f704ef62926f1111a166d39077d8b29723..47c145cf4cae56aee092b8dce60f2900afbf9264 100644 (file)
--- 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) \
 {                                       \