Exemplo n.º 1
0
static grn_id
grn_plugin_open_mrb(grn_ctx *ctx, const char *filename, size_t filename_size)
{
  grn_id id = GRN_ID_NIL;
  grn_plugin **plugin = NULL;

  if (!ctx->impl->mrb.state) {
    ERR(GRN_FUNCTION_NOT_IMPLEMENTED, "mruby support isn't enabled");
    return GRN_ID_NIL;
  }

  id = grn_hash_add(&grn_gctx, grn_plugins, filename, filename_size,
                    (void **)&plugin, NULL);
  if (!id) {
    return id;
  }

  *plugin = GRN_GMALLOCN(grn_plugin, 1);
  if (!*plugin) {
    grn_hash_delete_by_id(&grn_gctx, grn_plugins, id, NULL);
    return GRN_ID_NIL;
  }

  grn_memcpy((*plugin)->path, filename, filename_size);
  (*plugin)->dl = NULL;
  (*plugin)->init_func = NULL;
  (*plugin)->register_func = NULL;
  (*plugin)->fin_func = NULL;
  (*plugin)->refcount = 1;

  return id;
}
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
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.º 4
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;
}