Exemplo n.º 1
0
grn_rc
grn_plugin_close(grn_ctx *ctx, grn_id id)
{
  grn_rc rc;
  grn_plugin *plugin;

  if (id == GRN_ID_NIL) {
    return GRN_INVALID_ARGUMENT;
  }

  CRITICAL_SECTION_ENTER(grn_plugins_lock);
  if (!grn_hash_get_value(&grn_gctx, grn_plugins, id, &plugin)) {
    rc = GRN_INVALID_ARGUMENT;
    goto exit;
  }
  if (--plugin->refcount) {
    rc = GRN_SUCCESS;
    goto exit;
  }
  if (plugin->dl) {
    grn_plugin_call_fin(ctx, id);
    if (!grn_dl_close(plugin->dl)) {
      const char *label;
      label = grn_dl_close_error_label();
      SERR("%s", label);
    }
  }
  GRN_GFREE(plugin);
  rc = grn_hash_delete_by_id(&grn_gctx, grn_plugins, id, NULL);

exit:
  CRITICAL_SECTION_LEAVE(grn_plugins_lock);

  return rc;
}
Exemplo n.º 2
0
grn_id
grn_plugin_open(grn_ctx *ctx, const char *filename)
{
    grn_id id;
    grn_dl dl;
    grn_plugin **plugin = NULL;

    CRITICAL_SECTION_ENTER(grn_plugins_lock);
    if ((id = grn_hash_get(&grn_gctx, grn_plugins, filename, PATHLEN(filename),
                           (void **)&plugin))) {
        (*plugin)->refcount++;
        goto exit;
    }

    if ((dl = grn_dl_open(filename))) {
        if ((id = grn_hash_add(&grn_gctx, grn_plugins, filename, PATHLEN(filename),
                               (void **)&plugin, NULL))) {
            *plugin = GRN_GMALLOCN(grn_plugin, 1);
            if (*plugin) {
                if (grn_plugin_initialize(ctx, *plugin, dl, id, filename)) {
                    GRN_GFREE(*plugin);
                    *plugin = NULL;
                }
            }
            if (!*plugin) {
                grn_hash_delete_by_id(&grn_gctx, grn_plugins, id, NULL);
                if (grn_dl_close(dl)) {
                    /* Now, __FILE__ set in plugin is invalid. */
                    ctx->errline = 0;
                    ctx->errfile = NULL;
                } else {
                    const char *label;
                    label = grn_dl_close_error_label();
                    SERR(label);
                }
                id = GRN_ID_NIL;
            } else {
                (*plugin)->refcount = 1;
            }
        } else {
            if (!grn_dl_close(dl)) {
                const char *label;
                label = grn_dl_close_error_label();
                SERR(label);
            }
        }
    } else {
        const char *label;
        label = grn_dl_open_error_label();
        SERR(label);
    }

exit:
    CRITICAL_SECTION_LEAVE(grn_plugins_lock);

    return id;
}
Exemplo n.º 3
0
Arquivo: store.c Projeto: ueno/groonga
grn_rc
grn_ja_close(grn_ctx *ctx, grn_ja *ja)
{
  grn_rc rc;
  if (!ja) { return GRN_INVALID_ARGUMENT; }
  rc = grn_io_close(ctx, ja->io);
  GRN_GFREE(ja);
  return rc;
}
Exemplo n.º 4
0
Arquivo: store.c Projeto: ueno/groonga
grn_rc
grn_ra_close(grn_ctx *ctx, grn_ra *ra)
{
  grn_rc rc;
  if (!ra) { return GRN_INVALID_ARGUMENT; }
  rc = grn_io_close(ctx, ra->io);
  GRN_GFREE(ra);
  return rc;
}
Exemplo n.º 5
0
grn_ctx *
grn_ctx_open(int flags)
{
  grn_ctx *ctx = GRN_GMALLOCN(grn_ctx, 1);
  if (ctx) {
    grn_ctx_init(ctx, flags|GRN_CTX_ALLOCATED);
    if (ERRP(ctx, GRN_ERROR)) {
      GRN_GFREE(ctx);
      ctx = NULL;
    }
  }
  return ctx;
}
Exemplo n.º 6
0
grn_rc
grn_plugin_close(grn_ctx *ctx, grn_id id)
{
  grn_plugin *plugin;

  if (!grn_hash_get_value(ctx, grn_plugins, id, &plugin)) {
    return GRN_INVALID_ARGUMENT;
  }
  if (--plugin->refcount) { return GRN_SUCCESS; }
  grn_plugin_call_fin(ctx, id);
  if (!grn_dl_close(plugin->dl)) {
    const char *label;
    label = grn_dl_close_error_label;
    SERR(label);
  }
  GRN_GFREE(plugin);
  return grn_hash_delete_by_id(ctx, grn_plugins, id, NULL);
}
Exemplo n.º 7
0
grn_id
grn_plugin_open(grn_ctx *ctx, const char *filename)
{
  grn_id id = GRN_ID_NIL;
  grn_dl dl;
  grn_plugin **plugin = NULL;
  size_t filename_size;

  filename_size = GRN_PLUGIN_KEY_SIZE(filename);

  CRITICAL_SECTION_ENTER(grn_plugins_lock);
  if ((id = grn_hash_get(&grn_gctx, grn_plugins, filename, filename_size,
                         (void **)&plugin))) {
    (*plugin)->refcount++;
    goto exit;
  }

#ifdef GRN_WITH_MRUBY
  {
    const char *mrb_suffix;
    mrb_suffix = grn_plugin_get_ruby_suffix();
    if (filename_size > strlen(mrb_suffix) &&
      strcmp(filename + (strlen(filename) - strlen(mrb_suffix)),
             mrb_suffix) == 0) {
      id = grn_plugin_open_mrb(ctx, filename, filename_size);
      goto exit;
    }
  }
#endif /* GRN_WITH_MRUBY */

  if ((dl = grn_dl_open(filename))) {
    if ((id = grn_hash_add(&grn_gctx, grn_plugins, filename, filename_size,
                           (void **)&plugin, NULL))) {
      *plugin = GRN_GMALLOCN(grn_plugin, 1);
      if (*plugin) {
        grn_memcpy((*plugin)->path, filename, filename_size);
        if (grn_plugin_initialize(ctx, *plugin, dl, id, filename)) {
          GRN_GFREE(*plugin);
          *plugin = NULL;
        }
      }
      if (!*plugin) {
        grn_hash_delete_by_id(&grn_gctx, grn_plugins, id, NULL);
        if (grn_dl_close(dl)) {
          /* Now, __FILE__ set in plugin is invalid. */
          ctx->errline = 0;
          ctx->errfile = NULL;
        } else {
          const char *label;
          label = grn_dl_close_error_label();
          SERR("%s", label);
        }
        id = GRN_ID_NIL;
      } else {
        (*plugin)->refcount = 1;
      }
    } else {
      if (!grn_dl_close(dl)) {
        const char *label;
        label = grn_dl_close_error_label();
        SERR("%s", label);
      }
    }
  } else {
    const char *label;
    label = grn_dl_open_error_label();
    SERR("%s", label);
  }

exit:
  CRITICAL_SECTION_LEAVE(grn_plugins_lock);

  return id;
}