null+****@clear*****
null+****@clear*****
2012年 4月 9日 (月) 17:11:17 JST
Kouhei Sutou 2012-04-09 17:11:17 +0900 (Mon, 09 Apr 2012) New Revision: a33622631bc4d1aa6c2e6e46bc89fb1e89123e30 Log: Use bool for boolean value Modified files: ha_mroonga.cc mrn_sys.cpp mrn_sys.hpp Modified: ha_mroonga.cc (+3 -3) =================================================================== --- ha_mroonga.cc 2012-04-09 17:08:37 +0900 (f6124c3) +++ ha_mroonga.cc 2012-04-09 17:11:17 +0900 (86f5e53) @@ -926,7 +926,7 @@ static void mrn_drop_db(const char *path) mrn::PathMapper mapper(path); pthread_mutex_lock(&mrn_db_mutex); grn_obj *db = NULL; - if (mrn_hash_get(&mrn_ctx, mrn_hash, mapper.db_name(), &db) != 0) { + if (!mrn_hash_get(&mrn_ctx, mrn_hash, mapper.db_name(), &db)) { struct stat dummy; if (stat(mapper.db_path(), &dummy) == 0) { db = grn_db_open(&mrn_ctx, mapper.db_path()); @@ -2884,7 +2884,7 @@ int ha_mroonga::ensure_database_create(const char *name) mrn::PathMapper mapper(name); pthread_mutex_lock(&mrn_db_mutex); - if (mrn_hash_get(&mrn_ctx, mrn_hash, mapper.db_name(), &db) != 0) { + if (!mrn_hash_get(&mrn_ctx, mrn_hash, mapper.db_name(), &db)) { if (stat(mapper.db_path(), &db_stat)) { // creating new database GRN_LOG(ctx, GRN_LOG_INFO, @@ -2927,7 +2927,7 @@ int ha_mroonga::ensure_database_open(const char *name) mrn::PathMapper mapper(name); pthread_mutex_lock(&mrn_db_mutex); - if (mrn_hash_get(&mrn_ctx, mrn_hash, mapper.db_name(), &db) != 0) { + if (!mrn_hash_get(&mrn_ctx, mrn_hash, mapper.db_name(), &db)) { db = grn_db_open(&mrn_ctx, mapper.db_path()); if (ctx->rc) { pthread_mutex_unlock(&mrn_db_mutex); Modified: mrn_sys.cpp (+17 -13) =================================================================== --- mrn_sys.cpp 2012-04-09 17:08:37 +0900 (2bffc67) +++ mrn_sys.cpp 2012-04-09 17:11:17 +0900 (fed650d) @@ -28,59 +28,63 @@ #include <string.h> #include "mrn_sys.hpp" -int mrn_hash_put(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj *value) +bool mrn_hash_put(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj *value) { - int added, res=0; + int added; + bool succeed; void *buf; grn_hash_add(ctx, hash, (const char *)key, strlen(key), &buf, &added); // duplicate check if (added == 0) { GRN_LOG(ctx, GRN_LOG_WARNING, "hash put duplicated (key=%s)", key); - res = -1; + succeed = false; } else { // store address of value memcpy(buf, &value, sizeof(grn_obj *)); GRN_LOG(ctx, GRN_LOG_DEBUG, "hash put (key=%s)", key); + succeed = true; } - return res; + return succeed; } -int mrn_hash_get(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj **value) +bool mrn_hash_get(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj **value) { - int res = 0; + bool found; grn_id id; void *buf; id = grn_hash_get(ctx, hash, (const char *)key, strlen(key), &buf); // key not found if (id == GRN_ID_NIL) { GRN_LOG(ctx, GRN_LOG_DEBUG, "hash get not found (key=%s)", key); - res = -1; + found = false; } else { // restore address of value memcpy(value, buf, sizeof(grn_obj *)); + found = true; } - return res; + return found; } -int mrn_hash_remove(grn_ctx *ctx, grn_hash *hash, const char *key) +bool mrn_hash_remove(grn_ctx *ctx, grn_hash *hash, const char *key) { - int res = 0; + bool succeed; grn_rc rc; grn_id id; id = grn_hash_get(ctx, hash, (const char*) key, strlen(key), NULL); if (id == GRN_ID_NIL) { GRN_LOG(ctx, GRN_LOG_WARNING, "hash remove not found (key=%s)", key); - res = -1; + succeed = false; } else { rc = grn_hash_delete_by_id(ctx, hash, id, NULL); if (rc != GRN_SUCCESS) { GRN_LOG(ctx, GRN_LOG_ERROR, "hash remove error (key=%s)", key); - res = -1; + succeed = false; } else { GRN_LOG(ctx, GRN_LOG_DEBUG, "hash remove (key=%s)", key); + succeed = true; } } - return res; + return succeed; } /** Modified: mrn_sys.hpp (+3 -3) =================================================================== --- mrn_sys.hpp 2012-04-09 17:08:37 +0900 (08b8cab) +++ mrn_sys.hpp 2012-04-09 17:11:17 +0900 (bc19f8d) @@ -48,9 +48,9 @@ MRN_BEGIN_DECLS #endif /* functions */ -int mrn_hash_put(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj *value); -int mrn_hash_get(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj **value); -int mrn_hash_remove(grn_ctx *ctx, grn_hash *hash, const char *key); +bool mrn_hash_put(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj *value); +bool mrn_hash_get(grn_ctx *ctx, grn_hash *hash, const char *key, grn_obj **value); +bool mrn_hash_remove(grn_ctx *ctx, grn_hash *hash, const char *key); char *mrn_index_table_name_gen(const char *arg, const char *idx_name, char *dest);