]> git.lizzy.rs Git - dragonstd.git/commitdiff
Merge branch 'main' of https://github.com/dragonblocks/dragonstd
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 13 Apr 2022 17:55:01 +0000 (19:55 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 13 Apr 2022 17:55:01 +0000 (19:55 +0200)
1  2 
bits/wrappers.h
map.c
refcount.c
test/test_refcount_map.c

diff --cc bits/wrappers.h
index 652becbc7f1178bc80bdb533a5d394c131c37c32,cfeb0091465ca1ea5d3494560e0bd65553838314..9169053e0366ab6475e8a2ca6471d36a2408ab79
        { \
                Type ## Node **node = prefix ## nfd(self, key, cmp); \
   \
-               if (! *node) \
+               if (!*node) \
 -                      return NULL; \
 +                      return false; \
 + \
 +              if (call) \
 +                      call((*node)->dat); \
   \
 -              void *dat = trans ? trans((*node)->dat) : (*node)->dat; \
                prefix ## nrm(self, node); \
 -              return dat; \
 +              return true; \
        }
diff --cc map.c
index c45069fdef5945bf5f9ec201ba3c61cc0685d53d,fa9b073afcdcce67ef966f66b268a62d7aa4eed2..abdd7052ed7d36e77662899932d6b5a1389d47e3
--- 1/map.c
--- 2/map.c
+++ b/map.c
@@@ -45,20 -45,20 +45,20 @@@ void map_cnl(Map *map, Iterator iter, v
        pthread_rwlock_unlock(&map->tlk);
  }
  
 -#define WRAP_TREE_FUNC(name, write) \
 -      void *map_ ## name(Map *map, void *dat, Comparator cmp, Transformer trans) \
 +#define WRAP_TREE_FUNC(type, name, write, CallbackType, null) \
 +      type map_ ## name(Map *map, void *dat, Comparator cmp, CallbackType func) \
        { \
-               if (! get_lock(map, write)) \
+               if (!get_lock(map, write)) \
 -                      return NULL; \
 +                      return null; \
   \
 -              dat = tree_ ## name(&map->tre, dat, cmp, trans); \
 +              type ret = tree_ ## name(&map->tre, dat, cmp, func); \
                pthread_rwlock_unlock(&map->tlk); \
 -              return dat; \
 +              return ret; \
        }
  
 -WRAP_TREE_FUNC(add, true)
 -WRAP_TREE_FUNC(get, false)
 -WRAP_TREE_FUNC(del, true)
 +WRAP_TREE_FUNC(bool,   add, true,  Transformer, false)
 +WRAP_TREE_FUNC(void *, get, false, Transformer, NULL)
 +WRAP_TREE_FUNC(bool,   del, true,  Callback,    false)
  
  void map_trv(Map *map, Iterator iter, void *arg, Transformer trans, TreeTraversionOrder order)
  {
diff --cc refcount.c
index 8473787e7ba1ec7b6a4b5c23aa40de507d0813bc,eef329785ae5d599d36cc9fccc78c22658da418d..dcb5b18565c390ac0028275b89b5a513694e8b2a
@@@ -36,8 -36,10 +36,8 @@@ void refcount_drp(void *refcount
        unsigned short count = --rc->cnt;
        pthread_mutex_unlock(&rc->mtx);
  
-       if (! count)
+       if (!count)
 -              return rc->del(rc->obj);
 -
 -      return rc->obj;
 +              rc->del(rc->obj);
  }
  
  void *refcount_obj(void *refcount)
Simple merge