当前位置: 首页>>代码示例>>C++>>正文


C++ enif_release_resource函数代码示例

本文整理汇总了C++中enif_release_resource函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_release_resource函数的具体用法?C++ enif_release_resource怎么用?C++ enif_release_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了enif_release_resource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: do_prepare

static ERL_NIF_TERM
do_prepare(ErlNifEnv *env, esqlite_connection *conn, const ERL_NIF_TERM arg)
{
    ErlNifBinary bin;
    esqlite_statement *stmt;
    ERL_NIF_TERM esqlite_stmt;
    const char *tail;
    int rc;
    ERL_NIF_TERM eos = enif_make_int(env, 0);

    if(!enif_inspect_iolist_as_binary(env, enif_make_list2(env, arg, eos), &bin))
	    return make_error_tuple(env, "not an iolist");

    stmt = enif_alloc_resource(esqlite_statement_type, sizeof(esqlite_statement));
    if(!stmt)
	    return make_error_tuple(env, "no_memory");

    rc = sqlite3_prepare_v2(conn->db, (char *) bin.data, bin.size, &(stmt->statement), &tail);
    if(rc != SQLITE_OK) {
        enif_release_resource(stmt);
        return make_sqlite3_error_tuple(env, rc, conn->db);
    }

    esqlite_stmt = enif_make_resource(env, stmt);
    enif_release_resource(stmt);

    return make_ok_tuple(env, esqlite_stmt);
}
开发者ID:mmzeeman,项目名称:esqlite,代码行数:28,代码来源:esqlite3_nif.c

示例2: get_collator

/* Get a collator */
ERL_NIF_TERM get_collator(ErlNifEnv* env, int argc, 
    const ERL_NIF_TERM argv[])
{
    ERL_NIF_TERM out;
    char locale[LOCALE_LEN];
    UErrorCode status = U_ZERO_ERROR;
    UCollator* col;
    cloner* res;
    unsigned int index;


    if ((argc != 2) && (argc != 1))
        return enif_make_badarg(env);

    if (!enif_get_atom(env, argv[0], (char*) locale, 
            LOCALE_LEN, ERL_NIF_LATIN1)) {
        return enif_make_badarg(env);
    }

    col = ucol_open((char *) locale, &status);
    CHECK(env, status);



    res = (cloner*) enif_alloc_resource(collator_type, sizeof(cloner));

    if (collator_open(col, res)) {
        enif_release_resource(res);
        return enif_make_badarg(env);
    }
    CHECK_DEST(env, status,
        enif_release_resource(res);
    );
开发者ID:djui,项目名称:i18n,代码行数:34,代码来源:i18n_collation.cpp

示例3: exmagick_init_handle

static
ERL_NIF_TERM exmagick_init_handle (ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
  ERL_NIF_TERM result;

  EXM_INIT;
  ErlNifResourceType *type = (ErlNifResourceType *) enif_priv_data(env);
  exm_resource_t *resource = enif_alloc_resource(type, sizeof(exm_resource_t));
  if (resource == NULL)
  { EXM_FAIL(ehandler, "enif_alloc_resource"); }

  /* initializes exception to default values (badly named function) */
  GetExceptionInfo(&resource->e_info);

  resource->image  = NULL;
  resource->i_info = CloneImageInfo(0);
  if (resource->i_info == NULL)
  { EXM_FAIL(ehandler, "CloneImageInfo"); }

  result = enif_make_resource(env, (void *) resource);
  enif_release_resource(resource);
  return(enif_make_tuple2(env, enif_make_atom(env, "ok"), result));

ehandler:
  if (resource != NULL)
  {
    if (resource->i_info != NULL)
    { DestroyImageInfo(resource->i_info); }
    enif_release_resource(resource);
  }
  return(enif_make_tuple2(env, enif_make_atom(env, "error"), exmagick_make_utf8str(env, errmsg)));
}
开发者ID:Xerpa,项目名称:exmagick,代码行数:32,代码来源:exmagick.c

示例4: esqlite_start

/* 
 * Start the processing thread
 */
static ERL_NIF_TERM 
esqlite_start(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    esqlite_connection *conn;
    ERL_NIF_TERM db_conn;

    /* Initialize the resource */
    conn = enif_alloc_resource(esqlite_connection_type, sizeof(esqlite_connection));
    if(!conn) 
	    return make_error_tuple(env, "no_memory");
	  
    conn->db = NULL;

    /* Create command queue */
    conn->commands = queue_create();
    if(!conn->commands) {
	    enif_release_resource(conn);
	    return make_error_tuple(env, "command_queue_create_failed");
    }

    /* Start command processing thread */
    conn->opts = enif_thread_opts_create("esqldb_thread_opts");
    if(enif_thread_create("esqlite_connection", &conn->tid, esqlite_connection_run, conn, conn->opts) != 0) {
	    enif_release_resource(conn);
	    return make_error_tuple(env, "thread_create_failed");
    }

    db_conn = enif_make_resource(env, conn);
    enif_release_resource(conn);
  
    return make_ok_tuple(env, db_conn);
}
开发者ID:alepharchives,项目名称:esqlite,代码行数:35,代码来源:esqlite3_nif.c

示例5: open_calendar

ERL_NIF_TERM open_calendar(ErlNifEnv* env, int argc, 
    const ERL_NIF_TERM argv[])
{
    ERL_NIF_TERM out;
    ErlNifBinary tz;

    cloner* res;
    UCalendar* cal;
    UCalendarType type = UCAL_DEFAULT;
    UErrorCode status = U_ZERO_ERROR;
    char type_atom[ATOM_LEN], locale[LOCALE_LEN];
    
    tz.size = 0; 
    tz.data = 0;

    switch (argc) {
        case 3:
            if (!enif_get_atom(env, argv[2], (char*) type_atom, ATOM_LEN,
                ERL_NIF_LATIN1))
                return enif_make_badarg(env);
            type = parserCalendarType((const char *) type_atom);
        case 2:
            if (!enif_inspect_binary(env, argv[1], &tz))
                return enif_make_badarg(env);
        case 1:
            if (!enif_get_atom(env, argv[0], (char*) locale, 
                    LOCALE_LEN, ERL_NIF_LATIN1))
                return enif_make_badarg(env);
        break;
        default:
            return enif_make_badarg(env);
    }


    /* get a calendar type */
    cal = ucal_open(
        (const UChar *) tz.data,
        (int32_t) tz.size,
        (const char *) locale,
        type,
        &status);
    CHECK(env, status);


    res = (cloner*) enif_alloc_resource(calendar_type, sizeof(cloner));
    if (calendar_open(cal, res)) {
        enif_release_resource(res);
        return enif_make_badarg(env);
    }
    out = enif_make_resource(env, res);
    enif_release_resource(res);
    /* resource now only owned by "Erlang" */
    return out;
}
开发者ID:djui,项目名称:i18n,代码行数:54,代码来源:i18n_date.cpp

示例6: start

static nif_term_t
start(nif_heap_t *hp, int argc, const nif_term_t argv[])
{
	struct salt_pcb 	*sc;
	nif_cond_t 		*cv;
	nif_lock_t 		*lk;
	nif_term_t 		pcb;

	if (argc != 0)
		return (BADARG);

	/* Create thread control block, pass ownership to Erlang. */
	assert(salt_pcb_type != NULL);
	sc = enif_alloc_resource(salt_pcb_type, sizeof(*sc));
	if (sc == NULL)
		goto fail_0;

	cv = enif_cond_create("lots_pcb_cv");
	if (cv == NULL)
		goto fail_1;

	lk = enif_mutex_create("lots_pcb_lock");
	if (lk == NULL)
		goto fail_2;

	sc->sc_vsn = SALT_VSN(1, 0, 0);
	sc->sc_lock = lk;
	sc->sc_cond = cv;
	sc->sc_req_first = NULL;
	sc->sc_req_lastp = &sc->sc_req_first;
	sc->sc_req_npend = 0;
	sc->sc_exit_flag = false;

	if (enif_thread_create("salt_thread", &sc->sc_thread, salt_worker_loop, sc, NULL) != 0)
		goto fail_3;

	pcb = enif_make_resource(hp, sc);
	enif_release_resource(sc);

	return (pcb);

	/* Failure handling. */
 fail_3:
	enif_mutex_destroy(lk);
 fail_2:
	enif_cond_destroy(cv);
 fail_1:
	enif_release_resource(sc);
 fail_0:
	return (BADARG);
}
开发者ID:AnsonSmith,项目名称:salt,代码行数:51,代码来源:salt_nif.c

示例7: ucrypto_ec_new_by_curve_nif

ERL_NIF_TERM ucrypto_ec_new_by_curve_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    int nid;
    struct ec_key_handle *handle;
    ERL_NIF_TERM ec_key;

    ERL_NIF_TERM curve = argv[0];

    if (ATOM_secp112r1 == curve)
        nid = NID_secp112r1;
    else if (ATOM_secp112r2 == curve)
        nid = NID_secp112r2;
    else if (ATOM_secp128r1 == curve)
        nid = NID_secp128r1;
    else if (ATOM_secp128r2 == curve)
        nid = NID_secp128r2;
    else if (ATOM_secp160k1 == curve)
        nid = NID_secp160k1;
    else if (ATOM_secp160r1 == curve)
        nid = NID_secp160r1;
    else if (ATOM_secp160r2 == curve)
        nid = NID_secp160r2;
    else if (ATOM_secp192k1 == curve)
        nid = NID_secp192k1;
    else if (ATOM_secp224k1 == curve)
        nid = NID_secp224k1;
    else if (ATOM_secp224r1 == curve)
        nid = NID_secp224r1;
    else if (ATOM_secp256k1 == curve)
        nid = NID_secp256k1;
    else if (ATOM_secp384r1 == curve)
        nid = NID_secp384r1;
    else if (ATOM_secp521r1 == curve)
        nid = NID_secp521r1;
    else
        return enif_make_tuple2(env, ATOM_ERROR, enif_make_tuple2(env, ATOM_UNKNOWN_CURVE, curve));

    handle = enif_alloc_resource(ec_key_resource, sizeof(struct ec_key_handle));
    handle->key = EC_KEY_new_by_curve_name(nid);

    if (! handle->key) {
        enif_release_resource(handle);
        return ATOM_ERROR;
    }

    ec_key = enif_make_resource(env, handle);
    enif_release_resource(handle);

    return ec_key;
}
开发者ID:ahf,项目名称:erlang-ucrypto,代码行数:50,代码来源:ucrypto_ec.c

示例8: _hi_open

ERL_NIF_TERM _hi_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    uint32_t iterator_type = 0;

    if (argc != 1 ||
        !enif_get_uint(env, argv[0], &iterator_type))
    {
        return enif_make_badarg(env);
    }

    if (iterator_type != HDR_ITER_REC &&
        iterator_type != HDR_ITER_LIN &&
        iterator_type != HDR_ITER_LOG &&
        iterator_type != HDR_ITER_PCT)
    {
        return make_error(env, "bad_iterator_type");
    }

    ErlNifResourceType* ctx_type = get_hi_ctx_type(env);
    hi_ctx_t* ctx = (hi_ctx_t*)enif_alloc_resource(ctx_type, sizeof(hi_ctx_t));

    ctx->type = iterator_type;
    ctx->opts = NULL;
    ctx->iter = NULL;

    ERL_NIF_TERM result = enif_make_resource(env, ctx);
    enif_release_resource(ctx);

    return enif_make_tuple2(env, ATOM_OK, result);
}
开发者ID:jlouis,项目名称:hdr_histogram_erl,代码行数:30,代码来源:hdr_histogram_nif.c

示例9: enc_new

static Encoder*
enc_new(ErlNifEnv* env)
{
    jiffy_st* st = (jiffy_st*) enif_priv_data(env);
    Encoder* e = enif_alloc_resource(st->res_enc, sizeof(Encoder));

    e->atoms = st;
    e->bytes_per_iter = DEFAULT_BYTES_PER_ITER;
    e->uescape = 0;
    e->pretty = 0;
    e->use_nil = 0;
    e->shiftcnt = 0;
    e->count = 0;

    e->iolen = 0;
    e->iosize = 0;
    e->curr = &(e->bin);
    if(!enif_alloc_binary(BIN_INC_SIZE, e->curr)) {
        e->curr = NULL;
        enif_release_resource(e);
        return NULL;
    }

    memset(e->curr->data, 0, e->curr->size);

    e->p = (char*) e->curr->data;
    e->u = (unsigned char*) e->curr->data;
    e->i = 0;

    return e;
}
开发者ID:nevar,项目名称:jiffy,代码行数:31,代码来源:encoder.c

示例10: new_parser

static ERL_NIF_TERM new_parser(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    XML_Parser parser;
    expat_parser *parser_data = (expat_parser *)enif_alloc(sizeof(expat_parser));
    ERL_NIF_TERM parser_resource;

    // this is the variant from esl/exml:208d5e17e547b303b310627e3e525b57b2843e83
    /*parser = XML_ParserCreate_MM("UTF-8", &ms, "\n");*/

    // this makes the tests pass, but according to expat documentation it turns namespace support off
    /*parser = XML_ParserCreate_MM("UTF-8", &ms, NULL);*/

    // this is a try to preserve namespace support but make the tests pass;
    // this is the character defined as a macro in xmlwf sources for namespace-enabled parser
    /*XML_Char namespaceSeparator = '\001';*/
    /*parser = XML_ParserCreate_MM("UTF-8", &ms, &namespaceSeparator);*/
    parser = XML_ParserCreate_MM("UTF-8", &ms, ":");

    parser_data->env = env;
    parser_data->xmlns = (ERL_NIF_TERM)NULL;

    init_parser(parser, parser_data);

    XML_Parser *xml_parser = (XML_Parser *)enif_alloc_resource(PARSER_POINTER, sizeof(XML_Parser));
    *xml_parser = parser;
    parser_resource = enif_make_resource(env, (void *)xml_parser);
    enif_release_resource(xml_parser);

    return enif_make_tuple(env, 2, OK, parser_resource);
};
开发者ID:erszcz,项目名称:exml,代码行数:30,代码来源:exml_event.c

示例11: _hh_from_binary

ERL_NIF_TERM _hh_from_binary(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary source;

    if (!enif_inspect_binary(env, argv[0], &source))
    {
      return enif_make_badarg(env);
    }

    hdr_histogram_t* target = NULL;
    int success = hdr_decode(source.data, source.size, &target);

    if (success != 0)
    {
        return make_error(env, "bad_hdr_binary");
    }

    ErlNifResourceType* ctx_type = get_hh_ctx_type(env);
    hh_ctx_t* ctx = (hh_ctx_t*)enif_alloc_resource(ctx_type, sizeof(hh_ctx_t));

    ctx->data = (hdr_histogram_t*)target;
    ctx->highest_trackable_value = target->highest_trackable_value;
    ctx->significant_figures = target->significant_figures;

    ERL_NIF_TERM result = enif_make_resource(env, ctx);
    enif_release_resource(ctx);

    return enif_make_tuple2(env, ATOM_OK, result);
}
开发者ID:jlouis,项目名称:hdr_histogram_erl,代码行数:29,代码来源:hdr_histogram_nif.c

示例12: open_nif

static ERL_NIF_TERM
open_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	ks_returner_t	*ret;
	ks_handle_t	*handle;
	ERL_NIF_TERM	term;

	ret = new_returner(env);

	handle = (ks_handle_t *)(enif_alloc_resource(kstat_handle, sizeof(ks_handle_t)));
	handle->ks_id = -1;
	list_create(&handle->instances_list, sizeof (ks_instance_t), offsetof(ks_instance_t, ks_next));
	term = enif_make_resource(env, handle);
	enif_release_resource(handle);

	while ((handle->ks_ctl = kstat_open()) == NULL) {
		if (errno == EAGAIN) {
			(void) poll(NULL, 0, 200);
		} else {
			return EKSTAT_RETURN(EKSTAT_ERROR("kstat_open failed"));
		}
	}

	return EKSTAT_RETURN(EKSTAT_OK(term));
}
开发者ID:potatosalad,项目名称:ekstat,代码行数:25,代码来源:ekstat.c

示例13: init_ctx

ctx_t*
init_ctx()
{
    int status;

    ctx_t *ctx = static_cast<ctx_t*>(enif_alloc_resource(res_type, sizeof(*ctx)));

    if (ctx == NULL) {
        goto done;
    }

    ctx->queue = async_queue_create();
    ctx->topts = enif_thread_opts_create(const_cast<char*>("snappy_thread_opts"));

    status = enif_thread_create(const_cast<char*>("worker"), 
        &ctx->tid, worker, ctx, ctx->topts);

    if (status != 0) {
        enif_release_resource(ctx);
        ctx = NULL;
        goto done;
    }

done:
    return ctx;
}
开发者ID:fdmanana,项目名称:esnappy,代码行数:26,代码来源:esnappy_nif.cpp

示例14: open_nif

static ERL_NIF_TERM open_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
    posix_errno_t posix_errno;
    efile_data_t *d;

    ErlNifPid controlling_process;
    enum efile_modes_t modes;
    ERL_NIF_TERM result;
    efile_path_t path;

    if(argc != 2 || !enif_is_list(env, argv[1])) {
        return enif_make_badarg(env);
    }

    modes = efile_translate_modelist(env, argv[1]);

    if((posix_errno = efile_marshal_path(env, argv[0], &path))) {
        return posix_error_to_tuple(env, posix_errno);
    } else if((posix_errno = efile_open(&path, modes, efile_resource_type, &d))) {
        return posix_error_to_tuple(env, posix_errno);
    }

    result = enif_make_resource(env, d);
    enif_release_resource(d);

    enif_self(env, &controlling_process);

    if(enif_monitor_process(env, d, &controlling_process, &d->monitor)) {
        return posix_error_to_tuple(env, EINVAL);
    }

    return enif_make_tuple2(env, am_ok, result);
}
开发者ID:cypherfox,项目名称:otp,代码行数:32,代码来源:prim_file_nif.c

示例15: l_get_layer_defn

/* OGRFeatureDefnH OGR_L_GetLayerDefn(OGRLayerH hLayer)

{ok, DataSource} = lgeo_ogr:open("test/polygon.shp"),
{ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0),
{ok, FeatureDefn} = lgeo_ogr:l_get_layer_defn(Layer).

*/
static ERL_NIF_TERM
l_get_layer_defn(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    EnvLayer_t **layer;
    ERL_NIF_TERM eterm;

    if (argc != 1) {
        return enif_make_badarg(env);
    }

    if(!enif_get_resource(env, argv[0], OGR_L_RESOURCE, (void**)&layer)) {
        return enif_make_badarg(env);
    }

    OGRFeatureDefnH feat_defn = OGR_L_GetLayerDefn((**layer).obj);

    EnvFeatureDefn_t **feature_defn = \
        enif_alloc_resource(OGR_FD_RESOURCE, sizeof(EnvFeatureDefn_t*));

    ErlNifEnv *feature_defn_env = enif_alloc_env();

    *feature_defn = (EnvFeatureDefn_t*) enif_alloc(sizeof(EnvFeatureDefn_t));
    (**feature_defn).env = feature_defn_env;
    (**feature_defn).obj = feat_defn;

    // Save copy of layer so is not garbage collected
    enif_make_copy(feature_defn_env, argv[0]);

    eterm = enif_make_resource(env, feature_defn);
    enif_release_resource(feature_defn);
    return enif_make_tuple2(env, enif_make_atom(env, "ok"), eterm);
}
开发者ID:namjae,项目名称:lgeo,代码行数:39,代码来源:lgeo_ogr.c


注:本文中的enif_release_resource函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。