• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ NIL_P函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: rb_mysql_result_fetch_row

static VALUE rb_mysql_result_fetch_row(VALUE self, ID db_timezone, ID app_timezone, int symbolizeKeys, int asArray, int castBool) {
    VALUE rowVal;
    mysql2_result_wrapper * wrapper;
    MYSQL_ROW row;
    MYSQL_FIELD * fields = NULL;
    unsigned int i = 0;
    unsigned long * fieldLengths;
    void * ptr;
#ifdef HAVE_RUBY_ENCODING_H
    rb_encoding *default_internal_enc = rb_default_internal_encoding();
    rb_encoding *conn_enc = rb_to_encoding(GET_ENCODING(self));
#endif

    GetMysql2Result(self, wrapper);

    ptr = wrapper->result;
    row = (MYSQL_ROW)rb_thread_blocking_region(nogvl_fetch_row, ptr, RUBY_UBF_IO, 0);
    if (row == NULL) {
        return Qnil;
    }

    if (asArray) {
        rowVal = rb_ary_new2(wrapper->numberOfFields);
    } else {
        rowVal = rb_hash_new();
    }
    fields = mysql_fetch_fields(wrapper->result);
    fieldLengths = mysql_fetch_lengths(wrapper->result);
    if (wrapper->fields == Qnil) {
        wrapper->numberOfFields = mysql_num_fields(wrapper->result);
        wrapper->fields = rb_ary_new2(wrapper->numberOfFields);
    }

    for (i = 0; i < wrapper->numberOfFields; i++) {
        VALUE field = rb_mysql_result_fetch_field(self, i, symbolizeKeys);
        if (row[i]) {
            VALUE val;
            switch(fields[i].type) {
            case MYSQL_TYPE_NULL:       // NULL-type field
                val = Qnil;
                break;
            case MYSQL_TYPE_BIT:        // BIT field (MySQL 5.0.3 and up)
                val = rb_str_new(row[i], fieldLengths[i]);
                break;
            case MYSQL_TYPE_TINY:       // TINYINT field
                if (castBool && fields[i].length == 1) {
                    val = *row[i] == '1' ? Qtrue : Qfalse;
                    break;
                }
            case MYSQL_TYPE_SHORT:      // SMALLINT field
            case MYSQL_TYPE_LONG:       // INTEGER field
            case MYSQL_TYPE_INT24:      // MEDIUMINT field
            case MYSQL_TYPE_LONGLONG:   // BIGINT field
            case MYSQL_TYPE_YEAR:       // YEAR field
                val = rb_cstr2inum(row[i], 10);
                break;
            case MYSQL_TYPE_DECIMAL:    // DECIMAL or NUMERIC field
            case MYSQL_TYPE_NEWDECIMAL: // Precision math DECIMAL or NUMERIC field (MySQL 5.0.3 and up)
                if (strtod(row[i], NULL) == 0.000000) {
                    val = rb_funcall(cBigDecimal, intern_new, 1, opt_decimal_zero);
                } else {
                    val = rb_funcall(cBigDecimal, intern_new, 1, rb_str_new(row[i], fieldLengths[i]));
                }
                break;
            case MYSQL_TYPE_FLOAT:      // FLOAT field
            case MYSQL_TYPE_DOUBLE: {     // DOUBLE or REAL field
                double column_to_double;
                column_to_double = strtod(row[i], NULL);
                if (column_to_double == 0.000000) {
                    val = opt_float_zero;
                } else {
                    val = rb_float_new(column_to_double);
                }
                break;
            }
            case MYSQL_TYPE_TIME: {     // TIME field
                int hour, min, sec, tokens;
                tokens = sscanf(row[i], "%2d:%2d:%2d", &hour, &min, &sec);
                val = rb_funcall(rb_cTime, db_timezone, 6, opt_time_year, opt_time_month, opt_time_month, INT2NUM(hour), INT2NUM(min), INT2NUM(sec));
                if (!NIL_P(app_timezone)) {
                    if (app_timezone == intern_local) {
                        val = rb_funcall(val, intern_localtime, 0);
                    } else { // utc
                        val = rb_funcall(val, intern_utc, 0);
                    }
                }
                break;
            }
            case MYSQL_TYPE_TIMESTAMP:  // TIMESTAMP field
            case MYSQL_TYPE_DATETIME: { // DATETIME field
                int year, month, day, hour, min, sec, tokens;
                tokens = sscanf(row[i], "%4d-%2d-%2d %2d:%2d:%2d", &year, &month, &day, &hour, &min, &sec);
                if (year+month+day+hour+min+sec == 0) {
                    val = Qnil;
                } else {
                    if (month < 1 || day < 1) {
                        rb_raise(cMysql2Error, "Invalid date: %s", row[i]);
                        val = Qnil;
                    } else {
                        val = rb_funcall(rb_cTime, db_timezone, 6, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec));
//.........这里部分代码省略.........
开发者ID:methodmissing,项目名称:mysql2,代码行数:101,代码来源:result.c


示例17: shoes_place_decide

void shoes_place_decide(shoes_place *place, VALUE c, VALUE attr, int dw, int dh, unsigned char rel, int padded) {
    shoes_canvas *canvas = NULL;
    if (!NIL_P(c)) Data_Get_Struct(c, shoes_canvas, canvas);
    VALUE ck = rb_obj_class(c);
    VALUE stuck = ATTR(attr, attach);

    // for image : we want to scale the image, given only one attribute :width or :height
    // get dw and dh, set width or height
    if (REL_FLAGS(rel) & REL_SCALE) {   // 8
        VALUE rw = ATTR(attr, width), rh = ATTR(attr, height);

        if (NIL_P(rw) && !NIL_P(rh)) {          // we have height
            // fetch height in pixels whatever the input (string, float, positive/negative int)
            int spx = shoes_px(rh, dh, CPH(canvas), 1);
            // compute width with image aspect ratio [(dh == dw) means a square ]
            dw = (dh == dw) ? spx : ROUND(((dh * 1.) / dw) * spx);
            dh = spx;                           // now re-init 'dh' for next calculations
            ATTRSET(attr, width, INT2NUM(dw));  // set calculated width
        } else if (NIL_P(rh) && !NIL_P(rw)) {
            int spx = shoes_px(rw, dw, CPW(canvas), 1);
            dh = (dh == dw) ? spx : ROUND(((dh * 1.) / dw) * spx);
            dw = spx;
            ATTRSET(attr, height, INT2NUM(dh));
        }
    }

    ATTR_MARGINS(attr, 0, canvas);
    if (padded || dh == 0) dh += tmargin + bmargin;
    if (padded || dw == 0) dw += lmargin + rmargin;

    int testw = dw;
    if (testw == 0) testw = lmargin + 1 + rmargin;

    if (!NIL_P(stuck)) {
        if (stuck == cShoesWindow)
            rel = REL_FLAGS(rel) | REL_WINDOW;
        else if (stuck == cMouse)
            rel = REL_FLAGS(rel) | REL_CURSOR;
        else
            rel = REL_FLAGS(rel) | REL_STICKY;
    }

    place->flags = rel;
    place->dx = place->dy = 0;
    if (canvas == NULL) {
        place->ix = place->x = 0;
        place->iy = place->y = 0;
        place->iw = place->w = dw;
        place->ih = place->h = dh;
    } else {
        int cx, cy, ox, oy, tw = dw, th = dh;

        switch (REL_COORDS(rel)) {
            case REL_WINDOW:
                cx = 0;
                cy = 0;
                ox = 0;
                oy = canvas->slot->scrolly;
                break;

            case REL_CANVAS:
                cx = canvas->cx - CPX(canvas);
                cy = canvas->cy - CPY(canvas);
                ox = CPX(canvas);
                oy = CPY(canvas);
                break;

            case REL_CURSOR:
                cx = 0;
                cy = 0;
                ox = canvas->app->mousex;
                oy = canvas->app->mousey;
                break;

            case REL_TILE:
                cx = 0;
                cy = 0;
                ox = CPX(canvas);
                oy = CPY(canvas);
                testw = dw = CPW(canvas);
                dh = max(canvas->height, CPH(canvas));
                // Fix #2 ?
                //dh = (max(canvas->height, canvas->fully - CPB(canvas)) - CPY(canvas));
                break;

            default:
                cx = 0;
                cy = 0;
                ox = canvas->cx;
                oy = canvas->cy;
                if ((REL_COORDS(rel) & REL_STICKY) && shoes_is_element(stuck)) {
                    shoes_element *element;
                    Data_Get_Struct(stuck, shoes_element, element);
                    ox = element->place.x;
                    oy = element->place.y;
                }
                break;
        }

        place->w = PX(attr, width, testw, CPW(canvas));
//.........这里部分代码省略.........
开发者ID:Shoes3,项目名称:shoes3,代码行数:101,代码来源:ruby.c


示例18: rb_gsl_function_graph

static VALUE rb_gsl_function_graph(int argc, VALUE *argv, VALUE obj)
{
#ifdef HAVE_GNU_GRAPH
  gsl_function *F = NULL;
  gsl_vector *v = NULL;
  double x, y;
  char opt[256] = "", command[1024];
  size_t i, n;
  int flag = 0;
  FILE *fp = NULL;
  VALUE ary, params, proc;
  switch (argc) {
  case 2:
    Check_Type(argv[1], T_STRING);
    strcpy(opt, STR2CSTR(argv[1]));
    /* no break, do next */
  case 1:
    if (CLASS_OF(argv[0]) == rb_cRange) argv[0] = rb_gsl_range2ary(argv[0]);
    if (TYPE(argv[0]) == T_ARRAY) {
      n = RARRAY(argv[0])->len;
      v = gsl_vector_alloc(n);
      flag = 1;
      for (i = 0; i < n; i++) 
	gsl_vector_set(v, i, NUM2DBL(rb_ary_entry(argv[0], i)));
    } else if (rb_obj_is_kind_of(argv[0], cgsl_vector)) {
      Data_Get_Struct(argv[0], gsl_vector, v);
      n = v->size;
      flag = 0;
    } else {
      rb_raise(rb_eTypeError, 
	       "wrong argument type %s (Array or GSL::Vector expected)", 
	       rb_class2name(CLASS_OF(argv[0])));
    }
    break;
  default:
    rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
    break;
  }
  Data_Get_Struct(obj, gsl_function, F);
  ary = (VALUE) F->params;
  proc = rb_ary_entry(ary, 0);
  params = rb_ary_entry(ary, 1);
  sprintf(command, "graph -T X -g 3 %s", opt);
  fp = popen(command, "w");
  if (fp == NULL)
    rb_raise(rb_eIOError, "GNU graph not found.");
  for (i = 0; i < n; i++) {
    x = gsl_vector_get(v, i);
    if (NIL_P(params)) y = NUM2DBL(rb_funcall(proc, RBGSL_ID_call, 1, rb_float_new(x)));
    else y = NUM2DBL(rb_funcall(proc, RBGSL_ID_call, 2, rb_float_new(x), params));
    fprintf(fp, "%e %e\n", x, y);
  }
  fflush(fp);
 pclose(fp);
  fp = NULL;
  if (flag == 1) gsl_vector_free(v);
  return Qtrue;
#else
  rb_raise(rb_eNoMethodError, "not implemented");
  return Qfalse;
#endif
}
开发者ID:davidrichards,项目名称:rb-gsl,代码行数:62,代码来源:function.c


示例19: new

static VALUE new(int argc, VALUE *argv, VALUE klass)
{
  xmlDocPtr xml_doc;
  xmlNodePtr node;
  VALUE doc;
  VALUE content;
  VALUE rest;
  VALUE rb_node;
  const xmlChar *content_str;
  int content_str_len;

  rb_scan_args(argc, argv, "2*", &doc, &content, &rest);

  Data_Get_Struct(doc, xmlDoc, xml_doc);

  content_str = NIL_P(content) ? NULL : (const xmlChar *)StringValueCStr(content);
  content_str_len = (content_str == NULL) ? 0 : strlen(content_str);

  node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);

  nokogiri_root_node(node);

  rb_node = Nokogiri_wrap_xml_node(klass, node);
  rb_obj_call_init(rb_node, argc, argv);

  if(rb_block_given_p()) { rb_yield(rb_node); }

  return rb_node;
}

VALUE cNokogiriXmlCData;
开发者ID:Alicture,项目名称:Alicture.github.io,代码行数:31,代码来源:xml_cdata.c


示例20: cState_configure

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NIM_SDK_GET_FUNC函数代码示例发布时间:2022-05-30
下一篇:
C++ NILP函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap