Merge pull request #4374 from opensourcerouting/typesafe-minor-fixes

Minor fixes in the typesafe API for better C++ compatibility
This commit is contained in:
Donald Sharp 2019-05-21 16:43:38 -04:00 committed by GitHub
commit 5349270f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 43 additions and 22 deletions

View File

@ -25,6 +25,9 @@ CommentPragmas: '\$(FRR|clippy)'
ContinuationIndentWidth: 8 ContinuationIndentWidth: 8
ForEachMacros: ForEachMacros:
# lib # lib
- frr_each
- frr_each_safe
- frr_each_from
- LIST_FOREACH - LIST_FOREACH
- LIST_FOREACH_SAFE - LIST_FOREACH_SAFE
- SLIST_FOREACH - SLIST_FOREACH

View File

@ -551,7 +551,7 @@ static void isis_circuit_update_all_srmflags(struct isis_circuit *circuit,
if (!lspdb_count(&area->lspdb[level - 1])) if (!lspdb_count(&area->lspdb[level - 1]))
continue; continue;
for_each (lspdb, &area->lspdb[level - 1], lsp) { frr_each (lspdb, &area->lspdb[level - 1], lsp) {
if (is_set) { if (is_set) {
isis_tx_queue_add(circuit->tx_queue, lsp, isis_tx_queue_add(circuit->tx_queue, lsp,
TX_LSP_NORMAL); TX_LSP_NORMAL);

View File

@ -574,7 +574,7 @@ void lsp_build_list_nonzero_ht(struct lspdb_head *head, const uint8_t *start_id,
memcpy(&searchfor.hdr.lsp_id, start_id, sizeof(searchfor.hdr.lsp_id)); memcpy(&searchfor.hdr.lsp_id, start_id, sizeof(searchfor.hdr.lsp_id));
start = lspdb_find_gteq(head, &searchfor); start = lspdb_find_gteq(head, &searchfor);
for_each_from (lspdb, head, lsp, start) { frr_each_from (lspdb, head, lsp, start) {
if (memcmp(lsp->hdr.lsp_id, stop_id, if (memcmp(lsp->hdr.lsp_id, stop_id,
ISIS_SYS_ID_LEN + 2) > 0) ISIS_SYS_ID_LEN + 2) > 0)
break; break;
@ -682,12 +682,12 @@ int lsp_print_all(struct vty *vty, struct lspdb_head *head, char detail,
int lsp_count = 0; int lsp_count = 0;
if (detail == ISIS_UI_LEVEL_BRIEF) { if (detail == ISIS_UI_LEVEL_BRIEF) {
for_each (lspdb, head, lsp) { frr_each (lspdb, head, lsp) {
lsp_print(lsp, vty, dynhost); lsp_print(lsp, vty, dynhost);
lsp_count++; lsp_count++;
} }
} else if (detail == ISIS_UI_LEVEL_DETAIL) { } else if (detail == ISIS_UI_LEVEL_DETAIL) {
for_each (lspdb, head, lsp) { frr_each (lspdb, head, lsp) {
lsp_print_detail(lsp, vty, dynhost); lsp_print_detail(lsp, vty, dynhost);
lsp_count++; lsp_count++;
} }
@ -1855,7 +1855,7 @@ int lsp_tick(struct thread *thread)
*/ */
for (level = 0; level < ISIS_LEVELS; level++) { for (level = 0; level < ISIS_LEVELS; level++) {
struct isis_lsp *next = lspdb_first(&area->lspdb[level]); struct isis_lsp *next = lspdb_first(&area->lspdb[level]);
for_each_from (lspdb, &area->lspdb[level], lsp, next) { frr_each_from (lspdb, &area->lspdb[level], lsp, next) {
/* /*
* The lsp rem_lifetime is kept at 0 for MaxAge * The lsp rem_lifetime is kept at 0 for MaxAge
* or * or

View File

@ -2258,7 +2258,7 @@ static int send_psnp(int level, struct isis_circuit *circuit)
if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND)) if (CHECK_FLAG(passwd->snp_auth, SNP_AUTH_SEND))
isis_tlvs_add_auth(tlvs, passwd); isis_tlvs_add_auth(tlvs, passwd);
for_each (lspdb, &circuit->area->lspdb[level - 1], lsp) { frr_each (lspdb, &circuit->area->lspdb[level - 1], lsp) {
if (ISIS_CHECK_FLAG(lsp->SSNflags, circuit)) if (ISIS_CHECK_FLAG(lsp->SSNflags, circuit))
isis_tlvs_add_lsp_entry(tlvs, lsp); isis_tlvs_add_lsp_entry(tlvs, lsp);

View File

@ -3552,7 +3552,7 @@ void isis_tlvs_add_csnp_entries(struct isis_tlvs *tlvs, uint8_t *start_id,
if (!first) if (!first)
return; return;
for_each_from (lspdb, head, lsp, first) { frr_each_from (lspdb, head, lsp, first) {
if (memcmp(lsp->hdr.lsp_id, stop_id, sizeof(lsp->hdr.lsp_id)) if (memcmp(lsp->hdr.lsp_id, stop_id, sizeof(lsp->hdr.lsp_id))
> 0 || tlvs->lsp_entries.count == num_lsps) > 0 || tlvs->lsp_entries.count == num_lsps)
break; break;

View File

@ -176,7 +176,7 @@ DEFUN (show_lsp_flooding,
continue; continue;
} }
for_each (lspdb, head, lsp) { frr_each (lspdb, head, lsp) {
lsp_print_flooding(vty, lsp); lsp_print_flooding(vty, lsp);
vty_out(vty, "\n"); vty_out(vty, "\n");
} }

View File

@ -1034,7 +1034,7 @@ static void do_thread_cancel(struct thread_master *master)
if (cr->eventobj) { if (cr->eventobj) {
struct thread *t; struct thread *t;
for_each_safe(thread_list, &master->event, t) { frr_each_safe(thread_list, &master->event, t) {
if (t->arg != cr->eventobj) if (t->arg != cr->eventobj)
continue; continue;
thread_list_del(&master->event, t); thread_list_del(&master->event, t);
@ -1043,7 +1043,7 @@ static void do_thread_cancel(struct thread_master *master)
thread_add_unuse(master, t); thread_add_unuse(master, t);
} }
for_each_safe(thread_list, &master->ready, t) { frr_each_safe(thread_list, &master->ready, t) {
if (t->arg != cr->eventobj) if (t->arg != cr->eventobj)
continue; continue;
thread_list_del(&master->ready, t); thread_list_del(&master->ready, t);

View File

@ -22,6 +22,10 @@
#include "typesafe.h" #include "typesafe.h"
#ifdef __cplusplus
extern "C" {
#endif
struct typed_rb_entry { struct typed_rb_entry {
struct typed_rb_entry *rbt_parent; struct typed_rb_entry *rbt_parent;
struct typed_rb_entry *rbt_left; struct typed_rb_entry *rbt_left;
@ -179,4 +183,8 @@ macro_inline int prefix ## __cmp_uq(const struct typed_rb_entry *a, \
_DECLARE_RBTREE(prefix, type, field, prefix ## __cmp, prefix ## __cmp_uq) \ _DECLARE_RBTREE(prefix, type, field, prefix ## __cmp, prefix ## __cmp_uq) \
/* ... */ /* ... */
#ifdef __cplusplus
}
#endif
#endif /* _FRR_TYPERB_H */ #endif /* _FRR_TYPERB_H */

View File

@ -23,19 +23,23 @@
#include <assert.h> #include <assert.h>
#include "compiler.h" #include "compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
/* generic macros for all list-like types */ /* generic macros for all list-like types */
#define for_each(prefix, head, item) \ #define frr_each(prefix, head, item) \
for (item = prefix##_first(head); item; \ for (item = prefix##_first(head); item; \
item = prefix##_next(head, item)) item = prefix##_next(head, item))
#define for_each_safe(prefix, head, item) \ #define frr_each_safe(prefix, head, item) \
for (typeof(prefix##_next_safe(head, NULL)) prefix##_safe = \ for (typeof(prefix##_next_safe(head, NULL)) prefix##_safe = \
prefix##_next_safe(head, \ prefix##_next_safe(head, \
(item = prefix##_first(head))); \ (item = prefix##_first(head))); \
item; \ item; \
item = prefix##_safe, \ item = prefix##_safe, \
prefix##_safe = prefix##_next_safe(head, prefix##_safe)) prefix##_safe = prefix##_next_safe(head, prefix##_safe))
#define for_each_from(prefix, head, item, from) \ #define frr_each_from(prefix, head, item, from) \
for (item = from, from = prefix##_next_safe(head, item); \ for (item = from, from = prefix##_next_safe(head, item); \
item; \ item; \
item = from, from = prefix##_next_safe(head, from)) item = from, from = prefix##_next_safe(head, from))
@ -850,6 +854,10 @@ extern void typesafe_skiplist_del(struct sskip_head *head,
const struct sskip_item *b)); const struct sskip_item *b));
extern struct sskip_item *typesafe_skiplist_pop(struct sskip_head *head); extern struct sskip_item *typesafe_skiplist_pop(struct sskip_head *head);
#ifdef __cplusplus
}
#endif
/* this needs to stay at the end because both files include each other. /* this needs to stay at the end because both files include each other.
* the resolved order is typesafe.h before typerb.h * the resolved order is typesafe.h before typerb.h
*/ */

View File

@ -92,6 +92,8 @@
#include "lib/table.h" #include "lib/table.h"
#include "lib/termtable.h" #include "lib/termtable.h"
#include "lib/thread.h" #include "lib/thread.h"
#include "lib/typesafe.h"
#include "lib/typerb.h"
#include "lib/vector.h" #include "lib/vector.h"
#include "lib/vlan.h" #include "lib/vlan.h"
#include "lib/vrf.h" #include "lib/vrf.h"

View File

@ -308,7 +308,7 @@ static void run_tr(struct testrun *tr)
if (tr->sorted) { if (tr->sorted) {
uint64_t prevval = 0; uint64_t prevval = 0;
for_each(asort, &shead, item) { frr_each(asort, &shead, item) {
assert(item->val1 >= prevval); assert(item->val1 >= prevval);
prevval = item->val1; prevval = item->val1;
c++; c++;
@ -316,7 +316,7 @@ static void run_tr(struct testrun *tr)
assert(c == asort_count(&shead)); assert(c == asort_count(&shead));
} else { } else {
prev = &dummy; prev = &dummy;
for_each(alist, &ahead, item) { frr_each(alist, &ahead, item) {
assert(item != prev); assert(item != prev);
prev = item; prev = item;
c++; c++;
@ -335,7 +335,7 @@ static void dump(const char *lbl)
size_t ctr = 0; size_t ctr = 0;
printf("dumping %s:\n", lbl); printf("dumping %s:\n", lbl);
for_each_safe(alist, &ahead, item) { frr_each_safe(alist, &ahead, item) {
printf("%s %3zu %p %3"PRIu64" %3"PRIu64"\n", lbl, ctr++, printf("%s %3zu %p %3"PRIu64" %3"PRIu64"\n", lbl, ctr++,
(void *)item, item->val1, item->val2); (void *)item, item->val1, item->val2);
} }

View File

@ -105,7 +105,7 @@ static void ts_hash(const char *text, const char *expect)
SHA256_Init(&ctx); SHA256_Init(&ctx);
SHA256_Update(&ctx, &count, sizeof(count)); SHA256_Update(&ctx, &count, sizeof(count));
for_each (list, &head, item) { frr_each (list, &head, item) {
struct { struct {
uint32_t val_upper, val_lower, index; uint32_t val_upper, val_lower, index;
} hashitem = { } hashitem = {
@ -177,7 +177,7 @@ static void concat(test_, TYPE)(void)
k = 0; k = 0;
prev = NULL; prev = NULL;
for_each(list, &head, item) { frr_each(list, &head, item) {
#if IS_HASH(REALTYPE) || IS_HEAP(REALTYPE) #if IS_HASH(REALTYPE) || IS_HEAP(REALTYPE)
/* hash table doesn't give sorting */ /* hash table doesn't give sorting */
(void)prev; (void)prev;
@ -303,7 +303,7 @@ static void concat(test_, TYPE)(void)
assert(l + list_count(&head) == k); assert(l + list_count(&head) == k);
ts_hashx("del", "cb2e5d80f08a803ef7b56c15e981b681adcea214bebc2f55e12e0bfb242b07ca"); ts_hashx("del", "cb2e5d80f08a803ef7b56c15e981b681adcea214bebc2f55e12e0bfb242b07ca");
for_each_safe(list, &head, item) { frr_each_safe(list, &head, item) {
assert(item->scratchpad != 0); assert(item->scratchpad != 0);
if (item->val & 1) { if (item->val & 1) {
@ -313,7 +313,7 @@ static void concat(test_, TYPE)(void)
} }
} }
assert(l + list_count(&head) == k); assert(l + list_count(&head) == k);
ts_hashx("for_each_safe+del", "e0beb71dd963a75af05b722b8e71b61b304587d860c8accdc4349067542b86bb"); ts_hashx("frr_each_safe+del", "e0beb71dd963a75af05b722b8e71b61b304587d860c8accdc4349067542b86bb");
#else /* !IS_SORTED */ #else /* !IS_SORTED */
prng = prng_new(0); prng = prng_new(0);

View File

@ -1229,7 +1229,7 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq)
* nht resolution and as such we need to call the * nht resolution and as such we need to call the
* nexthop tracking evaluation code * nexthop tracking evaluation code
*/ */
for_each (rnh_list, &dest->nht, rnh) { frr_each (rnh_list, &dest->nht, rnh) {
struct zebra_vrf *zvrf = struct zebra_vrf *zvrf =
zebra_vrf_lookup_by_id(rnh->vrf_id); zebra_vrf_lookup_by_id(rnh->vrf_id);
struct prefix *p = &rnh->node->p; struct prefix *p = &rnh->node->p;
@ -3223,7 +3223,7 @@ unsigned long rib_score_proto(uint8_t proto, unsigned short instance)
proto, instance, proto, instance,
zvrf->table[AFI_IP6][SAFI_UNICAST]); zvrf->table[AFI_IP6][SAFI_UNICAST]);
for_each(otable, &zvrf->other_tables, ort) cnt += frr_each(otable, &zvrf->other_tables, ort) cnt +=
rib_score_proto_table(proto, instance, ort->table); rib_score_proto_table(proto, instance, ort->table);
} }