Navigation Menu

Skip to content

Commit

Permalink
Support owning other grn_obj by PTR/PVECTOR
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Sep 4, 2015
1 parent f5eee16 commit 599af4a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/groonga/groonga.h
Expand Up @@ -406,6 +406,7 @@ struct _grn_obj {

#define GRN_OBJ_REFER (0x01<<0)
#define GRN_OBJ_OUTPLACE (0x01<<1)
#define GRN_OBJ_OWN (0x01<<5)

#define GRN_OBJ_INIT(obj,obj_type,obj_flags,obj_domain) do { \
(obj)->header.type = (obj_type);\
Expand Down
25 changes: 23 additions & 2 deletions lib/db.c
Expand Up @@ -9379,14 +9379,35 @@ grn_obj_close(grn_ctx *ctx, grn_obj *obj)
break;
case GRN_VOID :
case GRN_BULK :
case GRN_PTR :
case GRN_UVECTOR :
case GRN_PVECTOR :
case GRN_MSG :
obj->header.type = GRN_VOID;
rc = grn_bulk_fin(ctx, obj);
if (obj->header.impl_flags & GRN_OBJ_ALLOCATED) { GRN_FREE(obj); }
break;
case GRN_PTR :
if (obj->header.impl_flags & GRN_OBJ_OWN) {
if (GRN_BULK_VSIZE(obj) == sizeof(grn_obj *)) {
grn_obj_close(ctx, GRN_PTR_VALUE(obj));
}
}
obj->header.type = GRN_VOID;
rc = grn_bulk_fin(ctx, obj);
if (obj->header.impl_flags & GRN_OBJ_ALLOCATED) { GRN_FREE(obj); }
break;
case GRN_PVECTOR :
if (obj->header.impl_flags & GRN_OBJ_OWN) {
unsigned int i, n_elements;
n_elements = GRN_BULK_VSIZE(obj) / sizeof(grn_obj *);
for (i = 0; i < n_elements; i++) {
grn_obj *element = GRN_PTR_VALUE_AT(obj, i);
grn_obj_close(ctx, element);
}
}
obj->header.type = GRN_VOID;
rc = grn_bulk_fin(ctx, obj);
if (obj->header.impl_flags & GRN_OBJ_ALLOCATED) { GRN_FREE(obj); }
break;
case GRN_ACCESSOR :
{
grn_accessor *p, *n;
Expand Down

0 comments on commit 599af4a

Please sign in to comment.