From 3399fd9e8f22c74ea24ad81894861ca4b7063488 Mon Sep 17 00:00:00 2001 From: Theofrastos Mantadelis Date: Tue, 7 Sep 2010 19:28:56 +0200 Subject: [PATCH] db tries library small null bug fix --- library/tries/base_dbtries.c | 4 ++-- library/tries/core_dbtries.c | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/library/tries/base_dbtries.c b/library/tries/base_dbtries.c index a82a159c7..999744667 100644 --- a/library/tries/base_dbtries.c +++ b/library/tries/base_dbtries.c @@ -338,9 +338,9 @@ TrNode breadth_reduction(TrEntry trie, TrNode breadth_node, YAP_Int opt_level) { stop_data = TrData_previous(TrEntry_first_data(trie)); data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie); while ((data != stop_data) && (data != NULL)) { -/* printf("hi1\n");*/ +// printf("hi\n"); node = core_breadth_reduction(TRIE_ENGINE, TrData_leaf(data), breadth_node, opt_level, &trie_data_construct, &trie_data_destruct, &trie_data_copy, &trie_data_order_correction); -// printf("bye1\n"); +// printf("bye\n"); if (node && IS_FUNCTOR_NODE(TrNode_parent(node)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(node))))), NESTED_TRIE_TERM) == 0)) { //nested trie stop procedure return nested trie node return node; diff --git a/library/tries/core_dbtries.c b/library/tries/core_dbtries.c index 682a49cd4..99d7205dd 100644 --- a/library/tries/core_dbtries.c +++ b/library/tries/core_dbtries.c @@ -553,7 +553,7 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, child = TrNode_child(child); } else child = TrNode_child(node); -/* printf("start node: "); displaynode(child);*/ +// printf("Chosen start node: "); displaynode(child); if (IS_HASH_NODE(child)) { printf("warning\n"); TrNode *first_bucket, *bucket; @@ -576,6 +576,8 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, } } TrNode temp = TrNode_child(child); + if (temp == NULL) + return NULL; if (IS_HASH_NODE(temp)) { TrNode *first_bucket2, *bucket2; TrHash hash2 = (TrHash) temp; @@ -591,8 +593,6 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, while((temp != NULL) && (TrNode_entry(temp) != PairEndTag)) temp = TrNode_next(temp); } - if (temp == NULL) - return NULL; //Nested Trie code if (IS_FUNCTOR_NODE(TrNode_parent(child)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(child))))), NESTED_TRIE_TERM) == 0)) { /* nested trie: stop procedure and return nested trie node */ @@ -628,6 +628,9 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, } } TrNode temp = TrNode_child(child); + if (temp == NULL) + return NULL; +// printf("Chosen start node child: "); displaynode(temp); if (IS_HASH_NODE(temp)) { TrNode *first_bucket, *bucket; TrHash hash = (TrHash) temp; @@ -644,8 +647,7 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, while((temp != NULL) && (TrNode_entry(temp) != PairEndTag)) temp = TrNode_next(temp); } - if (temp == NULL) - return NULL; +// printf("while end\n"); //Nested Trie code if (IS_FUNCTOR_NODE(TrNode_parent(child)) && (strcmp(YAP_AtomName(YAP_NameOfFunctor((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(child))))), NESTED_TRIE_TERM) == 0)) { /* nested trie: stop procedure and return nested trie node */ @@ -664,7 +666,7 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, } child = TrNode_next(child); } while (child); -// printf("pass through\n"); +// printf("pass through\n"); } if (!count) { /* termination condition */ @@ -684,7 +686,7 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node, node = trie_node_check_insert(node, t); node = trie_node_check_insert(node, PairEndTag); INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE); -// printf("end node: "); displaynode(node); +// printf("end node: "); displaynode(node); return node; }