本文整理汇总了C++中enif_make_copy函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_make_copy函数的具体用法?C++ enif_make_copy怎么用?C++ enif_make_copy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_make_copy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}