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


C++ enif_alloc_resource函数代码示例

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


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

示例1: ex_slp_open

static ERL_NIF_TERM
ex_slp_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) {
  char         *lang;
  char         *ret_code;
  int           isasync;
  unsigned int  term_len;
  SLPHandle    *hslp;
  SLPEXP SLPError SLPAPI error;

  if (enif_get_atom_length(env, argv[0], &term_len, ERL_NIF_LATIN1) < 0) {
    return enif_make_badarg(env);
  }

  if (enif_get_atom(env, argv[0], lang, term_len, ERL_NIF_LATIN1) < 0) {
    return enif_make_badarg(env);
  }

  if ( ! enif_get_int(env, argv[1], &isasync)) return enif_make_badarg(env);

  hslp = enif_alloc_resource(NIF_SLP_HANDLE, sizeof(SLPHandle));

  if (hslp == NULL) return enif_make_badarg(env);

  //error = SLPOpen(lang, isasync > 0 ? SLP_TRUE : SLP_FALSE, hslp);
  error = SLPOpen(lang, isasync > 0 ? SLP_TRUE : SLP_FALSE, hslp);

  ERL_NIF_TERM term = enif_make_resource(env, hslp);

  enif_release_resource(hslp);

  return enif_make_tuple2(env, enif_make_int(env, error), term);
}
开发者ID:icanhazbroccoli,项目名称:ex_slp,代码行数:32,代码来源:ex_slp.c

示例2: 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

示例3: 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

示例4: f_get_geometry

/*
{ok, DataSource} = lgeo_ogr:open("test/polygon.shp"),
{ok, Layer} = lgeo_ogr:ds_get_layer(DataSource, 0),
{ok, Feature} = lgeo_ogr:l_get_feature(Layer, 0),
{ok, Geometry} = lgeo_ogr:f_get_geometry(Feature).

*/
static ERL_NIF_TERM
f_get_geometry(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    EnvFeature_t **feature;
    ERL_NIF_TERM eterm;

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

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

    OGRGeometryH geom = OGR_F_GetGeometryRef((**feature).obj);
    if(geom == NULL) {
        return enif_make_atom(env, "undefined");
    }

    OGRGeometryH geom_clone = OGR_G_Clone(geom);

    EnvGeometry_t **geometry = \
        enif_alloc_resource(OGR_G_RESOURCE, sizeof(EnvGeometry_t*));

    *geometry = (EnvGeometry_t*) enif_alloc(sizeof(EnvGeometry_t));
    (**geometry).env = NULL;
    (**geometry).obj = geom_clone;

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

示例5: _open

static ERL_NIF_TERM
_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  CAN_handle*  handle;
  ERL_NIF_TERM result;
  char        dev_path[512];
  if (!enif_get_string(env, argv[0], dev_path, 512, ERL_NIF_LATIN1))
    return enif_make_int(env, -2000);
  handle = enif_alloc_resource(CAN_handle_type, sizeof(CAN_handle));
  memset(handle, 0, sizeof(CAN_handle));
  handle->device = open((const char*)dev_path,  O_RDWR | O_SYNC);
  if (!enif_get_int(env, argv[1], &handle->raw))
    return enif_make_int(env, -2001);
  handle->threaded = 0;
  if (handle->device >= 0)
    {
      int len = strlen(dev_path);
      result = enif_make_resource(env, handle);
      handle->devpath = enif_alloc(len);
      memcpy(handle->devpath, dev_path, len);
      handle->devpath_bin = enif_make_resource_binary(env, handle, handle->devpath, len);
    }
  else
    {
      result = enif_make_int(env, errno);
    }
  enif_release_resource(handle);
  return result;
}
开发者ID:qoocku,项目名称:erleos,代码行数:29,代码来源:CAN_nif.c

示例6: 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

示例7: 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

示例8: _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

示例9: compile

static ERL_NIF_TERM compile(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    ErlNifBinary patternbin;

    if (enif_inspect_iolist_as_binary(env, argv[0], &patternbin)) {
        ERL_NIF_TERM ret;
        xmlRegexpPtr xre;
        char *patternstr = enif_alloc(patternbin.size + 1);
        patternstr[patternbin.size] = 0;
        memcpy(patternstr, patternbin.data, patternbin.size);

        if ((xre = xmlRegexpCompile((xmlChar *)patternstr)) != NULL) {
            struct regexp *r;
            r = enif_alloc_resource(regexp_type, sizeof(struct regexp));
            memset(r, 0, sizeof(*r));
            r->xre = xre;
            r->string = patternstr;

            /* transfer ownership to calling process */
            ret = enif_make_tuple2(env, am_ok(env),
                                   enif_make_resource(env, r));
            enif_release_resource(r);
        } else {
            enif_free(patternstr);
            ret = last_error(env, "Bad Pattern");
        }

        return ret;
    }

    return enif_make_badarg(env);
}
开发者ID:tail-f-systems,项目名称:xsdre,代码行数:32,代码来源:xsdre.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: generate_keypair_from_seed

static void generate_keypair_from_seed(brine_task_s *task) {
  ErlNifEnv *env = task->env;
  ERL_NIF_TERM result;
  brine_keypair_s *keypair = (brine_keypair_s *) enif_alloc_resource(brine_keypair_resource, sizeof(brine_keypair_s));
  ErlNifBinary seed;

  if (!keypair) {
    result = BRINE_ERROR_NO_MEMORY;
  }
  else {
    if (!enif_inspect_binary(env, task->options.generate.seed, &seed)) {
      result = BRINE_ATOM_ERROR;
    }
    else {
      if (!brine_init_keypair_from_seed(keypair, seed.data, seed.size)) {
        result = BRINE_ATOM_ERROR;
      }
      else {
        result = enif_make_tuple2(env, enif_make_copy(env, BRINE_ATOM_OK), make_keypair_record(env, keypair));
      }
    }
    enif_release_resource(keypair);
  }
  enif_send(NULL, &task->owner, task->env, enif_make_tuple2(env, task->ref, result));
}
开发者ID:monkeygroover,项目名称:brine,代码行数:25,代码来源:brine_nif.c

示例12: 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;

    enif_inspect_iolist_as_binary(env, arg, &bin);

    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)
	    return make_sqlite3_error_tuple(env, rc, conn->db);

    enif_keep_resource(conn);
    stmt->connection = conn;

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

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

示例13: 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

示例14: 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

示例15: wrap_pointer

static ERL_NIF_TERM wrap_pointer(ErlNifEnv* env,ErlNifResourceType* type,void* ptr) {
    void** resource = (void**) enif_alloc_resource(env,type,sizeof(void*));
    *resource = ptr;
    ERL_NIF_TERM term = enif_make_resource(env,resource);
    enif_release_resource(env,(void*)resource);
    return term;
}
开发者ID:BigDwarf,项目名称:ennui,代码行数:7,代码来源:bullet.cpp


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