static VALUE rb_writev(VALUE io, VALUE list) { rb_io_t * fptr; struct iovec * iov; long i; ssize_t written; VALUE tmp; Check_Type(list, T_ARRAY); #ifdef IOV_MAX if(RARRAY_LEN(list) > IOV_MAX) #else if(RARRAY_LEN(list) > NUM2INT(rb_IOV_MAX)) #endif rb_raise(rb_eArgError, "list is too long"); tmp = rb_io_check_io(io); GetOpenFile(tmp, fptr); rb_io_check_writable(fptr); iov = xcalloc(RARRAY_LEN(list), sizeof(struct iovec)); for(i = 0; i < RARRAY_LEN(list); i++) { VALUE string = rb_ary_entry(list, i); iov[i].iov_base = StringValuePtr(string); iov[i].iov_len = RSTRING_LEN(string); } written = writev(fptr->fd, iov, (int)RARRAY_LEN(list)); xfree(iov); if (written == -1) rb_sys_fail_path(fptr->pathv); return LONG2FIX(written); }
static VALUE stackprof_results(int argc, VALUE *argv, VALUE self) { VALUE results, frames; if (!_stackprof.frames || _stackprof.running) return Qnil; results = rb_hash_new(); rb_hash_aset(results, sym_version, DBL2NUM(1.1)); rb_hash_aset(results, sym_mode, _stackprof.mode); rb_hash_aset(results, sym_interval, _stackprof.interval); rb_hash_aset(results, sym_samples, SIZET2NUM(_stackprof.overall_samples)); rb_hash_aset(results, sym_gc_samples, SIZET2NUM(_stackprof.during_gc)); rb_hash_aset(results, sym_missed_samples, SIZET2NUM(_stackprof.overall_signals - _stackprof.overall_samples)); frames = rb_hash_new(); rb_hash_aset(results, sym_frames, frames); st_foreach(_stackprof.frames, frame_i, (st_data_t)frames); st_free_table(_stackprof.frames); _stackprof.frames = NULL; if (_stackprof.raw && _stackprof.raw_samples_len) { size_t len, n, o; VALUE raw_samples = rb_ary_new_capa(_stackprof.raw_samples_len); for (n = 0; n < _stackprof.raw_samples_len; n++) { len = (size_t)_stackprof.raw_samples[n]; rb_ary_push(raw_samples, SIZET2NUM(len)); for (o = 0, n++; o < len; n++, o++) rb_ary_push(raw_samples, rb_obj_id(_stackprof.raw_samples[n])); rb_ary_push(raw_samples, SIZET2NUM((size_t)_stackprof.raw_samples[n])); } free(_stackprof.raw_samples); _stackprof.raw_samples = NULL; _stackprof.raw_samples_len = 0; _stackprof.raw_samples_capa = 0; _stackprof.raw_sample_index = 0; _stackprof.raw = 0; rb_hash_aset(results, sym_raw, raw_samples); } if (argc == 1) _stackprof.out = argv[0]; if (RTEST(_stackprof.out)) { VALUE file; if (RB_TYPE_P(_stackprof.out, T_STRING)) { file = rb_file_open_str(_stackprof.out, "w"); } else { file = rb_io_check_io(_stackprof.out); } rb_marshal_dump(results, file); rb_io_flush(file); _stackprof.out = Qnil; return file; } else { return results; } }