Corrected a memory leak problem
This commit is contained in:
parent
9f945c152d
commit
75985b8fff
@ -231,6 +231,7 @@ static TrData CURRENT_DEPTH_BREADTH_DATA;
|
|||||||
|
|
||||||
YAP_Term trie_depth_breadth(TrEntry trie, TrEntry db_trie, YAP_Int opt_level, YAP_Int start_counter, YAP_Int *end_counter) {
|
YAP_Term trie_depth_breadth(TrEntry trie, TrEntry db_trie, YAP_Int opt_level, YAP_Int start_counter, YAP_Int *end_counter) {
|
||||||
TrNode depth_node, breadth_node, nested_trie;
|
TrNode depth_node, breadth_node, nested_trie;
|
||||||
|
TrEntry otrie = CURRENT_TRIE;
|
||||||
core_set_label_counter(start_counter);
|
core_set_label_counter(start_counter);
|
||||||
CURRENT_TRIE = db_trie;
|
CURRENT_TRIE = db_trie;
|
||||||
core_set_trie_db_return_term(YAP_MkAtomTerm(YAP_LookupAtom("false")));
|
core_set_trie_db_return_term(YAP_MkAtomTerm(YAP_LookupAtom("false")));
|
||||||
@ -248,6 +249,7 @@ YAP_Term trie_depth_breadth(TrEntry trie, TrEntry db_trie, YAP_Int opt_level, YA
|
|||||||
set_depth_breadth_reduction_current_data(get_data_from_trie_node(nested_trie));
|
set_depth_breadth_reduction_current_data(get_data_from_trie_node(nested_trie));
|
||||||
core_finalize_depth_breadth_trie(depth_node, breadth_node);
|
core_finalize_depth_breadth_trie(depth_node, breadth_node);
|
||||||
*end_counter = core_get_label_counter();
|
*end_counter = core_get_label_counter();
|
||||||
|
CURRENT_TRIE = otrie;
|
||||||
return YAP_MkApplTerm((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(nested_trie))), 1, &TrNode_entry(nested_trie));
|
return YAP_MkApplTerm((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(nested_trie))), 1, &TrNode_entry(nested_trie));
|
||||||
}
|
}
|
||||||
// printf("breadth\n"); trie_print(trie);
|
// printf("breadth\n"); trie_print(trie);
|
||||||
@ -256,11 +258,13 @@ YAP_Term trie_depth_breadth(TrEntry trie, TrEntry db_trie, YAP_Int opt_level, YA
|
|||||||
set_depth_breadth_reduction_current_data(get_data_from_trie_node(nested_trie));
|
set_depth_breadth_reduction_current_data(get_data_from_trie_node(nested_trie));
|
||||||
core_finalize_depth_breadth_trie(depth_node, breadth_node);
|
core_finalize_depth_breadth_trie(depth_node, breadth_node);
|
||||||
*end_counter = core_get_label_counter();
|
*end_counter = core_get_label_counter();
|
||||||
|
CURRENT_TRIE = otrie;
|
||||||
return YAP_MkApplTerm((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(nested_trie))), 1, &TrNode_entry(nested_trie));
|
return YAP_MkApplTerm((YAP_Functor)(~ApplTag & TrNode_entry(TrNode_parent(nested_trie))), 1, &TrNode_entry(nested_trie));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core_finalize_depth_breadth_trie(depth_node, breadth_node);
|
core_finalize_depth_breadth_trie(depth_node, breadth_node);
|
||||||
*end_counter = core_get_label_counter();
|
*end_counter = core_get_label_counter();
|
||||||
|
CURRENT_TRIE = otrie;
|
||||||
return core_get_trie_db_return_term();
|
return core_get_trie_db_return_term();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,8 +283,10 @@ TrData trie_get_depth_breadth_reduction_current_data(void) {
|
|||||||
|
|
||||||
|
|
||||||
void trie_replace_nested_trie(TrEntry trie, YAP_Int nested_trie_id, YAP_Term new_term) {
|
void trie_replace_nested_trie(TrEntry trie, YAP_Int nested_trie_id, YAP_Term new_term) {
|
||||||
|
TrEntry otrie = CURRENT_TRIE;
|
||||||
CURRENT_TRIE = trie;
|
CURRENT_TRIE = trie;
|
||||||
core_depth_breadth_trie_replace_nested_trie(TrNode_child(TrEntry_trie(trie)), nested_trie_id, new_term, &trie_data_construct, &trie_data_destruct);
|
core_depth_breadth_trie_replace_nested_trie(TrNode_child(TrEntry_trie(trie)), nested_trie_id, new_term, &trie_data_construct, &trie_data_destruct);
|
||||||
|
CURRENT_TRIE = otrie;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,13 +322,17 @@ void simplification_reduction(TrEntry trie) {
|
|||||||
TrData stop_data, new_data, data = NULL;
|
TrData stop_data, new_data, data = NULL;
|
||||||
stop_data = TrData_previous(TrEntry_first_data(trie));
|
stop_data = TrData_previous(TrEntry_first_data(trie));
|
||||||
data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie);
|
data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie);
|
||||||
while ((data != stop_data) && (data != NULL)) {
|
while (data && (data != stop_data) && (TrData_trie(data))) {
|
||||||
node = core_simplification_reduction(TRIE_ENGINE, TrData_leaf(data), &trie_data_destruct);
|
node = core_simplification_reduction(TRIE_ENGINE, TrData_leaf(data), &trie_data_destruct);
|
||||||
if (node) {
|
if (node) {
|
||||||
new_trie_data(new_data, trie, node);
|
new_trie_data(new_data, trie, node);
|
||||||
PUT_DATA_IN_LEAF_TRIE_NODE(node, new_data);
|
PUT_DATA_IN_LEAF_TRIE_NODE(node, new_data);
|
||||||
|
data = NULL;
|
||||||
}
|
}
|
||||||
if (data == TrEntry_traverse_data(trie)) {
|
if (data && TrEntry_traverse_data(trie) && TrEntry_traverse_data(trie) != stop_data && !TrData_trie(data)) {
|
||||||
|
data = TrData_previous(data);
|
||||||
|
TrEntry_traverse_data(trie) = data;
|
||||||
|
} else if (data && TrEntry_traverse_data(trie) && TrEntry_traverse_data(trie) != stop_data && data == TrEntry_traverse_data(trie)) {
|
||||||
data = TrData_previous(data);
|
data = TrData_previous(data);
|
||||||
TrEntry_traverse_data(trie) = data;
|
TrEntry_traverse_data(trie) = data;
|
||||||
} else
|
} else
|
||||||
@ -338,7 +348,7 @@ TrNode depth_reduction(TrEntry trie, TrNode depth_node, YAP_Int opt_level) {
|
|||||||
|
|
||||||
stop_data = TrData_previous(TrEntry_first_data(trie));
|
stop_data = TrData_previous(TrEntry_first_data(trie));
|
||||||
data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie);
|
data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie);
|
||||||
while (data != stop_data) {
|
while (data && (data != stop_data) && (TrData_trie(data))) {
|
||||||
node = core_depth_reduction(TRIE_ENGINE, TrData_leaf(data), depth_node, opt_level, &trie_data_construct, &trie_data_destruct, &trie_data_copy, &trie_data_order_correction);
|
node = core_depth_reduction(TRIE_ENGINE, TrData_leaf(data), depth_node, opt_level, &trie_data_construct, &trie_data_destruct, &trie_data_copy, &trie_data_order_correction);
|
||||||
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)) {
|
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
|
//nested trie stop procedure return nested trie node
|
||||||
@ -347,8 +357,12 @@ TrNode depth_reduction(TrEntry trie, TrNode depth_node, YAP_Int opt_level) {
|
|||||||
if (node) {
|
if (node) {
|
||||||
new_trie_data(new_data, trie, node);
|
new_trie_data(new_data, trie, node);
|
||||||
PUT_DATA_IN_LEAF_TRIE_NODE(node, new_data);
|
PUT_DATA_IN_LEAF_TRIE_NODE(node, new_data);
|
||||||
|
data = NULL;
|
||||||
}
|
}
|
||||||
if (data == TrEntry_traverse_data(trie)) {
|
if (data && TrEntry_traverse_data(trie) && TrEntry_traverse_data(trie) != stop_data && !TrData_trie(data)) {
|
||||||
|
data = TrData_previous(data);
|
||||||
|
TrEntry_traverse_data(trie) = data;
|
||||||
|
} else if (data && TrEntry_traverse_data(trie) && TrEntry_traverse_data(trie) != stop_data && data == TrEntry_traverse_data(trie)) {
|
||||||
data = TrData_previous(data);
|
data = TrData_previous(data);
|
||||||
TrEntry_traverse_data(trie) = data;
|
TrEntry_traverse_data(trie) = data;
|
||||||
} else
|
} else
|
||||||
@ -365,7 +379,7 @@ TrNode breadth_reduction(TrEntry trie, TrNode breadth_node, YAP_Int opt_level) {
|
|||||||
|
|
||||||
stop_data = TrData_previous(TrEntry_first_data(trie));
|
stop_data = TrData_previous(TrEntry_first_data(trie));
|
||||||
data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie);
|
data = TrEntry_traverse_data(trie) = TrEntry_last_data(trie);
|
||||||
while ((data != stop_data) && (data != NULL)) {
|
while (data && (data != stop_data) && (TrData_trie(data))) {
|
||||||
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);
|
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);
|
||||||
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)) {
|
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
|
//nested trie stop procedure return nested trie node
|
||||||
@ -374,8 +388,12 @@ TrNode breadth_reduction(TrEntry trie, TrNode breadth_node, YAP_Int opt_level) {
|
|||||||
if (node) {
|
if (node) {
|
||||||
new_trie_data(new_data, trie, node);
|
new_trie_data(new_data, trie, node);
|
||||||
PUT_DATA_IN_LEAF_TRIE_NODE(node, new_data);
|
PUT_DATA_IN_LEAF_TRIE_NODE(node, new_data);
|
||||||
|
data = NULL;
|
||||||
}
|
}
|
||||||
if (data == TrEntry_traverse_data(trie)) {
|
if (data && TrEntry_traverse_data(trie) && TrEntry_traverse_data(trie) != stop_data && !TrData_trie(data)) {
|
||||||
|
data = TrData_previous(data);
|
||||||
|
TrEntry_traverse_data(trie) = data;
|
||||||
|
} else if (data && TrEntry_traverse_data(trie) && TrEntry_traverse_data(trie) != stop_data && data == TrEntry_traverse_data(trie)) {
|
||||||
data = TrData_previous(data);
|
data = TrData_previous(data);
|
||||||
TrEntry_traverse_data(trie) = data;
|
TrEntry_traverse_data(trie) = data;
|
||||||
} else
|
} else
|
||||||
|
@ -215,7 +215,7 @@ TrNode replace_nested_trie(TrNode node, TrNode child, YAP_Term new_term, void
|
|||||||
void check_attach_childs(TrNode parent, TrNode search_child, TrNode existing_child, void (*construct_function)(TrNode), void (*destruct_function)(TrNode));
|
void check_attach_childs(TrNode parent, TrNode search_child, TrNode existing_child, void (*construct_function)(TrNode), void (*destruct_function)(TrNode));
|
||||||
TrNode get_simplification_sibling(TrNode node);
|
TrNode get_simplification_sibling(TrNode node);
|
||||||
TrNode check_parent_first(TrNode node);
|
TrNode check_parent_first(TrNode node);
|
||||||
//TrNode TrNode_myparent(TrNode node);
|
TrNode TrNode_myparent(TrNode node);
|
||||||
|
|
||||||
/* -------------------------- */
|
/* -------------------------- */
|
||||||
/* Debug Procedures */
|
/* Debug Procedures */
|
||||||
@ -411,6 +411,7 @@ TrNode replace_nested_trie(TrNode node, TrNode child, YAP_Term new_term, void (*
|
|||||||
temp = TrNode_next(temp);
|
temp = TrNode_next(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DATA_DESTRUCT_FUNCTION = destruct_function;
|
||||||
TrNode_child(child) = NULL;
|
TrNode_child(child) = NULL;
|
||||||
remove_entry(child);
|
remove_entry(child);
|
||||||
return newnode;
|
return newnode;
|
||||||
@ -538,24 +539,24 @@ TrNode get_simplification_sibling(TrNode node) {
|
|||||||
|
|
||||||
TrNode check_parent_first(TrNode node) {
|
TrNode check_parent_first(TrNode node) {
|
||||||
TrNode simplification;
|
TrNode simplification;
|
||||||
if (TrNode_entry(TrNode_parent(node)) != PairInitTag) {
|
if (TrNode_entry(TrNode_myparent(node)) != PairInitTag) {
|
||||||
simplification = check_parent_first(TrNode_parent(node));
|
simplification = check_parent_first(TrNode_myparent(node));
|
||||||
if (simplification != NULL && TrNode_entry(simplification) == PairEndTag) return simplification;
|
if (simplification != NULL && TrNode_entry(simplification) == PairEndTag) return simplification;
|
||||||
}
|
}
|
||||||
simplification = get_simplification_sibling(node);
|
simplification = get_simplification_sibling(node);
|
||||||
return simplification;
|
return simplification;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*TrNode TrNode_myparent(TrNode node) {
|
TrNode TrNode_myparent(TrNode node) {
|
||||||
TrNode parent = TrNode_parent(node);
|
TrNode parent = TrNode_parent(node);
|
||||||
while (parent != NULL && IS_FUNCTOR_NODE(parent))
|
while (parent != NULL && IS_FUNCTOR_NODE(parent))
|
||||||
parent = TrNode_parent(parent);
|
parent = TrNode_parent(parent);
|
||||||
return parent;
|
return parent;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
TrNode core_simplification_reduction(TrEngine engine, TrNode node, void (*destruct_function)(TrNode)) {
|
TrNode core_simplification_reduction(TrEngine engine, TrNode node, void (*destruct_function)(TrNode)) {
|
||||||
/* Try to find the greatest parent that has a sibling that is a PairEndTag: this indicates a deep simplification */
|
/* Try to find the greatest parent that has a sibling that is a PairEndTag: this indicates a deep simplification */
|
||||||
node = check_parent_first(TrNode_parent(node));
|
node = check_parent_first(TrNode_myparent(node));
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
/* do breadth reduction simplification */
|
/* do breadth reduction simplification */
|
||||||
node = TrNode_parent(node);
|
node = TrNode_parent(node);
|
||||||
@ -631,6 +632,7 @@ TrNode core_depth_reduction(TrEngine engine, TrNode node, TrNode depth_node, YAP
|
|||||||
INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
|
INCREMENT_ENTRIES(CURRENT_TRIE_ENGINE);
|
||||||
temp = TrNode_parent(leaf);
|
temp = TrNode_parent(leaf);
|
||||||
remove_child_nodes(TrNode_child(temp));
|
remove_child_nodes(TrNode_child(temp));
|
||||||
|
TrNode_child(temp) = NULL;
|
||||||
remove_entry(temp);
|
remove_entry(temp);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -774,6 +776,7 @@ TrNode core_breadth_reduction(TrEngine engine, TrNode node, TrNode breadth_node,
|
|||||||
/* termination condition */
|
/* termination condition */
|
||||||
core_set_trie_db_return_term(get_return_node_term(TrNode_child(node)));
|
core_set_trie_db_return_term(get_return_node_term(TrNode_child(node)));
|
||||||
node = TrNode_parent(node);
|
node = TrNode_parent(node);
|
||||||
|
DATA_DESTRUCT_FUNCTION = destruct_function;
|
||||||
remove_child_nodes(TrNode_child(node));
|
remove_child_nodes(TrNode_child(node));
|
||||||
TrNode_child(node) = NULL;
|
TrNode_child(node) = NULL;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user