[PATCH] rbtree: API change for Insert routines.

Gedare Bloom gedare at rtems.org
Sun May 13 17:40:28 UTC 2012


Make the Insert routines return either valid nodes or NULL.
---
 cpukit/score/include/rtems/score/rbtree.h |    4 ++--
 cpukit/score/src/rbtreeinsert.c           |    4 ++--
 testsuites/sptests/sprbtree01/init.c      |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/cpukit/score/include/rtems/score/rbtree.h b/cpukit/score/include/rtems/score/rbtree.h
index 271e2fa..ed0b752 100644
--- a/cpukit/score/include/rtems/score/rbtree.h
+++ b/cpukit/score/include/rtems/score/rbtree.h
@@ -262,10 +262,10 @@ RBTree_Control *_RBTree_Find_header(
  * @param[in] the_rbtree The red-black tree.
  * @param[in] the_node The node to insert.
  *
- *  @retval 0 if successfully inserted.
+ *  @retval @a the_node if successfully inserted.
  *  @retval a node that compares equal to @a the_node if it exists and
  *          the_rbtree->is_unique is true
- *  @retval -1 otherwise.
+ *  @retval NULL otherwise.
  */
 RBTree_Node *_RBTree_Insert_unprotected(
   RBTree_Control *the_rbtree,
diff --git a/cpukit/score/src/rbtreeinsert.c b/cpukit/score/src/rbtreeinsert.c
index 9c889bd..75359a5 100644
--- a/cpukit/score/src/rbtreeinsert.c
+++ b/cpukit/score/src/rbtreeinsert.c
@@ -75,7 +75,7 @@ RBTree_Node *_RBTree_Insert_unprotected(
 )
 {
   if ( !the_node ) {
-    return (RBTree_Node*)-1;
+    return NULL;
   }
 
   RBTree_Node *iter_node = the_rbtree->root;
@@ -120,7 +120,7 @@ RBTree_Node *_RBTree_Insert_unprotected(
     /* verify red-black properties */
     _RBTree_Insert_validate( the_node );
   }
-  return (RBTree_Node*)0;
+  return the_node;
 }
 
 RBTree_Node *_RBTree_Insert(
diff --git a/testsuites/sptests/sprbtree01/init.c b/testsuites/sptests/sprbtree01/init.c
index f94a010..00f922c 100644
--- a/testsuites/sptests/sprbtree01/init.c
+++ b/testsuites/sptests/sprbtree01/init.c
@@ -117,7 +117,7 @@ rtems_task Init(
   rtems_rbtree_insert( &rbtree1, &node2.Node );
 
   p = rtems_rbtree_insert( &rbtree1, NULL );
-  if (p != (void *)(-1))
+  if ( p )
     puts( "INIT - FAILED NULL NODE INSERT" );
 
   _RBTree_Rotate(NULL, RBT_LEFT);
-- 
1.7.1




More information about the devel mailing list