[svn-commits] rmudgett: trunk r402439 - in /trunk: ./ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Nov 1 23:30:50 CDT 2013


Author: rmudgett
Date: Fri Nov  1 23:30:49 2013
New Revision: 402439

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=402439
Log:
vector: Uppercase API to follow C convention.

C does not support templates like C++.
........

Merged revisions 402438 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/vector.h
    trunk/main/stasis.c
    trunk/main/stasis_message_router.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Fri Nov  1 23:30:49 2013
@@ -1,1 +1,1 @@
-/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-402367,402387,402398,402416,402427,402429
+/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-402367,402387,402398,402416,402427,402429,402438

Modified: trunk/include/asterisk/vector.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/vector.h?view=diff&rev=402439&r1=402438&r2=402439
==============================================================================
--- trunk/include/asterisk/vector.h (original)
+++ trunk/include/asterisk/vector.h Fri Nov  1 23:30:49 2013
@@ -39,7 +39,7 @@
  * \param name Optional vector struct name.
  * \param type Vector element type.
  */
-#define ast_vector(name, type)			\
+#define AST_VECTOR(name, type)			\
 	struct name {				\
 		type *elems;			\
 		size_t max;			\
@@ -58,7 +58,7 @@
  * \return 0 on success.
  * \return Non-zero on failure.
  */
-#define ast_vector_init(vec, size) ({					\
+#define AST_VECTOR_INIT(vec, size) ({					\
 	size_t __size = (size);						\
 	size_t alloc_size = __size * sizeof(*((vec)->elems));		\
 	(vec)->elems = alloc_size ? ast_malloc(alloc_size) : NULL;	\
@@ -79,7 +79,7 @@
  *
  * \param vec Vector to deallocate.
  */
-#define ast_vector_free(vec) do {		\
+#define AST_VECTOR_FREE(vec) do {		\
 	ast_free((vec)->elems);			\
 	(vec)->elems = NULL;			\
 	(vec)->max = 0;				\
@@ -95,7 +95,7 @@
  * \return 0 on success.
  * \return Non-zero on failure.
  */
-#define ast_vector_append(vec, elem) ({						\
+#define AST_VECTOR_APPEND(vec, elem) ({						\
 	int res = 0;								\
 	do {									\
 		if ((vec)->current + 1 > (vec)->max) {				\
@@ -125,7 +125,7 @@
  * \param idx Index of the element to remove.
  * \return The element that was removed.
  */
-#define ast_vector_remove_unordered(vec, idx) ({		\
+#define AST_VECTOR_REMOVE_UNORDERED(vec, idx) ({		\
 	typeof((vec)->elems[0]) res;				\
 	size_t __idx = (idx);					\
 	ast_assert(__idx < (vec)->current);			\
@@ -146,14 +146,14 @@
  * \return 0 if element was removed.
  * \return Non-zero if element was not in the vector.
  */
-#define ast_vector_remove_cmp_unordered(vec, value, cmp, cleanup) ({	\
+#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup) ({	\
 	int res = -1;							\
 	size_t idx;							\
 	typeof(value) __value = (value);				\
 	for (idx = 0; idx < (vec)->current; ++idx) {			\
 		if (cmp((vec)->elems[idx], __value)) {			\
 			cleanup((vec)->elems[idx]);			\
-			ast_vector_remove_unordered((vec), idx);	\
+			AST_VECTOR_REMOVE_UNORDERED((vec), idx);	\
 			res = 0;					\
 			break;						\
 		}							\
@@ -162,7 +162,7 @@
 })
 
 /*!
- * \brief Default comparator for ast_vector_remove_elem_unordered()
+ * \brief Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED()
  *
  * \param elem Element to compare against
  * \param value Value to compare with the vector element.
@@ -191,8 +191,8 @@
  * \return 0 if element was removed.
  * \return Non-zero if element was not in the vector.
  */
-#define ast_vector_remove_elem_unordered(vec, elem, cleanup) ({	\
-	ast_vector_remove_cmp_unordered((vec), (elem),		\
+#define AST_VECTOR_REMOVE_ELEM_UNORDERED(vec, elem, cleanup) ({	\
+	AST_VECTOR_REMOVE_CMP_UNORDERED((vec), (elem),		\
 		AST_VECTOR_ELEM_DEFAULT_CMP, cleanup);		\
 })
 
@@ -202,7 +202,7 @@
  * \param vec Vector to query.
  * \return Number of elements in the vector.
  */
-#define ast_vector_size(vec) (vec)->current
+#define AST_VECTOR_SIZE(vec) (vec)->current
 
 /*!
  * \brief Get an address of element in a vector.
@@ -210,7 +210,7 @@
  * \param vec Vector to query.
  * \param idx Index of the element to get address of.
  */
-#define ast_vector_get_addr(vec, idx) ({	\
+#define AST_VECTOR_GET_ADDR(vec, idx) ({	\
 	size_t __idx = (idx);			\
 	ast_assert(__idx < (vec)->current);	\
 	&(vec)->elems[__idx];			\
@@ -222,7 +222,7 @@
  * \param vec Vector to query.
  * \param idx Index of the element to get.
  */
-#define ast_vector_get(vec, idx) ({		\
+#define AST_VECTOR_GET(vec, idx) ({		\
 	size_t __idx = (idx);			\
 	ast_assert(__idx < (vec)->current);	\
 	(vec)->elems[__idx];			\

Modified: trunk/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis.c?view=diff&rev=402439&r1=402438&r2=402439
==============================================================================
--- trunk/main/stasis.c (original)
+++ trunk/main/stasis.c Fri Nov  1 23:30:49 2013
@@ -140,10 +140,10 @@
 struct stasis_topic {
 	char *name;
 	/*! Variable length array of the subscribers */
-	ast_vector(, struct stasis_subscription *) subscribers;
+	AST_VECTOR(, struct stasis_subscription *) subscribers;
 
 	/*! Topics forwarding into this topic */
-	ast_vector(, struct stasis_topic *) upstream_topics;
+	AST_VECTOR(, struct stasis_topic *) upstream_topics;
 };
 
 /* Forward declarations for the tightly-coupled subscription object */
@@ -167,13 +167,13 @@
 
 	/* Subscribers hold a reference to topics, so they should all be
 	 * unsubscribed before we get here. */
-	ast_assert(ast_vector_size(&topic->subscribers) == 0);
+	ast_assert(AST_VECTOR_SIZE(&topic->subscribers) == 0);
 
 	ast_free(topic->name);
 	topic->name = NULL;
 
-	ast_vector_free(&topic->subscribers);
-	ast_vector_free(&topic->upstream_topics);
+	AST_VECTOR_FREE(&topic->subscribers);
+	AST_VECTOR_FREE(&topic->upstream_topics);
 }
 
 struct stasis_topic *stasis_topic_create(const char *name)
@@ -192,8 +192,8 @@
 		return NULL;
 	}
 
-	res |= ast_vector_init(&topic->subscribers, INITIAL_SUBSCRIBERS_MAX);
-	res |= ast_vector_init(&topic->upstream_topics, 0);
+	res |= AST_VECTOR_INIT(&topic->subscribers, INITIAL_SUBSCRIBERS_MAX);
+	res |= AST_VECTOR_INIT(&topic->upstream_topics, 0);
 
 	if (res != 0) {
 		return NULL;
@@ -428,8 +428,8 @@
 		struct stasis_topic *topic = sub->topic;
 		SCOPED_AO2LOCK(lock_topic, topic);
 
-		for (i = 0; i < ast_vector_size(&topic->subscribers); ++i) {
-			if (ast_vector_get(&topic->subscribers, i) == sub) {
+		for (i = 0; i < AST_VECTOR_SIZE(&topic->subscribers); ++i) {
+			if (AST_VECTOR_GET(&topic->subscribers, i) == sub) {
 				return 1;
 			}
 		}
@@ -480,11 +480,11 @@
 	 *
 	 * If we bumped the refcount here, the owner would have to unsubscribe
 	 * and cleanup, which is a bit awkward. */
-	ast_vector_append(&topic->subscribers, sub);
-
-	for (idx = 0; idx < ast_vector_size(&topic->upstream_topics); ++idx) {
+	AST_VECTOR_APPEND(&topic->subscribers, sub);
+
+	for (idx = 0; idx < AST_VECTOR_SIZE(&topic->upstream_topics); ++idx) {
 		topic_add_subscription(
-			ast_vector_get(&topic->upstream_topics, idx), sub);
+			AST_VECTOR_GET(&topic->upstream_topics, idx), sub);
 	}
 
 	return 0;
@@ -495,12 +495,12 @@
 	size_t idx;
 	SCOPED_AO2LOCK(lock_topic, topic);
 
-	for (idx = 0; idx < ast_vector_size(&topic->upstream_topics); ++idx) {
+	for (idx = 0; idx < AST_VECTOR_SIZE(&topic->upstream_topics); ++idx) {
 		topic_remove_subscription(
-			ast_vector_get(&topic->upstream_topics, idx), sub);
-	}
-
-	return ast_vector_remove_elem_unordered(&topic->subscribers, sub,
+			AST_VECTOR_GET(&topic->upstream_topics, idx), sub);
+	}
+
+	return AST_VECTOR_REMOVE_ELEM_UNORDERED(&topic->subscribers, sub,
 		AST_VECTOR_ELEM_CLEANUP_NOOP);
 }
 
@@ -549,8 +549,8 @@
 	 */
 	ao2_ref(topic, +1);
 	ao2_lock(topic);
-	for (i = 0; i < ast_vector_size(&topic->subscribers); ++i) {
-		struct stasis_subscription *sub = ast_vector_get(&topic->subscribers, i);
+	for (i = 0; i < AST_VECTOR_SIZE(&topic->subscribers); ++i) {
+		struct stasis_subscription *sub = AST_VECTOR_GET(&topic->subscribers, i);
 
 		ast_assert(sub != NULL);
 
@@ -599,11 +599,11 @@
 	to = forward->to_topic;
 
 	topic_lock_both(to, from);
-	ast_vector_remove_elem_unordered(&to->upstream_topics, from,
+	AST_VECTOR_REMOVE_ELEM_UNORDERED(&to->upstream_topics, from,
 		AST_VECTOR_ELEM_CLEANUP_NOOP);
 
-	for (idx = 0; idx < ast_vector_size(&to->subscribers); ++idx) {
-		topic_remove_subscription(from, ast_vector_get(&to->subscribers, idx));
+	for (idx = 0; idx < AST_VECTOR_SIZE(&to->subscribers); ++idx) {
+		topic_remove_subscription(from, AST_VECTOR_GET(&to->subscribers, idx));
 	}
 	ao2_unlock(from);
 	ao2_unlock(to);
@@ -633,15 +633,15 @@
 	forward->to_topic = ao2_bump(to_topic);
 
 	topic_lock_both(to_topic, from_topic);
-	res = ast_vector_append(&to_topic->upstream_topics, from_topic);
+	res = AST_VECTOR_APPEND(&to_topic->upstream_topics, from_topic);
 	if (res != 0) {
 		ao2_unlock(from_topic);
 		ao2_unlock(to_topic);
 		return NULL;
 	}
 
-	for (idx = 0; idx < ast_vector_size(&to_topic->subscribers); ++idx) {
-		topic_add_subscription(from_topic, ast_vector_get(&to_topic->subscribers, idx));
+	for (idx = 0; idx < AST_VECTOR_SIZE(&to_topic->subscribers); ++idx) {
+		topic_add_subscription(from_topic, AST_VECTOR_GET(&to_topic->subscribers, idx));
 	}
 	ao2_unlock(from_topic);
 	ao2_unlock(to_topic);

Modified: trunk/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis_message_router.c?view=diff&rev=402439&r1=402438&r2=402439
==============================================================================
--- trunk/main/stasis_message_router.c (original)
+++ trunk/main/stasis_message_router.c Fri Nov  1 23:30:49 2013
@@ -45,7 +45,7 @@
 	void *data;
 };
 
-ast_vector(route_table, struct stasis_message_route);
+AST_VECTOR(route_table, struct stasis_message_route);
 
 static struct stasis_message_route *route_table_find(struct route_table *table,
 	struct stasis_message_type *message_type)
@@ -59,8 +59,8 @@
 	 * tables, then we can look into containers with more efficient
 	 * lookups.
 	 */
-	for (idx = 0; idx < ast_vector_size(table); ++idx) {
-		route = ast_vector_get_addr(table, idx);
+	for (idx = 0; idx < AST_VECTOR_SIZE(table); ++idx) {
+		route = AST_VECTOR_GET_ADDR(table, idx);
 		if (route->message_type == message_type) {
 			return route;
 		}
@@ -70,7 +70,7 @@
 }
 
 /*!
- * \brief route_table comparator for ast_vector_remove_cmp_unordered()
+ * \brief route_table comparator for AST_VECTOR_REMOVE_CMP_UNORDERED()
  *
  * \param elem Element to compare against
  * \param value Value to compare with the vector element.
@@ -92,7 +92,7 @@
 static int route_table_remove(struct route_table *table,
 	struct stasis_message_type *message_type)
 {
-	return ast_vector_remove_cmp_unordered(table, message_type, ROUTE_TABLE_ELEM_CMP,
+	return AST_VECTOR_REMOVE_CMP_UNORDERED(table, message_type, ROUTE_TABLE_ELEM_CMP,
 		ROUTE_TABLE_ELEM_CLEANUP);
 }
 
@@ -110,7 +110,7 @@
 	route.callback = callback;
 	route.data = data;
 
-	res = ast_vector_append(table, route);
+	res = AST_VECTOR_APPEND(table, route);
 	if (res) {
 		ROUTE_TABLE_ELEM_CLEANUP(route);
 	}
@@ -122,11 +122,11 @@
 	size_t idx;
 	struct stasis_message_route *route;
 
-	for (idx = 0; idx < ast_vector_size(table); ++idx) {
-		route = ast_vector_get_addr(table, idx);
+	for (idx = 0; idx < AST_VECTOR_SIZE(table); ++idx) {
+		route = AST_VECTOR_GET_ADDR(table, idx);
 		ROUTE_TABLE_ELEM_CLEANUP(*route);
 	}
-	ast_vector_free(table);
+	AST_VECTOR_FREE(table);
 }
 
 /*! \internal */
@@ -218,8 +218,8 @@
 	}
 
 	res = 0;
-	res |= ast_vector_init(&router->routes, 0);
-	res |= ast_vector_init(&router->cache_routes, 0);
+	res |= AST_VECTOR_INIT(&router->routes, 0);
+	res |= AST_VECTOR_INIT(&router->cache_routes, 0);
 	if (res) {
 		return NULL;
 	}




More information about the svn-commits mailing list