Tasuku SUENAGA
a****@razil*****
2008年 9月 26日 (金) 18:58:25 JST
すえながです。
やっとfail malloc系のテストを始めたところです。
動的にmalloc系の関数を差し替えることが出来て、
cutterと連動できると嬉しいですねー。
というわけで、以下のパッチについて
現在のconfigureオプションである--enable-fmallocをつけたときだけ
有効になるようになると嬉しいなぁ…と。
昨日から僕がコミットしている分は自分のテスト用にコミットしているだけですので、
独自に作業いただけると嬉しいです。
さて、ぜんぜん話は違うのですが、
現状では環境によって./run-test.shが落ちたり、
失敗したりしているようです。
具体的には、
64bit環境では2つを除いてテストが成功するのですが、
32bit環境では以下のようにクラッシュしたり、
ソートがうまくいかなかったりしています。
デバッグしないと…
---
CRASH!!!
#5 0xb7762ef5 in trie_test_data_newv (
#6 0xb7764895 in test_data_new (key=0xb77734f1 "?\202\211?\203\213?\202?",
#7 0xb776a2a5 in data_delete () at test-patricia-trie.c:340
#8 0xb7f9bb81 in run (test=0x808a808, test_context=0x808b1f0,
#9 0xb7f98e5f in cut_test_run (test=0x808a808, test_context=0x808b1f0,
#10 0xb7f9c74e in cut_test_case_run_with_filter (test_case=0x8062670,
#11 0xb7f9cfd0 in run (data=0x80b0538) at cut-test-suite.c:242
#12 0xb7f9d6dc in cut_test_suite_run_test_cases (test_suite=0x805e808,
#13 0xb7f9da09 in cut_test_suite_run_with_filter (test_suite=0x805e808,
#14 0xb7f9da96 in cut_test_suite_run (suite=0x805e808, run_context=0x8059800)
#15 0xb7f96f58 in runner_run (runner=0x8059800) at cut-test-runner.c
(gdbだと)
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7cbf700 (LWP 24536)]
0xb775eef5 in trie_test_data_newv (key=0xb776f4f1 "?\202\211?\203\213?\202?",
search_key=0x0, expected_key=0x0, expected_rc=sen_success,
expected_strings=0x0, increment=0,
set_parameters=0xb775f0f5 <set_sis_and_utf8_encoding>, args=0x0)
at test-patricia-trie.h:300
300 if (!*args)
(gdb) bt
#0 0xb775eef5 in trie_test_data_newv (key=0xb776f4f1 "?\202\211?\203\213?\202?",
search_key=0x0, expected_key=0x0, expected_rc=sen_success,
expected_strings=0x0, increment=0,
set_parameters=0xb775f0f5 <set_sis_and_utf8_encoding>, args=0x0)
at test-patricia-trie.h:300
#1 0xb7760895 in test_data_new (key=0xb776f4f1 "?\202\211?\203\213?\202?",
set_parameters=0xb775f0f5 <set_sis_and_utf8_encoding>)
at test-patricia-trie.c:182
#2 0xb77662a5 in data_delete () at test-patricia-trie.c:340
#3 0xb7f97b81 in run (test=0x808a808, test_context=0x808b1f0,
run_context=0x8059800) at cut-test-iterator.c:388
#4 0xb7f94e5f in cut_test_run (test=0x808a808, test_context=0x808b1f0,
run_context=0x8059800) at cut-test.c:460
#5 0xb7f9874e in cut_test_case_run_with_filter (test_case=0x8062670,
run_context=0x8059800, test_names=0x0) at cut-test-case.c:360
#6 0xb7f98fd0 in run (data=0x80b0538) at cut-test-suite.c:242
#7 0xb7f996dc in cut_test_suite_run_test_cases (test_suite=0x805e808,
run_context=0x8059800, test_cases=0x8061f90, test_names=0x0)
at cut-test-suite.c:287
#8 0xb7f99a09 in cut_test_suite_run_with_filter (test_suite=0x805e808,
run_context=0x8059800, test_case_names=0x0, test_names=0x0)
at cut-test-suite.c:567
#9 0xb7f99a96 in cut_test_suite_run (suite=0x805e808, run_context=0x8059800)
at cut-test-suite.c:490
#10 0xb7f92f58 in runner_run (runner=0x8059800) at cut-test-runner.c:614
#11 0xb7f9250e in cut_runner_run (runner=0x8059800) at cut-runner.c:67
#12 0xb7f8f2a4 in cut_run_context_start (context=0x8059800)
at cut-run-context.c:1772
#13 0xb7fb9f3d in run (ui=0x804c740, run_context=0x8059800) at cut-console-ui.c:901
#14 0xb7fa0d46 in cut_ui_run (ui=0x804c740, run_context=0x8059800) at cut-ui.c:103
#15 0xb7f9455a in cut_start_run_context (run_context=0x8059800) at cut-main.c:398
#16 0xb7f94702 in cut_run () at cut-main.c:431
#17 0x0804856a in main (argc=-1217007371, argv=0x0) at main.c:35
以下1) 2)以外は32bit環境のみで起こる。
1) Omission: test_create_with_null_path
sen_ii_create() doesn't check NULL path. should be checked?
./test-inverted-index.c:206: test_create_with_null_path()
2) Failure: test_crud
<gcut_take_new_list_string("1", "2", "3", NULL) == retrieve_record_ids("検索")>
expected: <("1", "2", "3")>
but was: <()>
./test-inverted-index.c:399: test_crud()
3) Failure: test_sort_by_variable_size_key (ascending)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ")>
but was: <("セナ", "セナセナ", "ナセナセ", "セナ + Ruby", "Senna")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
4) Failure: test_sort_by_variable_size_key (ascending - limit)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby")>
but was: <("セナ", "セナセナ", "ナセナセ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
5) Failure: test_sort_by_variable_size_key (descending)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Senna")>
but was: <("Senna", "セナ + Ruby", "ナセナセ", "セナセナ", "セナ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
6) Failure: test_sort_by_variable_size_key (descending - limit)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby")>
but was: <("Senna", "セナ + Ruby", "ナセナセ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
7) Failure: test_sort_by_variable_size_key (ascending - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ")>
but was: <("セナ", "セナセナ", "ナセナセ", "セナ + Ruby", "Senna")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
8) Failure: test_sort_by_variable_size_key (ascending - limit - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby")>
but was: <("セナ", "セナセナ", "ナセナセ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
9) Failure: test_sort_by_variable_size_key (descending - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Senna")>
but was: <("Senna", "セナ + Ruby", "ナセナセ", "セナセナ", "セナ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
10) Failure: test_sort_by_variable_size_key (descending - limit - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby")>
but was: <("Senna", "セナ + Ruby", "ナセナセ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
11) Failure: test_sort_by_variable_size_key (many - ascending)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna", "Tritton", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ", "ブラジル")>
but was: <("セナ", "ナセナセ", "セナセナ", "ブラジル", "Ludia", "Ruby", "セナ + Ruby", "Senna", "Tritton")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
12) Failure: test_sort_by_variable_size_key (many - ascending - limit)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna")>
but was: <("セナ", "ナセナセ", "セナセナ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
13) Failure: test_sort_by_variable_size_key (many - descending)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Tritton", "Senna", "Ruby", "Ludia")>
but was: <("Tritton", "Senna", "セナ + Ruby", "Ruby", "Ludia", "ナセナセ", "セナセナ", "ブラジル", "セナ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
14) Failure: test_sort_by_variable_size_key (many - descending - limit)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ")>
but was: <("Tritton", "Senna", "セナ + Ruby")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
15) Failure: test_sort_by_variable_size_key (many - ascending - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna", "Tritton", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ", "ブラジル")>
but was: <("セナ", "ナセナセ", "セナセナ", "ブラジル", "Ludia", "Ruby", "セナ + Ruby", "Senna", "Tritton")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
16) Failure: test_sort_by_variable_size_key (many - ascending - limit - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna")>
but was: <("セナ", "ナセナセ", "セナセナ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
17) Failure: test_sort_by_variable_size_key (many - descending - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Tritton", "Senna", "Ruby", "Ludia")>
but was: <("Tritton", "Senna", "セナ + Ruby", "Ruby", "Ludia", "ナセナセ", "セナセナ", "ブラジル", "セナ")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
18) Failure: test_sort_by_variable_size_key (many - descending - limit - tiny)
<test_data->expected_strings == retrieve_all_keys(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ")>
but was: <("Tritton", "Senna", "セナ + Ruby")>
./test-hash-sort.c:676: test_sort_by_variable_size_key()
19) Failure: test_sort_by_value (ascending)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ")>
but was: <("セナ", "セナセナ", "ナセナセ", "セナ + Ruby", "Senna")>
./test-hash-sort.c:878: test_sort_by_value()
20) Failure: test_sort_by_value (ascending - limit)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby")>
but was: <("セナ", "セナセナ", "ナセナセ")>
./test-hash-sort.c:878: test_sort_by_value()
21) Failure: test_sort_by_value (descending)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Senna")>
but was: <("Senna", "セナ + Ruby", "ナセナセ", "セナセナ", "セナ")>
./test-hash-sort.c:878: test_sort_by_value()
22) Failure: test_sort_by_value (descending - limit)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby")>
but was: <("Senna", "セナ + Ruby", "ナセナセ")>
./test-hash-sort.c:878: test_sort_by_value()
23) Failure: test_sort_by_value (ascending - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ")>
but was: <("セナ", "セナセナ", "ナセナセ", "セナ + Ruby", "Senna")>
./test-hash-sort.c:878: test_sort_by_value()
24) Failure: test_sort_by_value (ascending - limit - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Senna", "セナ", "セナ + Ruby")>
but was: <("セナ", "セナセナ", "ナセナセ")>
./test-hash-sort.c:878: test_sort_by_value()
25) Failure: test_sort_by_value (descending - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Senna")>
but was: <("Senna", "セナ + Ruby", "ナセナセ", "セナセナ", "セナ")>
./test-hash-sort.c:878: test_sort_by_value()
26) Failure: test_sort_by_value (descending - limit - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ナセナセ", "セナセナ", "セナ + Ruby")>
but was: <("Senna", "セナ + Ruby", "ナセナセ")>
./test-hash-sort.c:878: test_sort_by_value()
27) Failure: test_sort_by_value (many - ascending)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna", "Tritton", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ", "ブラジル")>
but was: <("セナ", "ナセナセ", "セナセナ", "ブラジル", "Ludia", "Ruby", "セナ + Ruby", "Senna", "Tritton")>
./test-hash-sort.c:878: test_sort_by_value()
28) Failure: test_sort_by_value (many - ascending - limit)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna")>
but was: <("セナ", "ナセナセ", "セナセナ")>
./test-hash-sort.c:878: test_sort_by_value()
29) Failure: test_sort_by_value (many - descending)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Tritton", "Senna", "Ruby", "Ludia")>
but was: <("Tritton", "Senna", "セナ + Ruby", "Ruby", "Ludia", "ナセナセ", "セナセナ", "ブラジル", "セナ")>
./test-hash-sort.c:878: test_sort_by_value()
30) Failure: test_sort_by_value (many - descending - limit)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ")>
but was: <("Tritton", "Senna", "セナ + Ruby")>
./test-hash-sort.c:878: test_sort_by_value()
31) Failure: test_sort_by_value (many - ascending - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna", "Tritton", "セナ", "セナ + Ruby", "セナセナ", "ナセナセ", "ブラジル")>
but was: <("セナ", "ナセナセ", "セナセナ", "ブラジル", "Ludia", "Ruby", "セナ + Ruby", "Senna", "Tritton")>
./test-hash-sort.c:878: test_sort_by_value()
32) Failure: test_sort_by_value (many - ascending - limit - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("Ludia", "Ruby", "Senna")>
but was: <("セナ", "ナセナセ", "セナセナ")>
./test-hash-sort.c:878: test_sort_by_value()
33) Failure: test_sort_by_value (many - descending - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ", "セナ + Ruby", "セナ", "Tritton", "Senna", "Ruby", "Ludia")>
but was: <("Tritton", "Senna", "セナ + Ruby", "Ruby", "Ludia", "ナセナセ", "セナセナ", "ブラジル", "セナ")>
./test-hash-sort.c:878: test_sort_by_value()
34) Failure: test_sort_by_value (many - descending - limit - tiny)
<test_data->expected_strings == retrieve_all_values(sort_result, n_entries)>
expected: <("ブラジル", "ナセナセ", "セナセナ")>
but was: <("Tritton", "Senna", "セナ + Ruby")>
./test-hash-sort.c:878: test_sort_by_value()
Finished in 13.438791 seconds (total: 52.374363 seconds)
681 test(s), 15462 assertion(s), 33 failure(s), 0 error(s), 0 pending(s), 1 omission(s), 0 notification(s)
95.1542% passed
Kouhei Sutou さんは書きました:
> 須藤です。
>
> 現在はビルド時に--enable-fmallocオプションを指定することで
> fail mallocの機能を有効がなり、sen_malloc()の代わりに
> sen_fail_malloc()が使用されるようになります。もし、実行
> 時に動的にsen_malloc()の代わりの関数を変更できるとテストが書
> きやすくなる気がしています。(特定の処理の間だけfailするよう
> にするとかが簡単にできそう)
>
>
> 実装のイメージはパッチの通りなのですが、これに加えて
> sen_ctx_set_malloc_func()のようなアクセサがあるとよいのかと
> 思っています。
>
> 速度の事もあるので、ビルド時のオプションで有効・無効を切り替
> えるようにした方がよいのもしれません。
> (ほんとはベンチマークをとってから言った方がよいのですが。。。)
>
>
> どうでしょうか?
>
> -------------- next part --------------
> Index: lib/ctx.c
> ===================================================================
> --- lib/ctx.c (リビジョン 1138)
> +++ lib/ctx.c (作業コピー)
> @@ -207,6 +207,17 @@
> ctx->impl->encoding = ctx->encoding;
> ctx->impl->lifoseg = -1;
> ctx->impl->currseg = -1;
> +#ifdef USE_FAIL_MALLOC
> + ctx->impl->malloc_func = sen_malloc_fail;
> + ctx->impl->calloc_func = sen_calloc_fail;
> + ctx->impl->realloc_func = sen_realloc_fail;
> + ctx->impl->strdup_func = sen_strdup_fail;
> +#else
> + ctx->impl->malloc_func = sen_malloc_default;
> + ctx->impl->calloc_func = sen_calloc_default;
> + ctx->impl->realloc_func = sen_realloc_default;
> + ctx->impl->strdup_func = sen_strdup_default;
> +#endif
> ctx->impl->db = NULL;
> ctx->impl->phs = NIL;
> ctx->impl->code = NIL;
> @@ -880,8 +891,48 @@
> }
>
> void *
> -sen_malloc(sen_ctx *ctx, size_t size, const char* file, int line)
> +sen_malloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> {
> + if (ctx && ctx->impl && ctx->impl->malloc_func) {
> + return ctx->impl->malloc_func(ctx, size, file, line, func);
> + } else {
> + return sen_malloc_default(ctx, size, file, line, func);
> + }
> +}
> +
> +void *
> +sen_calloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> +{
> + if (ctx && ctx->impl && ctx->impl->calloc_func) {
> + return ctx->impl->calloc_func(ctx, size, file, line, func);
> + } else {
> + return sen_calloc_default(ctx, size, file, line, func);
> + }
> +}
> +
> +void *
> +sen_realloc(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func)
> +{
> + if (ctx && ctx->impl && ctx->impl->realloc_func) {
> + return ctx->impl->realloc_func(ctx, ptr, size, file, line, func);
> + } else {
> + return sen_realloc_default(ctx, ptr, size, file, line, func);
> + }
> +}
> +
> +char *
> +sen_strdup(sen_ctx *ctx, const char *string, const char* file, int line, const char *func)
> +{
> + if (ctx && ctx->impl && ctx->impl->strdup_func) {
> + return ctx->impl->strdup_func(ctx, string, file, line, func);
> + } else {
> + return sen_strdup_default(ctx, string, file, line, func);
> + }
> +}
> +
> +void *
> +sen_malloc_default(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> +{
> void *res = malloc(size);
> if (res) {
> alloc_count++;
> @@ -895,7 +946,7 @@
> }
>
> void *
> -sen_calloc(sen_ctx *ctx, size_t size, const char* file, int line)
> +sen_calloc_default(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> {
> void *res = calloc(size, 1);
> if (res) {
> @@ -921,7 +972,7 @@
> }
>
> void *
> -sen_realloc(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line)
> +sen_realloc_default(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func)
> {
> void *res;
> if (!size) {
> @@ -953,7 +1004,7 @@
> }
>
> char *
> -sen_strdup(sen_ctx *ctx, const char *s, const char* file, int line)
> +sen_strdup_default(sen_ctx *ctx, const char *s, const char* file, int line, const char *func)
> {
> char *res = strdup(s);
> if (res) {
> @@ -968,7 +1019,7 @@
> }
>
> #ifdef USE_FAIL_MALLOC
> -int
> +static int
> fail_malloc_check(size_t size, const char *file, int line, const char *func)
> {
> if ((sen_fmalloc_file && strcmp(file, sen_fmalloc_file)) ||
> @@ -983,10 +1034,10 @@
> }
>
> void *
> -sen_fail_malloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> +sen_malloc_fail(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> {
> if (fail_malloc_check(size, file, line, func)) {
> - return sen_malloc(ctx, size, file, line);
> + return sen_malloc_default(ctx, size, file, line);
> } else {
> sen_index_expire();
> MERR("fail_malloc (%d) (%s:%d@%s) <%d>", size, file, line, func, alloc_count);
> @@ -995,10 +1046,10 @@
> }
>
> void *
> -sen_fail_calloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> +sen_calloc_fail(sen_ctx *ctx, size_t size, const char* file, int line, const char *func)
> {
> if (fail_malloc_check(size, file, line, func)) {
> - return sen_calloc(ctx, size, file, line);
> + return sen_calloc_default(ctx, size, file, line);
> } else {
> sen_index_expire();
> MERR("fail_calloc (%d) (%s:%d@%s) <%d>", size, file, line, func, alloc_count);
> @@ -1007,24 +1058,23 @@
> }
>
> void *
> -sen_fail_realloc(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line,
> +sen_realloc_fail(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line,
> const char *func)
> {
> if (fail_malloc_check(size, file, line, func)) {
> - return sen_realloc(ctx, ptr, size, file, line);
> + return sen_realloc_default(ctx, ptr, size, file, line);
> } else {
> sen_index_expire();
> - MERR("fail_realloc (%p,%zu) (%s:%d@%s) <%d>", ptr, size
> - , file, line, func, alloc_count);
> + MERR("fail_realloc (%p,%zu) (%s:%d@%s) <%d>", ptr, size, file, line, func, alloc_count);
> return NULL;
> }
> }
>
> char *
> -sen_fail_strdup(sen_ctx *ctx, const char *s, const char* file, int line, const char *func)
> +sen_strdup_fail(sen_ctx *ctx, const char *s, const char* file, int line, const char *func)
> {
> if (fail_malloc_check(strlen(s), file, line, func)) {
> - return sen_strdup(ctx, s, file, line);
> + return sen_strdup_default(ctx, s, file, line);
> } else {
> sen_index_expire();
> MERR("fail_strdup(%p) (%s:%d@%s) <%d>", s, file, line, func, alloc_count);
> Index: lib/ctx.h
> ===================================================================
> --- lib/ctx.h (リビジョン 1138)
> +++ lib/ctx.h (作業コピー)
> @@ -99,25 +99,14 @@
> #define GMERR(...) ERRSET(&sen_gctx, SEN_ALERT, sen_memory_exhausted, __VA_ARGS__)
> #define GSERR(str) GERR(sen_other_error, "syscall error '%s' (%s)", str, strerror(errno))
>
> -#ifdef USE_FAIL_MALLOC
> -#define SEN_MALLOC(s) sen_fail_malloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_CALLOC(s) sen_fail_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_REALLOC(p,s) sen_fail_realloc(ctx,p,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_STRDUP(s) sen_fail_strdup(ctx,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_GMALLOC(s) sen_fail_malloc(&sen_gctx,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_GCALLOC(s) sen_fail_calloc(&sen_gctx,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_GREALLOC(p,s) sen_fail_realloc(&sen_gctx,p,s,__FILE__,__LINE__,__FUNCTION__)
> -#define SEN_GSTRDUP(s) sen_fail_strdup(&sen_gctx,s,__FILE__,__LINE__,__FUNTION__)
> -#else /* USE_FAIL_MALLOC */
> -#define SEN_MALLOC(s) sen_malloc(ctx,s,__FILE__,__LINE__)
> -#define SEN_CALLOC(s) sen_calloc(ctx,s,__FILE__,__LINE__)
> -#define SEN_REALLOC(p,s) sen_realloc(ctx,p,s,__FILE__,__LINE__)
> -#define SEN_STRDUP(s) sen_strdup(ctx,s,__FILE__,__LINE__)
> -#define SEN_GMALLOC(s) sen_malloc(&sen_gctx,s,__FILE__,__LINE__)
> -#define SEN_GCALLOC(s) sen_calloc(&sen_gctx,s,__FILE__,__LINE__)
> -#define SEN_GREALLOC(p,s) sen_realloc(&sen_gctx,p,s,__FILE__,__LINE__)
> -#define SEN_GSTRDUP(s) sen_strdup(&sen_gctx,s,__FILE__,__LINE__)
> -#endif /* USE_FAIL_MALLOC */
> +#define SEN_MALLOC(s) sen_malloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_CALLOC(s) sen_calloc(ctx,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_REALLOC(p,s) sen_realloc(ctx,p,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_STRDUP(s) sen_strdup(ctx,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_GMALLOC(s) sen_malloc(&sen_gctx,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_GCALLOC(s) sen_calloc(&sen_gctx,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_GREALLOC(p,s) sen_realloc(&sen_gctx,p,s,__FILE__,__LINE__,__FUNCTION__)
> +#define SEN_GSTRDUP(s) sen_strdup(&sen_gctx,s,__FILE__,__LINE__,__FUNCTION__)
> #define SEN_FREE(p) sen_free(ctx,p,__FILE__,__LINE__)
> #define SEN_MALLOCN(t,n) ((t *)(SEN_MALLOC(sizeof(t) * (n))))
> #define SEN_GFREE(p) sen_free(&sen_gctx,p,__FILE__,__LINE__)
> @@ -143,17 +132,32 @@
> void sen_ctx_free_lifo(sen_ctx *ctx, void *ptr,
> const char* file, int line, const char *func);
>
> +typedef void *(*sen_malloc_func) (sen_ctx *ctx, size_t size,
> + const char *file, int line, const char *func);
> +typedef void *(*sen_calloc_func) (sen_ctx *ctx, size_t size,
> + const char *file, int line, const char *func);
> +typedef void *(*sen_realloc_func) (sen_ctx *ctx, void *ptr, size_t size,
> + const char *file, int line, const char *func);
> +typedef void *(*sen_strdup_func) (sen_ctx *ctx, const char *string,
> + const char *file, int line, const char *func);
> +
> +void *sen_malloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> +void *sen_calloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> +void *sen_realloc(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
> +char *sen_strdup(sen_ctx *ctx, const char *s, const char* file, int line, const char *func);
> +
> +void *sen_malloc_default(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> +void *sen_calloc_default(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> +void *sen_realloc_default(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
> +char *sen_strdup_default(sen_ctx *ctx, const char *s, const char* file, int line, const char *func);
> +
> #ifdef USE_FAIL_MALLOC
> -int fail_malloc_check(size_t size, const char *file, int line, const char *func);
> -void *sen_fail_malloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> -void *sen_fail_calloc(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> -void *sen_fail_realloc(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
> -char *sen_fail_strdup(sen_ctx *ctx, const char *s, const char* file, int line, const char *func);
> -#endif /* USE_FAIL_MALLOC */
> -void *sen_malloc(sen_ctx *ctx, size_t size, const char* file, int line);
> -void *sen_calloc(sen_ctx *ctx, size_t size, const char* file, int line);
> -void *sen_realloc(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line);
> -char *sen_strdup(sen_ctx *ctx, const char *s, const char* file, int line);
> +void *sen_malloc_fail(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> +void *sen_calloc_fail(sen_ctx *ctx, size_t size, const char* file, int line, const char *func);
> +void *sen_realloc_fail(sen_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
> +char *sen_strdup_fail(sen_ctx *ctx, const char *s, const char* file, int line, const char *func);
> +#endif
> +
> void sen_free(sen_ctx *ctx, void *ptr, const char* file, int line);
>
> void sen_assert(int cond, const char* file, int line, const char* func);
> @@ -327,6 +331,12 @@
> sen_io_mapinfo mi;
> sen_io_mapinfo *segs;
>
> + /* memory allocation portion */
> + sen_malloc_func malloc_func;
> + sen_calloc_func calloc_func;
> + sen_realloc_func realloc_func;
> + sen_strdup_func strdup_func;
> +
> /* ql portion */
> uint32_t ncells;
> uint32_t seqno;
---
tasuku