summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2022-06-01 11:47:23 +0800
committerPeng Wu <alexepico@gmail.com>2022-06-01 12:06:24 +0800
commit706188e5080f29665ecd41791df611f4e3a6e248 (patch)
tree77cfedb552ddec6fbbee079ef324e592e60a8ce1
parenteea629ed12aa44600e681427f543ef181a4653d0 (diff)
downloadlibpinyin-706188e5080f29665ecd41791df611f4e3a6e248.tar.gz
Use check_result macro in src directory
-rw-r--r--src/lookup/phonetic_lookup.cpp2
-rw-r--r--src/lookup/phonetic_lookup.h33
-rw-r--r--src/lookup/pinyin_lookup2.cpp11
-rw-r--r--src/pinyin.cpp22
-rw-r--r--src/pinyin_internal.h1
-rw-r--r--src/storage/chewing_large_table.h1
-rw-r--r--src/storage/chewing_large_table2_kyotodb.cpp10
-rw-r--r--src/storage/flexible_ngram.h1
-rw-r--r--src/storage/flexible_ngram_kyotodb.h8
-rw-r--r--src/storage/ngram.cpp28
-rw-r--r--src/storage/ngram.h1
-rw-r--r--src/storage/ngram_bdb.cpp8
-rw-r--r--src/storage/ngram_kyotodb.cpp10
-rw-r--r--src/storage/phrase_large_table3.h1
-rw-r--r--src/storage/phrase_large_table3_kyotodb.cpp10
-rw-r--r--src/zhuyin.cpp6
16 files changed, 80 insertions, 73 deletions
diff --git a/src/lookup/phonetic_lookup.cpp b/src/lookup/phonetic_lookup.cpp
index e658911..4205630 100644
--- a/src/lookup/phonetic_lookup.cpp
+++ b/src/lookup/phonetic_lookup.cpp
@@ -200,7 +200,7 @@ bool ForwardPhoneticConstraints::diff_result(MatchResult best,
}
}
- assert(add_constraint(pos, next_pos, other_token));
+ check_result(add_constraint(pos, next_pos, other_token));
}
return changed;
diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h
index 78fac1b..30e1db4 100644
--- a/src/lookup/phonetic_lookup.h
+++ b/src/lookup/phonetic_lookup.h
@@ -22,9 +22,10 @@
#define PHONETIC_LOOKUP_H
-#include "novel_types.h"
#include <limits.h>
#include <math.h>
+#include "novel_types.h"
+#include "pinyin_utils.h"
#include "phonetic_key_matrix.h"
#include "ngram.h"
#include "lookup.h"
@@ -250,7 +251,7 @@ public:
initial_value.m_handles[1] = token;
trellis_node<nstore> initial_node;
- assert(initial_node.eval_item(&initial_value));
+ check_result(initial_node.eval_item(&initial_value));
LookupStepContent initial_step_content = (LookupStepContent)
g_ptr_array_index(m_steps_content, 0);
@@ -308,7 +309,7 @@ public:
if (!lookup_result) {
trellis_node<nstore> node;
- assert(node.eval_item(candidate));
+ check_result(node.eval_item(candidate));
g_array_append_val(step_content, node);
g_hash_table_insert(step_index, GUINT_TO_POINTER(token), GUINT_TO_POINTER(step_content->len - 1));
@@ -388,7 +389,7 @@ bool extract_result(const ForwardPhoneticTrellis<nstore, nbest> * trellis,
phrase_token_t last_token = tail->m_handles[0];
int sub_index = tail->m_sub_index;
- assert(trellis->get_candidate(index, last_token, sub_index, tail));
+ check_result(trellis->get_candidate(index, last_token, sub_index, tail));
}
/* no need to reverse the result */
@@ -406,7 +407,7 @@ public:
/* set tail node */
bool set_tail(const matrix_step<nstore> * tail);
/* back trace */
- /* always assume/assert matrix_step.eval_item(...) return true? */
+ /* always assume/check_result matrix_step.eval_item(...) return true? */
bool back_trace(const ForwardPhoneticTrellis * trellis);
/* extract results */
int extract(/* out */ GPtrArray * arrays);
@@ -546,7 +547,7 @@ protected:
g_ptr_array_index(topresults, 0);
const trellis_constraint_t * constraint = NULL;
- assert(m_constraints->get_constraint(start, constraint));
+ check_result(m_constraints->get_constraint(start, constraint));
if (CONSTRAINT_ONESTEP == constraint->m_type) {
return unigram_gen_next_step(start, constraint->m_constraint_step,
@@ -578,7 +579,7 @@ protected:
int start, int end,
PhraseIndexRanges ranges) {
const trellis_constraint_t * constraint = NULL;
- assert(m_constraints->get_constraint(start, constraint));
+ check_result(m_constraints->get_constraint(start, constraint));
bool found = false;
BigramPhraseArray bigram_phrase_items = g_array_new
@@ -761,7 +762,7 @@ public:
/* begin the viterbi beam search. */
for ( int i = 0; i < nstep - 1; ++i ){
const trellis_constraint_t * cur_constraint = NULL;
- assert(m_constraints->get_constraint(i, cur_constraint));
+ check_result(m_constraints->get_constraint(i, cur_constraint));
if (CONSTRAINT_NOSEARCH == cur_constraint->m_type)
continue;
@@ -792,7 +793,7 @@ public:
for ( int m = i + 1; m < nstep; ++m ){
const trellis_constraint_t * next_constraint = NULL;
- assert(m_constraints->get_constraint(m, next_constraint));
+ check_result(m_constraints->get_constraint(m, next_constraint));
if (CONSTRAINT_NOSEARCH == next_constraint->m_type)
break;
@@ -830,7 +831,7 @@ public:
const trellis_value_t * tail = (const trellis_value_t *)
g_ptr_array_index(tails, i);
- assert(extract_result<nstore>(&m_trellis, tail, result));
+ check_result(extract_result<nstore>(&m_trellis, tail, result));
results->add_result(result);
}
@@ -860,7 +861,7 @@ public:
continue;
const trellis_constraint_t * constraint = NULL;
- assert(constraints->get_constraint(i, constraint));
+ check_result(constraints->get_constraint(i, constraint));
if (train_next || CONSTRAINT_ONESTEP == constraint->m_type) {
if (CONSTRAINT_ONESTEP == constraint->m_type) {
@@ -880,12 +881,12 @@ public:
if (!user) {
user = new SingleGram;
}
- assert(user->get_total_freq(total_freq));
+ check_result(user->get_total_freq(total_freq));
guint32 freq = 0;
/* compute train factor */
if (!user->get_freq(token, freq)) {
- assert(user->insert_freq(token, 0));
+ check_result(user->insert_freq(token, 0));
seed = initial_seed;
} else {
seed = std_lite::max(freq, initial_seed);
@@ -897,10 +898,10 @@ public:
if (seed > 0 && total_freq > total_freq + seed)
goto next;
- assert(user->set_total_freq(total_freq + seed));
+ check_result(user->set_total_freq(total_freq + seed));
/* if total_freq is not overflow, then freq won't overflow. */
- assert(user->set_freq(token, freq + seed));
- assert(m_user_bigram->store(last_token, user));
+ check_result(user->set_freq(token, freq + seed));
+ check_result(m_user_bigram->store(last_token, user));
next:
assert(NULL != user);
if (user)
diff --git a/src/lookup/pinyin_lookup2.cpp b/src/lookup/pinyin_lookup2.cpp
index bb3d053..8946de3 100644
--- a/src/lookup/pinyin_lookup2.cpp
+++ b/src/lookup/pinyin_lookup2.cpp
@@ -22,6 +22,7 @@
#include "facade_chewing_table2.h"
#include "pinyin_lookup2.h"
#include "stl_lite.h"
+#include "pinyin_utils.h"
using namespace pinyin;
@@ -602,12 +603,12 @@ bool PinyinLookup2::train_result2(PhoneticKeyMatrix * matrix,
if (!user) {
user = new SingleGram;
}
- assert(user->get_total_freq(total_freq));
+ check_result(user->get_total_freq(total_freq));
guint32 freq = 0;
/* compute train factor */
if (!user->get_freq(token, freq)) {
- assert(user->insert_freq(token, 0));
+ check_result(user->insert_freq(token, 0));
seed = initial_seed;
} else {
seed = std_lite::max(freq, initial_seed);
@@ -619,10 +620,10 @@ bool PinyinLookup2::train_result2(PhoneticKeyMatrix * matrix,
if (seed > 0 && total_freq > total_freq + seed)
goto next;
- assert(user->set_total_freq(total_freq + seed));
+ check_result(user->set_total_freq(total_freq + seed));
/* if total_freq is not overflow, then freq won't overflow. */
- assert(user->set_freq(token, freq + seed));
- assert(m_user_bigram->store(last_token, user));
+ check_result(user->set_freq(token, freq + seed));
+ check_result(m_user_bigram->store(last_token, user));
next:
assert(NULL != user);
if (user)
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 19b3f0d..801e78f 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -671,7 +671,7 @@ bool pinyin_iterator_get_next_phrase(export_iterator_t * iter,
/* fill phrase and pronunciation pair. */
ucs4_t phrase_ucs4[MAX_PHRASE_LENGTH];
guint8 len = item.get_phrase_length();
- assert(item.get_phrase_string(phrase_ucs4));
+ check_result(item.get_phrase_string(phrase_ucs4));
gchar * phrase_utf8 = g_ucs4_to_utf8
(phrase_ucs4, len, NULL, NULL, NULL);
@@ -681,7 +681,7 @@ bool pinyin_iterator_get_next_phrase(export_iterator_t * iter,
assert(nth_pronun < n_pronuns);
ChewingKey keys[MAX_PHRASE_LENGTH];
guint32 freq = 0;
- assert(item.get_nth_pronunciation(nth_pronun, keys, freq));
+ check_result(item.get_nth_pronunciation(nth_pronun, keys, freq));
GPtrArray * array = g_ptr_array_new();
for(size_t i = 0; i < len; ++i) {
@@ -1266,7 +1266,7 @@ bool pinyin_get_sentence(pinyin_instance_t * instance,
MatchResult result = NULL;
assert(index < results.size());
- assert(results.get_result(index, result));
+ check_result(results.get_result(index, result));
bool retval = pinyin::convert_to_utf8
(context->m_phrase_index, result,
@@ -1528,7 +1528,7 @@ static phrase_token_t _get_previous_token(pinyin_instance_t * instance,
/* use the first candidate. */
MatchResult result = NULL;
- assert(results.get_result(0, result));
+ check_result(results.get_result(0, result));
phrase_token_t cur_token = g_array_index
(result, phrase_token_t, offset);
@@ -2073,8 +2073,8 @@ int pinyin_choose_candidate(pinyin_instance_t * instance,
if (NBEST_MATCH_CANDIDATE == candidate->m_candidate_type) {
MatchResult best = NULL, other = NULL;
- assert(results.get_result(0, best));
- assert(results.get_result(candidate->m_nbest_index, other));
+ check_result(results.get_result(0, best));
+ check_result(results.get_result(candidate->m_nbest_index, other));
constraints->diff_result(best, other);
return matrix.size() - 1;
}
@@ -2152,14 +2152,14 @@ bool pinyin_choose_predicted_candidate(pinyin_instance_t * instance,
/* train bi-gram */
guint32 total_freq = 0;
- assert(user_gram->get_total_freq(total_freq));
+ check_result(user_gram->get_total_freq(total_freq));
guint32 freq = 0;
if (!user_gram->get_freq(token, freq)) {
- assert(user_gram->insert_freq(token, initial_seed));
+ check_result(user_gram->insert_freq(token, initial_seed));
} else {
- assert(user_gram->set_freq(token, freq + initial_seed));
+ check_result(user_gram->set_freq(token, freq + initial_seed));
}
- assert(user_gram->set_total_freq(total_freq + initial_seed));
+ check_result(user_gram->set_total_freq(total_freq + initial_seed));
context->m_user_bigram->store(prev_token, user_gram);
delete user_gram;
return true;
@@ -2207,7 +2207,7 @@ bool pinyin_train(pinyin_instance_t * instance, guint8 index){
MatchResult result = NULL;
assert(index < results.size());
- assert(results.get_result(index, result));
+ check_result(results.get_result(index, result));
bool retval = context->m_pinyin_lookup->train_result3
(&matrix, instance->m_constraints, result);
diff --git a/src/pinyin_internal.h b/src/pinyin_internal.h
index 082360b..44b455f 100644
--- a/src/pinyin_internal.h
+++ b/src/pinyin_internal.h
@@ -27,6 +27,7 @@
#include "memory_chunk.h"
#include "pinyin_custom2.h"
#include "chewing_key.h"
+#include "pinyin_utils.h"
#include "pinyin_parser2.h"
#include "zhuyin_parser2.h"
#include "phonetic_key_matrix.h"
diff --git a/src/storage/chewing_large_table.h b/src/storage/chewing_large_table.h
index d836769..21158e1 100644
--- a/src/storage/chewing_large_table.h
+++ b/src/storage/chewing_large_table.h
@@ -26,6 +26,7 @@
#include "novel_types.h"
#include "memory_chunk.h"
#include "chewing_key.h"
+#include "pinyin_utils.h"
#include "table_info.h"
namespace pinyin{
diff --git a/src/storage/chewing_large_table2_kyotodb.cpp b/src/storage/chewing_large_table2_kyotodb.cpp
index ef3bcbe..e57552c 100644
--- a/src/storage/chewing_large_table2_kyotodb.cpp
+++ b/src/storage/chewing_large_table2_kyotodb.cpp
@@ -30,7 +30,7 @@ namespace pinyin{
ChewingLargeTable2::ChewingLargeTable2() {
/* create in-memory db. */
m_db = new ProtoTreeDB;
- assert(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE));
+ check_result(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE));
m_entries = NULL;
init_entries();
@@ -144,8 +144,8 @@ int ChewingLargeTable2::search_internal(/* in */ const ChewingKey index[],
entry->m_chunk.set_size(vsiz);
/* m_chunk may re-allocate here. */
char * vbuf = (char *) entry->m_chunk.begin();
- assert(vsiz == m_db->get(kbuf, phrase_length * sizeof(ChewingKey),
- vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, phrase_length * sizeof(ChewingKey),
+ vbuf, vsiz));
result = entry->search(keys, ranges) | result;
@@ -236,7 +236,7 @@ int ChewingLargeTable2::add_index_internal(/* in */ const ChewingKey index[],
entry->m_chunk.set_size(vsiz);
/* m_chunk may re-allocate here. */
vbuf = (char *) entry->m_chunk.begin();
- assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
int result = entry->add_index(keys, token);
@@ -305,7 +305,7 @@ int ChewingLargeTable2::remove_index_internal(/* in */ const ChewingKey index[],
entry->m_chunk.set_size(vsiz);
/* m_chunk may re-allocate here. */
vbuf = (char *) entry->m_chunk.begin();
- assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
int result = entry->remove_index(keys, token);
if (ERROR_OK != result)
diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h
index f6b0161..a80baa3 100644
--- a/src/storage/flexible_ngram.h
+++ b/src/storage/flexible_ngram.h
@@ -28,6 +28,7 @@
* struct MagicHeader, ArrayHeader, ArrayItem.
*/
+#include "pinyin_utils.h"
#include "flexible_single_gram.h"
#ifdef HAVE_BERKELEY_DB
diff --git a/src/storage/flexible_ngram_kyotodb.h b/src/storage/flexible_ngram_kyotodb.h
index ad84b78..b12fa42 100644
--- a/src/storage/flexible_ngram_kyotodb.h
+++ b/src/storage/flexible_ngram_kyotodb.h
@@ -171,7 +171,7 @@ public:
m_chunk.set_size(vsiz);
char * vbuf = (char *) m_chunk.begin();
- assert (vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
if ( memcmp(vbuf, m_magic_number,
sizeof(m_magic_number)) == 0 )
@@ -206,8 +206,8 @@ public:
m_chunk.set_size(vsiz);
char * vbuf = (char *) m_chunk.begin();
- assert (vsiz == m_db->get(kbuf, sizeof(phrase_token_t),
- vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, sizeof(phrase_token_t),
+ vbuf, vsiz));
single_gram = new FlexibleSingleGram<ArrayHeader, ArrayItem>
(m_chunk.begin(), vsiz, copy);
@@ -397,7 +397,7 @@ public:
} else { /* found */
m_chunk.set_size(vsiz);
char * vbuf = (char *) m_chunk.begin();
- assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
}
m_chunk.set_content(0, &header, sizeof(ArrayHeader));
diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp
index f2e0aa3..ca845c5 100644
--- a/src/storage/ngram.cpp
+++ b/src/storage/ngram.cpp
@@ -68,7 +68,7 @@ guint32 SingleGram::get_length(){
if (0 == length) {
/* no items here, total freq should be zero. */
guint32 total_freq = 0;
- assert(get_total_freq(total_freq));
+ check_result(get_total_freq(total_freq));
assert(0 == total_freq);
}
@@ -79,7 +79,7 @@ guint32 SingleGram::mask_out(phrase_token_t mask, phrase_token_t value){
guint32 removed_items = 0;
guint32 total_freq = 0;
- assert(get_total_freq(total_freq));
+ check_result(get_total_freq(total_freq));
const SingleGramItem * begin = (const SingleGramItem *)
((const char *)(m_chunk.begin()) + sizeof(guint32));
@@ -100,7 +100,7 @@ guint32 SingleGram::mask_out(phrase_token_t mask, phrase_token_t value){
--cur;
}
- assert(set_total_freq(total_freq));
+ check_result(set_total_freq(total_freq));
return removed_items;
}
@@ -122,8 +122,8 @@ bool SingleGram::prune(){
}
}
guint32 total_freq;
- assert(get_total_freq(total_freq));
- assert(set_total_freq(total_freq - nitem));
+ check_result(get_total_freq(total_freq));
+ check_result(set_total_freq(total_freq - nitem));
#endif
return true;
}
@@ -140,7 +140,7 @@ bool SingleGram::retrieve_all(/* out */ BigramPhraseWithCountArray array)
guint32 total_freq;
BigramPhraseItemWithCount bigram_item_with_count;
- assert(get_total_freq(total_freq));
+ check_result(get_total_freq(total_freq));
for ( const SingleGramItem * cur_item = begin; cur_item != end; ++cur_item){
bigram_item_with_count.m_token = cur_item->m_token;
@@ -164,14 +164,14 @@ bool SingleGram::search(/* in */ PhraseIndexRange * range,
guint32 total_freq;
BigramPhraseItem bigram_item;
- assert(get_total_freq(total_freq));
+ check_result(get_total_freq(total_freq));
for ( ; cur_item != end; ++cur_item){
- if ( cur_item->m_token >= range->m_range_end )
- break;
- bigram_item.m_token = cur_item->m_token;
- bigram_item.m_freq = cur_item->m_freq / (gfloat)total_freq;
- g_array_append_val(array, bigram_item);
+ if ( cur_item->m_token >= range->m_range_end )
+ break;
+ bigram_item.m_token = cur_item->m_token;
+ bigram_item.m_freq = cur_item->m_freq / (gfloat)total_freq;
+ g_array_append_val(array, bigram_item);
}
return true;
@@ -302,8 +302,8 @@ bool merge_single_gram(SingleGram * merged, const SingleGram * system,
/* merge the origin info and delta info */
guint32 system_total, user_total;
- assert(system->get_total_freq(system_total));
- assert(user->get_total_freq(user_total));
+ check_result(system->get_total_freq(system_total));
+ check_result(user->get_total_freq(user_total));
const guint32 merged_total = system_total + user_total;
merged_chunk.set_content(0, &merged_total, sizeof(guint32));
diff --git a/src/storage/ngram.h b/src/storage/ngram.h
index 7f7a653..57979b4 100644
--- a/src/storage/ngram.h
+++ b/src/storage/ngram.h
@@ -24,6 +24,7 @@
#include "config.h"
#include <glib.h>
#include "novel_types.h"
+#include "pinyin_utils.h"
#ifdef HAVE_BERKELEY_DB
#include "ngram_bdb.h"
diff --git a/src/storage/ngram_bdb.cpp b/src/storage/ngram_bdb.cpp
index 95afdbd..8910f9d 100644
--- a/src/storage/ngram_bdb.cpp
+++ b/src/storage/ngram_bdb.cpp
@@ -227,12 +227,12 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){
phrase_token_t index = g_array_index(items, phrase_token_t, i);
if ((index & mask) == value) {
- assert(remove(index));
+ check_result(remove(index));
continue;
}
SingleGram * gram = NULL;
- assert(load(index, gram));
+ check_result(load(index, gram));
int num = gram->mask_out(mask, value);
if (0 == num) {
@@ -241,9 +241,9 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){
}
if (0 == gram->get_length()) {
- assert(remove(index));
+ check_result(remove(index));
} else {
- assert(store(index, gram));
+ check_result(store(index, gram));
}
delete gram;
diff --git a/src/storage/ngram_kyotodb.cpp b/src/storage/ngram_kyotodb.cpp
index 54c2055..560e196 100644
--- a/src/storage/ngram_kyotodb.cpp
+++ b/src/storage/ngram_kyotodb.cpp
@@ -133,7 +133,7 @@ bool Bigram::load(phrase_token_t index, SingleGram * & single_gram,
m_chunk.set_size(vsiz);
char * vbuf = (char *) m_chunk.begin();
- assert (vsiz == m_db->get(kbuf, sizeof(phrase_token_t),
+ check_result (vsiz == m_db->get(kbuf, sizeof(phrase_token_t),
vbuf, vsiz));
single_gram = new SingleGram(m_chunk.begin(), vsiz, copy);
@@ -206,12 +206,12 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){
phrase_token_t index = g_array_index(items, phrase_token_t, i);
if ((index & mask) == value) {
- assert(remove(index));
+ check_result(remove(index));
continue;
}
SingleGram * gram = NULL;
- assert(load(index, gram));
+ check_result(load(index, gram));
int num = gram->mask_out(mask, value);
if (0 == num) {
@@ -220,9 +220,9 @@ bool Bigram::mask_out(phrase_token_t mask, phrase_token_t value){
}
if (0 == gram->get_length()) {
- assert(remove(index));
+ check_result(remove(index));
} else {
- assert(store(index, gram));
+ check_result(store(index, gram));
}
delete gram;
diff --git a/src/storage/phrase_large_table3.h b/src/storage/phrase_large_table3.h
index 2774767..40654bb 100644
--- a/src/storage/phrase_large_table3.h
+++ b/src/storage/phrase_large_table3.h
@@ -24,6 +24,7 @@
#include <stdio.h>
#include "novel_types.h"
#include "memory_chunk.h"
+#include "pinyin_utils.h"
#ifdef HAVE_BERKELEY_DB
#include "phrase_large_table3_bdb.h"
diff --git a/src/storage/phrase_large_table3_kyotodb.cpp b/src/storage/phrase_large_table3_kyotodb.cpp
index 73e578c..571f97c 100644
--- a/src/storage/phrase_large_table3_kyotodb.cpp
+++ b/src/storage/phrase_large_table3_kyotodb.cpp
@@ -31,7 +31,7 @@ namespace pinyin{
PhraseLargeTable3::PhraseLargeTable3() {
/* create in-memory db. */
m_db = new ProtoTreeDB;
- assert(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE));
+ check_result(m_db->open("-", BasicDB::OREADER|BasicDB::OWRITER|BasicDB::OCREATE));
m_entry = new PhraseTableEntry;
}
@@ -147,8 +147,8 @@ int PhraseLargeTable3::search(int phrase_length,
m_entry->m_chunk.set_size(vsiz);
/* m_chunk may re-allocate here. */
char * vbuf = (char *) m_entry->m_chunk.begin();
- assert (vsiz == m_db->get(kbuf, phrase_length * sizeof(ucs4_t),
- vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, phrase_length * sizeof(ucs4_t),
+ vbuf, vsiz));
result = m_entry->search(tokens) | result;
@@ -202,7 +202,7 @@ int PhraseLargeTable3::add_index(int phrase_length,
m_entry->m_chunk.set_size(vsiz);
/* m_chunk may re-allocate here. */
vbuf = (char *) m_entry->m_chunk.begin();
- assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
int result = m_entry->add_index(token);
@@ -233,7 +233,7 @@ int PhraseLargeTable3::remove_index(int phrase_length,
m_entry->m_chunk.set_size(vsiz);
/* m_chunk may re-allocate here. */
vbuf = (char *) m_entry->m_chunk.begin();
- assert(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
+ check_result(vsiz == m_db->get(kbuf, ksiz, vbuf, vsiz));
int result = m_entry->remove_index(token);
if (ERROR_OK != result)
diff --git a/src/zhuyin.cpp b/src/zhuyin.cpp
index 85d5a44..3d418c4 100644
--- a/src/zhuyin.cpp
+++ b/src/zhuyin.cpp
@@ -989,7 +989,7 @@ bool zhuyin_get_sentence(zhuyin_instance_t * instance,
return false;
MatchResult result = NULL;
- assert(results.get_result(0, result));
+ check_result(results.get_result(0, result));
bool retval = pinyin::convert_to_utf8
(context->m_phrase_index, result,
@@ -1183,7 +1183,7 @@ static phrase_token_t _get_previous_token(zhuyin_instance_t * instance,
/* use the first candidate. */
MatchResult result = NULL;
- assert(results.get_result(0, result));
+ check_result(results.get_result(0, result));
phrase_token_t cur_token = g_array_index
(result, phrase_token_t, offset);
@@ -1707,7 +1707,7 @@ bool zhuyin_train(zhuyin_instance_t * instance){
context->m_modified = true;
MatchResult result = NULL;
- assert(results.get_result(0, result));
+ check_result(results.get_result(0, result));
bool retval = context->m_pinyin_lookup->train_result3
(&matrix, instance->m_constraints, result);