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

C++ enif_make_copy函数代码示例

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

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



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

示例1: esqlite_bind

/*
 * Bind a variable to a prepared statement
 */
static ERL_NIF_TERM 
esqlite_bind(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    esqlite_statement *stmt;
    esqlite_command *cmd = NULL;
    ErlNifPid pid;

    if(argc != 4) 
	    return enif_make_badarg(env);
    if(!enif_get_resource(env, argv[0], esqlite_statement_type, (void **) &stmt))
	    return enif_make_badarg(env);
    if(!enif_is_ref(env, argv[1])) 
	    return make_error_tuple(env, "invalid_ref");
    if(!enif_get_local_pid(env, argv[2], &pid)) 
	    return make_error_tuple(env, "invalid_pid"); 

    cmd = command_create();
    if(!cmd) 
	    return make_error_tuple(env, "command_create_failed");

    cmd->type = cmd_bind;
    cmd->ref = enif_make_copy(cmd->env, argv[1]);
    cmd->pid = pid;
    cmd->stmt = stmt->statement;
    cmd->arg = enif_make_copy(cmd->env, argv[3]);

    if(!stmt->connection) 
	    return make_error_tuple(env, "no_connection");
    if(!stmt->connection->commands)
	    return make_error_tuple(env, "no_command_queue");

    return push_command(env, stmt->connection, cmd);
}
开发者ID:alepharchives,项目名称:esqlite,代码行数:36,代码来源:esqlite3_nif.c


示例2: esqlite_prepare

/*
 * Prepare the sql statement
 */
static ERL_NIF_TERM 
esqlite_prepare(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    esqlite_connection *conn;
    esqlite_command *cmd = NULL;
    ErlNifPid pid;

    if(argc != 4) 
	    return enif_make_badarg(env);
    if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &conn))
	    return enif_make_badarg(env);
    if(!enif_is_ref(env, argv[1])) 
	    return make_error_tuple(env, "invalid_ref");
    if(!enif_get_local_pid(env, argv[2], &pid)) 
	    return make_error_tuple(env, "invalid_pid"); 

    cmd = command_create();
    if(!cmd) 
	    return make_error_tuple(env, "command_create_failed");

    cmd->type = cmd_prepare;
    cmd->ref = enif_make_copy(cmd->env, argv[1]);
    cmd->pid = pid;
    cmd->arg = enif_make_copy(cmd->env, argv[3]);

    return push_command(env, conn, cmd);
}
开发者ID:alepharchives,项目名称:esqlite,代码行数:30,代码来源:esqlite3_nif.c


示例3: init_task

task_t*
init_task(task_type_t type, ERL_NIF_TERM ref, ErlNifPid pid,
    ERL_NIF_TERM orig_term)
{
    ERL_NIF_TERM  term;
    task_t       *task;

    task = init_empty_task(type);

    task->pid = pid;
    task->env = enif_alloc_env();

    if (task->env == NULL) {
        cleanup_task(&task);
        goto done;
    }

    term = enif_make_copy(task->env, orig_term);

    if (!enif_inspect_binary(task->env, term, &task->data)) {
        cleanup_task(&task);
        goto done;
    }

    task->ref = enif_make_copy(task->env, ref);

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


示例4: esqlite_open

/* 
 * Open the database
 */
static ERL_NIF_TERM
esqlite_open(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    esqlite_connection *db;
    esqlite_command *cmd = NULL;
    ErlNifPid pid;
     
    if(argc != 4) 
	    return enif_make_badarg(env);     
    if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &db))
	    return enif_make_badarg(env);
    if(!enif_is_ref(env, argv[1])) 
	    return make_error_tuple(env, "invalid_ref");
    if(!enif_get_local_pid(env, argv[2], &pid)) 
	    return make_error_tuple(env, "invalid_pid");

    /* Note, no check is made for the type of the argument */
    cmd = command_create();
    if(!cmd) 
	    return make_error_tuple(env, "command_create_failed");

    cmd->type = cmd_open;
    cmd->ref = enif_make_copy(cmd->env, argv[1]);
    cmd->pid = pid;
    cmd->arg = enif_make_copy(cmd->env, argv[3]);

    return push_command(env, db, cmd);
}
开发者ID:alepharchives,项目名称:esqlite,代码行数:31,代码来源:esqlite3_nif.c


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


示例6: prefix_cb

static int prefix_cb(void *data, const unsigned char *k, uint32_t k_len, void *val) 
{
    callback_data *cb_data = data;
    art_elem_struct *elem = val;
    ErlNifBinary key, value;

    enif_alloc_binary(k_len - 1, &key);
    memcpy(key.data, k, k_len - 1);

    enif_alloc_binary(elem->size, &value);
    memcpy(value.data, elem->data, elem->size);

    ErlNifEnv *msg_env = enif_alloc_env();

    if(msg_env == NULL)
        return mk_error(cb_data->env, "env_alloc_error");;

    ERL_NIF_TERM caller_ref = enif_make_copy(msg_env, cb_data->caller_ref);

    ERL_NIF_TERM res = enif_make_tuple2(msg_env, 
        caller_ref,
        enif_make_tuple2(msg_env, 
            enif_make_binary(msg_env, &key), enif_make_binary(msg_env, &value)));
    
    if(!enif_send(cb_data->env, &cb_data->pid, msg_env, res))
    {
        enif_free(msg_env);

        return -1;
    }

    enif_free(msg_env);    

    return 0;
}
开发者ID:Leapsight,项目名称:elibart,代码行数:35,代码来源:elibart.c


示例7: send_blob_thread

static ERL_NIF_TERM send_blob_thread(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    union { void* vp; struct make_term_info* p; }mti;
    ERL_NIF_TERM copy;
    if (!enif_get_resource(env, argv[0], msgenv_resource_type, &mti.vp)
	|| !enif_get_local_pid(env,argv[1], &mti.p->to_pid)) {
	return enif_make_badarg(env);
    }
    copy = enif_make_copy(env, mti.p->blob);

    mti.p->send_it = enif_is_identical(argv[2],atom_join);
    if (enif_thread_create("nif_SUITE:send_from_thread", &mti.p->tid,
			   threaded_sender, mti.p, NULL) != 0) {
	return enif_make_badarg(env);
    }
    if (enif_is_identical(argv[2],atom_join)) {
	int err = enif_thread_join(mti.p->tid, NULL);
	assert(err == 0);
	return enif_make_tuple3(env, atom_ok, enif_make_int(env, mti.p->send_res), copy);
    }
    else {
	enif_keep_resource(mti.vp);
	return enif_make_tuple2(env, atom_ok, copy);
    }
}
开发者ID:cristiangreco,项目名称:otp,代码行数:25,代码来源:nif_SUITE.c


示例8: elua_newstate_async

static ERL_NIF_TERM
elua_newstate_async(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    msg_t *msg;
    ErlNifPid pid;

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

    // ref
    if(!enif_is_ref(env, argv[0])){
        return make_error_tuple(env, "invalid_ref");
    }

    // dest pid
    if(!enif_get_local_pid(env, argv[1], &pid)) {
        return make_error_tuple(env, "invalid_pid");
    }

    msg = msg_create();
    if(!msg) {
        return make_error_tuple(env, "command_create_failed");
    }

    msg->type = msg_newstate;
    msg->ref = enif_make_copy(msg->env, argv[0]);
    msg->pid = pid;
    msg->hold_env = env;
    msg->res=NULL;

    return push_command(env, NULL, msg);
}
开发者ID:indie21,项目名称:elua,代码行数:33,代码来源:elua.c


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


示例10: f_get_geometry_ref

/* OGRGeometryH OGR_F_GetGeometryRef(OGRFeatureH hFeat)

{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_ref(Feature).

*/
static ERL_NIF_TERM
f_get_geometry_ref(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");
    }

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

    ErlNifEnv *geometry_env = enif_alloc_env();

    *geometry = (EnvGeometry_t*) enif_alloc(sizeof(EnvGeometry_t));
    (**geometry).env = geometry_env;
    (**geometry).obj = geom;

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

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


示例11: ewpcap_error

void
ewpcap_error(EWPCAP_STATE *ep, char *msg)
{
    int rv = 0;

    if (ep->p == NULL)
        return;

    /* {ewpcap_error, Ref, Error} */
    rv = enif_send(
             NULL,
             &ep->pid,
             ep->env,
             enif_make_tuple3(ep->env,
                              atom_ewpcap_error,
                              enif_make_copy(ep->env, ep->ref),
                              enif_make_string(ep->env, msg, ERL_NIF_LATIN1)
                             )
         );

    if (!rv)
        pcap_breakloop(ep->p);

    enif_clear_env(ep->env);
}
开发者ID:hfeeki,项目名称:ewpcap,代码行数:25,代码来源:ewpcap.c


示例12: iterator_locales

ERL_NIF_TERM iterator_locales(ErlNifEnv* env, int argc, const
    ERL_NIF_TERM /*argv*/[])
{
    if (argc != 0)
        return enif_make_badarg(env);

    return enif_make_copy(env, available_locales);
}
开发者ID:alepharchives,项目名称:i18n,代码行数:8,代码来源:i18n_string.cpp


示例13: copy_blob

static ERL_NIF_TERM copy_blob(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    union { void* vp; struct make_term_info* p; }mti;
    if (!enif_get_resource(env, argv[0], msgenv_resource_type, &mti.vp)) {
	return enif_make_badarg(env);
    }
    return enif_make_copy(env, mti.p->blob);
}
开发者ID:cristiangreco,项目名称:otp,代码行数:8,代码来源:nif_SUITE.c


示例14: timezone_ids

ERL_NIF_TERM timezone_ids(ErlNifEnv* env, int argc, 
    const ERL_NIF_TERM /*argv*/[])
{
    if (argc != 0)
        return enif_make_badarg(env);

    return enif_make_copy(env, available_timezones);
}
开发者ID:alepharchives,项目名称:i18n,代码行数:8,代码来源:i18n_date.cpp


示例15: make_keypair_record

static ERL_NIF_TERM make_keypair_record(ErlNifEnv *env, brine_keypair_s *keypair) {
  return enif_make_tuple4(env, enif_make_copy(env, BRINE_ATOM_KEYPAIR),
                          enif_make_resource(env, (void *) keypair),
                          // private key
                          enif_make_resource_binary(env, (void *) keypair, (void *) keypair->private_key, BRINE_PRIVKEY_SZ),
                          // public key
                          enif_make_resource_binary(env, (void *) keypair, (void *) keypair->public_key, BRINE_PUBKEY_SZ));
}
开发者ID:monkeygroover,项目名称:brine,代码行数:8,代码来源:brine_nif.c


示例16: elua_gencall_async

static ERL_NIF_TERM
elua_gencall_async(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    elua_t *res;
    msg_t *msg;
    ErlNifPid pid;

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

    // first arg: ref
    if(!enif_get_resource(env, argv[0], RES_SYNC, (void**) &res)) {
        return enif_make_badarg(env);
    }

    // ref
    if(!enif_is_ref(env, argv[1])) {
        return make_error_tuple(env, "invalid_ref");
    }

    // dest pid
    if(!enif_get_local_pid(env, argv[2], &pid)) {
        return make_error_tuple(env, "invalid_pid");
    }

    // fourth arg: list of input args
    if(!enif_is_list(env, argv[5])) {
        return enif_make_badarg(env);
    }

    msg = msg_create();
    if(!msg) {
        return make_error_tuple(env, "command_create_failed");
    }

    msg->type = msg_gencall;
    msg->ref = enif_make_copy(msg->env, argv[1]);
    msg->pid = pid;
    msg->arg1 = enif_make_copy(msg->env, argv[3]);
    msg->arg2 = enif_make_copy(msg->env, argv[4]);
    msg->arg3 = enif_make_copy(msg->env, argv[5]);
    msg->res = res;

    return push_command(env, res, msg);
}
开发者ID:indie21,项目名称:elua,代码行数:46,代码来源:elua.c


示例17: vm_add_call

int
vm_add_call(vm_ptr vm, ENTERM ref, ENPID pid, ENTERM name, ENTERM args)
{
    job_ptr job = job_create();
    if(job == NULL) goto error;

    job->type = job_call;
    job->ref = enif_make_copy(job->env, ref);
    job->pid = pid;
    job->name = enif_make_copy(job->env, name);
    job->args = enif_make_copy(job->env, args);

    if(!queue_push(vm->jobs, job)) goto error;

    return 1;
error:
    if(job != NULL) job_destroy(job);
    return 0;
}
开发者ID:alepharchives,项目名称:emonk,代码行数:19,代码来源:vm.c


示例18: do_set

    void do_set(robin_q_handle *handle, ERL_NIF_TERM value) {
        const ERL_NIF_TERM *elements_tuple;
        int elements_size;
        ERL_NIF_TERM elements_term = enif_make_copy(handle->env, value);
        enif_get_tuple(handle->env, elements_term, &elements_size, &elements_tuple);

        handle->size        = elements_size;
        handle->elements    = elements_tuple;
        handle->index       = 0;
    }
开发者ID:AnakinSong,项目名称:robin_q,代码行数:10,代码来源:robin_q.cpp


示例19: op_alloc

// c_soc:op_alloc(ParentKey, Tuple, Arity) => ok
static ERL_NIF_TERM op_alloc(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
  soc::State* st = (soc::State*) enif_priv_data(env);

  int                 parentKey;
  int                 parentKeyInt;
  ERL_NIF_TERM*       tuple;
  ERL_NIF_TERM*       tupleInt;
  int                 tupleArity;
  int                 tupleArityInt;
  int                 arity;
  int                 arityInt;

  if (enif_get_int(env, argv[0], &parentKey) == 0) {
    printf("[op_alloc] error: failed to get parentKey\n");
    return -1;
  }

  parentKeyInt = enif_make_copy(st->GetEnv(), parentKey);
  
  if (enif_get_tuple(env, argv[1], &tupleArity, &tuple) == 0) {
    printf("[op_alloc] error: failed to get tuple\n");
    return -1;
  }

  (*tupleInt) = enif_make_copy(st->GetEnv(), (*tuple));
  tupleArityInt = enif_make_copy(st->GetEnv(), tupleArity);

  if (enif_get_int(env, argv[2], &arity) == 0) {
    printf("[op_alloc] error: failed to initialize arity\n");
    return -1;
  } 

  arityInt = enif_make_copy(st->GetEnv(), arity);

  printf("operation start\n");
  soc::Operation* op = new soc::Operation(parentKeyInt, tupleInt, tupleArityInt, arityInt);
  int currentIndex = st->Insert(op);
  int currentIndexExt = enif_make_copy(env, currentIndex);
  printf("operation index: %d end\n", currentIndexExt);

  return enif_make_int(env, currentIndexExt);
}
开发者ID:et4te,项目名称:paraphrase,代码行数:44,代码来源:c_soc.c


示例20: esqlite_multi_step

/*
 * Multi step to a prepared statement
 */
static ERL_NIF_TERM
esqlite_multi_step(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
    esqlite_connection *conn;
    esqlite_statement *stmt;
    esqlite_command *cmd = NULL;
    ErlNifPid pid;
    int chunk_size = 0;

    if(argc != 5)
        return enif_make_badarg(env);

    if(!enif_get_resource(env, argv[0], esqlite_connection_type, (void **) &conn))
        return enif_make_badarg(env);

    if(!enif_get_resource(env, argv[1], esqlite_statement_type, (void **) &stmt))
        return enif_make_badarg(env);

    if(!enif_get_int(env, argv[2], &chunk_size))
        return make_error_tuple(env, "invalid_chunk_size");

    if(!enif_is_ref(env, argv[3]))
        return make_error_tuple(env, "invalid_ref");

    if(!enif_get_local_pid(env, argv[4], &pid))
        return make_error_tuple(env, "invalid_pid");

    if(!stmt->statement)
        return make_error_tuple(env, "no_prepared_statement");

    cmd = command_create();
    if(!cmd)
        return make_error_tuple(env, "command_create_failed");

    cmd->type = cmd_multi_step;
    cmd->ref = enif_make_copy(cmd->env, argv[3]);
    cmd->pid = pid;
    cmd->stmt = enif_make_copy(cmd->env, argv[1]);
    cmd->arg = enif_make_copy(cmd->env, argv[2]);

    return push_command(env, conn, cmd);
}
开发者ID:mmzeeman,项目名称:esqlite,代码行数:45,代码来源:esqlite3_nif.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ enif_make_int函数代码示例发布时间:2022-05-30
下一篇:
C++ enif_make_binary函数代码示例发布时间: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