当前位置: 首页>>代码示例>>C++>>正文


C++ enif_make_badarg函数代码示例

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


在下文中一共展示了enif_make_badarg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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