• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ enif_alloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: cb_http_args

void* cb_http_args(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    http_args_t* args = (http_args_t*)enif_alloc(sizeof(http_args_t));

    unsigned int len;

    if (!enif_get_list_length(env, argv[0], &len)) goto error0;
    len += 1;
    args->path = (char *)enif_alloc(len * sizeof(char));
    if (!enif_get_string(env, argv[0], args->path, len, ERL_NIF_LATIN1)) goto error1;

    if (!enif_get_list_length(env, argv[1], &len)) goto error1;
    len += 1;
    args->body = (char *)enif_alloc(len * sizeof(char));
    if (!enif_get_string(env, argv[1], args->body, len, ERL_NIF_LATIN1)) goto error2;

    if (!enif_get_list_length(env, argv[2], &len)) goto error2;
    len += 1;
    args->content_type = (char *)enif_alloc(len * sizeof(char));
    if (!enif_get_string(env, argv[2], args->content_type, len, ERL_NIF_LATIN1)) goto error3;

    if (!enif_get_int(env, argv[3], (int*)&args->method)) goto error3;
    if (!enif_get_int(env, argv[4], (int*)&args->type)) goto error3;

    return (void*)args;

    error3:
    enif_free(args->content_type);
    error2:
    enif_free(args->path);
    error1:
    enif_free(args->body);
    error0:
    return NULL;
}
开发者ID:AdvertiSin,项目名称:cberl,代码行数:35,代码来源:cb.c


示例2: has_same_mount_point

/* @brief Checks whether two *paths* are on the same mount point; they don't
 * have to refer to existing or accessible files/directories. */
static int has_same_mount_point(const efile_path_t *path_a, const efile_path_t *path_b) {
    WCHAR *mount_a, *mount_b;
    int result = 0;

    mount_a = enif_alloc(path_a->size);
    mount_b = enif_alloc(path_b->size);

    if(mount_a != NULL && mount_b != NULL) {
        int length_a, length_b;

        length_a = PATH_LENGTH(path_a);
        length_b = PATH_LENGTH(path_b);

        if(GetVolumePathNameW((WCHAR*)path_a->data, mount_a, length_a)) {
            ASSERT(wcslen(mount_a) <= length_a);

            if(GetVolumePathNameW((WCHAR*)path_b->data, mount_b, length_b)) {
                ASSERT(wcslen(mount_b) <= length_b);

                result = !_wcsicmp(mount_a, mount_b);
            }
        }
    }

    if(mount_b != NULL) {
        enif_free(mount_b);
    }

    if(mount_a != NULL) {
        enif_free(mount_a);
    }

    return result;
}
开发者ID:HansN,项目名称:otp,代码行数:36,代码来源:win_prim_file.c


示例3: load

    static int
load(ErlNifEnv *env, void **priv, ERL_NIF_TERM load_info)
{
    PRIVDATA *data = NULL;
    int nelem = 0;


    if (!enif_get_int(env, load_info, &nelem) || (nelem < 1))
        return (-1);

    data = (PRIVDATA *)enif_alloc(sizeof(PRIVDATA));

    if (data == NULL)
        return (-1);

    data->data = (PRIVVAL *)enif_alloc(sizeof(PRIVVAL) * nelem);
    if (data->data == NULL) {
        enif_free(data);
        return (-1);
    }

    (void)memset(data->data, 0, sizeof(PRIVVAL) * nelem);

    data->lock = enif_mutex_create("wat_lock");
    if (data->lock == NULL)
        return (-1);

    NELEM(data) = nelem;
    *priv = data;

    return (0);
}
开发者ID:alepharchives,项目名称:wat,代码行数:32,代码来源:wat.c


示例4: on_load

int
on_load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
{
    UErrorCode status = U_ZERO_ERROR;
    int i, j;
    couch_ejson_global_ctx_t *globalCtx;

    globalCtx = (couch_ejson_global_ctx_t *) enif_alloc(sizeof(couch_ejson_global_ctx_t));

    if (globalCtx == NULL) {
        return 1;
    }

    if (!enif_get_int(env, info, &globalCtx->numCollators)) {
        return 2;
    }

    if (globalCtx->numCollators < 1) {
        return 3;
    }

    globalCtx->collMutex = enif_mutex_create("coll_mutex");

    if (globalCtx->collMutex == NULL) {
        return 4;
    }

    globalCtx->collators = (UCollator **) enif_alloc(sizeof(UCollator *) * globalCtx->numCollators);

    if (globalCtx->collators == NULL) {
        enif_mutex_destroy(globalCtx->collMutex);
        return 5;
    }

    for (i = 0; i < globalCtx->numCollators; i++) {
        globalCtx->collators[i] = ucol_open("", &status);

        if (U_FAILURE(status)) {
            for (j = 0; j < i; j++) {
                ucol_close(globalCtx->collators[j]);
            }

            enif_free(globalCtx->collators);
            enif_mutex_destroy(globalCtx->collMutex);

            return 5;
        }
    }

    globalCtx->collStackTop = 0;
    *priv = globalCtx;

    ATOM_TRUE = enif_make_atom(env, "true");
    ATOM_FALSE = enif_make_atom(env, "false");
    ATOM_NULL = enif_make_atom(env, "null");
    ATOM_ERROR = enif_make_atom(env, "error");

    return 0;
}
开发者ID:aatwgen,项目名称:couchdb,代码行数:59,代码来源:couch_ejson_compare.c


示例5: enif_alloc

static struct buf *init_buf(ErlNifEnv* env, int buf_len)
{
    struct buf *rbuf = enif_alloc(sizeof(struct buf));
    rbuf->limit = buf_len;
    rbuf->len = 0;
    rbuf->b = enif_alloc(rbuf->limit);
    return rbuf;
}
开发者ID:askskype,项目名称:ttalk-server,代码行数:8,代码来源:exml_escape.c


示例6: get_engine_load_cmd_list

static int get_engine_load_cmd_list(ErlNifEnv* env, const ERL_NIF_TERM term, char **cmds, int i)
{
    ERL_NIF_TERM head, tail;
    const ERL_NIF_TERM *tmp_tuple;
    ErlNifBinary tmpbin;
    int arity;
    char *tuple1 = NULL, *tuple2 = NULL;

    if (enif_is_empty_list(env, term)) {
        cmds[i] = NULL;
        return 0;
    }

    if (!enif_get_list_cell(env, term, &head, &tail))
        goto err;
    if (!enif_get_tuple(env, head, &arity, &tmp_tuple))
        goto err;
    if (arity != 2)
        goto err;
    if (!enif_inspect_binary(env, tmp_tuple[0], &tmpbin))
        goto err;

    if ((tuple1 = enif_alloc(tmpbin.size + 1)) == NULL)
        goto err;

    (void) memcpy(tuple1, tmpbin.data, tmpbin.size);
    tuple1[tmpbin.size] = '\0';
    cmds[i] = tuple1;
    i++;

    if (!enif_inspect_binary(env, tmp_tuple[1], &tmpbin))
        goto err;

    if (tmpbin.size == 0) {
        cmds[i] = NULL;
    } else {
        if ((tuple2 = enif_alloc(tmpbin.size + 1)) == NULL)
            goto err;
        (void) memcpy(tuple2, tmpbin.data, tmpbin.size);
        tuple2[tmpbin.size] = '\0';
        cmds[i] = tuple2;
    }
    i++;
    return get_engine_load_cmd_list(env, tail, cmds, i);

 err:
    if (tuple1 != NULL) {
        i--;
        enif_free(tuple1);
    }
    cmds[i] = NULL;
    return -1;
}
开发者ID:bjorng,项目名称:otp,代码行数:53,代码来源:engine.c


示例7: handle_start

static int handle_start(void *ctx, int array)
{
  state_t *st = (state_t *)ctx;
  container_t *c = enif_alloc(st->env, sizeof(container_t));
  /* link and initialize container struct */
  c->next = st->c;
  st->c = c;
  c->count = 0;
  c->arraysz = 32;  /* initial term buffer size */
  c->array = enif_alloc(st->env, c->arraysz);
  return 1;
}
开发者ID:Waterback,项目名称:Erlang-and-OTP-in-Action-Source,代码行数:12,代码来源:jp_nifs_R13.c


示例8: nif_create_main_thread

void* nif_create_main_thread(char* name)
{
	nif_thread_state* st = (nif_thread_state*)enif_alloc(sizeof(nif_thread_state));

	st->lock = enif_mutex_create("esdl2_lock");
	st->cond = enif_cond_create("esdl2_cond");
	st->mailbox = (nif_thread_mailbox*)enif_alloc(sizeof(nif_thread_mailbox));
	TAILQ_INIT(st->mailbox);

	enif_thread_create(name, &(st->tid), nif_main_thread, st, NULL);

	return (void*)st;
}
开发者ID:276361270,项目名称:esdl2,代码行数:13,代码来源:nif_helpers.c


示例9: queue_push

int
queue_push(queue *queue, void *item) {
    qitem * entry = (qitem *) enif_alloc(sizeof(qitem));
    if (entry == NULL)
      return 0;

    entry->data = item;
    entry->next = NULL;

    enif_mutex_lock(queue->lock);

    assert(queue->length >= 0 && "Invalid queue size at push");

    if (queue->tail != NULL) {
        queue->tail->next = entry;
    }

    queue->tail = entry;

    if (queue->head == NULL) {
        queue->head = queue->tail;
    }

    queue->length += 1;

    enif_cond_signal(queue->cond);
    enif_mutex_unlock(queue->lock);

    return 1;
}
开发者ID:discoproject,项目名称:discodb,代码行数:30,代码来源:queue.c


示例10: queue_new

queue *
queue_new() {
    queue *ret;

    ret = (queue *) enif_alloc(sizeof(queue));
    if (ret == NULL)
      goto error;

    ret->lock = NULL;
    ret->cond = NULL;
    ret->head = NULL;
    ret->tail = NULL;
    ret->message = NULL;
    ret->length = 0;

    ret->lock = enif_mutex_create("queue_lock");
    if (ret->lock == NULL)
      goto error;

    ret->cond = enif_cond_create("queue_cond");
    if (ret->cond == NULL)
      goto error;

    return ret;

error:
    if (ret->lock != NULL)
      enif_mutex_destroy(ret->lock);
    if (ret->cond != NULL)
      enif_cond_destroy(ret->cond);
    if (ret != NULL)
      enif_free(ret);
    return NULL;
}
开发者ID:discoproject,项目名称:discodb,代码行数:34,代码来源:queue.c


示例11: on_load

static int
on_load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM load_info)
{
    gmperl_privdata_t *priv;

    priv = (gmperl_privdata_t *)enif_alloc(sizeof(gmperl_privdata_t));
    priv->gmperl_mpz_rt = NULL;
    priv->gmperl_mpq_rt = NULL;
    priv->gmperl_mpf_rt = NULL;
    *priv_data = priv;

    /* Use Erlang NIF memory allocation/deallocation */
    mp_set_memory_functions(gmperl_allocate, gmperl_reallocate, gmperl_free);

    /* Create resource types */
    ErlNifResourceFlags flags = (ErlNifResourceFlags)(ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER);
    priv->gmperl_mpz_rt = enif_open_resource_type(env, "gmperl_nifs", "gmperl_mpz_resource", gmperl_mpz_t_dtor, flags, NULL);
    priv->gmperl_mpq_rt = enif_open_resource_type(env, "gmperl_nifs", "gmperl_mpq_resource", gmperl_mpq_t_dtor, flags, NULL);
    priv->gmperl_mpf_rt = enif_open_resource_type(env, "gmperl_nifs", "gmperl_mpf_resource", gmperl_mpf_t_dtor, flags, NULL);
    if (!enif_make_existing_atom(env, "ok", &priv->atom_ok, ERL_NIF_LATIN1)
            || !enif_make_existing_atom(env, "true", &priv->atom_true, ERL_NIF_LATIN1)
            || !enif_make_existing_atom(env, "false", &priv->atom_false, ERL_NIF_LATIN1)) {
        return -1;
    }
    return 0;
}
开发者ID:hntrmrrs,项目名称:gmperl,代码行数:26,代码来源:gmperl_nifs.c


示例12: float_ref

static ERL_NIF_TERM
float_ref(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  int err;
  double helper;
  float *value;
  
  value = enif_alloc(sizeof(float));
  if (!value) {
    goto error;
  }

  err = enif_get_double(env, argv[0], &helper);
  if (!err) {
    enif_free(value);
    goto error;
  }

  *value = (float)helper;
  
  return enif_make_tuple2(env, 
			  nifty_make_ptr(env, (ptr_t)value),
			  enif_make_string(env, "nifty.float *", ERL_NIF_LATIN1));

 error:
  return enif_make_badarg(env);
}
开发者ID:276361270,项目名称:nifty,代码行数:27,代码来源:nifty.c


示例13: queue_push

int
queue_push(queue_t* queue, ErlNifPid* pid)
{
    qitem_t* item = (qitem_t*) enif_alloc(sizeof(qitem_t));
    if(item == NULL) return 0;

    item->pid = pid;
    item->next = NULL;

    enif_mutex_lock(queue->lock);

    if(queue->tail != NULL)
    {
        queue->tail->next = item;
    }

    queue->tail = item;

    if(queue->head == NULL)
    {
        queue->head = queue->tail;
    }

    enif_cond_signal(queue->cond);
    enif_mutex_unlock(queue->lock);

    return 1;
}
开发者ID:thijsterlouw,项目名称:nif-examples,代码行数:28,代码来源:termsend_threaded.c


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


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


示例16: cb_store_args

void* cb_store_args(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    store_args_t* args = (store_args_t*)enif_alloc(sizeof(store_args_t));

    ErlNifBinary value_binary;
    ErlNifBinary key_binary;

    if (!enif_get_int(env, argv[0], &args->operation)) goto error0;
    if (!enif_inspect_iolist_as_binary(env, argv[1], &key_binary)) goto error0;
    if (!enif_inspect_iolist_as_binary(env, argv[2], &value_binary)) goto error0;

    args->nkey = key_binary.size;
    args->nbytes = value_binary.size;
    args->key = (char*)malloc(key_binary.size);
    args->bytes = (char*)malloc(value_binary.size);
    memcpy(args->bytes, value_binary.data, value_binary.size);
    memcpy(args->key, key_binary.data, key_binary.size);

    if (!enif_get_uint(env, argv[3], &args->flags)) goto error1;
    if (!enif_get_int(env, argv[4], &args->exp)) goto error1;
    if (!enif_get_uint64(env, argv[5], (ErlNifUInt64*)&args->cas)) goto error1;

    return args;

    error1:
    free(args->bytes);
    free(args->key);
    error0:
    enif_free(args);

    return NULL;
}
开发者ID:muut,项目名称:cberl,代码行数:32,代码来源:cb.c


示例17: do_column_types

static ERL_NIF_TERM
do_column_types(ErlNifEnv *env, sqlite3_stmt *stmt)
{
    int i, size;
    const char *type;
    ERL_NIF_TERM *array;
    ERL_NIF_TERM column_types;

    size = sqlite3_column_count(stmt);
    if(size == 0)
        return enif_make_tuple(env, 0);
    else if(size < 0)
        return make_error_tuple(env, "invalid_column_count");

    array = (ERL_NIF_TERM *) enif_alloc(sizeof(ERL_NIF_TERM) * size);
    if(!array)
        return make_error_tuple(env, "no_memory");

    for(i = 0; i < size; i++) {
        type = sqlite3_column_decltype(stmt, i);
        if(type == NULL) {
	    type = "nil";
        }

        array[i] = make_atom(env, type);
    }

    column_types = enif_make_tuple_from_array(env, array, size);
    enif_free(array);
    return column_types;
}
开发者ID:mmzeeman,项目名称:esqlite,代码行数:31,代码来源:esqlite3_nif.c


示例18: enq_char

static void enq_char(yang_scanner_t* obj, int c)
{
    token_t* t = (token_t*) enif_alloc(sizeof(token_t));
    t->type = c;
    t->line = obj->line;
    enq_token(obj, t);
}
开发者ID:Dasudian,项目名称:yang,代码行数:7,代码来源:yang_scan_nif.c


示例19: load

static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
    PrivData* data = enif_alloc(sizeof(PrivData));
    assert(data != NULL);
    data->ref_cnt = 1;
    data->call_history = NULL;
    data->nif_mod = NULL;

    add_call(env, data, "load");

    data->rt_arr[0].t = enif_open_resource_type(env,NULL,"Gold",resource_dtor,
						ERL_NIF_RT_CREATE,NULL);
    data->rt_arr[1].t = enif_open_resource_type(env,NULL,"Silver",resource_dtor,
						ERL_NIF_RT_CREATE,NULL);

    binary_resource_type =  enif_open_resource_type(env,NULL,"nif_SUITE.binary",
						    binary_resource_dtor,
						    ERL_NIF_RT_CREATE, NULL);

    msgenv_resource_type =  enif_open_resource_type(env,NULL,"nif_SUITE.msgenv",
						    msgenv_dtor,
						    ERL_NIF_RT_CREATE, NULL);

    atom_self = enif_make_atom(env,"self");
    atom_ok = enif_make_atom(env,"ok");
    atom_join = enif_make_atom(env,"join");
    atom_binary_resource_type = enif_make_atom(env,"binary_resource_type");

    *priv_data = data;
    return 0;
}
开发者ID:cristiangreco,项目名称:otp,代码行数:31,代码来源:nif_SUITE.c


示例20: make_num

static int make_num(ErlNifEnv* env, const unsigned char *value,
		    size_t size, long int *i, double *d)
{
    int ret = 0;

    if (size>0) {
	char *buf = enif_alloc(size + 1);
	if (buf) {
	    memcpy(buf, value, size);
	    buf[size] = '\0';
	    char *check;
	    *i = strtol(buf, &check, 10);
	    if (*check == '\0')
		ret = INTEGER;
	    else if (*check == '.') {
		*d = strtod(buf, &check);
		if (*check == '\0')
		    ret = FLOAT;
	    }
	    enif_free(buf);
	}
    }

    return ret;
}
开发者ID:jabber-at,项目名称:p1_yaml,代码行数:25,代码来源:fast_yaml.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ enif_alloc_binary函数代码示例发布时间:2022-05-30
下一篇:
C++ engine_table_register函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap