[Groonga-commit] groonga/groonga at ff27eef [master] Add missing custom free() function support

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Apr 16 14:01:24 JST 2015


Kouhei Sutou	2015-04-16 14:01:24 +0900 (Thu, 16 Apr 2015)

  New Revision: ff27eef9770aa576af17ccb6cf46da0c531b37eb
  https://github.com/groonga/groonga/commit/ff27eef9770aa576af17ccb6cf46da0c531b37eb

  Message:
    Add missing custom free() function support

  Modified files:
    lib/ctx.c
    lib/grn_ctx.h
    lib/grn_ctx_impl.h

  Modified: lib/ctx.c (+24 -0)
===================================================================
--- lib/ctx.c    2015-04-16 11:06:07 +0900 (047b062)
+++ lib/ctx.c    2015-04-16 14:01:24 +0900 (1b48bda)
@@ -2275,6 +2275,20 @@ grn_ctx_set_strdup(grn_ctx *ctx, grn_strdup_func strdup_func)
   ctx->impl->strdup_func = strdup_func;
 }
 
+grn_free_func
+grn_ctx_get_free(grn_ctx *ctx)
+{
+  if (!ctx || !ctx->impl) { return NULL; }
+  return ctx->impl->free_func;
+}
+
+void
+grn_ctx_set_free(grn_ctx *ctx, grn_free_func free_func)
+{
+  if (!ctx || !ctx->impl) { return; }
+  ctx->impl->free_func = free_func;
+}
+
 void *
 grn_malloc(grn_ctx *ctx, size_t size, const char* file, int line, const char *func)
 {
@@ -2314,6 +2328,16 @@ grn_strdup(grn_ctx *ctx, const char *string, const char* file, int line, const c
     return grn_strdup_default(ctx, string, file, line, func);
   }
 }
+
+void
+grn_free(grn_ctx *ctx, void *ptr, const char* file, int line, const char *func)
+{
+  if (ctx && ctx->impl && ctx->impl->free_func) {
+    return ctx->impl->free_func(ctx, ptr, file, line, func);
+  } else {
+    return grn_free_default(ctx, ptr, file, line, func);
+  }
+}
 #endif
 
 void *

  Modified: lib/grn_ctx.h (+5 -0)
===================================================================
--- lib/grn_ctx.h    2015-04-16 11:06:07 +0900 (fdcb028)
+++ lib/grn_ctx.h    2015-04-16 14:01:24 +0900 (6230048)
@@ -504,6 +504,8 @@ typedef void *(*grn_realloc_func) (grn_ctx *ctx, void *ptr, size_t size,
                                    const char *file, int line, const char *func);
 typedef char *(*grn_strdup_func) (grn_ctx *ctx, const char *string,
                                   const char *file, int line, const char *func);
+typedef void (*grn_free_func) (grn_ctx *ctx, void *ptr,
+                               const char *file, int line, const char *func);
 grn_malloc_func grn_ctx_get_malloc(grn_ctx *ctx);
 void grn_ctx_set_malloc(grn_ctx *ctx, grn_malloc_func malloc_func);
 grn_calloc_func grn_ctx_get_calloc(grn_ctx *ctx);
@@ -512,11 +514,14 @@ grn_realloc_func grn_ctx_get_realloc(grn_ctx *ctx);
 void grn_ctx_set_realloc(grn_ctx *ctx, grn_realloc_func realloc_func);
 grn_strdup_func grn_ctx_get_strdup(grn_ctx *ctx);
 void grn_ctx_set_strdup(grn_ctx *ctx, grn_strdup_func strdup_func);
+grn_free_func grn_ctx_get_free(grn_ctx *ctx);
+void grn_ctx_set_free(grn_ctx *ctx, grn_free_func free_func);
 
 void *grn_malloc(grn_ctx *ctx, size_t size, const char* file, int line, const char *func);
 void *grn_calloc(grn_ctx *ctx, size_t size, const char* file, int line, const char *func);
 void *grn_realloc(grn_ctx *ctx, void *ptr, size_t size, const char* file, int line, const char *func);
 char *grn_strdup(grn_ctx *ctx, const char *s, const char* file, int line, const char *func);
+void grn_free(grn_ctx *ctx, void *ptr, const char *file, int line, const char *func);
 #else
 #  define grn_malloc  grn_malloc_default
 #  define grn_calloc  grn_calloc_default

  Modified: lib/grn_ctx_impl.h (+1 -0)
===================================================================
--- lib/grn_ctx_impl.h    2015-04-16 11:06:07 +0900 (7b24018)
+++ lib/grn_ctx_impl.h    2015-04-16 14:01:24 +0900 (b653f35)
@@ -130,6 +130,7 @@ struct _grn_ctx_impl {
   grn_calloc_func calloc_func;
   grn_realloc_func realloc_func;
   grn_strdup_func strdup_func;
+  grn_free_func free_func;
 #endif
 
 #ifdef USE_MEMORY_DEBUG
-------------- next part --------------
HTML����������������������������...
Descargar 



More information about the Groonga-commit mailing list
Back to archive index