null+****@clear*****
null+****@clear*****
2011年 5月 25日 (水) 18:00:09 JST
Kouhei Sutou 2011-05-25 09:00:09 +0000 (Wed, 25 May 2011)
New Revision: 85483a99a4cee2c8cd361e0ba9076a94d4a37f1c
Log:
add grn_obj_is_builtin(). fixes #921
Modified files:
include/groonga.h
lib/db.c
test/unit/core/Makefile.am
Modified: include/groonga.h (+10 -0)
===================================================================
--- include/groonga.h 2011-05-25 07:30:55 +0000 (3a335da)
+++ include/groonga.h 2011-05-25 09:00:09 +0000 (ee17621)
@@ -1342,6 +1342,16 @@ GRN_API grn_obj *grn_obj_get_element_info(grn_ctx *ctx, grn_obj *obj, grn_id id,
GRN_API grn_rc grn_obj_set_element_info(grn_ctx *ctx, grn_obj *obj, grn_id id,
grn_info_type type, grn_obj *value);
+/**
+ * c:function:: grn_bool grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj)
+ *
+ * Check whether groonga built-in object.
+ *
+ * :param ctx: context
+ * :param obj: target object
+ * :retype: ``GRN_TRUE`` for built-in groonga object, ``GRN_FALSE`` otherwise.
+ **/
+GRN_API grn_bool grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj);
/**
* grn_obj_get_value:
Modified: lib/db.c (+15 -0)
===================================================================
--- lib/db.c 2011-05-25 07:30:55 +0000 (d01b97d)
+++ lib/db.c 2011-05-25 09:00:09 +0000 (c461fa2)
@@ -5381,6 +5381,21 @@ grn_obj_set_element_info(grn_ctx *ctx, grn_obj *obj, grn_id id,
GRN_API_RETURN(GRN_SUCCESS);
}
+grn_bool
+grn_obj_is_builtin(grn_ctx *ctx, grn_obj *obj)
+{
+ grn_id id;
+
+ if (!obj) { return GRN_FALSE; }
+
+ id = grn_obj_id(ctx, obj);
+ if (id == GRN_ID_NIL) {
+ return GRN_FALSE;
+ } else {
+ return id < GRN_N_RESERVED_TYPES;
+ }
+}
+
static void
grn_hook_free(grn_ctx *ctx, grn_hook *h)
{
Modified: test/unit/core/Makefile.am (+3 -1)
===================================================================
--- test/unit/core/Makefile.am 2011-05-25 07:30:55 +0000 (078841f)
+++ test/unit/core/Makefile.am 2011-05-25 09:00:09 +0000 (58b98d6)
@@ -54,7 +54,8 @@ noinst_LTLIBRARIES = \
test-command-dump.la \
test-command-truncate.la \
test-geo.la \
- test-accessor.la
+ test-accessor.la \
+ test-object.la
endif
INCLUDES = \
@@ -133,3 +134,4 @@ test_command_dump_la_SOURCES = test-command-dump.c
test_command_truncate_la_SOURCES = test-command-truncate.c
test_geo_la_SOURCES = test-geo.c
test_accessor_la_SOURCES = test-accessor.c
+test_object_la_SOURCES = test-object.c