本文整理汇总了C++中enif_alloc_resource函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_alloc_resource函数的具体用法?C++ enif_alloc_resource怎么用?C++ enif_alloc_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_alloc_resource函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: nif_open
static ERL_NIF_TERM
nif_open(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary dev;
SRLY_STATE *sp = NULL;
if (!enif_inspect_iolist_as_binary(env, argv[0], (ErlNifBinary *)&dev))
return enif_make_badarg(env);
sp = enif_alloc_resource(SRLY_STATE_RESOURCE, sizeof(SRLY_STATE));
if (sp == NULL)
return error_tuple(env, ENOMEM);
if (!enif_realloc_binary(&dev, dev.size+1))
return enif_make_badarg(env);
dev.data[dev.size-1] = '\0';
sp->fd = open((char *)dev.data, O_RDWR|O_NOCTTY|O_NONBLOCK);
if (sp->fd < 0 || isatty(sp->fd) != 1) {
int err = errno;
enif_release_resource(sp);
return error_tuple(env, err);
}
return enif_make_tuple2(env,
atom_ok,
enif_make_resource(env, sp));
}
开发者ID:jj1bdx,项目名称:srly,代码行数:30,代码来源:serctl.c
示例17: create
static ERL_NIF_TERM
create(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
Example* res;
ERL_NIF_TERM ret;
unsigned int id;
Tracker* tracker;
if(argc != 1)
{
return enif_make_badarg(env);
}
if(!enif_get_uint(env, argv[0], &id))
{
return enif_make_badarg(env);
}
res = enif_alloc_resource(RES_TYPE, sizeof(Example));
if(res == NULL) return enif_make_badarg(env);
ret = enif_make_resource(env, res);
enif_release_resource(res);
res->id = id;
tracker = (Tracker*) enif_priv_data(env);
tracker->count += 1;
return enif_make_tuple2(env, atom_ok, ret);
}
开发者ID:szpzs,项目名称:nif-examples,代码行数:31,代码来源:resources.c
示例18: _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
示例19: 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
示例20: newstate
static ERL_NIF_TERM
newstate(ErlNifEnv *env, ErlNifEnv *hold_env)
{
ERL_NIF_TERM ret;
lua_State *L;
elua_t *res;
L = luaL_newstate();
if(L==NULL) {
return enif_make_tuple2(env, atom_error, enif_make_string(env, STR_NOT_ENOUGHT_MEMORY, ERL_NIF_LATIN1));
}
luaL_openlibs(L);
res = enif_alloc_resource(RES_SYNC, sizeof(elua_t));
if(res == NULL) return enif_make_badarg(env);
//printf("alloc res 0x%x\n" ,(unsigned int)res);
ret = enif_make_resource(env, res);
enif_release_resource(res);
res->L = L;
return enif_make_tuple2(env, atom_ok, ret);
}
开发者ID:indie21,项目名称:elua,代码行数:26,代码来源:elua.c
注:本文中的enif_alloc_resource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论