static VALUE process_times(VALUE self) { struct rusage usage; unsigned long long utime, stime; if (getrusage(RUSAGE_SELF, &usage) == -1) { rb_sys_fail("getrusage()"); } utime = (unsigned long long) usage.ru_utime.tv_sec * 1000000 + usage.ru_utime.tv_usec; stime = (unsigned long long) usage.ru_stime.tv_sec * 1000000 + usage.ru_stime.tv_usec; return rb_struct_new(S_ProcessTimes, rb_ull2inum(utime), rb_ull2inum(stime)); }
/* Extern: rm_progress_monitor Purpose: SetImage(Info)ProgressMonitor exit Notes: ImageMagick's "tag" argument is unused. We pass along the method name instead. */ MagickBooleanType rm_progress_monitor( const char *tag, const MagickOffsetType of, const MagickSizeType sp, void *client_data) { volatile VALUE rval; volatile VALUE method, offset, span; tag = tag; // defeat gcc message #if defined(HAVE_LONG_LONG) // defined in Ruby's defines.h offset = rb_ll2inum(of); span = rb_ull2inum(sp); #else offset = rb_int2big((long)of); span = rb_uint2big((unsigned long)sp); #endif method = rb_str_new2(rb_id2name(THIS_FUNC())); rval = rb_funcall((VALUE)client_data, rm_ID_call, 3, method, offset, span); return RTEST(rval) ? MagickTrue : MagickFalse; }
static VALUE Download_total_size(VALUE self) { VALUE __p_retval = Qnil; WebKitDownload *_self = ((WebKitDownload*)RVAL2GOBJ(self)); #line 239 "/home/geoff/Projects/gtk-webkit-ruby/ext/webkit/webkit.cr" do { __p_retval = rb_ull2inum(webkit_download_get_total_size(_self)); goto out; } while(0); out: return __p_retval; }
static VALUE parse_date_time(const char *date) { VALUE ajd, offset; int year, month, day, hour, min, sec, usec, hour_offset, minute_offset; int jd; do_int64 num, den; long int gmt_offset; int is_dst; time_t rawtime; struct tm * timeinfo; int tokens_read, max_tokens; if (0 != strchr(date, '.')) { // This is a datetime with sub-second precision tokens_read = sscanf(date, "%4d-%2d-%2d %2d:%2d:%2d.%d%3d:%2d", &year, &month, &day, &hour, &min, &sec, &usec, &hour_offset, &minute_offset); max_tokens = 9; } else { // This is a datetime second precision tokens_read = sscanf(date, "%4d-%2d-%2d %2d:%2d:%2d%3d:%2d", &year, &month, &day, &hour, &min, &sec, &hour_offset, &minute_offset); max_tokens = 8; } if (max_tokens == tokens_read) { // We read the Date, Time, and Timezone info minute_offset *= hour_offset < 0 ? -1 : 1; } else if ((max_tokens - 1) == tokens_read) { // We read the Date and Time, but no Minute Offset minute_offset = 0; } else if (tokens_read == 3 || tokens_read >= (max_tokens - 3)) { if (tokens_read == 3) { hour = 0; min = 0; hour_offset = 0; minute_offset = 0; sec = 0; } // We read the Date and Time, default to the current locale's offset // Get localtime time(&rawtime); timeinfo = localtime(&rawtime); is_dst = timeinfo->tm_isdst * 3600; // Reset to GM Time timeinfo = gmtime(&rawtime); gmt_offset = mktime(timeinfo) - rawtime; if ( is_dst > 0 ) gmt_offset -= is_dst; hour_offset = -(gmt_offset / 3600); minute_offset = -(gmt_offset % 3600 / 60); } else { // Something went terribly wrong rb_raise(eDataError, "Couldn't parse date: %s", date); } jd = jd_from_date(year, month, day); // Generate ajd with fractional days for the time // Extracted from Date#jd_to_ajd, Date#day_fraction_to_time, and Rational#+ and #- num = (hour * 1440) + (min * 24); // Modify the numerator so when we apply the timezone everything works out num -= (hour_offset * 1440) + (minute_offset * 24); den = (24 * 1440); reduce(&num, &den); num = (num * 86400) + (sec * den); den = den * 86400; reduce(&num, &den); num = (jd * den) + num; num = num * 2; num = num - den; den = den * 2; reduce(&num, &den); ajd = rb_funcall(rb_mKernel, ID_RATIONAL, 2, rb_ull2inum(num), rb_ull2inum(den)); offset = timezone_to_offset(hour_offset, minute_offset); return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161)); }
void callback(ffi_cif *cif, void *resp, void **args, void *ctx) { VALUE self = (VALUE)ctx; VALUE rbargs = rb_iv_get(self, "@args"); VALUE ctype = rb_iv_get(self, "@ctype"); int argc = RARRAY_LENINT(rbargs); VALUE *params = xcalloc(argc, sizeof(VALUE *)); VALUE ret; VALUE cPointer; int i, type; cPointer = rb_const_get(mFiddle, rb_intern("Pointer")); for (i = 0; i < argc; i++) { type = NUM2INT(RARRAY_PTR(rbargs)[i]); switch (type) { case TYPE_VOID: argc = 0; break; case TYPE_INT: params[i] = INT2NUM(*(int *)args[i]); break; case TYPE_VOIDP: params[i] = rb_funcall(cPointer, rb_intern("[]"), 1, PTR2NUM(*(void **)args[i])); break; case TYPE_LONG: params[i] = LONG2NUM(*(long *)args[i]); break; case TYPE_CHAR: params[i] = INT2NUM(*(char *)args[i]); break; case TYPE_DOUBLE: params[i] = rb_float_new(*(double *)args[i]); break; case TYPE_FLOAT: params[i] = rb_float_new(*(float *)args[i]); break; #if HAVE_LONG_LONG case TYPE_LONG_LONG: params[i] = rb_ull2inum(*(unsigned LONG_LONG *)args[i]); break; #endif default: rb_raise(rb_eRuntimeError, "closure args: %d", type); } } ret = rb_funcall2(self, rb_intern("call"), argc, params); type = NUM2INT(ctype); switch (type) { case TYPE_VOID: break; case TYPE_LONG: *(long *)resp = NUM2LONG(ret); break; case TYPE_CHAR: *(char *)resp = NUM2INT(ret); break; case TYPE_VOIDP: *(void **)resp = NUM2PTR(ret); break; case TYPE_INT: *(int *)resp = NUM2INT(ret); break; case TYPE_DOUBLE: *(double *)resp = NUM2DBL(ret); break; case TYPE_FLOAT: *(float *)resp = (float)NUM2DBL(ret); break; #if HAVE_LONG_LONG case TYPE_LONG_LONG: *(unsigned LONG_LONG *)resp = rb_big2ull(ret); break; #endif default: rb_raise(rb_eRuntimeError, "closure retval: %d", type); } xfree(params); }
static inline int template_callback_uint64(unpack_user* u, uint64_t d, VALUE* o) { *o = rb_ull2inum(d); return 0; }
VALUE bpObjectToRuby(const bp::Object * obj, unsigned int tid) { if (obj == NULL) return Qnil; VALUE v = Qnil; switch (obj->type()) { case BPTNull: v = Qnil; break; case BPTBoolean: { if (((bp::Bool *) obj)->value()) v = Qtrue; else v = Qfalse; break; } case BPTInteger: v = rb_ull2inum(((bp::Integer *) obj)->value()); break; case BPTCallBack: { VALUE args[2]; args[0] = rb_uint2inum(tid); args[1] = rb_ull2inum(((bp::Integer *) obj)->value()); v = rb_class_new_instance(2, args, bp_rb_cCallback); break; } case BPTDouble: v = rb_float_new(((bp::Double *) obj)->value()); break; case BPTString: v = rb_str_new2(((bp::String *) obj)->value()); break; case BPTNativePath: { VALUE id = rb_intern("Pathname"); VALUE klass = 0; if (rb_const_defined(rb_cObject, id) && (klass = rb_const_get(rb_cObject, id)) && TYPE(klass) == T_CLASS) { std::string path = convert::toUTF8(((bp::Path *) obj)->value()); VALUE p = rb_str_new2(path.c_str()); v = rb_class_new_instance(1, &p, klass); } break; } case BPTMap: { bp::Map * m = (bp::Map *) obj; v = rb_hash_new(); bp::Map::Iterator i(*m); const char * key; while (NULL != (key = i.nextKey())) { rb_hash_aset(v,ID2SYM(rb_intern(key)), bpObjectToRuby(m->value(key), tid)); } break; } case BPTList: { bp::List * l = (bp::List *) obj; v = rb_ary_new(); unsigned int i; for (i=0; i < l->size(); i++) { rb_ary_push(v, bpObjectToRuby(l->value(i), tid)); } break; } case BPTAny: // invalid break; } return v; }
VALUE MSP::Music::c_music_to_value(Mix_Music* address) { return rb_ull2inum(reinterpret_cast<unsigned long long>(address)); }
static VALUE Unpacker_buffer_read (unpacker_t* ptr) { uint64_t num; switch (*ptr->ch++) { case 'a': // int 4 num = Unpacker_int4(ptr); return INT2FIX(num); case 'b': // int 8 num = Unpacker_int8(ptr); return INT2FIX(num); case 'c': // int 16 num = Unpacker_int16(ptr); return INT2FIX(num); case 'd': // int 32 num = Unpacker_int32(ptr); return LONG2NUM(num); case 'e': // int 64 num = Unpacker_int64(ptr); return rb_ll2inum(num); case 'g': // uint 8 num = Unpacker_uint(ptr, 2); return INT2FIX(num); case 'h': // uint 16 num = Unpacker_uint(ptr, 4); return INT2FIX(num); case 'i': // uint 32 num = Unpacker_uint(ptr, 8); return LONG2NUM(num); case 'j': // uint 64 num = Unpacker_uint(ptr, 16); return rb_ull2inum(num); case 'k': // float 32 return rb_float_new(Unpacker_float(ptr, 8)); case 'l': // float 64 return rb_float_new(Unpacker_float(ptr, 16)); case 'n': // str 8 num = Unpacker_uint(ptr, 2); return Unpacker_str(ptr, num); case 'o': // str 16 num = Unpacker_uint(ptr, 4); return Unpacker_str(ptr, num); case 'p': // str 32 num = Unpacker_uint(ptr, 8); return Unpacker_str(ptr, num); case 'r': // map 4 num = Unpacker_uint(ptr, 1); return Unpacker_map(ptr, num); case 's': // map 8 num = Unpacker_uint(ptr, 2); return Unpacker_map(ptr, num); case 't': // map16 num = Unpacker_uint(ptr, 4); return Unpacker_map(ptr, num); case 'u': // map 32 num = Unpacker_uint(ptr, 8); return Unpacker_map(ptr, num); case 'v': // array 4 num = Unpacker_uint(ptr, 1); return Unpacker_array(ptr, num); case 'w': // array 8 num = Unpacker_uint(ptr, 2); return Unpacker_array(ptr, num); case 'x': // array 16 num = Unpacker_uint(ptr, 4); return Unpacker_array(ptr, num); case 'y': // array 32 num = Unpacker_uint(ptr, 8); return Unpacker_array(ptr, num); // positive fixint case '0': return INT2FIX(0); case '1': return INT2FIX(1); case '2': return INT2FIX(2); case '3': return INT2FIX(3); case '4': return INT2FIX(4); case '5': return INT2FIX(5); case '6': return INT2FIX(6); case '7': return INT2FIX(7); case '8': return INT2FIX(8); case '9': return INT2FIX(9); case 'A': return INT2FIX(10); case 'B': return INT2FIX(11); case 'C': return INT2FIX(12); case 'D': return INT2FIX(13); case 'E': return INT2FIX(14); case 'F': return INT2FIX(15); // fixstr case 'G': return rb_str_new2(""); case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': num = *(ptr->ch - 1) - 'G'; return Unpacker_str(ptr, num); // others case 'W': return Qnil; case 'X': return Qfalse; case 'Y': return Qtrue; } rb_raise(rb_eArgError, "undefined type:%c,data:%s,at:%ld", *(ptr->ch), ptr->buffer, ptr->ch - ptr->buffer); return Qnil; }