*/
#include <ccan/idtree/idtree.h>
-#include <ccan/talloc/talloc.h>
+#include <ccan/tal/tal.h>
#include <stdint.h>
#include <string.h>
#define MAX_LEVEL (MAX_ID_SHIFT + IDTREE_BITS - 1) / IDTREE_BITS
#define IDTREE_FREE_MAX MAX_LEVEL + MAX_LEVEL
-#define set_bit(bit, v) (v) |= (1<<(bit))
-#define clear_bit(bit, v) (v) &= ~(1<<(bit))
-#define test_bit(bit, v) ((v) & (1<<(bit)))
+#define set_bit(bit, v) (v) |= (1U<<(bit))
+#define clear_bit(bit, v) (v) &= ~(1U<<(bit))
+#define test_bit(bit, v) ((v) & (1U<<(bit)))
struct idtree_layer {
uint32_t bitmap;
static int idtree_pre_get(struct idtree *idp)
{
while (idp->id_free_cnt < IDTREE_FREE_MAX) {
- struct idtree_layer *pn = talloc_zero(idp, struct idtree_layer);
+ struct idtree_layer *pn = talz(idp, struct idtree_layer);
if(pn == NULL)
return (0);
free_layer(idp, pn);
int n, m, sh;
struct idtree_layer *p, *pn;
struct idtree_layer *pa[MAX_LEVEL+1];
- unsigned int l, id, oid;
+ unsigned int l;
+ int id, oid;
uint32_t bm;
memset(pa, 0, sizeof(pa));
/* no space available go back to previous layer. */
l++;
oid = id;
- id = (id | ((1 << (IDTREE_BITS*l))-1)) + 1;
+ id = (id | ((1U << (IDTREE_BITS*l))-1)) + 1;
/* if already at the top layer, we need to grow */
if (!(p = pa[l])) {
*/
sh = IDTREE_BITS * (l + 1);
if (oid >> sh == id >> sh)
- continue;
+ continue;
else
goto restart;
}
* present. If so, tain't one of ours!
*/
if (n + IDTREE_BITS < 31 &&
- (id & ~(~0 << MAX_ID_SHIFT)) >> (n + IDTREE_BITS))
+ (id & ~(~0U << MAX_ID_SHIFT)) >> (n + IDTREE_BITS))
return NULL;
/* Mask off upper bits we don't use for the search. */
}
while (idp->id_free_cnt >= IDTREE_FREE_MAX) {
p = alloc_layer(idp);
- talloc_free(p);
+ tal_free(p);
}
return true;
}
struct idtree *idtree_new(void *mem_ctx)
{
- return talloc_zero(mem_ctx, struct idtree);
+ return talz(mem_ctx, struct idtree);
}
int idtree_add(struct idtree *idp, const void *ptr, int limit)