[asterisk-commits] vectors: Add new macro and a string vector definition. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 13 17:26:23 CST 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7165 )

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, 23 insertions(+), 0 deletions(-)

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 68ce130..8bd1cef 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,26 @@
 })
 
 /*!
+ * \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.
+ *
+ * \note The stolen array must eventually be released using ast_free.
+ *
+ * \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/7165
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I104d1b204be03fccf67e02a195596adcb5ab1e42
Gerrit-Change-Number: 7165
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20171113/4a0899d5/attachment.html>


More information about the asterisk-commits mailing list