//.........这里部分代码省略.........
#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;
}
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));
//.........这里部分代码省略.........
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));
//.........这里部分代码省略.........
请发表评论