about summary refs log tree commit diff
path: root/malloc/dynarray-skeleton.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2017-06-13 17:03:56 +0200
committerFlorian Weimer <fweimer@redhat.com>2017-06-13 21:55:10 +0200
commitf8bf87face3304f216bcd838081fa33bb4976ac6 (patch)
tree1dc3e2a512d5b040aa12c760a6b751b8916cbc9d /malloc/dynarray-skeleton.c
parenta65ea28d1833d3502c5070472e43bda04410e6b5 (diff)
downloadglibc-f8bf87face3304f216bcd838081fa33bb4976ac6.tar.gz
glibc-f8bf87face3304f216bcd838081fa33bb4976ac6.tar.xz
glibc-f8bf87face3304f216bcd838081fa33bb4976ac6.zip
dynarray: Implement begin/end functions in the spirit of C++
Diffstat (limited to 'malloc/dynarray-skeleton.c')
-rw-r--r--malloc/dynarray-skeleton.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/malloc/dynarray-skeleton.c b/malloc/dynarray-skeleton.c
index 7a10e083f4..7ec5878808 100644
--- a/malloc/dynarray-skeleton.c
+++ b/malloc/dynarray-skeleton.c
@@ -65,6 +65,8 @@
      bool DYNARRAY_PREFIX##has_failed (const struct DYNARRAY_STRUCT *);
      void DYNARRAY_PREFIX##mark_failed (struct DYNARRAY_STRUCT *);
      size_t DYNARRAY_PREFIX##size (const struct DYNARRAY_STRUCT *);
+     DYNARRAY_ELEMENT *DYNARRAY_PREFIX##begin (const struct DYNARRAY_STRUCT *);
+     DYNARRAY_ELEMENT *DYNARRAY_PREFIX##end (const struct DYNARRAY_STRUCT *);
      DYNARRAY_ELEMENT *DYNARRAY_PREFIX##at (struct DYNARRAY_STRUCT *, size_t);
      void DYNARRAY_PREFIX##add (struct DYNARRAY_STRUCT *, DYNARRAY_ELEMENT);
      DYNARRAY_ELEMENT *DYNARRAY_PREFIX##emplace (struct DYNARRAY_STRUCT *);
@@ -248,6 +250,26 @@ DYNARRAY_NAME (at) (struct DYNARRAY_STRUCT *list, size_t index)
   return list->dynarray_header.array + index;
 }
 
+/* Return a pointer to the first array element, if any.  For a
+   zero-length array, the pointer can be NULL even though the dynamic
+   array has not entered the failure state.  */
+__attribute__ ((nonnull (1)))
+static inline DYNARRAY_ELEMENT *
+DYNARRAY_NAME (begin) (struct DYNARRAY_STRUCT *list)
+{
+  return list->dynarray_header.array;
+}
+
+/* Return a pointer one element past the last array element.  For a
+   zero-length array, the pointer can be NULL even though the dynamic
+   array has not entered the failure state.  */
+__attribute__ ((nonnull (1)))
+static inline DYNARRAY_ELEMENT *
+DYNARRAY_NAME (end) (struct DYNARRAY_STRUCT *list)
+{
+  return list->dynarray_header.array + list->dynarray_header.used;
+}
+
 /* Internal function.  Slow path for the add function below.  */
 static void
 DYNARRAY_NAME (add__) (struct DYNARRAY_STRUCT *list, DYNARRAY_ELEMENT item)