Exemplo n.º 1
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.º 2
0
grn_id
grn_plugin_reference(grn_ctx *ctx, const char *filename)
{
    grn_id id;
    grn_plugin **plugin = NULL;

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

    return id;
}
Exemplo n.º 3
0
grn_id
grn_plugin_get(grn_ctx *ctx, const char *filename)
{
  return grn_hash_get(ctx, grn_plugins, filename, PATHLEN(filename), NULL);
}