本文整理汇总了C++中enif_make_badarg函数的典型用法代码示例。如果您正苦于以下问题:C++ enif_make_badarg函数的具体用法?C++ enif_make_badarg怎么用?C++ enif_make_badarg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了enif_make_badarg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: meter_stats
ERL_NIF_TERM meter_stats(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
meter_handle* handle;
if (enif_get_resource(env,argv[0],meter_RESOURCE,(void**)&handle))
{
pthread_mutex_lock(&(handle->m));
ERL_NIF_TERM result =
enif_make_list4(env,
enif_make_tuple2(env,ATOM_COUNT,
enif_make_ulong(env, handle->p->count())),
enif_make_tuple2(env,ATOM_ONE,
enif_make_double(env,handle->p->one())),
enif_make_tuple2(env,ATOM_FIVE,enif_make_double(env, handle->p->five())),
enif_make_tuple2(env,ATOM_FIFTEEN,enif_make_double(env, handle->p->fifteen())));
pthread_mutex_unlock(&(handle->m));
return result;
}
else
return enif_make_badarg(env);
}
开发者ID:basho,项目名称:basho_metrics,代码行数:21,代码来源:basho_metrics_nifs.cpp
示例2: meter_new
ERL_NIF_TERM meter_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
meter_handle *handle =
(meter_handle *)enif_alloc_resource(meter_RESOURCE,
sizeof(meter_handle));
if (enif_is_list(env, argv[0]))
{
memset(handle, '\0', sizeof(meter_handle));
pthread_mutex_init(&(handle->m), NULL);
handle->tick_interval = DEFAULT_METER_TICK_INTERVAL;
fold(env, argv[0], parse_meter_option, *handle);
handle->p = new meter<>(handle->tick_interval);
ERL_NIF_TERM result = enif_make_resource(env, handle);
enif_release_resource(handle);
return enif_make_tuple2(env, ATOM_OK, result);
}
else
{
return enif_make_badarg(env);
}
}
开发者ID:basho,项目名称:basho_metrics,代码行数:21,代码来源:basho_metrics_nifs.cpp
示例3: set_time_nif
static ERL_NIF_TERM set_time_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
posix_errno_t posix_errno;
Sint64 accessed, modified, created;
efile_path_t path;
ASSERT(argc == 4);
if(!enif_get_int64(env, argv[1], &accessed)
|| !enif_get_int64(env, argv[2], &modified)
|| !enif_get_int64(env, argv[3], &created)) {
return enif_make_badarg(env);
}
if((posix_errno = efile_marshal_path(env, argv[0], &path))) {
return posix_error_to_tuple(env, posix_errno);
} else if((posix_errno = efile_set_time(&path, accessed, modified, created))) {
return posix_error_to_tuple(env, posix_errno);
}
return am_ok;
}
开发者ID:HansN,项目名称:otp,代码行数:21,代码来源:prim_file_nif.c
示例4: emmap_close
static ERL_NIF_TERM emmap_close(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
mhandle *handle;
if (argc==1 && enif_get_resource(env, argv[0], MMAP_RESOURCE, (void**)&handle))
{
int res;
RW_LOCK;
res = emmap_unmap(handle, false);
RW_UNLOCK;
if (res == 0) {
return ATOM_OK;
}
return make_error_tuple(env, errno);
}
else
{
return enif_make_badarg(env);
}
}
开发者ID:alepharchives,项目名称:emmap,代码行数:21,代码来源:emmap.cpp
示例5: _hi_close
ERL_NIF_TERM _hi_close(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
hi_ctx_t* ctx = NULL;
ErlNifResourceType* ctx_type = get_hi_ctx_type(env);
if (ctx_type != NULL &&
!enif_get_resource(env, argv[0], ctx_type, (void **)&ctx))
{
return enif_make_badarg(env);
}
if (ctx != NULL && ctx->opts != NULL)
{
enif_free(ctx->opts);
enif_free(ctx->iter);
ctx->opts = NULL;
ctx->iter = NULL;
}
return ATOM_OK;
}
开发者ID:jlouis,项目名称:hdr_histogram_erl,代码行数:21,代码来源:hdr_histogram_nif.c
示例6: open_tty
static ERL_NIF_TERM
open_tty(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
char ttyname[MAXPATHLEN];
int ttyfd = -1;
if (enif_get_string(env, argv[0], ttyname, sizeof(ttyname), ERL_NIF_LATIN1) < 1)
{
return enif_make_badarg(env);
}
ttyfd = open(ttyname, O_RDWR|O_NOCTTY|O_NONBLOCK);
if (ttyfd < 0)
{
return mk_errno(env, errno);
}
return enif_make_tuple2(env, atom_ok,
enif_make_int(env, ttyfd));
}
开发者ID:alepharchives,项目名称:cereal,代码行数:21,代码来源:cereal.c
示例7: yang_scan_new
// Create a new scanner resource
ERL_NIF_TERM yang_scan_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
yang_scanner_t* obj;
ERL_NIF_TERM r;
if (!(obj = enif_alloc_resource(yang_scan_resource, sizeof(yang_scanner_t))))
return enif_make_badarg(env);
obj->line = 1;
obj->column = 1;
obj->t_line = 0;
obj->t_column = 0;
obj->t_skip = false;
obj->state = STATE_WSP;
obj->n_tokens = 0;
obj->first = NULL;
obj->last = NULL;
obj->pos = 0;
r = enif_make_resource(env, obj);
enif_release_resource(obj);
return r;
}
开发者ID:Dasudian,项目名称:yang,代码行数:22,代码来源:yang_scan_nif.c
示例8: make_new_resource_binary
static ERL_NIF_TERM make_new_resource_binary(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary data_bin;
union { struct binary_resource* p; void* vp; long l;} br;
void* buf;
ERL_NIF_TERM ret;
if (!enif_inspect_binary(env, argv[0], &data_bin)
|| (br.vp = enif_alloc_resource(binary_resource_type,
sizeof(struct binary_resource)))==NULL
|| (buf = enif_alloc(data_bin.size)) == NULL) {
return enif_make_badarg(env);
}
memset(br.vp,0xba,sizeof(struct binary_resource)); /* avoid valgrind warning */
br.p->data = buf;
br.p->size = data_bin.size;
memcpy(br.p->data, data_bin.data, data_bin.size);
ret = enif_make_resource_binary(env, br.vp, br.p->data, br.p->size);
enif_release_resource(br.p);
return enif_make_tuple2(env, enif_make_long(env,br.l), ret);
}
开发者ID:cristiangreco,项目名称:otp,代码行数:21,代码来源:nif_SUITE.c
示例9: pteracuda_nifs_new_context
ERL_NIF_TERM pteracuda_nifs_new_context(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
CUdevice device;
int deviceNum = 0;
PCudaContextRef *ref = (PCudaContextRef *) enif_alloc_resource(pteracuda_context_resource, sizeof(PCudaContextRef));
if (!ref) {
return OOM_ERROR;
}
if (argc == 1 && !enif_get_int(env, argv[0], &deviceNum)) {
return enif_make_badarg(env);
}
if (cuDeviceGet(&device, deviceNum) == CUDA_SUCCESS &&
cuCtxCreate(&(ref->ctx), CU_CTX_SCHED_AUTO, device) == CUDA_SUCCESS) {
ref->destroyed = false;
ERL_NIF_TERM result = enif_make_resource(env, ref);
enif_release_resource(ref);
return enif_make_tuple2(env, ATOM_OK, result);
}
else {
return ATOM_ERROR;
}
}
开发者ID:jacktang,项目名称:pteracuda,代码行数:21,代码来源:pteracuda_nifs.cpp
示例10: decode
static ERL_NIF_TERM decode(ErlNifEnv* env, int argc,
const ERL_NIF_TERM argv[])
{
ErlNifBinary input;
ERL_NIF_TERM result;
unsigned int flags;
yaml_parser_t parser;
if (argc == 2) {
if (enif_inspect_iolist_as_binary(env, argv[0], &input) &&
enif_get_uint(env, argv[1], &flags))
{
yaml_parser_initialize(&parser);
result = parse(env, &parser, flags, input.data, input.size);
yaml_parser_delete(&parser);
return result;
}
}
return enif_make_badarg(env);
}
开发者ID:jabber-at,项目名称:p1_yaml,代码行数:21,代码来源:fast_yaml.c
示例11: pteracuda_nifs_log
ERL_NIF_TERM pteracuda_nifs_log(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
PCudaContextRef *ctxRef;
PCudaBufferRef *ref_A, *ref_B;
if (argc != 3 || !enif_get_resource(env, argv[0], pteracuda_context_resource, (void **) &ctxRef) ||
!enif_get_resource(env, argv[1], pteracuda_buffer_resource, (void **) &ref_A) ||
!enif_get_resource(env, argv[2], pteracuda_buffer_resource, (void **) &ref_B)
) {
return enif_make_badarg(env);
}
if(((PCudaFloatBuffer*)ref_A->buffer)->size() != ((PCudaFloatBuffer*)ref_B->buffer)->size()){
return enif_make_tuple2(env, ATOM_ERROR, enif_make_atom(env, "Buffer A size does not match buffer B size"));
}
cuCtxSetCurrent(ctxRef->ctx);
pcuda_log(((PCudaFloatBuffer*)ref_A->buffer)->get_data(), ((PCudaFloatBuffer*)ref_B->buffer)->get_data());
return ATOM_OK;
}
开发者ID:jacktang,项目名称:pteracuda,代码行数:21,代码来源:pteracuda_nifs.cpp
示例12: nacl_box_open_padded
static ERL_NIF_TERM nacl_box_open_padded(ErlNifEnv *env, int argc, ERL_NIF_TERM const argv[])
{
ErlNifBinary padded_ciphertext;
ErlNifBinary nonce;
ErlNifBinary pk;
ErlNifBinary sk;
ErlNifBinary result;
if (!enif_inspect_iolist_as_binary(env, argv[0], &padded_ciphertext))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[1], &nonce))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[2], &pk))
return enif_make_badarg(env);
if (!enif_inspect_iolist_as_binary(env, argv[3], &sk))
return enif_make_badarg(env);
if (nonce.size != crypto_box_NONCEBYTES) return enif_make_badarg(env);
if (pk.size != crypto_box_PUBLICKEYBYTES) return enif_make_badarg(env);
if (sk.size != crypto_box_SECRETKEYBYTES) return enif_make_badarg(env);
if (padded_ciphertext.size < crypto_box_BOXZEROBYTES) return enif_make_badarg(env);
if (!enif_alloc_binary(padded_ciphertext.size, &result))
return nacl_error_tuple(env, "alloc_failed");
if (crypto_box_open(result.data, padded_ciphertext.data, padded_ciphertext.size,
nonce.data, pk.data, sk.data)) {
return nacl_error_tuple(env, "crypto_failed");
}
return enif_make_sub_binary(env,
enif_make_binary(env, &result),
crypto_box_ZEROBYTES,
padded_ciphertext.size - crypto_box_ZEROBYTES);
}
开发者ID:chinnurtb,项目名称:erlang-nacl,代码行数:38,代码来源:nacl_nif.c
示例13: file_handle_wrapper
static ERL_NIF_TERM file_handle_wrapper(file_op_impl_t operation, ErlNifEnv *env,
int argc, const ERL_NIF_TERM argv[]) {
efile_data_t *d;
enum efile_state_t previous_state;
ERL_NIF_TERM result;
if(argc < 1 || !get_file_data(env, argv[0], &d)) {
return enif_make_badarg(env);
}
previous_state = erts_atomic32_cmpxchg_acqb(&d->state,
EFILE_STATE_BUSY, EFILE_STATE_IDLE);
if(previous_state == EFILE_STATE_IDLE) {
result = operation(d, env, argc - 1, &argv[1]);
previous_state = erts_atomic32_cmpxchg_relb(&d->state,
EFILE_STATE_IDLE, EFILE_STATE_BUSY);
ASSERT(previous_state != EFILE_STATE_IDLE);
if(previous_state == EFILE_STATE_CLOSE_PENDING) {
/* This is the only point where a change from CLOSE_PENDING is
* possible, and we're running synchronously, so we can't race with
* anything else here. */
erts_atomic32_set_acqb(&d->state, EFILE_STATE_CLOSED);
efile_close(d);
}
} else {
/* CLOSE_PENDING should be impossible at this point since it requires
* a transition from BUSY; the only valid state here is CLOSED. */
ASSERT(previous_state == EFILE_STATE_CLOSED);
result = posix_error_to_tuple(env, EINVAL);
}
return result;
}
开发者ID:cypherfox,项目名称:otp,代码行数:40,代码来源:prim_file_nif.c
示例14: engine_free_nif
ERL_NIF_TERM engine_free_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{/* (Engine) */
#ifdef HAS_ENGINE_SUPPORT
struct engine_ctx *ctx;
// Get Engine
ASSERT(argc == 1);
if (!enif_get_resource(env, argv[0], engine_ctx_rtype, (void**)&ctx))
goto bad_arg;
if (!ENGINE_free(ctx->engine))
goto err;
return atom_ok;
bad_arg:
err:
return enif_make_badarg(env);
#else
return atom_notsup;
#endif
}
开发者ID:bjorng,项目名称:otp,代码行数:22,代码来源:engine.c
示例15: histogram_new
ERL_NIF_TERM histogram_new(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
histogram_handle *handle =
(histogram_handle *)enif_alloc_resource(histogram_RESOURCE,
sizeof(histogram_handle));
if (enif_is_list(env, argv[0]))
{
memset(handle, '\0', sizeof(histogram_handle));
pthread_mutex_init(&(handle->m), NULL);
handle->size = DEFAULT_RESERVOIR_SIZE;
handle->width = DEFAULT_WINDOW_WIDTH;
fold(env, argv[0], parse_histogram_option, *handle);
handle->p = new histogram<>(handle->size, handle->width);
ERL_NIF_TERM result = enif_make_resource(env, handle);
enif_release_resource(handle);
return enif_make_tuple2(env, ATOM_OK, result);
}
else
{
return enif_make_badarg(env);
}
}
开发者ID:basho,项目名称:basho_metrics,代码行数:22,代码来源:basho_metrics_nifs.cpp
示例16: pread_nif_impl
static ERL_NIF_TERM pread_nif_impl(efile_data_t *d, ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
Sint64 bytes_read, block_size, offset;
SysIOVec read_vec[1];
ErlNifBinary result;
ASSERT(argc == 2);
if(!enif_is_number(env, argv[0]) || !enif_is_number(env, argv[1])) {
return enif_make_badarg(env);
}
if(!enif_get_int64(env, argv[0], &offset) ||
!enif_get_int64(env, argv[1], &block_size) ||
(offset < 0 || block_size < 0)) {
return posix_error_to_tuple(env, EINVAL);
}
if(!enif_alloc_binary(block_size, &result)) {
return posix_error_to_tuple(env, ENOMEM);
}
read_vec[0].iov_base = result.data;
read_vec[0].iov_len = result.size;
bytes_read = efile_preadv(d, offset, read_vec, 1);
if(bytes_read < 0) {
enif_release_binary(&result);
return posix_error_to_tuple(env, d->posix_errno);
} else if(bytes_read == 0) {
enif_release_binary(&result);
return am_eof;
}
if(bytes_read < block_size && !enif_realloc_binary(&result, bytes_read)) {
ERTS_INTERNAL_ERROR("Failed to shrink pread result.");
}
return enif_make_tuple2(env, am_ok, enif_make_binary(env, &result));
}
开发者ID:HansN,项目名称:otp,代码行数:39,代码来源:prim_file_nif.c
示例17: date_roll
ERL_NIF_TERM date_roll(ErlNifEnv* env, int argc,
const ERL_NIF_TERM argv[])
{
UErrorCode status = U_ZERO_ERROR;
UCalendar* cal;
cloner* ptr;
double date;
if(!((argc == 3)
&& enif_get_resource(env, argv[0], calendar_type, (void**) &ptr)
&& enif_get_double(env, argv[1], &date))) {
return enif_make_badarg(env);
}
cal = (UCalendar*) cloner_get(ptr);
CHECK_RES(env, cal);
ucal_setMillis(cal, (UDate) date, &status);
CHECK(env, status);
return do_offset(env, cal, ucal_roll, argv[2]);
}
开发者ID:djui,项目名称:i18n,代码行数:22,代码来源:i18n_date.cpp
示例18: erl_geonum_decode_bbox
/**
* Erlang Wrapper for geonum_decode_bbox
*/
ERL_NIF_TERM
erl_geonum_decode_bbox(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
double tl[2], br[2];
long long geonum;
if(!enif_get_int64(env, argv[0], &geonum)) {
return enif_make_badarg(env);
}
geonum_decode_bbox(geonum, tl, br);
ERL_NIF_TERM top_left = enif_make_tuple2(env,
enif_make_double(env, tl[0]),
enif_make_double(env, tl[1]));
ERL_NIF_TERM bottom_right = enif_make_tuple2(env,
enif_make_double(env, br[0]),
enif_make_double(env, br[1]));
ERL_NIF_TERM bbox = enif_make_tuple2(env, top_left, bottom_right);
return make_ok(env, bbox);
}
开发者ID:chinnurtb,项目名称:geonum,代码行数:25,代码来源:geonum.c
示例19: mem_alloc
static ERL_NIF_TERM
mem_alloc(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ptr_t ptr, size, err;
err = nifty_get_ptr(env, argv[0], &size);
if (!err) {
goto error;
}
ptr = (ptr_t)enif_alloc(size);
if (!ptr) {
goto error;
}
return enif_make_tuple2(env,
nifty_make_ptr(env, (ptr_t)ptr),
enif_make_string(env, "nifty.void *", ERL_NIF_LATIN1));
error:
return enif_make_badarg(env);
}
开发者ID:276361270,项目名称:nifty,代码行数:22,代码来源:nifty.c
示例20: get_resource
static ERL_NIF_TERM get_resource(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
ErlNifBinary data_bin;
union { ErlNifResourceType* t; long l; } type;
union { void* p; long l; } data;
type.t = NULL;
if (enif_is_identical(argv[0], atom_binary_resource_type)) {
type.t = binary_resource_type;
}
else {
enif_get_long(env, argv[0], &type.l);
}
if (type.t == NULL
|| !enif_get_resource(env, argv[1], type.t, &data.p)) {
return enif_make_badarg(env);
}
enif_alloc_binary(enif_sizeof_resource(data.p), &data_bin);
memcpy(data_bin.data, data.p, data_bin.size);
return enif_make_tuple2(env, enif_make_long(env,data.l),
enif_make_binary(env, &data_bin));
}
开发者ID:cristiangreco,项目名称:otp,代码行数:22,代码来源:nif_SUITE.c
注:本文中的enif_make_badarg函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论