Anonymous avatar Anonymous committed b27465c

Use GC_MALLOC_ATOMIC where applicable.

Comments (0)

Files changed (7)

 #define AR_ALLOCTE(x, e) GC_MALLOC(sizeof(x) + (e))
 #define AR_ALLOCT(x) AR_ALLOCTE(x, 0)
 #define AR_ALLOCTN(x, n) GC_MALLOC((n) * sizeof(x))
+/* the "atomic" version, for memory that won't contain pointers */
+#define AR_ALLOCA(x) GC_MALLOC_ATOMIC(x)
+#define AR_ALLOCNA(x, n) GC_MALLOC_ATOMIC((n) * (x))
+#define AR_ALLOCTEA(x, e) GC_MALLOC_ATOMIC(sizeof(x) + (e))
+#define AR_ALLOCTA(x) AR_ALLOCTEA(x, 0)
+#define AR_ALLOCTNA(x, n) GC_MALLOC_ATOMIC((n) * sizeof(x))
+/* realloc figures out atomic or not for itself */
 #define AR_REALLOC(p, x) GC_REALLOC(p, x)
 #define AR_REALLOCN(p, x, n) GC_REALLOC(p, (n) * (x))
 #define AR_REALLOCTE(p, x, e) GC_REALLOC(p, sizeof(x) + (e))
 #define AR_REALLOCT(p, x) AR_REALLOCTE(p, x, 0)
 #define AR_REALLOCTN(p, x, n) GC_REALLOC(p, (n) * sizeof(x))
+/* citing Boehm: "If you insist..." */
 #define AR_FREE(x) GC_FREE((void *)x)
 #define AR_COPY_CHARP(s) _arana_copy_charp(s)
 
 _arana_copy_charp(char *string)
 {
     Ar_size_t length = strlen(string) + 1;
-    char *copy = AR_ALLOC(length);
+    char *copy = AR_ALLOCA(length);
     memcpy(copy, string, length);
     return copy;
 }
         AR_RAISE_OOM();
     unit->filename = filename;
     unit->ops_allocated = 32;
-    unit->ops = AR_ALLOCTN(ArOp, unit->ops_allocated);
+    unit->ops = AR_ALLOCTNA(ArOp, unit->ops_allocated);
     if (!unit->ops) {
         AR_FREE(unit);
         AR_RAISE_OOM();
     Ar_size_t read;
     char *result;
     FILE *fp = ((ArFile *)file)->fp;
-    if (!(result = AR_ALLOC(bytes + 1)))
+    if (!(result = AR_ALLOCA(bytes + 1)))
         AR_RAISE_OOM();
     if ((read = fread(result, 1, bytes, fp)) != bytes) {
         if (!feof(fp))

arana/lexnparse.rl

 
     if (fp) {
         bufsize = 1024;
-        buffer = AR_ALLOC(bufsize);
+        buffer = AR_ALLOCA(bufsize);
         done = 0;
     } else {
         bufsize = 0;
 
     void *pParser = ArParseAlloc(GC_malloc);
     if (!pParser) AR_RAISE_OOM();
-    stack = AR_ALLOCTN(int, stacksize);
+    stack = AR_ALLOCTNA(int, stacksize);
     if (!stack) AR_RAISE_OOM();
     ps = AR_ALLOCT(ArParseState);
     if (!ps) AR_RAISE_OOM();
     ps->lasttok = -1;
     ps->nesting = 0;
     ps->indentstacksize = INDENTSTACKSIZE;
-    ps->indentstack = AR_ALLOCTN(int, INDENTSTACKSIZE);
+    ps->indentstack = AR_ALLOCTNA(int, INDENTSTACKSIZE);
     if (!ps->indentstack) AR_RAISE_OOM();
     ps->indenttop = -1;
     ps->indentstyle = '\0';
     }
     if (!value && try_getter) {
         Ar_size_t length = strlen(member);
-        char *getter_name = AR_ALLOC(length + 5);
+        char *getter_name = AR_ALLOCA(length + 5);
         memcpy(getter_name, member, length);
         memcpy(getter_name + length, ":get", 5);
         value = arana_call_method_unchecked(AR_ISIG, object, getter_name,
     if (nocopy)
         self->value = value;
     else {
-        char *copy = AR_ALLOC(size + 1);
+        char *copy = AR_ALLOCA(size + 1);
         if (!copy)
             AR_RAISE_OOM();
         memcpy(copy, value, size);
     if (!AR_IS_STRING(other))
         other = AR_TO_STRING(other);
     Ar_size_t length = AR_STRING_SIZE(self) + AR_STRING_SIZE(other);
-    char *result = AR_ALLOC(length + 1);
+    char *result = AR_ALLOCA(length + 1);
     if (!result)
         AR_RAISE_OOM();
     memcpy(result, AR_AS_CHARP(self), AR_STRING_SIZE(self));
         times = 0;
     Ar_size_t size = AR_STRING_SIZE(self);
     Ar_size_t totalsize = size * times;
-    char *result = AR_ALLOC(totalsize + 1);
+    char *result = AR_ALLOCA(totalsize + 1);
     char *cur = result;
     if (!result)
         AR_RAISE_OOM();
         in++;
     }
 
-    result = out = AR_ALLOC(new_length + 1);
+    result = out = AR_ALLOCA(new_length + 1);
     in = AR_AS_CHARP(self);
     *out++ = '"';
     for (chars_left = true_length; chars_left--; in++) {

arana/utils/stringbuilder.c

         AR_ALLOCATE_OBJECT(ArStringBuilder, ArStringBuilderType);
     builder->length = 0;
     builder->allocated = 160;
-    builder->buffer = AR_ALLOC(builder->allocated);
+    builder->buffer = AR_ALLOCA(builder->allocated);
     if (!builder->buffer) {
         AR_FREE(builder);
         AR_RAISE_OOM();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.