atomic allocation functions
authorRobin Templeton <robin@terpri.org>
Mon, 30 Jun 2014 08:21:37 +0000 (04:21 -0400)
committerRobin Templeton <robin@terpri.org>
Sat, 18 Apr 2015 22:49:07 +0000 (18:49 -0400)
* src/alloc.c (xmalloc_atomic, xzalloc_atomic, xmalloc_atomic_unsafe)
  (xnmalloc_atomic): New functions.

Conflicts:
src/alloc.c
src/lisp.h

src/alloc.c
src/lisp.h

index 2dc21b8..366fd34 100644 (file)
@@ -232,6 +232,23 @@ xfree (void *block)
   return;
 }
 
+/* Allocate pointerless memory.  */
+
+void *
+xmalloc_atomic (size_t size)
+{
+  void *val = GC_MALLOC_ATOMIC (size);
+  if (! val && size)
+    memory_full (size);
+  return val;
+}
+
+void *
+xzalloc_atomic (size_t size)
+{
+  return xmalloc_atomic (size);
+}
+
 /* Allocate uncollectable memory.  */
 
 void *
@@ -252,6 +269,15 @@ xmalloc_unsafe (size_t size)
   return GC_MALLOC (size);
 }
 
+/* Allocate pointerless memory, but if memory is exhausted, return
+   NULL instead of signalling an error.  */
+
+void *
+xmalloc_atomic_unsafe (size_t size)
+{
+  return GC_MALLOC_ATOMIC (size);
+}
+
 /* Other parts of Emacs pass large int values to allocator functions
    expecting ptrdiff_t.  This is portable in practice, but check it to
    be safe.  */
@@ -270,6 +296,16 @@ xnmalloc (ptrdiff_t nitems, ptrdiff_t item_size)
   return xmalloc (nitems * item_size);
 }
 
+/* Like xnmalloc for pointerless objects.  */
+
+void *
+xnmalloc_atomic (ptrdiff_t nitems, ptrdiff_t item_size)
+{
+  eassert (0 <= nitems && 0 < item_size);
+  if (min (PTRDIFF_MAX, SIZE_MAX) / item_size < nitems)
+    memory_full (SIZE_MAX);
+  return xmalloc_atomic (nitems * item_size);
+}
 
 /* Reallocate an array PA to make it of NITEMS items, each of size ITEM_SIZE.
    Signal an error on memory exhaustion.  */
index 9e1bb70..1de6fca 100644 (file)
@@ -4182,6 +4182,10 @@ extern void *xnmalloc (ptrdiff_t, ptrdiff_t) ATTRIBUTE_MALLOC_SIZE ((1,2));
 extern void *xnrealloc (void *, ptrdiff_t, ptrdiff_t)
   ATTRIBUTE_ALLOC_SIZE ((2,3));
 extern void *xpalloc (void *, ptrdiff_t *, ptrdiff_t, ptrdiff_t, ptrdiff_t);
+extern void *xmalloc_atomic (size_t) ATTRIBUTE_MALLOC_SIZE ((1));
+extern void *xzalloc_atomic (size_t) ATTRIBUTE_MALLOC_SIZE ((1));
+extern void *xmalloc_atomic_unsafe (size_t) ATTRIBUTE_MALLOC_SIZE ((1));
+extern void *xnmalloc_atomic (ptrdiff_t, ptrdiff_t) ATTRIBUTE_MALLOC_SIZE ((1,2));
 
 extern char *xstrdup (const char *) ATTRIBUTE_MALLOC;
 extern char *xlispstrdup (Lisp_Object) ATTRIBUTE_MALLOC;