Print this page
6091 avl_add doesn't assert on non-debug builds
Reviewed by: Andy Stormont <astormont@racktopsystems.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/common/avl/avl.c
          +++ new/usr/src/common/avl/avl.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
  24   24   */
  25   25  
  26   26  /*
  27   27   * Copyright (c) 2014 by Delphix. All rights reserved.
       28 + * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  28   29   */
  29   30  
  30   31  /*
  31   32   * AVL - generic AVL tree implementation for kernel use
  32   33   *
  33   34   * A complete description of AVL trees can be found in many CS textbooks.
  34   35   *
  35   36   * Here is a very brief overview. An AVL tree is a binary search tree that is
  36   37   * almost perfectly balanced. By "almost" perfectly balanced, we mean that at
  37   38   * any given node, the left and right subtrees are allowed to differ in height
↓ open down ↓ 590 lines elided ↑ open up ↑
 628  629   * Add a new node to an AVL tree.
 629  630   */
 630  631  void
 631  632  avl_add(avl_tree_t *tree, void *new_node)
 632  633  {
 633  634          avl_index_t where;
 634  635  
 635  636          /*
 636  637           * This is unfortunate.  We want to call panic() here, even for
 637  638           * non-DEBUG kernels.  In userland, however, we can't depend on anything
 638      -         * in libc or else the rtld build process gets confused.  So, all we can
 639      -         * do in userland is resort to a normal ASSERT().
      639 +         * in libc or else the rtld build process gets confused.
      640 +         * Thankfully, rtld provides us with its own assfail() so we can use
      641 +         * that here.  We use assfail() directly to get a nice error message
      642 +         * in the core - much like what panic() does for crashdumps.
 640  643           */
 641  644          if (avl_find(tree, new_node, &where) != NULL)
 642  645  #ifdef _KERNEL
 643  646                  panic("avl_find() succeeded inside avl_add()");
 644  647  #else
 645      -                ASSERT(0);
      648 +                (void) assfail("avl_find() succeeded inside avl_add()",
      649 +                    __FILE__, __LINE__);
 646  650  #endif
 647  651          avl_insert(tree, new_node, where);
 648  652  }
 649  653  
 650  654  /*
 651  655   * Delete a node from the AVL tree.  Deletion is similar to insertion, but
 652  656   * with 2 complications.
 653  657   *
 654  658   * First, we may be deleting an interior node. Consider the following subtree:
 655  659   *
↓ open down ↓ 404 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX