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


C++ NIL_P函数代码示例

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


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

示例1: rb_dlhandle_initialize

/*
 * call-seq:
 *    initialize(lib = nil, flags = DL::RTLD_LAZY | DL::RTLD_GLOBAL)
 *
 * Create a new handler that opens library named +lib+ with +flags+.  If no
 * library is specified, RTLD_DEFAULT is used.
 */
VALUE
rb_dlhandle_initialize(int argc, VALUE argv[], VALUE self)
{
    void *ptr;
    struct dl_handle *dlhandle;
    VALUE lib, flag;
    char  *clib;
    int   cflag;
    const char *err;

    switch( rb_scan_args(argc, argv, "02", &lib, &flag) ){
      case 0:
	clib = NULL;
	cflag = RTLD_LAZY | RTLD_GLOBAL;
	break;
      case 1:
	clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
	cflag = RTLD_LAZY | RTLD_GLOBAL;
	break;
      case 2:
	clib = NIL_P(lib) ? NULL : StringValuePtr(lib);
	cflag = NUM2INT(flag);
	break;
      default:
	rb_bug("rb_dlhandle_new");
    }

    rb_secure(2);

#if defined(HAVE_WINDOWS_H)
    if( !clib ){
	HANDLE rb_libruby_handle(void);
	ptr = rb_libruby_handle();
    }
    else if( STRCASECMP(clib, "libc") == 0
# ifdef RUBY_COREDLL
	     || STRCASECMP(clib, RUBY_COREDLL) == 0
	     || STRCASECMP(clib, RUBY_COREDLL".dll") == 0
# endif
	){
# ifdef _WIN32_WCE
	ptr = dlopen("coredll.dll", cflag);
# else
	ptr = w32_coredll();
# endif
    }
    else
#endif
	ptr = dlopen(clib, cflag);
#if defined(HAVE_DLERROR)
    if( !ptr && (err = dlerror()) ){
	rb_raise(rb_eDLError, "%s", err);
    }
#else
    if( !ptr ){
	err = dlerror();
	rb_raise(rb_eDLError, "%s", err);
    }
#endif
    TypedData_Get_Struct(self, struct dl_handle, &dlhandle_data_type, dlhandle);
    if( dlhandle->ptr && dlhandle->open && dlhandle->enable_close ){
	dlclose(dlhandle->ptr);
    }
    dlhandle->ptr = ptr;
    dlhandle->open = 1;
    dlhandle->enable_close = 0;

    if( rb_block_given_p() ){
	rb_ensure(rb_yield, self, rb_dlhandle_close, self);
    }

    return Qnil;
}
开发者ID:qnighy,项目名称:ruby-1.9.2p0,代码行数:80,代码来源:handle.c

示例2: spec_s_open


//.........这里部分代码省略.........
#elif RPM_VERSION_CODE < RPM_VERSION(5,0,0)
	if (RPM_SPEC(spec)->buildRoot) {
		return rb_str_new2(RPM_SPEC(spec)->buildRoot);
	}
#else
	const char *buildRootURL = rpmGenPath(RPM_SPEC(spec)->rootURL, "%{?buildroot}", NULL);
	VALUE result = rb_str_new2(buildRootURL);
	buildRootURL = _free(buildRootURL);
	return result;
#endif
	return Qnil;
}

/*
 * @return [String] Return Build subdirectory defined in the spec file
 */
VALUE
rpm_spec_get_buildsubdir(VALUE spec)
{
	if (RPM_SPEC(spec)->buildSubdir) {
		return rb_str_new2(RPM_SPEC(spec)->buildSubdir);
	}
	return Qnil;
}

/*
 * @return [Array<String>] Return Build architectures defined in the spec file
 */
VALUE
rpm_spec_get_buildarchs(VALUE spec)
{
	VALUE ba = rb_ivar_get(spec, id_ba);

	if (NIL_P(ba)) {
		register int i;
		ba = rb_ary_new();
		for (i = 0; i < RPM_SPEC(spec)->BACount; i++) {
			rb_ary_push(ba, rb_str_new2(RPM_SPEC(spec)->BANames[i]));
		}
		rb_ivar_set(spec, id_ba, ba);
	}

	return ba;
}

/*
 * @return [Array<RPM::Require>] Return Build requires defined in the spec file
 */
VALUE
rpm_spec_get_buildrequires(VALUE spec)
{
	VALUE br = rb_ivar_get(spec, id_br);

#if RPM_VERSION_CODE < RPM_VERSION(4,6,0) || RPM_VERSION_CODE >= RPM_VERSION(5,0,0)
	if (NIL_P(br)) {
		const char** names;
		const char** vers;
		int_32* flags;
		int_32 count;
		rpmTagType nt, vt, type;
		register int i;

		br = rb_ary_new();
		if (!headerGetEntryMinMemory(RPM_SPEC(spec)->buildRestrictions,
									 RPMTAG_REQUIRENAME, (hTYP_t)&nt,
									 (hPTR_t*)&names, (hCNT_t)&count)) {
开发者ID:daviddavis,项目名称:rpm.rb,代码行数:67,代码来源:spec.c

示例3: rb_mysql_result_each

static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
  VALUE defaults, opts, block;
  ID db_timezone, app_timezone, dbTz, appTz;
  mysql2_result_wrapper * wrapper;
  unsigned long i;
  int symbolizeKeys = 0, asArray = 0, castBool = 0, cacheRows = 1, cast = 1, streaming = 0;
  MYSQL_FIELD * fields = NULL;

  GetMysql2Result(self, wrapper);

  defaults = rb_iv_get(self, "@query_options");
  if (rb_scan_args(argc, argv, "01&", &opts, &block) == 1) {
    opts = rb_funcall(defaults, intern_merge, 1, opts);
  } else {
    opts = defaults;
  }

  if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue) {
    symbolizeKeys = 1;
  }

  if (rb_hash_aref(opts, sym_as) == sym_array) {
    asArray = 1;
  }

  if (rb_hash_aref(opts, sym_cast_booleans) == Qtrue) {
    castBool = 1;
  }

  if (rb_hash_aref(opts, sym_cache_rows) == Qfalse) {
    cacheRows = 0;
  }

  if (rb_hash_aref(opts, sym_cast) == Qfalse) {
    cast = 0;
  }

  if(rb_hash_aref(opts, sym_stream) == Qtrue) {
    streaming = 1;
  }

  if(streaming && cacheRows) {
    rb_warn("cacheRows is ignored if streaming is true");
  }

  dbTz = rb_hash_aref(opts, sym_database_timezone);
  if (dbTz == sym_local) {
    db_timezone = intern_local;
  } else if (dbTz == sym_utc) {
    db_timezone = intern_utc;
  } else {
    if (!NIL_P(dbTz)) {
      rb_warn(":database_timezone option must be :utc or :local - defaulting to :local");
    }
    db_timezone = intern_local;
  }

  appTz = rb_hash_aref(opts, sym_application_timezone);
  if (appTz == sym_local) {
    app_timezone = intern_local;
  } else if (appTz == sym_utc) {
    app_timezone = intern_utc;
  } else {
    app_timezone = Qnil;
  }

  if (wrapper->lastRowProcessed == 0) {
    if(streaming) {
      // We can't get number of rows if we're streaming,
      // until we've finished fetching all rows
      wrapper->numberOfRows = 0;
      wrapper->rows = rb_ary_new();
    } else {
      wrapper->numberOfRows = mysql_num_rows(wrapper->result);
      if (wrapper->numberOfRows == 0) {
        wrapper->rows = rb_ary_new();
        return wrapper->rows;
      }
      wrapper->rows = rb_ary_new2(wrapper->numberOfRows);
    }
  }

  if (streaming) {
    if(!wrapper->streamingComplete) {
      VALUE row;

      fields = mysql_fetch_fields(wrapper->result);

      do {
        row = rb_mysql_result_fetch_row(self, db_timezone, app_timezone, symbolizeKeys, asArray, castBool, cast, fields);

        if (block != Qnil) {
          rb_yield(row);
          wrapper->lastRowProcessed++;
        }
      } while(row != Qnil);

      rb_mysql_result_free_result(wrapper);

      wrapper->numberOfRows = wrapper->lastRowProcessed;
//.........这里部分代码省略.........
开发者ID:ab,项目名称:mysql2,代码行数:101,代码来源:result.c

示例4: rkadm5_policy_init

/*
 * call-seq:
 *   Kerberos::Kadm5::Policy.new(options)
 *
 * Returns a new policy object using +options+ you choose to pass, where
 * the +options+ argument is a hash. This does NOT actually create the policy
 * object within Kerberos. To do that pass your Policy object to the
 * Kadm5.create_policy method.
 *
 * The possible options are:
 *
 * * name        - the name of the policy (mandatory) 
 * * min_life    - minimum lifetime of a password
 * * max_life    - maximum lifetime of a password
 * * min_length  - minimum length of a password
 * * min_classes - minimum number of character classes allowed in a password
 * * history_num - number of past key kept for a principal
 *
 * If you do not provide a :name then an ArgumentError will be raised.
 */
static VALUE rkadm5_policy_init(VALUE self, VALUE v_options){
  RUBY_KADM5_POLICY* ptr;
  VALUE v_name, v_minlife, v_maxlife, v_minlength;
  VALUE v_minclasses, v_historynum;

  Data_Get_Struct(self, RUBY_KADM5_POLICY, ptr);

  Check_Type(v_options, T_HASH);

  if(RTEST(rb_funcall(v_options, rb_intern("empty?"), 0, 0)))
    rb_raise(rb_eArgError, "no policy options provided");

  v_name       = rb_hash_aref2(v_options, "name");
  v_minlife    = rb_hash_aref2(v_options, "min_life");
  v_maxlife    = rb_hash_aref2(v_options, "max_life");
  v_minlength  = rb_hash_aref2(v_options, "min_length");
  v_minclasses = rb_hash_aref2(v_options, "min_classes");
  v_historynum = rb_hash_aref2(v_options, "history_num");

  if(NIL_P(v_name)){
    rb_raise(rb_eArgError, "name policy option is mandatory");
  }
  else{
    ptr->policy.policy = StringValueCStr(v_name);
    rb_iv_set(self, "@policy", v_name);
  }

  if(!NIL_P(v_minlife)){
    ptr->policy.pw_min_life = NUM2LONG(v_minlife);
    rb_iv_set(self, "@min_life", v_minlife);
  }
  else{
    rb_iv_set(self, "@min_life", Qnil);
  }

  if(!NIL_P(v_maxlife)){
    ptr->policy.pw_max_life = NUM2LONG(v_maxlife);
    rb_iv_set(self, "@max_life", v_maxlife);
  }
  else{
    rb_iv_set(self, "@max_life", Qnil);
  }
  
  if(!NIL_P(v_minlength)){
    ptr->policy.pw_min_length = NUM2LONG(v_minlength);
    rb_iv_set(self, "@min_length", v_minlength);
  }
  else{
    rb_iv_set(self, "@min_length", Qnil);
  }

  if(!NIL_P(v_minclasses)){
    ptr->policy.pw_min_classes = NUM2LONG(v_minclasses);
    rb_iv_set(self, "@min_classes", v_minclasses);
  }
  else{
    rb_iv_set(self, "@min_classes", Qnil);
  }

  if(!NIL_P(v_historynum)){
    ptr->policy.pw_history_num = NUM2LONG(v_historynum);
    rb_iv_set(self, "@history_num", v_historynum);
  }
  else{
    rb_iv_set(self, "@history_num", Qnil);
  }

  return self;
}
开发者ID:domcleal,项目名称:rkerberos,代码行数:89,代码来源:policy.c

示例5: ossl_ocspbres_add_status

static VALUE
ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
			 VALUE reason, VALUE revtime,
			 VALUE thisupd, VALUE nextupd, VALUE ext)
{
    OCSP_BASICRESP *bs;
    OCSP_SINGLERESP *single;
    OCSP_CERTID *id;
    int st, rsn;
    ASN1_TIME *ths, *nxt, *rev;
    int error, i, rstatus = 0;
    VALUE tmp;

    st = NUM2INT(status);
    rsn = NIL_P(status) ? 0 : NUM2INT(reason);
    if(!NIL_P(ext)){
	/* All ary's members should be X509Extension */
	Check_Type(ext, T_ARRAY);
	for (i = 0; i < RARRAY_LEN(ext); i++)
	    OSSL_Check_Kind(RARRAY_PTR(ext)[i], cX509Ext);
    }

    error = 0;
    ths = nxt = rev = NULL;
    if(!NIL_P(revtime)){
	tmp = rb_protect(rb_Integer, revtime, &rstatus);
	if(rstatus) goto err;
	rev = X509_gmtime_adj(NULL, NUM2INT(tmp));
    }
    tmp = rb_protect(rb_Integer, thisupd, &rstatus);
    if(rstatus) goto err;
    ths = X509_gmtime_adj(NULL, NUM2INT(tmp));
    tmp = rb_protect(rb_Integer, nextupd, &rstatus);
    if(rstatus) goto err;
    nxt = X509_gmtime_adj(NULL, NUM2INT(tmp));

    GetOCSPBasicRes(self, bs);
    SafeGetOCSPCertId(cid, id);
    if(!(single = OCSP_basic_add1_status(bs, id, st, rsn, rev, ths, nxt))){
	error = 1;
	goto err;
    }

    if(!NIL_P(ext)){
	X509_EXTENSION *x509ext;
	sk_X509_EXTENSION_pop_free(single->singleExtensions, X509_EXTENSION_free);
	single->singleExtensions = NULL;
	for(i = 0; i < RARRAY_LEN(ext); i++){
	    x509ext = DupX509ExtPtr(RARRAY_PTR(ext)[i]);
	    if(!OCSP_SINGLERESP_add_ext(single, x509ext, -1)){
		X509_EXTENSION_free(x509ext);
		error = 1;
		goto err;
	    }
	    X509_EXTENSION_free(x509ext);
	}
    }

 err:
    ASN1_TIME_free(ths);
    ASN1_TIME_free(nxt);
    ASN1_TIME_free(rev);
    if(error) ossl_raise(eOCSPError, NULL);
    if(rstatus) rb_jump_tag(rstatus);

    return self;
}
开发者ID:4nkh,项目名称:rhodes,代码行数:67,代码来源:ossl_ocsp.c

示例6: rb_gsl_function_eval

/*
 * Calculates a function at x, and returns the rusult.
 */
static VALUE rb_gsl_function_eval(VALUE obj, VALUE x)
{
  gsl_function *F = NULL;
  VALUE ary, proc, params, result, arynew, x2;
  gsl_vector *v = NULL, *vnew = NULL;
  gsl_matrix *m = NULL, *mnew = NULL;
  size_t i, j, n;
#ifdef HAVE_NARRAY_H
  double *ptr1, *ptr2;
  struct NARRAY *na;
#endif
  Data_Get_Struct(obj, gsl_function, F);
  ary = (VALUE) F->params;
  proc = rb_ary_entry(ary, 0);
  params = rb_ary_entry(ary, 1);
  if (CLASS_OF(x) == rb_cRange) x = rb_gsl_range2ary(x);
  switch (TYPE(x)) {
  case T_FIXNUM:
  case T_BIGNUM:
  case T_FLOAT:
    if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x);
    else result = rb_funcall(proc, RBGSL_ID_call, 2, x, params);
    return result;
    break;
  case T_ARRAY:
    n = RARRAY(x)->len;
    arynew = rb_ary_new2(n);
    for (i = 0; i < n; i++) {
      x2 = rb_ary_entry(x, i);
      Need_Float(x2);
      if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
      else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
      rb_ary_store(arynew, i, result);
    }
    return arynew;
    break;
  default:
#ifdef HAVE_NARRAY_H
    if (NA_IsNArray(x)) {
      GetNArray(x, na);
      ptr1 = (double *) na->ptr;
      n = na->total;
      ary = na_make_object(NA_DFLOAT, na->rank, na->shape, CLASS_OF(x));
      ptr2 = NA_PTR_TYPE(ary, double*);
      for (i = 0; i < n; i++) {
	x2 = rb_float_new(ptr1[i]);
	if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
	else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
	ptr2[i] = NUM2DBL(result);
      }
      return ary;
    }
#endif
    if (VECTOR_P(x)) {
      Data_Get_Struct(x, gsl_vector, v);
      vnew = gsl_vector_alloc(v->size);
      for (i = 0; i < v->size; i++) {
	x2 = rb_float_new(gsl_vector_get(v, i));
	if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
	else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
	gsl_vector_set(vnew, i, NUM2DBL(result));
      }
      return Data_Wrap_Struct(cgsl_vector, 0, gsl_vector_free, vnew);
    } else if (MATRIX_P(x)) {
      Data_Get_Struct(x, gsl_matrix, m);
      mnew = gsl_matrix_alloc(m->size1, m->size2);
      for (i = 0; i < m->size1; i++) {
	for (j = 0; j < m->size2; j++) {
	  x2 = rb_float_new(gsl_matrix_get(m, i, j));
	  if (NIL_P(params)) result = rb_funcall(proc, RBGSL_ID_call, 1, x2);
	  else result = rb_funcall(proc, RBGSL_ID_call, 2, x2, params);
	  gsl_matrix_set(mnew, i, j, NUM2DBL(result));
	}
      }
      return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, mnew);
    } else {
      rb_raise(rb_eTypeError, "wrong argument type");
    }
    break;
  }
  /* never reach here */
  return Qnil;
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:86,代码来源:function.c

示例7: read_anything

static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {
  VALUE result = Qnil;

  if (ttype == TTYPE_BOOL) {
    result = default_read_bool(protocol);
  } else if (ttype == TTYPE_BYTE) {
    result = default_read_byte(protocol);
  } else if (ttype == TTYPE_I16) {
    result = default_read_i16(protocol);
  } else if (ttype == TTYPE_I32) {
    result = default_read_i32(protocol);
  } else if (ttype == TTYPE_I64) {
    result = default_read_i64(protocol);
  } else if (ttype == TTYPE_STRING) {
    result = default_read_string(protocol);
  } else if (ttype == TTYPE_DOUBLE) {
    result = default_read_double(protocol);
  } else if (ttype == TTYPE_STRUCT) {
    VALUE klass = rb_hash_aref(field_info, class_sym);
    result = rb_class_new_instance(0, NULL, klass);

    if (rb_obj_is_kind_of(result, thrift_union_class)) {
      rb_thrift_union_read(result, protocol);
    } else {
      rb_thrift_struct_read(result, protocol);
    }
  } else if (ttype == TTYPE_MAP) {
    int i;

    VALUE map_header = default_read_map_begin(protocol);
    int key_ttype = FIX2INT(rb_ary_entry(map_header, 0));
    int value_ttype = FIX2INT(rb_ary_entry(map_header, 1));
    int num_entries = FIX2INT(rb_ary_entry(map_header, 2));

    // Check the declared key and value types against the expected ones and skip the map contents
    // if the types don't match.
    VALUE key_info = rb_hash_aref(field_info, key_sym);
    VALUE value_info = rb_hash_aref(field_info, value_sym);

    if (!NIL_P(key_info) && !NIL_P(value_info)) {
      int specified_key_type = FIX2INT(rb_hash_aref(key_info, type_sym));
      int specified_value_type = FIX2INT(rb_hash_aref(value_info, type_sym));
      if (num_entries == 0 || (specified_key_type == key_ttype && specified_value_type == value_ttype)) {
        result = rb_hash_new();

        for (i = 0; i < num_entries; ++i) {
          VALUE key, val;

          key = read_anything(protocol, key_ttype, key_info);
          val = read_anything(protocol, value_ttype, value_info);

          rb_hash_aset(result, key, val);
        }
      } else {
        skip_map_contents(protocol, INT2FIX(key_ttype), INT2FIX(value_ttype), num_entries);
      }
    } else {
      skip_map_contents(protocol, INT2FIX(key_ttype), INT2FIX(value_ttype), num_entries);
    }

    default_read_map_end(protocol);
  } else if (ttype == TTYPE_LIST) {
    int i;

    VALUE list_header = default_read_list_begin(protocol);
    int element_ttype = FIX2INT(rb_ary_entry(list_header, 0));
    int num_elements = FIX2INT(rb_ary_entry(list_header, 1));

    // Check the declared element type against the expected one and skip the list contents
    // if the types don't match.
    VALUE element_info = rb_hash_aref(field_info, element_sym);
    if (!NIL_P(element_info)) {
      int specified_element_type = FIX2INT(rb_hash_aref(element_info, type_sym));
      if (specified_element_type == element_ttype) {
        result = rb_ary_new2(num_elements);

        for (i = 0; i < num_elements; ++i) {
          rb_ary_push(result, read_anything(protocol, element_ttype, rb_hash_aref(field_info, element_sym)));
        }
      } else {
        skip_list_or_set_contents(protocol, INT2FIX(element_ttype), num_elements);
      }
    } else {
      skip_list_or_set_contents(protocol, INT2FIX(element_ttype), num_elements);
    }

    default_read_list_end(protocol);
  } else if (ttype == TTYPE_SET) {
    VALUE items;
    int i;

    VALUE set_header = default_read_set_begin(protocol);
    int element_ttype = FIX2INT(rb_ary_entry(set_header, 0));
    int num_elements = FIX2INT(rb_ary_entry(set_header, 1));

    // Check the declared element type against the expected one and skip the set contents
    // if the types don't match.
    VALUE element_info = rb_hash_aref(field_info, element_sym);
    if (!NIL_P(element_info)) {
      int specified_element_type = FIX2INT(rb_hash_aref(element_info, type_sym));
//.........这里部分代码省略.........
开发者ID:AnnapurnaVemuri,项目名称:thrift,代码行数:101,代码来源:struct.c

示例8: shoes_hash_int

int shoes_hash_int(VALUE hsh, ID key, int dn) {
    VALUE v = shoes_hash_get(hsh, key);
    if (!NIL_P(v)) return NUM2INT(v);
    return dn;
}
开发者ID:Shoes3,项目名称:shoes3,代码行数:5,代码来源:ruby.c

示例9: shoes_hash_dbl

double shoes_hash_dbl(VALUE hsh, ID key, double dn) {
    VALUE v = shoes_hash_get(hsh, key);
    if (!NIL_P(v)) return NUM2DBL(v);
    return dn;
}
开发者ID:Shoes3,项目名称:shoes3,代码行数:5,代码来源:ruby.c

示例10: rb_str_format


//.........这里部分代码省略.........

	    prec = 0;
	    p++;
	    if (*p == '*') {
		GETASTER(prec);
		if (prec < 0) {	/* ignore negative precision */
		    flags &= ~FPREC;
		}
		p++;
		goto retry;
	    }

	    GETNUM(prec, precision);
	    goto retry;

	  case '\n':
	  case '\0':
	    p--;
	  case '%':
	    if (flags != FNONE) {
		rb_raise(rb_eArgError, "invalid format character - %%");
	    }
	    PUSH("%", 1);
	    break;

	  case 'c':
	    {
		VALUE val = GETARG();
		VALUE tmp;
		unsigned int c;
		int n;

		tmp = rb_check_string_type(val);
		if (!NIL_P(tmp)) {
		    if (rb_enc_strlen(RSTRING_PTR(tmp),RSTRING_END(tmp),enc) != 1) {
			rb_raise(rb_eArgError, "%%c requires a character");
		    }
		    c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
		}
		else {
		    c = NUM2INT(val);
		    n = rb_enc_codelen(c, enc);
		}
		if (n <= 0) {
		    rb_raise(rb_eArgError, "invalid character");
		}
		if (!(flags & FWIDTH)) {
		    CHECK(n);
		    rb_enc_mbcput(c, &buf[blen], enc);
		    blen += n;
		}
		else if ((flags & FMINUS)) {
		    CHECK(n);
		    rb_enc_mbcput(c, &buf[blen], enc);
		    blen += n;
		    FILL(' ', width-1);
		}
		else {
		    FILL(' ', width-1);
		    CHECK(n);
		    rb_enc_mbcput(c, &buf[blen], enc);
		    blen += n;
		}
	    }
	    break;
开发者ID:agrimm,项目名称:ruby-benchmark-suite,代码行数:66,代码来源:sprintf.c

示例11: shoes_hash_set

VALUE shoes_hash_set(VALUE hsh, ID key, VALUE val) {
    if (NIL_P(hsh))
        hsh = rb_hash_new();
    rb_hash_aset(hsh, ID2SYM(key), val);
    return hsh;
}
开发者ID:Shoes3,项目名称:shoes3,代码行数:6,代码来源:ruby.c

示例12: rbgobj_rvalue_to_gvalue

void
rbgobj_rvalue_to_gvalue(VALUE val, GValue* result)
{
    GType type, fundamental_type;

    type = G_VALUE_TYPE(result);
    if (rbgobj_convert_rvalue2gvalue(type, val, result))
        return;

    fundamental_type = G_TYPE_FUNDAMENTAL(type);
    switch (fundamental_type) {
      case G_TYPE_NONE:
        return;
      case G_TYPE_CHAR:
        g_value_set_char(result, NUM2INT(val));
        return;
      case G_TYPE_UCHAR:
        g_value_set_uchar(result, NUM2UINT(val));
        return;
      case G_TYPE_BOOLEAN:
        g_value_set_boolean(result, RVAL2CBOOL(val));
        return;
      case G_TYPE_INT:
        g_value_set_int(result, NUM2INT(val));
        return;
      case G_TYPE_UINT:
        g_value_set_uint(result, NUM2UINT(val));
        return;
      case G_TYPE_LONG:
        g_value_set_long(result, NUM2LONG(val));
        return;
      case G_TYPE_ULONG:
        g_value_set_ulong(result, NUM2ULONG(val));
        return;
      case G_TYPE_INT64:
        g_value_set_int64(result, rbglib_num_to_int64(val));
        return;
      case G_TYPE_UINT64:
        g_value_set_uint64(result, rbglib_num_to_uint64(val));
        return;
      case G_TYPE_ENUM:
        g_value_set_enum(result, rbgobj_get_enum(val, G_VALUE_TYPE(result)));
        return;
      case G_TYPE_FLAGS:
        g_value_set_flags(result, rbgobj_get_flags(val, G_VALUE_TYPE(result)));
        return;
      case G_TYPE_FLOAT:
        g_value_set_float(result, NUM2DBL(val));
        return;
      case G_TYPE_DOUBLE:
        g_value_set_double(result, NUM2DBL(val));
        return;
      case G_TYPE_STRING:
        {
            if (SYMBOL_P(val))
                val = rb_funcall(val, id_to_s, 0);
            g_value_set_string(result, RVAL2CSTR_ACCEPT_NIL(val));
            return;
        }
      case G_TYPE_OBJECT:
      case G_TYPE_INTERFACE:
        g_value_set_object(result, NIL_P(val) ? NULL : RVAL2GOBJ(val));
        return;
      case G_TYPE_PARAM:
        g_value_set_param(result, NIL_P(val) ? NULL : RVAL2GOBJ(val));
        return;
      case G_TYPE_POINTER:
        g_value_set_pointer(result, NIL_P(val) ? NULL : rbgobj_ptr2cptr(val));
        return;
      case G_TYPE_BOXED:
        {
            GType gtype;
            for (gtype = type;
                 gtype != G_TYPE_INVALID;
                 gtype = g_type_parent(gtype))
            {
                RValueToGValueFunc func =
                    g_type_get_qdata(gtype, qRValueToGValueFunc);
                if (!func)
                    continue;
                func(val, result);
                return;
            }
        }

      default:
        if (!rbgobj_convert_rvalue2gvalue(fundamental_type, val, result)) {
            RValueToGValueFunc func =
                g_type_get_qdata(type, qRValueToGValueFunc);
            if (!func){
                g_warning("rbgobj_rvalue_to_gvalue: unsupported type: %s\n",
                          g_type_name(type));
            } else {
                func(val, result);
            }
        }
    }
}
开发者ID:Mazwak,项目名称:ruby-gnome2,代码行数:98,代码来源:rbgobj_value.c

示例13: default_to_zero

double default_to_zero(VALUE value) {
  if (NIL_P(value)) return 0;
  return NUM2DBL(value);
}
开发者ID:fmd,项目名称:national_grid,代码行数:4,代码来源:common.c

示例14: rb_mysql_result_each

static VALUE rb_mysql_result_each(int argc, VALUE * argv, VALUE self) {
    VALUE defaults, opts, block;
    ID db_timezone, app_timezone, dbTz, appTz;
    mysql2_result_wrapper * wrapper;
    unsigned long i;
    int symbolizeKeys = 0, asArray = 0, castBool = 0;

    GetMysql2Result(self, wrapper);

    defaults = rb_iv_get(self, "@query_options");
    if (rb_scan_args(argc, argv, "01&", &opts, &block) == 1) {
        opts = rb_funcall(defaults, intern_merge, 1, opts);
    } else {
        opts = defaults;
    }

    if (rb_hash_aref(opts, sym_symbolize_keys) == Qtrue) {
        symbolizeKeys = 1;
    }

    if (rb_hash_aref(opts, sym_as) == sym_array) {
        asArray = 1;
    }

    if (rb_hash_aref(opts, sym_cast_booleans) == Qtrue) {
        castBool = 1;
    }

    dbTz = rb_hash_aref(opts, sym_database_timezone);
    if (dbTz == sym_local) {
        db_timezone = intern_local;
    } else if (dbTz == sym_utc) {
        db_timezone = intern_utc;
    } else {
        if (!NIL_P(dbTz)) {
            rb_warn(":database_timezone option must be :utc or :local - defaulting to :local");
        }
        db_timezone = intern_local;
    }

    appTz = rb_hash_aref(opts, sym_application_timezone);
    if (appTz == sym_local) {
        app_timezone = intern_local;
    } else if (appTz == sym_utc) {
        app_timezone = intern_utc;
    } else {
        app_timezone = intern_local;
    }

    if (wrapper->lastRowProcessed == 0) {
        wrapper->numberOfRows = mysql_num_rows(wrapper->result);
        if (wrapper->numberOfRows == 0) {
            wrapper->rows = rb_ary_new();
            return wrapper->rows;
        }
        wrapper->rows = rb_ary_new2(wrapper->numberOfRows);
    }

    if (wrapper->lastRowProcessed == wrapper->numberOfRows) {
        // we've already read the entire dataset from the C result into our
        // internal array. Lets hand that over to the user since it's ready to go
        for (i = 0; i < wrapper->numberOfRows; i++) {
            rb_yield(rb_ary_entry(wrapper->rows, i));
        }
    } else {
        unsigned long rowsProcessed = 0;
        rowsProcessed = RARRAY_LEN(wrapper->rows);
        for (i = 0; i < wrapper->numberOfRows; i++) {
            VALUE row;
            if (i < rowsProcessed) {
                row = rb_ary_entry(wrapper->rows, i);
            } else {
                row = rb_mysql_result_fetch_row(self, db_timezone, app_timezone, symbolizeKeys, asArray, castBool);
                rb_ary_store(wrapper->rows, i, row);
                wrapper->lastRowProcessed++;
            }

            if (row == Qnil) {
                // we don't need the mysql C dataset around anymore, peace it
                rb_mysql_result_free_result(wrapper);
                return Qnil;
            }

            if (block != Qnil) {
                rb_yield(row);
            }
        }
        if (wrapper->lastRowProcessed == wrapper->numberOfRows) {
            // we don't need the mysql C dataset around anymore, peace it
            rb_mysql_result_free_result(wrapper);
        }
    }

    return wrapper->rows;
}
开发者ID:methodmissing,项目名称:mysql2,代码行数:95,代码来源:result.c

示例15: shoes_hash_cstr

char * shoes_hash_cstr(VALUE hsh, ID key, char *dn) {
    VALUE v = shoes_hash_get(hsh, key);
    if (!NIL_P(v)) return RSTRING_PTR(v);
    return dn;
}
开发者ID:Shoes3,项目名称:shoes3,代码行数:5,代码来源:ruby.c


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