static VALUE rb_tinytds_result_do(VALUE self) { GET_RESULT_WRAPPER(self); if (rwrap->client) { rb_tinytds_result_exec_helper(rwrap->client); return LONG2NUM((long)dbcount(rwrap->client)); } else { return Qnil; } }
inline static void call_error(const char *msg, ParseInfo pi, const char* file, int line) { char buf[128]; const char *s = pi->s; int jline = 1; int col = 1; for (; pi->str < s && '\n' != *s; s--) { col++; } for (; pi->str < s; s--) { if ('\n' == *s) { jline++; } } sprintf(buf, "%s at line %d, column %d [%s:%d]", msg, jline, col, file, line); rb_funcall(pi->handler, oj_error_id, 3, rb_str_new2(buf), LONG2NUM(jline), LONG2NUM(col)); }
static VALUE lazy_take_size(VALUE generator, VALUE args, VALUE lazy) { VALUE receiver = lazy_size(lazy); long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(lazy, id_arguments), 0)); if (NIL_P(receiver) || (FIXNUM_P(receiver) && FIX2LONG(receiver) < len)) return receiver; return LONG2NUM(len); }
/* * call-seq: * ctx.session_cache_size -> integer * */ static VALUE ossl_sslctx_get_session_cache_size(VALUE self) { SSL_CTX *ctx; Data_Get_Struct(self, SSL_CTX, ctx); return LONG2NUM(SSL_CTX_sess_get_cache_size(ctx)); }
static VALUE memory_size(VALUE self) { AbstractMemory* ptr; Data_Get_Struct(self, AbstractMemory, ptr); return LONG2NUM(ptr->size); }
/* * call-seq: from_string(s) * @param [String] s string * @return [MemoryPointer] * Create a {MemoryPointer} with +s+ inside. */ static VALUE memptr_s_from_string(VALUE klass, VALUE to_str) { VALUE s = StringValue(to_str); VALUE args[] = { INT2FIX(1), LONG2NUM(RSTRING_LEN(s) + 1), Qfalse }; VALUE obj = rb_class_new_instance(3, args, klass); rb_funcall(obj, rb_intern("put_string"), 2, INT2FIX(0), s); return obj; }
/** * call-seq: * hdfs.capacity -> retval * * Returns the capacity of this HDFS file system in bytes, raising a * DFSException if this was unsuccessful. */ VALUE HDFS_File_System_capacity(VALUE self) { FSData* data = get_FSData(self); long capacity = hdfsGetCapacity(data->fs); if (capacity < 0) { rb_raise(e_dfs_exception, "Error while retrieving capacity: %s", get_error(errno)); return Qnil; } return LONG2NUM(capacity); }
/** * call-seq: * hdfs.default_block_size -> retval * * Returns the default block size of this HDFS file system in bytes, raising a * DFSException if this was unsuccessful. */ VALUE HDFS_File_System_default_block_size(VALUE self) { FSData* data = get_FSData(self); long block_size = hdfsGetDefaultBlockSize(data->fs); if (block_size == -1) { rb_raise(e_dfs_exception, "Error while retrieving default block size: %s", get_error(errno)); return Qnil; } return LONG2NUM(block_size); }
VALUE supplement_rindex_val( VALUE ary, VALUE val) { long i; for (i = RARRAY_LEN( ary); i;) if (rb_equal( RARRAY_PTR( ary)[ --i], val)) return LONG2NUM( i); return Qnil; }
inline static VALUE f_imul(long a, long b) { VALUE r; long c; if (a == 0 || b == 0) return ZERO; else if (a == 1) return LONG2NUM(b); else if (b == 1) return LONG2NUM(a); c = a * b; r = LONG2NUM(c); if (NUM2LONG(r) != c || (c / a) != b) r = rb_big_mul(rb_int2big(a), rb_int2big(b)); return r; }
static VALUE rb_mysql_result_count(VALUE self) { mysql2_result_wrapper *wrapper; GetMysql2Result(self, wrapper); if(wrapper->resultFreed) { return LONG2NUM(RARRAY_LEN(wrapper->rows)); } else { return INT2FIX(mysql_num_rows(wrapper->result)); } }
/** * call-seq: * hdfs.used -> retval * * Returns the bytes currently in use by this filesystem, raising a * DFSException if unsuccessful. */ VALUE HDFS_File_System_used(VALUE self) { FSData* data = get_FSData(self); tOffset used = hdfsGetUsed(data->fs); if (used == -1) { rb_raise(e_dfs_exception, "Error while retrieving used capacity: %s", get_error(errno)); return Qnil; } return LONG2NUM(used); }
VALUE supplement_index_blk( VALUE ary) { long i, j; for (i = 0, j = RARRAY_LEN( ary); j > 0; i++, j--) { if (RTEST( rb_yield( RARRAY_PTR( ary)[ i]))) return LONG2NUM( i); } return Qnil; }
void rb_singleton_class_attached(VALUE klass, VALUE obj) { if (RCLASS_SINGLETON(klass)) { // Weak ref. VALUE wobj = LONG2NUM((long)obj); rb_ivar_set(klass, idAttached, wobj); // FIXME commented for now as it breaks some RubySpecs. //rb_singleton_class_promote_for_gc(klass); } }
static VALUE ossl_x509crl_get_version(VALUE self) { X509_CRL *crl; long ver; GetX509CRL(self, crl); ver = X509_CRL_get_version(crl); return LONG2NUM(ver); }
static VALUE ptrace_getsiginfo(VALUE self) { pid_t pid = get_pid(self); siginfo_t si; void *data_ptr = (void *)&si; long ret; VALUE v; CALL_PTRACE(ret, PT_GETSIGINFO, pid, 0, data_ptr); v = rb_hash_new(); #define SI_SET(name, val) rb_hash_aset(v, ID2SYM(rb_intern("si_" #name)), val) SI_SET(sig, si_signo_symbol(si.si_signo)); SI_SET(signo, INT2NUM(si.si_signo)); SI_SET(errno, INT2NUM(si.si_errno)); SI_SET(code, si_code_symbol(si.si_signo, si.si_code)); SI_SET(codeno, INT2NUM(si.si_code)); switch (si.si_signo) { case SIGKILL: SI_SET(pid, ULONG2NUM(si.si_pid)); SI_SET(uid, ULONG2NUM(si.si_uid)); break; case SIGILL: case SIGFPE: case SIGSEGV: case SIGBUS: SI_SET(addr, ULONG2NUM((unsigned long)si.si_addr)); break; case SIGCHLD: SI_SET(pid, ULONG2NUM(si.si_pid)); SI_SET(uid, ULONG2NUM(si.si_uid)); SI_SET(status, INT2NUM(si.si_status)); SI_SET(utime, ULONG2NUM(si.si_utime)); SI_SET(stime, ULONG2NUM(si.si_stime)); break; case SIGPOLL: SI_SET(band, LONG2NUM(si.si_band)); SI_SET(fd, INT2NUM(si.si_fd)); break; default: /* POSIX.1b signal? */ ; } #undef SI_SET return v; }
/* subColorInstantiate {{{ */ VALUE subColorInstantiate(unsigned long pixel) { VALUE klass = Qnil, color = Qnil; /* Create new instance */ klass = rb_const_get(mod, rb_intern("Color")); color = rb_funcall(klass, rb_intern("new"), 1, LONG2NUM(pixel)); return color; } /* }}} */
/** * call-seq: * hdfs.default_block_size_at_path(path) -> default_block_size * * Returns the default block size at the supplied HDFS path, raising a * DFSException if this was unsuccessful. */ VALUE HDFS_File_System_default_block_size_at_path(VALUE self, VALUE path) { FSData* data = get_FSData(self); long block_size = hdfsGetDefaultBlockSizeAtPath(data->fs, StringValuePtr(path)); if (block_size == -1) { rb_raise(e_dfs_exception, "Error while retrieving default block size at path %s: %s", StringValuePtr(path), get_error(errno)); return Qnil; } return LONG2NUM(block_size); }
VALUE supplement_rindex_blk( VALUE ary) { long i; for (i = RARRAY_LEN( ary); i;) { --i; if (RTEST( rb_yield( RARRAY_PTR( ary)[ i]))) return LONG2NUM( i); } return Qnil; }
static void shift(struct cparse_params *v, long act, VALUE tok, VALUE val) { PUSH(v->vstack, val); if (v->debug) { PUSH(v->tstack, tok); rb_funcall(v->parser, id_d_shift, 3, tok, v->tstack, v->vstack); } v->curstate = act; PUSH(v->state, LONG2NUM(v->curstate)); }
size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length) { if(b->io_buffer == Qnil) { b->io_buffer = rb_str_buf_new(0); } VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, LONG2NUM(length), b->io_buffer); if(ret == Qnil) { return 0; } return RSTRING_LEN(b->io_buffer); }
VALUE rb_ary_each_pair(VALUE array) { long i; volatile VALUE ary = array; RETURN_SIZED_ENUMERATOR(ary, 0, 0, rb_ary_length); for (i=0; i<RARRAY_LEN(ary); i++) { rb_yield(LONG2NUM(i), RARRAY_PTR(ary)[i]); } return ary; }
VALUE oily_png_canvas_resample_nearest_neighbor_bang(VALUE self, VALUE v_new_width, VALUE v_new_height) { long new_width = NUM2LONG(v_new_width); long new_height = NUM2LONG(v_new_height); long self_width = NUM2LONG(rb_funcall(self, rb_intern("width"), 0)); long self_height = NUM2LONG(rb_funcall(self, rb_intern("height"), 0)); VALUE pixels = rb_ary_new2(new_width*new_height); VALUE source = rb_iv_get(self, "@pixels"); long *steps_x = ALLOC_N(long, new_width); long *steps_y = ALLOC_N(long, new_height); oily_png_generate_steps_residues(self_width, new_width, steps_x, NULL); oily_png_generate_steps_residues(self_height, new_height, steps_y, NULL); long index = 0; long x, y; long src_index; for (y=0; y < new_height; y++) { for (x = 0; x < new_width; x++) { src_index = steps_y[y] * self_width + steps_x[x]; VALUE pixel = rb_ary_entry(source, src_index); rb_ary_store(pixels, index, pixel); index++; } } xfree(steps_x); steps_x = NULL; xfree(steps_y); steps_y = NULL; rb_iv_set(self, "@pixels", pixels); rb_iv_set(self, "@width", LONG2NUM(new_width)); rb_iv_set(self, "@height", LONG2NUM(new_height)); return self; }
VALUE subSubtleSingColors(VALUE self) { int i; unsigned long ncolors = 0, *colors = NULL; VALUE meth = Qnil, klass = Qnil, hash = Qnil; const char *names[] = { "title_fg", "title_bg", "title_bo_top", "title_bo_right", "title_bo_bottom", "title_bo_left", "view_fg", "view_bg", "view_bo_top", "view_bo_right", "view_bo_bottom", "view_bo_left", "focus_fg", "focus_bg", "focus_bo_top", "focus_bo_right", "focus_bo_bottom", "focus_bo_left", "urgent_fg", "urgent_bg", "urgent_bo_top", "urgent_bo_right", "urgent_bo_bottom", "urgent_bo_left", "occupied_fg", "occupied_bg", "occupied_bo_top", "occupied_bo_right", "occupied_bo_bottom", "occupied_bo_left", "unoccupied_fg", "unoccupied_bg", "unoccupied_bo_top", "unoccupied_bo_right", "unoccupied_bo_bottom", "unoccupied_bo_left", "sublets_fg", "sublets_bg", "sublets_bo_top", "sublets_bo_right", "sublets_bo_bottom", "sublets_bo_left", "separator_fg", "separator_bg", "separator_bo_top", "separator_bo_right", "separator_bo_bottom", "separator_bo_left", "client_active", "client_inactive", "panel_top", "panel_bottom", "stipple", "background" }; subSubtlextConnect(NULL); ///< Implicit open connection /* Fetch data */ meth = rb_intern("new"); klass = rb_const_get(mod, rb_intern("Color")); hash = rb_hash_new(); /* Check result */ if((colors = (unsigned long *)subSharedPropertyGet(display, DefaultRootWindow(display), XA_CARDINAL, XInternAtom(display, "SUBTLE_COLORS", False), &ncolors))) { for(i = 0; i < ncolors && i < LENGTH(names); i++) { VALUE c = rb_funcall(klass, meth, 1, LONG2NUM(colors[i])); rb_hash_aset(hash, CHAR2SYM(names[i]), c); } free(colors); } return hash; } /* }}} */
static VALUE make_struct(VALUE name, VALUE members, VALUE klass) { VALUE nstr; ID id; long i, count; OBJ_FREEZE(members); if (NIL_P(name)) { nstr = rb_class_new(klass); #if !WITH_OBJC rb_make_metaclass(nstr, RBASIC(klass)->klass); #endif rb_class_inherited(klass, nstr); } else { /* old style: should we warn? */ name = rb_str_to_str(name); id = rb_to_id(name); if (!rb_is_const_id(id)) { rb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name)); } if (rb_const_defined_at(klass, id)) { rb_warn("redefining constant Struct::%s", StringValuePtr(name)); rb_mod_remove_const(klass, ID2SYM(id)); } nstr = rb_define_class_under(klass, rb_id2name(id), klass); } rb_iv_set(nstr, "__size__", LONG2NUM(RARRAY_LEN(members))); rb_iv_set(nstr, "__members__", members); rb_objc_define_method(*(VALUE *)nstr, "alloc", struct_alloc, 0); rb_objc_define_method(*(VALUE *)nstr, "new", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)nstr, "[]", rb_class_new_instance_imp, -1); rb_objc_define_method(*(VALUE *)nstr, "members", rb_struct_s_members_m, 0); for (i = 0, count = RARRAY_LEN(members); i < count; i++) { ID id = SYM2ID(RARRAY_AT(members, i)); if (rb_is_local_id(id) || rb_is_const_id(id)) { if (i < N_REF_FUNC) { rb_objc_define_method(nstr, rb_id2name(id), ref_func[i], 0); } else { rb_objc_define_method(nstr, rb_id2name(id), rb_struct_ref, 0); } rb_objc_define_method(nstr, rb_id2name(rb_id_attrset(id)), rb_struct_set, 1); } } return nstr; }
VALUE wrap_geo_known_position(int argc, VALUE *argv, VALUE self) { int result; VALUE vresult = Qnil; if ((argc < 0) || (argc > 0)) { rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)",argc); goto fail; } result = (int)geo_known_position(); vresult = LONG2NUM((int)(result)); return vresult; fail: return Qnil; }
VALUE rb_rt_read_string(VALUE self, VALUE rb_buf) { rt_ctx *ctx; Check_Type(rb_buf, T_STRING); Data_Get_Struct(self, rt_ctx, ctx); if(ctx->ended) rb_raise(rb_eIOError, "data cannot be added after finalizing"); rt_add(ctx, RSTRING_PTR(rb_buf), RSTRING_LEN(rb_buf)); return LONG2NUM(RSTRING_LEN(rb_buf)); }
VALUE supplement_index_ref( VALUE ary, VALUE ref) { long i, j; if (!id_eqq) id_eqq = rb_intern( "==="); for (i = 0, j = RARRAY_LEN( ary); j > 0; i++, j--) { if (RTEST( rb_funcall( ref, id_eqq, 1, RARRAY_PTR( ary)[ i]))) return LONG2NUM( i); } return Qnil; }
static VALUE lazy_drop_size(VALUE generator, VALUE args, VALUE lazy) { long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(lazy, id_arguments), 0)); VALUE receiver = lazy_size(lazy); if (NIL_P(receiver)) return receiver; if (FIXNUM_P(receiver)) { len = FIX2LONG(receiver) - len; return LONG2FIX(len < 0 ? 0 : len); } return rb_funcall(receiver, '-', 1, LONG2NUM(len)); }
VALUE method_cpu(VALUE self) { VALUE cpus = rb_ary_new(); int cpu_count = system_int("hw.ncpu"); size_t len = sizeof(cpu_time_t) * cpu_count; cpu_time_t * cp_times = ALLOC_N(cpu_time_t, cpu_count); int i; if (sysctlbyname("kern.cp_times", cp_times, &len, NULL, 0) == 0) { for (i = 0; i < cpu_count; i++) { VALUE cpu = rb_hash_new(); cpu_time_t cp_time = cp_times[i]; rb_hash_aset(cpu, SYM_USER, LONG2NUM(cp_time.user)); rb_hash_aset(cpu, SYM_SYSTEM, LONG2NUM(cp_time.system + cp_time.intr)); rb_hash_aset(cpu, SYM_NICE, LONG2NUM(cp_time.nice)); rb_hash_aset(cpu, SYM_IDLE, LONG2NUM(cp_time.idle)); rb_ary_push(cpus, cpu); } } free(cp_times); return cpus; }