Kouhei Sutou
null+****@clear*****
Tue Jan 12 12:00:25 JST 2016
Kouhei Sutou 2016-01-12 12:00:25 +0900 (Tue, 12 Jan 2016) New Revision: c30235f4b6255ed887268662ae1a10ccb23e8b1c https://github.com/groonga/groonga/commit/c30235f4b6255ed887268662ae1a10ccb23e8b1c Message: Extract type related code Added files: lib/type.c Modified files: include/groonga.h lib/db.c lib/sources.am Modified: include/groonga.h (+2 -0) =================================================================== --- include/groonga.h 2016-01-12 11:43:07 +0900 (74b0c38) +++ include/groonga.h 2016-01-12 12:00:25 +0900 (db286ca) @@ -20,6 +20,7 @@ #include "groonga/portability.h" #include "groonga/groonga.h" + #include "groonga/conf.h" #include "groonga/obj.h" #include "groonga/ii.h" @@ -29,6 +30,7 @@ #include "groonga/util.h" #include "groonga/request_canceler.h" #include "groonga/thread.h" +#include "groonga/type.h" #include "groonga/windows.h" #include "groonga/windows_event_logger.h" #include "groonga/file_reader.h" Modified: lib/db.c (+0 -35) =================================================================== --- lib/db.c 2016-01-12 11:43:07 +0900 (7b55422) +++ lib/db.c 2016-01-12 12:00:25 +0900 (5937a2c) @@ -643,41 +643,6 @@ grn_db_check_name(grn_ctx *ctx, const char *name, unsigned int name_size) return GRN_SUCCESS; } -grn_obj * -grn_type_create(grn_ctx *ctx, const char *name, unsigned int name_size, - grn_obj_flags flags, unsigned int size) -{ - grn_id id; - struct _grn_type *res = NULL; - grn_obj *db; - if (!ctx || !ctx->impl || !(db = ctx->impl->db)) { - ERR(GRN_INVALID_ARGUMENT, "db not initialized"); - return NULL; - } - GRN_API_ENTER; - if (grn_db_check_name(ctx, name, name_size)) { - GRN_DB_CHECK_NAME_ERR("[type][create]", name, name_size); - GRN_API_RETURN(NULL); - } - if (!GRN_DB_P(db)) { - ERR(GRN_INVALID_ARGUMENT, "invalid db assigned"); - GRN_API_RETURN(NULL); - } - id = grn_obj_register(ctx, db, name, name_size); - if (id && (res = GRN_MALLOC(sizeof(grn_db_obj)))) { - GRN_DB_OBJ_SET_TYPE(res, GRN_TYPE); - res->obj.header.flags = flags; - res->obj.header.domain = GRN_ID_NIL; - GRN_TYPE_SIZE(&res->obj) = size; - if (grn_db_obj_init(ctx, db, id, DB_OBJ(res))) { - // grn_obj_delete(ctx, db, id); - GRN_FREE(res); - GRN_API_RETURN(NULL); - } - } - GRN_API_RETURN((grn_obj *)res); -} - static grn_obj * grn_type_open(grn_ctx *ctx, grn_obj_spec *spec) { Modified: lib/sources.am (+1 -0) =================================================================== --- lib/sources.am 2016-01-12 11:43:07 +0900 (617210c) +++ lib/sources.am 2016-01-12 12:00:25 +0900 (3e91219) @@ -14,6 +14,7 @@ libgroonga_la_SOURCES = \ grn_db.h \ ts.c \ grn_ts.h \ + type.c \ error.c \ grn_error.h \ expr.c \ Added: lib/type.c (+56 -0) 100644 =================================================================== --- /dev/null +++ lib/type.c 2016-01-12 12:00:25 +0900 (01ca0ce) @@ -0,0 +1,56 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2009-2016 Brazil + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License version 2.1 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "grn_ctx_impl.h" +#include "grn_db.h" + +grn_obj * +grn_type_create(grn_ctx *ctx, const char *name, unsigned int name_size, + grn_obj_flags flags, unsigned int size) +{ + grn_id id; + struct _grn_type *res = NULL; + grn_obj *db; + if (!ctx || !ctx->impl || !(db = ctx->impl->db)) { + ERR(GRN_INVALID_ARGUMENT, "db not initialized"); + return NULL; + } + GRN_API_ENTER; + if (grn_db_check_name(ctx, name, name_size)) { + GRN_DB_CHECK_NAME_ERR("[type][create]", name, name_size); + GRN_API_RETURN(NULL); + } + if (!GRN_DB_P(db)) { + ERR(GRN_INVALID_ARGUMENT, "invalid db assigned"); + GRN_API_RETURN(NULL); + } + id = grn_obj_register(ctx, db, name, name_size); + if (id && (res = GRN_MALLOC(sizeof(grn_db_obj)))) { + GRN_DB_OBJ_SET_TYPE(res, GRN_TYPE); + res->obj.header.flags = flags; + res->obj.header.domain = GRN_ID_NIL; + GRN_TYPE_SIZE(&res->obj) = size; + if (grn_db_obj_init(ctx, db, id, DB_OBJ(res))) { + // grn_obj_delete(ctx, db, id); + GRN_FREE(res); + GRN_API_RETURN(NULL); + } + } + GRN_API_RETURN((grn_obj *)res); +} + -------------- next part -------------- HTML����������������������������...Download