[Asterisk-code-review] vectors: Add new macro and a string vector definition. (asterisk[15])

Corey Farrell asteriskteam at digium.com
Mon Nov 13 08:35:13 CST 2017


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7205


Change subject: vectors: Add new macro and a string vector definition.
......................................................................

vectors: Add new macro and a string vector definition.

* AST_VECTOR_STEAL_ELEMENTS - steal the array of elements for use
  with non-vector code.
* struct ast_vector_string - a vector of 'char *'.

Change-Id: I104d1b204be03fccf67e02a195596adcb5ab1e42
---
M include/asterisk/vector.h
1 file changed, 21 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/05/7205/1

diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 68ce130..1aacda6 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -51,6 +51,9 @@
 /*! \brief Integer vector definition */
 AST_VECTOR(ast_vector_int, int);
 
+/*! \brief String vector definition */
+AST_VECTOR(ast_vector_string, char *);
+
 /*!
  * \brief Define a vector structure with a read/write lock
  *
@@ -91,6 +94,24 @@
 })
 
 /*!
+ * \brief Steal the elements from a vector and reinitialize.
+ *
+ * \param vec Vector to operate on.
+ *
+ * This allows you to use vector.h to construct a list and use the
+ * data as a bare array.
+ *
+ * \warning AST_VECTOR_SIZE and AST_VECTOR_MAX_SIZE are both reset
+ *          to 0.  If either are needed they must be saved to a local
+ *          variable before stealing the elements.
+ */
+#define AST_VECTOR_STEAL_ELEMENTS(vec) ({ \
+	typeof((vec)->elems) __elems = (vec)->elems; \
+	AST_VECTOR_INIT((vec), 0); \
+	(__elems); \
+})
+
+/*!
  * \brief Initialize a vector with a read/write lock
  *
  * If \a size is 0, then no space will be allocated until the vector is

-- 
To view, visit https://gerrit.asterisk.org/7205
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: I104d1b204be03fccf67e02a195596adcb5ab1e42
Gerrit-Change-Number: 7205
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171113/47261a8d/attachment.html>


More information about the asterisk-code-review mailing list