[Asterisk-code-review] vector: Add REMOVE, SORT, INSERT SORTED and RESET macros (asterisk[13])

Corey Farrell asteriskteam at digium.com
Sun May 10 04:35:51 CDT 2015


Corey Farrell has posted comments on this change.

Change subject: vector:  Add REMOVE, SORT, INSERT_SORTED and RESET macros
......................................................................


Patch Set 3: Code-Review-1

(6 comments)

https://gerrit.asterisk.org/#/c/421/3/include/asterisk/vector.h
File include/asterisk/vector.h:

Line 280:  * \param comparison_fn The comparison_fn_t compatible compare function.
I'd prefer this be replaced with:
\param cmp Comparator function/macros (called as \c cmp(elem, value))

Since the AST_VECTOR_SORT function uses qsort for implementation the comparison_fn is needed for that.  In this case it's not, the cmp syntax is much easier to deal with.


Line 295: 		while (__idx >= 0 && (compare_fn(&elem, &(vec)->elems[__idx]) < 0)) { \
See comments above, I prefer we remove & from both params to the compare function.


Line 472: #define AST_VECTOR_RESET(vec, cleanup) ({ \
This feels like it's mostly a duplicate of AST_VECTOR_CALLBACK_VOID.  Personally I'd use that instead.  Clearing (vec)->current is not needed for my use case, the next step would be AST_VECTOR_PTR_FREE(vec).


Line 487: 	qsort((vec)->elems, (vec)->current, sizeof(*((vec)->elems)), comparison_fn)
man page for qsort says that if comparison_fn returns 0 the order of those two elements is undefined.  That's unfortunate.  If this is the only option we should add a warning to the doxygen.

int a=5, b=2, c=5, d=5;
If I append &a, &b, &c, and &d in that order then sort, I would expect the final order to be defined: &b, &a, &c, &d.

It would be best if appending an unordered list then running AST_VECTOR_SORT always produced the same order as using INSERT_SORTED.


https://gerrit.asterisk.org/#/c/421/3/tests/test_vector.c
File tests/test_vector.c:

Line 218: 	return (*ia > *ib) - (*ia < *ib);
Subtracting two conditionals does not make sense to me.  Much clearer:
return *ia - *ib;


Line 234: 		info->name = "basic integer";
I know this is existing, test name's should not have spaces.  It's impossible to run this test without running all of '/main/vector/'.


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I41d32dbdf7137e0557134efeff9f9f1064b58d14
Gerrit-PatchSet: 3
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: George Joseph <george.joseph at fairview5.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Y Ateya <y.ateya at starkbits.com>
Gerrit-HasComments: Yes



More information about the asterisk-code-review mailing list