VALUE Constant_Traverser_root(VALUE self ){VALUE vals[0]; VALUE it ,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_autovar_4=Qnil,_autovar_5=Qnil,_it=Qnil,_autovar_6=Qnil,__result=Qnil,_autovar_7=Qnil;VALUE bind2=bind_new2(2); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Constant_Traverser__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=rb_funcall(self,sy_Constant_Traverser_src_dot_dup_d768,1,bind2); _autovar_3=it;; cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ptr->src=failobj;ptr->ary=alloca(sizeof(VALUE));ptr->ary[0]=_autovar_3;ptr->len=1; switch(FIX2LONG(rb_hash_aref(switchhash_Constant_Traverser_1,rb_obj_class(ame_curobj2(ptr))))){case 0/*Rule*/:; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_4=it;; break; case 1/*Object*/:; if (1){it=failobj;goto pass1;} break; } goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto fail;} success1: *ptr=oldpass1; it=_autovar_4; _autovar_5=it;; cstruct oldpass2=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_5); bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Constant_Traverser_bind_lb_1_rb__lb__cf87,1,bind2);_autovar_2=bind_aget(bind2,1);;it=rb_funcall(self,sy_Constant_Traverser_src_dot_cfg_eq__15aa,1,bind2);bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Constant_Traverser__at__contex_d6d5,1,bind2);_autovar_2=bind_aget(bind2,1);; it=Constant_Traverser_traverse(self ); if (it==failobj){it=failobj;goto pass2;} _it=it;; bind_aset(bind2,1,_it);it=rb_funcall(self,sy_Constant_Traverser_bind_lb_1_rb__dot__f702,1,bind2);_it=bind_aget(bind2,1);; _autovar_6=it;; goto success2; pass2: *ptr=oldpass2;if (1){it=failobj;goto fail;} success2: *ptr=oldpass2; it=_autovar_6; __result=it;; _autovar_7=it;; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_7);it=rb_funcall(self,sy_Constant_Traverser__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_7=bind_aget(bind2,2);; fail: return it; }
/* * call-seq: * rat == object -> true or false * * Returns true if rat equals object numerically. * * For example: * * Rational(2, 3) == Rational(2, 3) #=> true * Rational(5) == 5 #=> true * Rational(0) == 0.0 #=> true * Rational('1/3') == 0.33 #=> false * Rational('1/2') == '1/2' #=> false */ static VALUE nurat_eqeq_p(VALUE self, SEL sel, VALUE other) { switch (TYPE(other)) { case T_FIXNUM: case T_BIGNUM: { get_dat1(self); if (f_zero_p(dat->num) && f_zero_p(other)) return Qtrue; if (!FIXNUM_P(dat->den)) return Qfalse; if (FIX2LONG(dat->den) != 1) return Qfalse; if (f_eqeq_p(dat->num, other)) return Qtrue; return Qfalse; } case T_FLOAT: return f_eqeq_p(f_to_f(self), other); case T_RATIONAL: { get_dat2(self, other); if (f_zero_p(adat->num) && f_zero_p(bdat->num)) return Qtrue; return f_boolcast(f_eqeq_p(adat->num, bdat->num) && f_eqeq_p(adat->den, bdat->den)); } default: return f_eqeq_p(other, self); } }
/** * Encodes and appends the serialized Ruby object `serializable` to `w` * * Examples of serializable objects include arrays, hashes, strings, numbers * (integers, floats), booleans, and nil. */ void watchman_dump(watchman_t *w, VALUE serializable) { switch (TYPE(serializable)) { case T_ARRAY: return watchman_dump_array(w, serializable); case T_HASH: return watchman_dump_hash(w, serializable); case T_STRING: return watchman_dump_string(w, serializable); case T_FIXNUM: // up to 63 bits return watchman_dump_int(w, FIX2LONG(serializable)); case T_BIGNUM: return watchman_dump_int(w, NUM2LL(serializable)); case T_FLOAT: return watchman_dump_double(w, NUM2DBL(serializable)); case T_TRUE: return watchman_append(w, &watchman_true, sizeof(watchman_true)); case T_FALSE: return watchman_append(w, &watchman_false, sizeof(watchman_false)); case T_NIL: return watchman_append(w, &watchman_nil, sizeof(watchman_nil)); default: rb_raise(rb_eTypeError, "unsupported type"); } }
VALUE Detect_Contextual_Arguments_visit(VALUE self ){VALUE vals[0]; VALUE it ,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,__result=Qnil;VALUE bind2=bind_new2(1); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_1,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar=it;; cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar); it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto pass1;} _autovar_2=it;; bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Detect_Contextual_Arguments__append_lp__6b01,1,bind2);_autovar_2=bind_aget(bind2,1);;it=_autovar_2; _autovar_3=it;; goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto fail;} success1: *ptr=oldpass1; it=_autovar_3; __result=it;; break; case 1/*Object*/:; if (1){it=failobj;goto fail;} break; } fail: return it; }
/** * grpc_rb_time_timeval creates a time_eval from a ruby time object. * * This func is copied from ruby source, MRI/source/time.c, which is published * under the same license as the ruby.h, on which the entire extensions is * based. */ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) { gpr_timespec t; gpr_timespec *time_const; const char *tstr = interval ? "time interval" : "time"; const char *want = " want <secs from epoch>|<Time>|<GRPC::TimeConst.*>"; t.clock_type = GPR_CLOCK_REALTIME; switch (TYPE(time)) { case T_DATA: if (CLASS_OF(time) == grpc_rb_cTimeVal) { TypedData_Get_Struct(time, gpr_timespec, &grpc_rb_timespec_data_type, time_const); t = *time_const; } else if (CLASS_OF(time) == rb_cTime) { t.tv_sec = NUM2INT(rb_funcall(time, id_tv_sec, 0)); t.tv_nsec = NUM2INT(rb_funcall(time, id_tv_nsec, 0)); } else { rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr, rb_obj_classname(time), want); } break; case T_FIXNUM: t.tv_sec = FIX2LONG(time); if (interval && t.tv_sec < 0) rb_raise(rb_eArgError, "%s must be positive", tstr); t.tv_nsec = 0; break; case T_FLOAT: if (interval && RFLOAT_VALUE(time) < 0.0) rb_raise(rb_eArgError, "%s must be positive", tstr); else { double f, d; d = modf(RFLOAT_VALUE(time), &f); if (d < 0) { d += 1; f -= 1; } t.tv_sec = (time_t)f; if (f != t.tv_sec) { rb_raise(rb_eRangeError, "%f out of Time range", RFLOAT_VALUE(time)); } t.tv_nsec = (int)(d * 1e9 + 0.5); } break; case T_BIGNUM: t.tv_sec = NUM2LONG(time); if (interval && t.tv_sec < 0) rb_raise(rb_eArgError, "%s must be positive", tstr); t.tv_nsec = 0; break; default: rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr, rb_obj_classname(time), want); break; } return t; }
/* * call-seq: * Curl::Multi.default_timeout = 4 => 4 * * Set the global default time out for all Curl::Multi Handles. This value is used * when libcurl cannot determine a timeout value when calling curl_multi_timeout. * */ VALUE ruby_curl_multi_set_default_timeout(VALUE klass, VALUE timeout) { cCurlMutiDefaulttimeout = FIX2LONG(timeout); return timeout; }
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt) { enum {default_float_precision = 6}; rb_encoding *enc; const char *p, *end; char *buf; long blen, bsiz; VALUE result; long scanned = 0; int coderange = ENC_CODERANGE_7BIT; int width, prec, flags = FNONE; int nextarg = 1; int posarg = 0; int tainted = 0; VALUE nextvalue; VALUE tmp; VALUE str; volatile VALUE hash = Qundef; #define CHECK_FOR_WIDTH(f) \ if ((f) & FWIDTH) { \ rb_raise(rb_eArgError, "width given twice"); \ } \ if ((f) & FPREC0) { \ rb_raise(rb_eArgError, "width after precision"); \ } #define CHECK_FOR_FLAGS(f) \ if ((f) & FWIDTH) { \ rb_raise(rb_eArgError, "flag after width"); \ } \ if ((f) & FPREC0) { \ rb_raise(rb_eArgError, "flag after precision"); \ } ++argc; --argv; if (OBJ_TAINTED(fmt)) tainted = 1; StringValue(fmt); enc = rb_enc_get(fmt); fmt = rb_str_new4(fmt); p = RSTRING_PTR(fmt); end = p + RSTRING_LEN(fmt); blen = 0; bsiz = 120; result = rb_str_buf_new(bsiz); rb_enc_copy(result, fmt); buf = RSTRING_PTR(result); memset(buf, 0, bsiz); ENC_CODERANGE_SET(result, coderange); for (; p < end; p++) { const char *t; int n; VALUE sym = Qnil; for (t = p; t < end && *t != '%'; t++) ; PUSH(p, t - p); if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange); ENC_CODERANGE_SET(result, coderange); } if (t >= end) { /* end of fmt string */ goto sprint_exit; } p = t + 1; /* skip `%' */ width = prec = -1; nextvalue = Qundef; retry: switch (*p) { default: if (rb_enc_isprint(*p, enc)) rb_raise(rb_eArgError, "malformed format string - %%%c", *p); else rb_raise(rb_eArgError, "malformed format string"); break; case ' ': CHECK_FOR_FLAGS(flags); flags |= FSPACE; p++; goto retry; case '#': CHECK_FOR_FLAGS(flags); flags |= FSHARP; p++; goto retry; case '+': CHECK_FOR_FLAGS(flags); flags |= FPLUS; p++; goto retry; case '-': CHECK_FOR_FLAGS(flags); flags |= FMINUS; p++; goto retry; case '0': CHECK_FOR_FLAGS(flags); flags |= FZERO; p++; goto retry; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': n = 0; GETNUM(n, width); if (*p == '$') { if (nextvalue != Qundef) { rb_raise(rb_eArgError, "value given twice - %d$", n); } nextvalue = GETPOSARG(n); p++; goto retry; } CHECK_FOR_WIDTH(flags); width = n; flags |= FWIDTH; goto retry; case '<': case '{': { const char *start = p; char term = (*p == '<') ? '>' : '}'; int len; for (; p < end && *p != term; ) { p += rb_enc_mbclen(p, end, enc); } if (p >= end) { rb_raise(rb_eArgError, "malformed name - unmatched parenthesis"); } #if SIZEOF_INT < SIZEOF_SIZE_T if ((size_t)(p - start) >= INT_MAX) { const int message_limit = 20; len = (int)(rb_enc_right_char_head(start, start + message_limit, p, enc) - start); rb_enc_raise(enc, rb_eArgError, "too long name (%"PRIdSIZE" bytes) - %.*s...%c", (size_t)(p - start - 2), len, start, term); } #endif len = (int)(p - start + 1); /* including parenthesis */ if (sym != Qnil) { rb_enc_raise(enc, rb_eArgError, "named%.*s after <%"PRIsVALUE">", len, start, rb_sym2str(sym)); } CHECKNAMEARG(start, len, enc); get_hash(&hash, argc, argv); sym = rb_check_symbol_cstr(start + 1, len - 2 /* without parenthesis */, enc); if (sym != Qnil) nextvalue = rb_hash_lookup2(hash, sym, Qundef); if (nextvalue == Qundef) { rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start); } if (term == '}') goto format_s; p++; goto retry; } case '*': CHECK_FOR_WIDTH(flags); flags |= FWIDTH; GETASTER(width); if (width < 0) { flags |= FMINUS; width = -width; } p++; goto retry; case '.': if (flags & FPREC0) { rb_raise(rb_eArgError, "precision given twice"); } flags |= FPREC|FPREC0; 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); RB_GC_GUARD(tmp); } 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; case 's': case 'p': format_s: { VALUE arg = GETARG(); long len, slen; if (*p == 'p') arg = rb_inspect(arg); str = rb_obj_as_string(arg); if (OBJ_TAINTED(str)) tainted = 1; len = RSTRING_LEN(str); rb_str_set_len(result, blen); if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { int cr = coderange; scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &cr); ENC_CODERANGE_SET(result, (cr == ENC_CODERANGE_UNKNOWN ? ENC_CODERANGE_BROKEN : (coderange = cr))); } enc = rb_enc_check(result, str); if (flags&(FPREC|FWIDTH)) { slen = rb_enc_strlen(RSTRING_PTR(str),RSTRING_END(str),enc); if (slen < 0) { rb_raise(rb_eArgError, "invalid mbstring sequence"); } if ((flags&FPREC) && (prec < slen)) { char *p = rb_enc_nth(RSTRING_PTR(str), RSTRING_END(str), prec, enc); slen = prec; len = p - RSTRING_PTR(str); } /* need to adjust multi-byte string pos */ if ((flags&FWIDTH) && (width > slen)) { width -= (int)slen; if (!(flags&FMINUS)) { CHECK(width); while (width--) { buf[blen++] = ' '; } } CHECK(len); memcpy(&buf[blen], RSTRING_PTR(str), len); RB_GC_GUARD(str); blen += len; if (flags&FMINUS) { CHECK(width); while (width--) { buf[blen++] = ' '; } } rb_enc_associate(result, enc); break; } } PUSH(RSTRING_PTR(str), len); RB_GC_GUARD(str); rb_enc_associate(result, enc); } break; case 'd': case 'i': case 'o': case 'x': case 'X': case 'b': case 'B': case 'u': { volatile VALUE val = GETARG(); int valsign; char nbuf[64], *s; const char *prefix = 0; int sign = 0, dots = 0; char sc = 0; long v = 0; int base, bignum = 0; int len; switch (*p) { case 'd': case 'i': case 'u': sign = 1; break; case 'o': case 'x': case 'X': case 'b': case 'B': if (flags&(FPLUS|FSPACE)) sign = 1; break; } if (flags & FSHARP) { switch (*p) { case 'o': prefix = "0"; break; case 'x': prefix = "0x"; break; case 'X': prefix = "0X"; break; case 'b': prefix = "0b"; break; case 'B': prefix = "0B"; break; } } bin_retry: switch (TYPE(val)) { case T_FLOAT: if (FIXABLE(RFLOAT_VALUE(val))) { val = LONG2FIX((long)RFLOAT_VALUE(val)); goto bin_retry; } val = rb_dbl2big(RFLOAT_VALUE(val)); if (FIXNUM_P(val)) goto bin_retry; bignum = 1; break; case T_STRING: val = rb_str_to_inum(val, 0, TRUE); goto bin_retry; case T_BIGNUM: bignum = 1; break; case T_FIXNUM: v = FIX2LONG(val); break; default: val = rb_Integer(val); goto bin_retry; } switch (*p) { case 'o': base = 8; break; case 'x': case 'X': base = 16; break; case 'b': case 'B': base = 2; break; case 'u': case 'd': case 'i': default: base = 10; break; } if (base != 10) { int numbits = ffs(base)-1; size_t abs_nlz_bits; size_t numdigits = rb_absint_numwords(val, numbits, &abs_nlz_bits); long i; if (INT_MAX-1 < numdigits) /* INT_MAX is used because rb_long2int is used later. */ rb_raise(rb_eArgError, "size too big"); if (sign) { if (numdigits == 0) numdigits = 1; tmp = rb_str_new(NULL, numdigits); valsign = rb_integer_pack(val, RSTRING_PTR(tmp), RSTRING_LEN(tmp), 1, CHAR_BIT-numbits, INTEGER_PACK_BIG_ENDIAN); for (i = 0; i < RSTRING_LEN(tmp); i++) RSTRING_PTR(tmp)[i] = ruby_digitmap[((unsigned char *)RSTRING_PTR(tmp))[i]]; s = RSTRING_PTR(tmp); if (valsign < 0) { sc = '-'; width--; } else if (flags & FPLUS) { sc = '+'; width--; } else if (flags & FSPACE) { sc = ' '; width--; } } else { /* Following conditional "numdigits++" guarantees the * most significant digit as * - '1'(bin), '7'(oct) or 'f'(hex) for negative numbers * - '0' for zero * - not '0' for positive numbers. * * It also guarantees the most significant two * digits will not be '11'(bin), '77'(oct), 'ff'(hex) * or '00'. */ if (numdigits == 0 || ((abs_nlz_bits != (size_t)(numbits-1) || !rb_absint_singlebit_p(val)) && (!bignum ? v < 0 : BIGNUM_NEGATIVE_P(val)))) numdigits++; tmp = rb_str_new(NULL, numdigits); valsign = rb_integer_pack(val, RSTRING_PTR(tmp), RSTRING_LEN(tmp), 1, CHAR_BIT-numbits, INTEGER_PACK_2COMP | INTEGER_PACK_BIG_ENDIAN); for (i = 0; i < RSTRING_LEN(tmp); i++) RSTRING_PTR(tmp)[i] = ruby_digitmap[((unsigned char *)RSTRING_PTR(tmp))[i]]; s = RSTRING_PTR(tmp); dots = valsign < 0; } len = rb_long2int(RSTRING_END(tmp) - s); } else if (!bignum) { valsign = 1; if (v < 0) { v = -v; sc = '-'; width--; valsign = -1; } else if (flags & FPLUS) { sc = '+'; width--; } else if (flags & FSPACE) { sc = ' '; width--; } snprintf(nbuf, sizeof(nbuf), "%ld", v); s = nbuf; len = (int)strlen(s); } else { tmp = rb_big2str(val, 10); s = RSTRING_PTR(tmp); valsign = 1; if (s[0] == '-') { s++; sc = '-'; width--; valsign = -1; } else if (flags & FPLUS) { sc = '+'; width--; } else if (flags & FSPACE) { sc = ' '; width--; } len = rb_long2int(RSTRING_END(tmp) - s); } if (dots) { prec -= 2; width -= 2; } if (*p == 'X') { char *pp = s; int c; while ((c = (int)(unsigned char)*pp) != 0) { *pp = rb_enc_toupper(c, enc); pp++; } } if (prefix && !prefix[1]) { /* octal */ if (dots) { prefix = 0; } else if (len == 1 && *s == '0') { len = 0; if (flags & FPREC) prec--; } else if ((flags & FPREC) && (prec > len)) { prefix = 0; } } else if (len == 1 && *s == '0') { prefix = 0; } if (prefix) { width -= (int)strlen(prefix); } if ((flags & (FZERO|FMINUS|FPREC)) == FZERO) { prec = width; width = 0; } else { if (prec < len) { if (!prefix && prec == 0 && len == 1 && *s == '0') len = 0; prec = len; } width -= prec; } if (!(flags&FMINUS)) { CHECK(width); while (width-- > 0) { buf[blen++] = ' '; } } if (sc) PUSH(&sc, 1); if (prefix) { int plen = (int)strlen(prefix); PUSH(prefix, plen); } CHECK(prec - len); if (dots) PUSH("..", 2); if (!sign && valsign < 0) { char c = sign_bits(base, p); while (len < prec--) { buf[blen++] = c; } } else if ((flags & (FMINUS|FPREC)) != FMINUS) { while (len < prec--) { buf[blen++] = '0'; } } PUSH(s, len); RB_GC_GUARD(tmp); CHECK(width); while (width-- > 0) { buf[blen++] = ' '; } } break; case 'f': { VALUE val = GETARG(), num, den; int sign = (flags&FPLUS) ? 1 : 0, zero = 0; long len, done = 0; int prefix = 0; if (!RB_TYPE_P(val, T_RATIONAL)) { nextvalue = val; goto float_value; } if (!(flags&FPREC)) prec = default_float_precision; den = rb_rational_den(val); num = rb_rational_num(val); if (FIXNUM_P(num)) { if ((SIGNED_VALUE)num < 0) { long n = -FIX2LONG(num); num = LONG2FIX(n); sign = -1; } } else if (rb_num_negative_p(num)) { sign = -1; num = rb_funcallv(num, idUMinus, 0, 0); } if (den != INT2FIX(1) || prec > 1) { const ID idDiv = rb_intern("div"); VALUE p10 = rb_int_positive_pow(10, prec); VALUE den_2 = rb_funcall(den, idDiv, 1, INT2FIX(2)); num = rb_funcallv(num, '*', 1, &p10); num = rb_funcallv(num, '+', 1, &den_2); num = rb_funcallv(num, idDiv, 1, &den); } else if (prec >= 0) { zero = prec; } val = rb_obj_as_string(num); len = RSTRING_LEN(val) + zero; if (prec >= len) ++len; /* integer part 0 */ if (sign || (flags&FSPACE)) ++len; if (prec > 0) ++len; /* period */ CHECK(len > width ? len : width); if (sign || (flags&FSPACE)) { buf[blen++] = sign > 0 ? '+' : sign < 0 ? '-' : ' '; prefix++; done++; } len = RSTRING_LEN(val) + zero; t = RSTRING_PTR(val); if (len > prec) { memcpy(&buf[blen], t, len - prec); blen += len - prec; done += len - prec; } else { buf[blen++] = '0'; done++; } if (prec > 0) { buf[blen++] = '.'; done++; } if (zero) { FILL('0', zero); done += zero; } else if (prec > len) { FILL('0', prec - len); memcpy(&buf[blen], t, len); blen += len; done += prec; } else if (prec > 0) { memcpy(&buf[blen], t + len - prec, prec); blen += prec; done += prec; } if ((flags & FWIDTH) && width > done) { int fill = ' '; long shifting = 0; if (!(flags&FMINUS)) { shifting = done; if (flags&FZERO) { shifting -= prefix; fill = '0'; } blen -= shifting; memmove(&buf[blen + width - done], &buf[blen], shifting); } FILL(fill, width - done); blen += shifting; } RB_GC_GUARD(val); break; } case 'g': case 'G': case 'e': case 'E': /* TODO: rational support */ case 'a': case 'A': float_value: { VALUE val = GETARG(); double fval; int i, need; char fbuf[32]; fval = RFLOAT_VALUE(rb_Float(val)); if (isnan(fval) || isinf(fval)) { const char *expr; if (isnan(fval)) { expr = "NaN"; } else { expr = "Inf"; } need = (int)strlen(expr); if ((!isnan(fval) && fval < 0.0) || (flags & FPLUS)) need++; if ((flags & FWIDTH) && need < width) need = width; CHECK(need + 1); snprintf(&buf[blen], need + 1, "%*s", need, ""); if (flags & FMINUS) { if (!isnan(fval) && fval < 0.0) buf[blen++] = '-'; else if (flags & FPLUS) buf[blen++] = '+'; else if (flags & FSPACE) blen++; memcpy(&buf[blen], expr, strlen(expr)); } else { if (!isnan(fval) && fval < 0.0) buf[blen + need - strlen(expr) - 1] = '-'; else if (flags & FPLUS) buf[blen + need - strlen(expr) - 1] = '+'; else if ((flags & FSPACE) && need > width) blen++; memcpy(&buf[blen + need - strlen(expr)], expr, strlen(expr)); } blen += strlen(&buf[blen]); break; } fmt_setup(fbuf, sizeof(fbuf), *p, flags, width, prec); need = 0; if (*p != 'e' && *p != 'E') { i = INT_MIN; frexp(fval, &i); if (i > 0) need = BIT_DIGITS(i); } need += (flags&FPREC) ? prec : default_float_precision; if ((flags&FWIDTH) && need < width) need = width; need += 20; CHECK(need); snprintf(&buf[blen], need, fbuf, fval); blen += strlen(&buf[blen]); } break; } flags = FNONE; } sprint_exit: RB_GC_GUARD(fmt); /* XXX - We cannot validate the number of arguments if (digit)$ style used. */ if (posarg >= 0 && nextarg < argc) { const char *mesg = "too many arguments for format string"; if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg); if (RTEST(ruby_verbose)) rb_warn("%s", mesg); } rb_str_resize(result, blen); if (tainted) OBJ_TAINT(result); return result; }
/* call-seq: stmt.bind_param(key, value) * * Binds value to the named (or positional) placeholder. If +param+ is a * Fixnum, it is treated as an index for a positional placeholder. * Otherwise it is used as the name of the placeholder to bind to. * * See also #bind_params. */ static VALUE bind_param(VALUE self, VALUE key, VALUE value) { sqlite3StmtRubyPtr ctx; int status; int index; Data_Get_Struct(self, sqlite3StmtRuby, ctx); REQUIRE_OPEN_STMT(ctx); switch(TYPE(key)) { case T_SYMBOL: key = rb_funcall(key, rb_intern("to_s"), 0); case T_STRING: if(RSTRING_PTR(key)[0] != ':') key = rb_str_plus(rb_str_new2(":"), key); index = sqlite3_bind_parameter_index(ctx->st, StringValuePtr(key)); break; default: index = (int)NUM2INT(key); } if(index == 0) rb_raise(rb_path2class("SQLite3::Exception"), "no such bind parameter"); switch(TYPE(value)) { case T_STRING: if(CLASS_OF(value) == cSqlite3Blob || rb_enc_get_index(value) == rb_ascii8bit_encindex() ) { status = sqlite3_bind_blob( ctx->st, index, (const char *)StringValuePtr(value), (int)RSTRING_LEN(value), SQLITE_TRANSIENT ); } else { if (UTF16_LE_P(value) || UTF16_BE_P(value)) { status = sqlite3_bind_text16( ctx->st, index, (const char *)StringValuePtr(value), (int)RSTRING_LEN(value), SQLITE_TRANSIENT ); } else { if (!UTF8_P(value) || !USASCII_P(value)) { value = rb_str_encode(value, rb_enc_from_encoding(rb_utf8_encoding()), 0, Qnil); } status = sqlite3_bind_text( ctx->st, index, (const char *)StringValuePtr(value), (int)RSTRING_LEN(value), SQLITE_TRANSIENT ); } } break; case T_BIGNUM: { sqlite3_int64 num64; if (bignum_to_int64(value, &num64)) { status = sqlite3_bind_int64(ctx->st, index, num64); break; } } case T_FLOAT: status = sqlite3_bind_double(ctx->st, index, NUM2DBL(value)); break; case T_FIXNUM: status = sqlite3_bind_int64(ctx->st, index, (sqlite3_int64)FIX2LONG(value)); break; case T_NIL: status = sqlite3_bind_null(ctx->st, index); break; default: rb_raise(rb_eRuntimeError, "can't prepare %s", rb_class2name(CLASS_OF(value))); break; } CHECK(sqlite3_db_handle(ctx->st), status); return self; }
VALUE my_method(VALUE self, VALUE num) { unsigned long myVal = FIX2LONG(num); printf("the int is %lu?\n", myVal); return LONG2FIX(num); }
VALUE symbol_spec_rb_intern3_c_compare(VALUE self, VALUE string, VALUE len, VALUE enc, VALUE sym) { ID symbol = rb_intern3(RSTRING_PTR(string), FIX2LONG(len), rb_enc_get(enc)); return (SYM2ID(sym) == symbol) ? Qtrue : Qfalse; }
VALUE symbol_spec_rb_intern3(VALUE self, VALUE string, VALUE len, VALUE enc) { return ID2SYM(rb_intern3(RSTRING_PTR(string), FIX2LONG(len), rb_enc_get(enc))); }
VALUE symbol_spec_rb_intern2(VALUE self, VALUE string, VALUE len) { return ID2SYM(rb_intern2(RSTRING_PTR(string), FIX2LONG(len))); }
static VALUE range_bsearch(VALUE range) { VALUE beg, end; int smaller, satisfied = 0; /* Implementation notes: * Floats are handled by mapping them to 64 bits integers. * Apart from sign issues, floats and their 64 bits integer have the * same order, assuming they are represented as exponent followed * by the mantissa. This is true with or without implicit bit. * * Finding the average of two ints needs to be careful about * potential overflow (since float to long can use 64 bits) * as well as the fact that -1/2 can be 0 or -1 in C89. * * Note that -0.0 is mapped to the same int as 0.0 as we don't want * (-1...0.0).bsearch to yield -0.0. */ #define BSEARCH_CHECK(val) \ do { \ VALUE v = rb_yield(val); \ if (FIXNUM_P(v)) { \ if (FIX2INT(v) == 0) return val; \ smaller = FIX2INT(v) < 0; \ } \ else if (v == Qtrue) { \ satisfied = 1; \ smaller = 1; \ } \ else if (v == Qfalse || v == Qnil) { \ smaller = 0; \ } \ else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \ int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \ if (!cmp) return val; \ smaller = cmp < 0; \ } \ else { \ rb_raise(rb_eTypeError, "wrong argument type %s" \ " (must be numeric, true, false or nil)", \ rb_obj_classname(v)); \ } \ } while (0) #define BSEARCH(conv) \ do { \ RETURN_ENUMERATOR(range, 0, 0); \ if (EXCL(range)) high--; \ org_high = high; \ while (low < high) { \ mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \ : (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \ BSEARCH_CHECK(conv(mid)); \ if (smaller) { \ high = mid; \ } \ else { \ low = mid + 1; \ } \ } \ if (low == org_high) { \ BSEARCH_CHECK(conv(low)); \ if (!smaller) return Qnil; \ } \ if (!satisfied) return Qnil; \ return conv(low); \ } while (0) beg = RANGE_BEG(range); end = RANGE_END(range); if (FIXNUM_P(beg) && FIXNUM_P(end)) { long low = FIX2LONG(beg); long high = FIX2LONG(end); long mid, org_high; BSEARCH(INT2FIX); } #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T) else if (RB_TYPE_P(beg, T_FLOAT) || RB_TYPE_P(end, T_FLOAT)) { int64_t low = double_as_int64(RFLOAT_VALUE(rb_Float(beg))); int64_t high = double_as_int64(RFLOAT_VALUE(rb_Float(end))); int64_t mid, org_high; BSEARCH(int64_as_double_to_num); } #endif else if (is_integer_p(beg) && is_integer_p(end)) { VALUE low = rb_to_int(beg); VALUE high = rb_to_int(end); VALUE mid, org_high; RETURN_ENUMERATOR(range, 0, 0); if (EXCL(range)) high = rb_funcall(high, '-', 1, INT2FIX(1)); org_high = high; while (rb_cmpint(rb_funcall(low, id_cmp, 1, high), low, high) < 0) { mid = rb_funcall(rb_funcall(high, '+', 1, low), id_div, 1, INT2FIX(2)); BSEARCH_CHECK(mid); if (smaller) { high = mid; } else { low = rb_funcall(mid, '+', 1, INT2FIX(1)); } } if (rb_equal(low, org_high)) { BSEARCH_CHECK(low); if (!smaller) return Qnil; } if (!satisfied) return Qnil; return low; } else { rb_raise(rb_eTypeError, "can't do binary search for %s", rb_obj_classname(beg)); } return range; }
static VALUE range_step(int argc, VALUE *argv, VALUE range) { VALUE b, e, step, tmp; RETURN_SIZED_ENUMERATOR(range, argc, argv, range_step_size); b = RANGE_BEG(range); e = RANGE_END(range); if (argc == 0) { step = INT2FIX(1); } else { rb_scan_args(argc, argv, "01", &step); if (!rb_obj_is_kind_of(step, rb_cNumeric)) { step = rb_to_int(step); } if (rb_funcall(step, '<', 1, INT2FIX(0))) { rb_raise(rb_eArgError, "step can't be negative"); } else if (!rb_funcall(step, '>', 1, INT2FIX(0))) { rb_raise(rb_eArgError, "step can't be 0"); } } if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */ long end = FIX2LONG(e); long i, unit = FIX2LONG(step); if (!EXCL(range)) end += 1; i = FIX2LONG(b); while (i < end) { rb_yield(LONG2NUM(i)); if (i + unit < i) break; i += unit; } } else if (SYMBOL_P(b) && SYMBOL_P(e)) { /* symbols are special */ VALUE args[2], iter[2]; args[0] = rb_sym_to_s(e); args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_block_call(rb_sym_to_s(b), rb_intern("upto"), 2, args, sym_step_i, (VALUE)iter); } else if (ruby_float_step(b, e, step, EXCL(range))) { /* done */ } else if (rb_obj_is_kind_of(b, rb_cNumeric) || !NIL_P(rb_check_to_integer(b, "to_int")) || !NIL_P(rb_check_to_integer(e, "to_int"))) { ID op = EXCL(range) ? '<' : idLE; VALUE v = b; int i = 0; while (RTEST(rb_funcall(v, op, 1, e))) { rb_yield(v); i++; v = rb_funcall(b, '+', 1, rb_funcall(INT2NUM(i), '*', 1, step)); } } else { tmp = rb_check_string_type(b); if (!NIL_P(tmp)) { VALUE args[2], iter[2]; b = tmp; args[0] = e; args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_block_call(b, rb_intern("upto"), 2, args, step_i, (VALUE)iter); } else { VALUE args[2]; if (!discrete_object_p(b)) { rb_raise(rb_eTypeError, "can't iterate from %s", rb_obj_classname(b)); } args[0] = INT2FIX(1); args[1] = step; range_each_func(range, step_i, (VALUE)args); } } return range; }
/* 1 - success, 0 - error */ static int set_oci_number_from_num(OCINumber *result, VALUE num, int force, OCIError *errhp) { signed long sl; if (!RTEST(rb_obj_is_kind_of(num, rb_cNumeric))) rb_raise(rb_eTypeError, "expect Numeric but %s", rb_class2name(CLASS_OF(num))); if (rb_respond_to(num, id_finite_p) && !RTEST(rb_funcall(num, id_finite_p, 0))) { rb_raise(rb_eTypeError, "cannot accept number which isn't finite."); } switch (rb_type(num)) { case T_FIXNUM: /* set from long. */ sl = NUM2LONG(num); chkerr(OCINumberFromInt(errhp, &sl, sizeof(sl), OCI_NUMBER_SIGNED, result)); return 1; case T_FLOAT: /* set from double. */ oci8_dbl_to_onum(result, NUM2DBL(num), errhp); return 1; case T_BIGNUM: /* change via string. */ num = rb_big2str(num, 10); set_oci_number_from_str(result, num, Qnil, Qnil, errhp); return 1; } if (RTEST(rb_obj_is_instance_of(num, cOCINumber))) { /* OCI::Number */ chkerr(OCINumberAssign(errhp, DATA_PTR(num), result)); return 1; } if (rb_respond_to(num, id_split)) { /* BigDecimal */ VALUE split = rb_funcall(num, id_split, 0); if (TYPE(split) == T_ARRAY && RARRAY_LEN(split) == 4) { /* * sign, significant_digits, base, exponent = num.split * onum = sign * "0.#{significant_digits}".to_f * (base ** exponent) */ VALUE *ary = RARRAY_PTR(split); int sign; OCINumber digits; int exponent; int digits_len; OCINumber work; /* check sign */ if (TYPE(ary[0]) != T_FIXNUM) { goto is_not_big_decimal; } sign = FIX2INT(ary[0]); /* check digits */ StringValue(ary[1]); digits_len = RSTRING_LEN(ary[1]); set_oci_number_from_str(&digits, ary[1], Qnil, Qnil, errhp); /* check base */ if (TYPE(ary[2]) != T_FIXNUM || FIX2LONG(ary[2]) != 10) { goto is_not_big_decimal; } /* check exponent */ if (TYPE(ary[3]) != T_FIXNUM) { goto is_not_big_decimal; } exponent = FIX2INT(ary[3]); chkerr(OCINumberShift(errhp, &digits, exponent - digits_len, &work)); if (sign >= 0) { chkerr(OCINumberAssign(errhp, &work, result)); } else { chkerr(OCINumberNeg(errhp, &work, result)); } return 1; } } is_not_big_decimal: if (rb_respond_to(num, id_numerator) && rb_respond_to(num, id_denominator)) { /* Rational */ OCINumber numerator; OCINumber denominator; if (set_oci_number_from_num(&numerator, rb_funcall(num, id_numerator, 0), 0, errhp) && set_oci_number_from_num(&denominator, rb_funcall(num, id_denominator, 0), 0, errhp)) { chkerr(OCINumberDiv(errhp, &numerator, &denominator, result)); return 1; } } if (force) { /* change via string as a last resort. */ /* TODO: if error, raise TypeError instead of OCI::Error */ set_oci_number_from_str(result, num, Qnil, Qnil, errhp); return 1; } return 0; }
/* * call-seq: configure(opts) * * Configure this State instance with the Hash _opts_, and return * itself. */ static VALUE cState_configure(VALUE self, VALUE opts) { VALUE tmp; GET_STATE(self); tmp = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h"); if (NIL_P(tmp)) { rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash"); } opts = tmp; tmp = rb_hash_aref(opts, ID2SYM(i_indent)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->indent = fstrndup(RSTRING_PTR(tmp), len); state->indent_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_space)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->space = fstrndup(RSTRING_PTR(tmp), len); state->space_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_space_before)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->space_before = fstrndup(RSTRING_PTR(tmp), len); state->space_before_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_array_nl)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->array_nl = fstrndup(RSTRING_PTR(tmp), len); state->array_nl_len = len; } tmp = rb_hash_aref(opts, ID2SYM(i_object_nl)); if (RTEST(tmp)) { unsigned long len; Check_Type(tmp, T_STRING); len = RSTRING_LEN(tmp); state->object_nl = fstrndup(RSTRING_PTR(tmp), len); state->object_nl_len = len; } tmp = ID2SYM(i_max_nesting); state->max_nesting = 19; if (option_given_p(opts, tmp)) { VALUE max_nesting = rb_hash_aref(opts, tmp); if (RTEST(max_nesting)) { Check_Type(max_nesting, T_FIXNUM); state->max_nesting = FIX2LONG(max_nesting); } else { state->max_nesting = 0; } } tmp = ID2SYM(i_depth); state->depth = 0; if (option_given_p(opts, tmp)) { VALUE depth = rb_hash_aref(opts, tmp); if (RTEST(depth)) { Check_Type(depth, T_FIXNUM); state->depth = FIX2LONG(depth); } else { state->depth = 0; } } tmp = ID2SYM(i_buffer_initial_length); if (option_given_p(opts, tmp)) { VALUE buffer_initial_length = rb_hash_aref(opts, tmp); if (RTEST(buffer_initial_length)) { long initial_length; Check_Type(buffer_initial_length, T_FIXNUM); initial_length = FIX2LONG(buffer_initial_length); if (initial_length > 0) state->buffer_initial_length = initial_length; } } tmp = rb_hash_aref(opts, ID2SYM(i_allow_nan)); state->allow_nan = RTEST(tmp); tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only)); state->ascii_only = RTEST(tmp); tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode)); state->quirks_mode = RTEST(tmp); return self; }
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj) { fbuffer_append_long(buffer, FIX2LONG(obj)); }
long fix2int(VALUE x) { printf("fix2long called\n"); // return rb_num2int(x); return FIX2LONG(x); // return FIX2INT(x); }
static VALUE rb_keychain_find(int argc, VALUE *argv, VALUE self){ VALUE kind; VALUE attributes; VALUE first_or_all; rb_scan_args(argc, argv, "2:", &first_or_all, &kind, &attributes); Check_Type(first_or_all, T_SYMBOL); Check_Type(kind, T_STRING); CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CFDictionarySetValue(query, kSecReturnAttributes, kCFBooleanTrue); CFDictionarySetValue(query, kSecReturnRef, kCFBooleanTrue); if(rb_to_id(first_or_all) == rb_intern("all")){ CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitAll); } rb_add_value_to_cf_dictionary(query, kSecClass, kind); if(!NIL_P(attributes)){ Check_Type(attributes, T_HASH); VALUE rb_keychains = rb_hash_aref(attributes, ID2SYM(rb_intern("keychains"))); if(!NIL_P(rb_keychains)){ Check_Type(rb_keychains, T_ARRAY); CFMutableArrayRef searchArray = CFArrayCreateMutable(NULL, RARRAY_LEN(rb_keychains), &kCFTypeArrayCallBacks); for(int index=0; index < RARRAY_LEN(rb_keychains); index++){ SecKeychainRef keychain = NULL; Data_Get_Struct(RARRAY_PTR(rb_keychains)[index], struct OpaqueSecKeychainRef, keychain); CFArrayAppendValue(searchArray, keychain); } CFDictionarySetValue(query, kSecMatchSearchList,searchArray); CFRelease(searchArray); } VALUE limit = rb_hash_aref(attributes, ID2SYM(rb_intern("limit"))); if(!NIL_P(limit)){ Check_Type(limit, T_FIXNUM); long c_limit = FIX2LONG(limit); CFNumberRef cf_limit = CFNumberCreate(NULL, kCFNumberLongType, &c_limit); CFDictionarySetValue(query, kSecMatchLimit, cf_limit); CFRelease(cf_limit); } VALUE conditions = rb_hash_aref(attributes, ID2SYM(rb_intern("conditions"))); if(!NIL_P(conditions)){ Check_Type(conditions, T_HASH); VALUE rQuery = Data_Wrap_Struct(rb_cPointerWrapper, NULL, NULL, query); rb_block_call(conditions, rb_intern("each"), 0, NULL, RUBY_METHOD_FUNC(add_conditions_to_query), rQuery); } } CFDictionaryRef result; OSStatus status = SecItemCopyMatching(query, (CFTypeRef*)&result); CFRelease(query); VALUE rb_item = rb_ary_new2(0); switch(status){ case errSecItemNotFound: break; default: CheckOSStatusOrRaise(status); if(CFArrayGetTypeID() == CFGetTypeID(result)){ CFArrayRef result_array = (CFArrayRef)result; for(CFIndex i = 0; i < CFArrayGetCount(result_array); i++){ rb_ary_push(rb_item,rb_keychain_item_from_sec_dictionary(CFArrayGetValueAtIndex(result_array,i))); } } else{ rb_ary_push(rb_item, rb_keychain_item_from_sec_dictionary(result)); } CFRelease(result); } if(rb_to_id(first_or_all) == rb_intern("first")){ return rb_ary_entry(rb_item,0); } else{ return rb_item; } }
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt) { rb_encoding *enc; const char *p, *end; char *buf; long blen, bsiz; VALUE result; long scanned = 0; int coderange = ENC_CODERANGE_7BIT; int width, prec, flags = FNONE; int nextarg = 1; int posarg = 0; int tainted = 0; VALUE nextvalue; VALUE tmp; VALUE str; volatile VALUE hash = Qundef; #define CHECK_FOR_WIDTH(f) \ if ((f) & FWIDTH) { \ rb_raise(rb_eArgError, "width given twice"); \ } \ if ((f) & FPREC0) { \ rb_raise(rb_eArgError, "width after precision"); \ } #define CHECK_FOR_FLAGS(f) \ if ((f) & FWIDTH) { \ rb_raise(rb_eArgError, "flag after width"); \ } \ if ((f) & FPREC0) { \ rb_raise(rb_eArgError, "flag after precision"); \ } ++argc; --argv; if (OBJ_TAINTED(fmt)) tainted = 1; StringValue(fmt); enc = rb_enc_get(fmt); fmt = rb_str_new4(fmt); p = RSTRING_PTR(fmt); end = p + RSTRING_LEN(fmt); blen = 0; bsiz = 120; result = rb_str_buf_new(bsiz); rb_enc_copy(result, fmt); buf = RSTRING_PTR(result); memset(buf, 0, bsiz); ENC_CODERANGE_SET(result, coderange); for (; p < end; p++) { const char *t; int n; ID id = 0; for (t = p; t < end && *t != '%'; t++) ; PUSH(p, t - p); if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &coderange); ENC_CODERANGE_SET(result, coderange); } if (t >= end) { /* end of fmt string */ goto sprint_exit; } p = t + 1; /* skip `%' */ width = prec = -1; nextvalue = Qundef; retry: switch (*p) { default: if (rb_enc_isprint(*p, enc)) rb_raise(rb_eArgError, "malformed format string - %%%c", *p); else rb_raise(rb_eArgError, "malformed format string"); break; case ' ': CHECK_FOR_FLAGS(flags); flags |= FSPACE; p++; goto retry; case '#': CHECK_FOR_FLAGS(flags); flags |= FSHARP; p++; goto retry; case '+': CHECK_FOR_FLAGS(flags); flags |= FPLUS; p++; goto retry; case '-': CHECK_FOR_FLAGS(flags); flags |= FMINUS; p++; goto retry; case '0': CHECK_FOR_FLAGS(flags); flags |= FZERO; p++; goto retry; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': n = 0; GETNUM(n, width); if (*p == '$') { if (nextvalue != Qundef) { rb_raise(rb_eArgError, "value given twice - %d$", n); } nextvalue = GETPOSARG(n); p++; goto retry; } CHECK_FOR_WIDTH(flags); width = n; flags |= FWIDTH; goto retry; case '<': case '{': { const char *start = p; char term = (*p == '<') ? '>' : '}'; int len; for (; p < end && *p != term; ) { p += rb_enc_mbclen(p, end, enc); } if (p >= end) { rb_raise(rb_eArgError, "malformed name - unmatched parenthesis"); } #if SIZEOF_INT < SIZEOF_SIZE_T if ((size_t)(p - start) >= INT_MAX) { const int message_limit = 20; len = (int)(rb_enc_right_char_head(start, start + message_limit, p, enc) - start); rb_enc_raise(enc, rb_eArgError, "too long name (%"PRIdSIZE" bytes) - %.*s...%c", (size_t)(p - start - 2), len, start, term); } #endif len = (int)(p - start + 1); /* including parenthesis */ if (id) { rb_enc_raise(enc, rb_eArgError, "named%.*s after <%s>", len, start, rb_id2name(id)); } nextvalue = GETNAMEARG((id = rb_check_id_cstr(start + 1, len - 2 /* without parenthesis */, enc), ID2SYM(id)), start, len, enc); if (nextvalue == Qundef) { rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start); } if (term == '}') goto format_s; p++; goto retry; } case '*': CHECK_FOR_WIDTH(flags); flags |= FWIDTH; GETASTER(width); if (width < 0) { flags |= FMINUS; width = -width; } p++; goto retry; case '.': if (flags & FPREC0) { rb_raise(rb_eArgError, "precision given twice"); } flags |= FPREC|FPREC0; 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); RB_GC_GUARD(tmp); } 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; case 's': case 'p': format_s: { VALUE arg = GETARG(); long len, slen; if (*p == 'p') arg = rb_inspect(arg); str = rb_obj_as_string(arg); if (OBJ_TAINTED(str)) tainted = 1; len = RSTRING_LEN(str); rb_str_set_len(result, blen); if (coderange != ENC_CODERANGE_BROKEN && scanned < blen) { int cr = coderange; scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &cr); ENC_CODERANGE_SET(result, (cr == ENC_CODERANGE_UNKNOWN ? ENC_CODERANGE_BROKEN : (coderange = cr))); } enc = rb_enc_check(result, str); if (flags&(FPREC|FWIDTH)) { slen = rb_enc_strlen(RSTRING_PTR(str),RSTRING_END(str),enc); if (slen < 0) { rb_raise(rb_eArgError, "invalid mbstring sequence"); } if ((flags&FPREC) && (prec < slen)) { char *p = rb_enc_nth(RSTRING_PTR(str), RSTRING_END(str), prec, enc); slen = prec; len = p - RSTRING_PTR(str); } /* need to adjust multi-byte string pos */ if ((flags&FWIDTH) && (width > slen)) { width -= (int)slen; if (!(flags&FMINUS)) { CHECK(width); while (width--) { buf[blen++] = ' '; } } CHECK(len); memcpy(&buf[blen], RSTRING_PTR(str), len); RB_GC_GUARD(str); blen += len; if (flags&FMINUS) { CHECK(width); while (width--) { buf[blen++] = ' '; } } rb_enc_associate(result, enc); break; } } PUSH(RSTRING_PTR(str), len); RB_GC_GUARD(str); rb_enc_associate(result, enc); } break; case 'd': case 'i': case 'o': case 'x': case 'X': case 'b': case 'B': case 'u': { volatile VALUE val = GETARG(); char fbuf[32], nbuf[64], *s; const char *prefix = 0; int sign = 0, dots = 0; char sc = 0; long v = 0; int base, bignum = 0; int len; switch (*p) { case 'd': case 'i': case 'u': sign = 1; break; case 'o': case 'x': case 'X': case 'b': case 'B': if (flags&(FPLUS|FSPACE)) sign = 1; break; } if (flags & FSHARP) { switch (*p) { case 'o': prefix = "0"; break; case 'x': prefix = "0x"; break; case 'X': prefix = "0X"; break; case 'b': prefix = "0b"; break; case 'B': prefix = "0B"; break; } } bin_retry: switch (TYPE(val)) { case T_FLOAT: if (FIXABLE(RFLOAT_VALUE(val))) { val = LONG2FIX((long)RFLOAT_VALUE(val)); goto bin_retry; } val = rb_dbl2big(RFLOAT_VALUE(val)); if (FIXNUM_P(val)) goto bin_retry; bignum = 1; break; case T_STRING: val = rb_str_to_inum(val, 0, TRUE); goto bin_retry; case T_BIGNUM: bignum = 1; break; case T_FIXNUM: v = FIX2LONG(val); break; default: val = rb_Integer(val); goto bin_retry; } switch (*p) { case 'o': base = 8; break; case 'x': case 'X': base = 16; break; case 'b': case 'B': base = 2; break; case 'u': case 'd': case 'i': default: base = 10; break; } if (!bignum) { if (base == 2) { val = rb_int2big(v); goto bin_retry; } if (sign) { char c = *p; if (c == 'i') c = 'd'; /* %d and %i are identical */ if (v < 0) { v = -v; sc = '-'; width--; } else if (flags & FPLUS) { sc = '+'; width--; } else if (flags & FSPACE) { sc = ' '; width--; } snprintf(fbuf, sizeof(fbuf), "%%l%c", c); snprintf(nbuf, sizeof(nbuf), fbuf, v); s = nbuf; } else { s = nbuf; if (v < 0) { dots = 1; } snprintf(fbuf, sizeof(fbuf), "%%l%c", *p == 'X' ? 'x' : *p); snprintf(++s, sizeof(nbuf) - 1, fbuf, v); if (v < 0) { char d = 0; s = remove_sign_bits(s, base); switch (base) { case 16: d = 'f'; break; case 8: d = '7'; break; } if (d && *s != d) { *--s = d; } } } len = (int)strlen(s); } else { if (sign) { tmp = rb_big2str(val, base); s = RSTRING_PTR(tmp); if (s[0] == '-') { s++; sc = '-'; width--; } else if (flags & FPLUS) { sc = '+'; width--; } else if (flags & FSPACE) { sc = ' '; width--; } } else { if (!RBIGNUM_SIGN(val)) { val = rb_big_clone(val); rb_big_2comp(val); } tmp = rb_big2str0(val, base, RBIGNUM_SIGN(val)); s = RSTRING_PTR(tmp); if (*s == '-') { dots = 1; if (base == 10) { rb_warning("negative number for %%u specifier"); } s = remove_sign_bits(++s, base); switch (base) { case 16: if (s[0] != 'f') *--s = 'f'; break; case 8: if (s[0] != '7') *--s = '7'; break; case 2: if (s[0] != '1') *--s = '1'; break; } } } len = rb_long2int(RSTRING_END(tmp) - s); } if (dots) { prec -= 2; width -= 2; } if (*p == 'X') { char *pp = s; int c; while ((c = (int)(unsigned char)*pp) != 0) { *pp = rb_enc_toupper(c, enc); pp++; } } if (prefix && !prefix[1]) { /* octal */ if (dots) { prefix = 0; } else if (len == 1 && *s == '0') { len = 0; if (flags & FPREC) prec--; } else if ((flags & FPREC) && (prec > len)) { prefix = 0; } } else if (len == 1 && *s == '0') { prefix = 0; } if (prefix) { width -= (int)strlen(prefix); } if ((flags & (FZERO|FMINUS|FPREC)) == FZERO) { prec = width; width = 0; } else { if (prec < len) { if (!prefix && prec == 0 && len == 1 && *s == '0') len = 0; prec = len; } width -= prec; } if (!(flags&FMINUS)) { CHECK(width); while (width-- > 0) { buf[blen++] = ' '; } } if (sc) PUSH(&sc, 1); if (prefix) { int plen = (int)strlen(prefix); PUSH(prefix, plen); } CHECK(prec - len); if (dots) PUSH("..", 2); if (!bignum && v < 0) { char c = sign_bits(base, p); while (len < prec--) { buf[blen++] = c; } } else if ((flags & (FMINUS|FPREC)) != FMINUS) { char c; if (!sign && bignum && !RBIGNUM_SIGN(val)) c = sign_bits(base, p); else c = '0'; while (len < prec--) { buf[blen++] = c; } } PUSH(s, len); RB_GC_GUARD(tmp); CHECK(width); while (width-- > 0) { buf[blen++] = ' '; } } break; case 'f': case 'g': case 'G': case 'e': case 'E': case 'a': case 'A': { VALUE val = GETARG(); double fval; int i, need = 6; char fbuf[32]; fval = RFLOAT_VALUE(rb_Float(val)); if (isnan(fval) || isinf(fval)) { const char *expr; if (isnan(fval)) { expr = "NaN"; } else { expr = "Inf"; } need = (int)strlen(expr); if ((!isnan(fval) && fval < 0.0) || (flags & FPLUS)) need++; if ((flags & FWIDTH) && need < width) need = width; CHECK(need + 1); snprintf(&buf[blen], need + 1, "%*s", need, ""); if (flags & FMINUS) { if (!isnan(fval) && fval < 0.0) buf[blen++] = '-'; else if (flags & FPLUS) buf[blen++] = '+'; else if (flags & FSPACE) blen++; memcpy(&buf[blen], expr, strlen(expr)); } else { if (!isnan(fval) && fval < 0.0) buf[blen + need - strlen(expr) - 1] = '-'; else if (flags & FPLUS) buf[blen + need - strlen(expr) - 1] = '+'; else if ((flags & FSPACE) && need > width) blen++; memcpy(&buf[blen + need - strlen(expr)], expr, strlen(expr)); } blen += strlen(&buf[blen]); break; } fmt_setup(fbuf, sizeof(fbuf), *p, flags, width, prec); need = 0; if (*p != 'e' && *p != 'E') { i = INT_MIN; frexp(fval, &i); if (i > 0) need = BIT_DIGITS(i); } need += (flags&FPREC) ? prec : 6; if ((flags&FWIDTH) && need < width) need = width; need += 20; CHECK(need); snprintf(&buf[blen], need, fbuf, fval); blen += strlen(&buf[blen]); } break; } flags = FNONE; } sprint_exit: RB_GC_GUARD(fmt); /* XXX - We cannot validate the number of arguments if (digit)$ style used. */ if (posarg >= 0 && nextarg < argc) { const char *mesg = "too many arguments for format string"; if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg); if (RTEST(ruby_verbose)) rb_warn("%s", mesg); } rb_str_resize(result, blen); if (tainted) OBJ_TAINT(result); return result; }
static int rb_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn) { VALUE features, this_feature_index = Qnil, v, p, load_path = 0; const char *f, *e; long i, len, elen, n; st_table *loading_tbl, *features_index; st_data_t data; int type; if (fn) *fn = 0; if (ext) { elen = strlen(ext); len = strlen(feature) - elen; type = rb ? 'r' : 's'; } else { len = strlen(feature); elen = 0; type = 0; } features = get_loaded_features(); features_index = get_loaded_features_index(); st_lookup(features_index, (st_data_t)feature, (st_data_t *)&this_feature_index); /* We search `features` for an entry such that either "#{features[i]}" == "#{load_path[j]}/#{feature}#{e}" for some j, or "#{features[i]}" == "#{feature}#{e}" Here `e` is an "allowed" extension -- either empty or one of the extensions accepted by IS_RBEXT, IS_SOEXT, or IS_DLEXT. Further, if `ext && rb` then `IS_RBEXT(e)`, and if `ext && !rb` then `IS_SOEXT(e) || IS_DLEXT(e)`. If `expanded`, then only the latter form (without load_path[j]) is accepted. Otherwise either form is accepted, *unless* `ext` is false and an otherwise-matching entry of the first form is preceded by an entry of the form "#{features[i2]}" == "#{load_path[j2]}/#{feature}#{e2}" where `e2` matches %r{^\.[^./]*$} but is not an allowed extension. After a "distractor" entry of this form, only entries of the form "#{feature}#{e}" are accepted. In `rb_provide_feature()` and `get_loaded_features_index()` we maintain an invariant that the array `this_feature_index` will point to every entry in `features` which has the form "#{prefix}#{feature}#{e}" where `e` is empty or matches %r{^\.[^./]*$}, and `prefix` is empty or ends in '/'. This includes both match forms above, as well as any distractors, so we may ignore all other entries in `features`. */ if (!NIL_P(this_feature_index)) { for (i = 0; ; i++) { VALUE entry; long index; if (RB_TYPE_P(this_feature_index, T_ARRAY)) { if (i >= RARRAY_LEN(this_feature_index)) break; entry = RARRAY_AREF(this_feature_index, i); } else { if (i > 0) break; entry = this_feature_index; } index = FIX2LONG(entry); v = RARRAY_AREF(features, index); f = StringValuePtr(v); if ((n = RSTRING_LEN(v)) < len) continue; if (strncmp(f, feature, len) != 0) { if (expanded) continue; if (!load_path) load_path = rb_get_expanded_load_path(); if (!(p = loaded_feature_path(f, n, feature, len, type, load_path))) continue; expanded = 1; f += RSTRING_LEN(p) + 1; } if (!*(e = f + len)) { if (ext) continue; return 'u'; } if (*e != '.') continue; if ((!rb || !ext) && (IS_SOEXT(e) || IS_DLEXT(e))) { return 's'; } if ((rb || !ext) && (IS_RBEXT(e))) { return 'r'; } } } loading_tbl = get_loading_table(); f = 0; if (!expanded) { struct loaded_feature_searching fs; fs.name = feature; fs.len = len; fs.type = type; fs.load_path = load_path ? load_path : rb_get_expanded_load_path(); fs.result = 0; st_foreach(loading_tbl, loaded_feature_path_i, (st_data_t)&fs); if ((f = fs.result) != 0) { if (fn) *fn = f; goto loading; } } if (st_get_key(loading_tbl, (st_data_t)feature, &data)) { if (fn) *fn = (const char*)data; loading: if (!ext) return 'u'; return !IS_RBEXT(ext) ? 's' : 'r'; } else { VALUE bufstr; char *buf; static const char so_ext[][4] = { ".so", ".o", }; if (ext && *ext) return 0; bufstr = rb_str_tmp_new(len + DLEXT_MAXLEN); buf = RSTRING_PTR(bufstr); MEMCPY(buf, feature, char, len); for (i = 0; (e = loadable_ext[i]) != 0; i++) { strlcpy(buf + len, e, DLEXT_MAXLEN + 1); if (st_get_key(loading_tbl, (st_data_t)buf, &data)) { rb_str_resize(bufstr, 0); if (fn) *fn = (const char*)data; return i ? 's' : 'r'; } } for (i = 0; i < numberof(so_ext); i++) { strlcpy(buf + len, so_ext[i], DLEXT_MAXLEN + 1); if (st_get_key(loading_tbl, (st_data_t)buf, &data)) { rb_str_resize(bufstr, 0); if (fn) *fn = (const char*)data; return 's'; } } rb_str_resize(bufstr, 0); } return 0; }
VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE bit_depth, VALUE filtering) { UNUSED_PARAMETER(bit_depth); // Get the data char depth = (char) FIX2INT(bit_depth); long width = FIX2LONG(rb_funcall(self, rb_intern("width"), 0)); long height = FIX2LONG(rb_funcall(self, rb_intern("height"), 0)); VALUE pixels = rb_funcall(self, rb_intern("pixels"), 0); if (RARRAY_LEN(pixels) != width * height) { rb_raise(rb_eRuntimeError, "The number of pixels does not match the canvas dimensions."); } // Get the encoding palette if we're encoding to an indexed bytestream. VALUE encoding_palette = Qnil; if (FIX2INT(color_mode) == OILY_PNG_COLOR_INDEXED) { encoding_palette = oily_png_encode_palette(self); } char pixel_size = oily_png_pixel_bytesize(FIX2INT(color_mode), depth); long line_size = oily_png_scanline_bytesize(FIX2INT(color_mode), depth, width); long pass_size = oily_png_pass_bytesize(FIX2INT(color_mode), depth, width, height); // Allocate memory for the byte array. BYTE* bytes = ALLOC_N(BYTE, pass_size); // Get the scanline encoder function. scanline_encoder_func scanline_encoder = oily_png_encode_scanline_func(FIX2INT(color_mode), depth); if (scanline_encoder == NULL) { rb_raise(rb_eRuntimeError, "No encoder for color mode %d and bit depth %d", FIX2INT(color_mode), depth); } long y, pos; for (y = height - 1; y >= 0; y--) { pos = line_size * y; bytes[pos] = (BYTE) FIX2INT(filtering); scanline_encoder(bytes + pos + 1, pixels, y, width, encoding_palette); } if (FIX2INT(filtering) != OILY_PNG_FILTER_NONE) { // Get the scanline filter function void (*scanline_filter)(BYTE*, long, long, char) = NULL; switch (FIX2INT(filtering)) { case OILY_PNG_FILTER_SUB: scanline_filter = &oily_png_encode_filter_sub; break; case OILY_PNG_FILTER_UP: scanline_filter = &oily_png_encode_filter_up; break; case OILY_PNG_FILTER_AVERAGE: scanline_filter = &oily_png_encode_filter_average; break; case OILY_PNG_FILTER_PAETH: scanline_filter = &oily_png_encode_filter_paeth; break; default: rb_raise(rb_eRuntimeError, "Unsupported filter type: %d", FIX2INT(filtering)); } for (y = height - 1; y >= 0; y--) { scanline_filter(bytes, line_size * y, line_size, pixel_size); } } // Append to encoded image pass to the output stream. rb_str_cat(stream, (char*) bytes, pass_size); xfree(bytes); return Qnil; }
// www.osr.com/ddk/graphics/gdifncs_027b.htm BOOL APIENTRY XFORMOBJ_bApplyXform( IN XFORMOBJ *pxo, IN ULONG iMode, IN ULONG cPoints, IN PVOID pvIn, OUT PVOID pvOut) { MATRIX mx; XFORMOBJ xoInv; POINTL *pptl; INT i; /* Check parameters */ if (!pxo || !pvIn || !pvOut || cPoints < 1) { return FALSE; } /* Use inverse xform? */ if (iMode == XF_INV_FXTOL || iMode == XF_INV_LTOL) { XFORMOBJ_vInit(&xoInv, &mx); if (XFORMOBJ_iInverse(&xoInv, pxo) == DDI_ERROR) { return FALSE; } pxo = &xoInv; } /* Convert POINTL to POINTFIX? */ if (iMode == XF_LTOFX || iMode == XF_LTOL || iMode == XF_INV_LTOL) { pptl = pvIn; for (i = cPoints - 1; i >= 0; i--) { pptl[i].x = LONG2FIX(pptl[i].x); pptl[i].y = LONG2FIX(pptl[i].y); } } /* Do the actual fixpoint transformation */ if (!XFORMOBJ_bXformFixPoints(pxo, cPoints, pvIn, pvOut)) { return FALSE; } /* Convert POINTFIX to POINTL? */ if (iMode == XF_INV_FXTOL || iMode == XF_INV_LTOL || iMode == XF_LTOL) { pptl = pvOut; for (i = cPoints - 1; i >= 0; i--) { pptl[i].x = FIX2LONG(pptl[i].x); pptl[i].y = FIX2LONG(pptl[i].y); } } return TRUE; }
VALUE Dead_Code_Deleter3_visit(VALUE self ){VALUE vals[0]; VALUE it ,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_this=Qnil,__result=Qnil,_autovar_4=Qnil,_autovar_5=Qnil,_autovar_6=Qnil,_autovar_7=Qnil,_autovar_8=Qnil,_autovar_9=Qnil,_autovar_10=Qnil,_autovar_11=Qnil,_autovar_12=Qnil,_autovar_13=Qnil,_t=Qnil,_autovar_14=Qnil;VALUE bind2=bind_new2(2); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);switch(FIX2LONG(rb_hash_aref(switchhash_Dead_Code_Deleter3_2,rb_obj_class(ame_curobj2(ptr))))){case 0/*Act*/:case 1/*CAct*/:case 2/*Local*/:case 3/*Result*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_3=it;; cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_3); it=rb_funcall(self,sy_Dead_Code_Deleter3_src_25d9,1,bind2); _this=it;; ptr->pos=ptr->len; goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto fail;} success1: *ptr=oldpass1; bind_aset(bind2,1,_autovar_2);bind_aset(bind2,2,_this);it=rb_funcall(self,sy_Dead_Code_Deleter3__lp_,1,bind2);_autovar_2=bind_aget(bind2,1);;_this=bind_aget(bind2,2);; __result=it;; _autovar_4=it;; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break; case 4/*Apply*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_5=it;; cstruct oldpass2=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_5); ptr->pos=ptr->len;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3_d_eq_src_dot_du_2b46,1,bind2);_autovar_2=bind_aget(bind2,1);; _autovar_6=it;; goto success2; pass2: *ptr=oldpass2;if (1){it=failobj;goto fail;} success2: *ptr=oldpass2; it=_autovar_6; __result=it;; _autovar_4=it;; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break; case 5/*Bind*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_7=it;; cstruct oldpass3=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_7); ptr->pos=ptr->len;it=rb_funcall(self,sy_Dead_Code_Deleter3_src_25d9,1,bind2);bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3_bind_lb_1_rb__lb__146c,1,bind2);_autovar_2=bind_aget(bind2,1);;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_d6d5,1,bind2);_autovar_2=bind_aget(bind2,1);; it=Dead_Code_Deleter3_traverse(self ); if (it==failobj){it=failobj;goto pass3;} _autovar_8=it;; cstruct oldpass4=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_8); ptr->pos=ptr->len;bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3_bind_lb_1_rb__lb__8eca,1,bind2);_autovar_2=bind_aget(bind2,1);; _autovar_9=it;; goto success4; pass4: *ptr=oldpass4;if (1){it=failobj;goto pass3;} success4: *ptr=oldpass4; it=_autovar_9; _autovar_10=it;; goto success3; pass3: *ptr=oldpass3;if (1){it=failobj;goto fail;} success3: *ptr=oldpass3; it=_autovar_10; __result=it;; _autovar_4=it;; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break; case 6/*Pass*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_11=it;; cstruct oldpass5=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_11); it=rb_funcall(self,sy_Dead_Code_Deleter3_src_dot_to_5e99,1,bind2); _autovar_12=it;; cstruct oldpass6=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ptr->src=failobj;ptr->ary=alloca(sizeof(VALUE));ptr->ary[0]=_autovar_12;ptr->len=1; bind_aset(bind2,1,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_d6d5,1,bind2);_autovar_2=bind_aget(bind2,1);; it=Dead_Code_Deleter3_traverse_item(self ); if (it==failobj){it=failobj;goto pass6;} _autovar_13=it;; goto success6; pass6: *ptr=oldpass6;if (1){it=failobj;goto pass5;} success6: *ptr=oldpass6; it=_autovar_13; _t=it;; bind_aset(bind2,1,_t);it=rb_funcall(self,sy_Dead_Code_Deleter3_d_eq_src_dot_du_d571,1,bind2);_t=bind_aget(bind2,1);; _autovar_14=it;; goto success5; pass5: *ptr=oldpass5;if (1){it=failobj;goto fail;} success5: *ptr=oldpass5; it=_autovar_14; __result=it;; _autovar_4=it;; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_4);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_cdb3,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_4=bind_aget(bind2,2);; break; case 7/*Object*/:; bind_aset(bind2,1,_autovar);bind_aset(bind2,2,_autovar_2);it=rb_funcall(self,sy_Dead_Code_Deleter3__at__contex_5f56,1,bind2);_autovar=bind_aget(bind2,1);;_autovar_2=bind_aget(bind2,2);;if (1){it=failobj;goto fail;} break; } fail: return it; }
/* * Document-method: Fixnum#to_msgpack * * call-seq: * fixnum.to_msgpack(out = '') -> String * * Serializes the Fixnum into raw bytes. */ static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self) { ARG_BUFFER(out, argc, argv); msgpack_pack_long(out, FIX2LONG(self)); return out; }
static VALUE range_step(VALUE range, SEL sel, int argc, VALUE *argv) { VALUE b, e, step, tmp; RETURN_ENUMERATOR(range, argc, argv); b = RANGE_BEG(range); e = RANGE_END(range); if (argc == 0) { step = INT2FIX(1); } else { rb_scan_args(argc, argv, "01", &step); if (!rb_obj_is_kind_of(step, rb_cNumeric)) { step = rb_to_int(step); } VALUE zero = INT2FIX(0); if (rb_vm_call(step, selLT, 1, &zero)) { rb_raise(rb_eArgError, "step can't be negative"); } else if (!rb_vm_call(step, selGT, 1, &zero)) { rb_raise(rb_eArgError, "step can't be 0"); } } if (FIXNUM_P(b) && FIXNUM_P(e) && FIXNUM_P(step)) { /* fixnums are special */ long end = FIX2LONG(e); long i, unit = FIX2LONG(step); if (!EXCL(range)) end += 1; i = FIX2LONG(b); while (i < end) { rb_yield(LONG2NUM(i)); RETURN_IF_BROKEN(); if (i + unit < i) break; i += unit; } } else if (SYMBOL_P(b) && SYMBOL_P(e)) { /* symbols are special */ VALUE args[2]; VALUE iter[2]; args[0] = rb_sym_to_s(e); args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_objc_block_call(rb_sym_to_s(b), selUpto, 2, args, sym_step_i, (VALUE)iter); } else if (ruby_float_step(b, e, step, EXCL(range))) { /* done */ } else if (rb_obj_is_kind_of(b, rb_cNumeric) || !NIL_P(rb_check_to_integer(b, "to_int")) || !NIL_P(rb_check_to_integer(e, "to_int"))) { SEL op = EXCL(range) ? selLT : selLE; VALUE v = b; int i = 0; while (RTEST(rb_vm_call(v, op, 1, &e))) { rb_yield(v); RETURN_IF_BROKEN(); i++; VALUE tmp = rb_vm_call(INT2NUM(i), selMULT, 1, &step); v = rb_vm_call(b, selPLUS, 1, &tmp); } } else { tmp = rb_check_string_type(b); if (!NIL_P(tmp)) { VALUE args[2], iter[2]; b = tmp; args[0] = e; args[1] = EXCL(range) ? Qtrue : Qfalse; iter[0] = INT2FIX(1); iter[1] = step; rb_objc_block_call(b, selUpto, 2, args, step_i, (VALUE)iter); } else { VALUE args[2]; if (!discrete_object_p(b)) { rb_raise(rb_eTypeError, "can't iterate from %s", rb_obj_classname(b)); } args[0] = INT2FIX(1); args[1] = step; return range_each_func(range, step_i, args); } } return range; }
/* * call-seq: * cmp ** numeric -> complex * * Performs exponentiation. * * Complex('i') ** 2 #=> (-1+0i) * Complex(-8) ** Rational(1, 3) #=> (1.0000000000000002+1.7320508075688772i) */ static VALUE nucomp_expt(VALUE self, VALUE other) { if (k_numeric_p(other) && k_exact_zero_p(other)) return f_complex_new_bang1(CLASS_OF(self), ONE); if (k_rational_p(other) && f_one_p(f_denominator(other))) other = f_numerator(other); /* c14n */ if (k_complex_p(other)) { get_dat1(other); if (k_exact_zero_p(dat->imag)) other = dat->real; /* c14n */ } if (k_complex_p(other)) { VALUE r, theta, nr, ntheta; get_dat1(other); r = f_abs(self); theta = f_arg(self); nr = m_exp_bang(f_sub(f_mul(dat->real, m_log_bang(r)), f_mul(dat->imag, theta))); ntheta = f_add(f_mul(theta, dat->real), f_mul(dat->imag, m_log_bang(r))); return f_complex_polar(CLASS_OF(self), nr, ntheta); } if (k_fixnum_p(other)) { if (f_gt_p(other, ZERO)) { VALUE x, z; long n; x = self; z = x; n = FIX2LONG(other) - 1; while (n) { long q, r; while (1) { get_dat1(x); q = n / 2; r = n % 2; if (r) break; x = nucomp_s_new_internal(CLASS_OF(self), f_sub(f_mul(dat->real, dat->real), f_mul(dat->imag, dat->imag)), f_mul(f_mul(TWO, dat->real), dat->imag)); n = q; } z = f_mul(z, x); n--; } return z; } return f_expt(f_reciprocal(self), f_negate(other)); } if (k_numeric_p(other) && f_real_p(other)) { VALUE r, theta; if (k_bignum_p(other)) rb_warn("in a**b, b may be too big"); r = f_abs(self); theta = f_arg(self); return f_complex_polar(CLASS_OF(self), f_expt(r, other), f_mul(theta, other)); } return rb_num_coerce_bin(self, other, id_expt); }
static size_t date_strftime_with_tmx(char *s, size_t maxsize, const char *format, const struct tmx *tmx) { char *endp = s + maxsize; char *start = s; const char *sp, *tp; auto char tbuf[100]; ptrdiff_t i; int v, w; size_t colons; int precision, flags; char padding; /* LOCALE_[OE] and COLONS are actually modifiers, not flags */ enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E, COLONS}; #define BIT_OF(n) (1U<<(n)) /* various tables for locale C */ static const char days_l[][10] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", }; static const char months_l[][10] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", }; static const char ampm[][3] = { "AM", "PM", }; if (s == NULL || format == NULL || tmx == NULL || maxsize == 0) return 0; /* quick check if we even need to bother */ if (strchr(format, '%') == NULL && strlen(format) + 1 >= maxsize) { err: errno = ERANGE; return 0; } for (; *format && s < endp - 1; format++) { #define FLAG_FOUND() do { \ if (precision > 0 || flags & (BIT_OF(LOCALE_E) | BIT_OF(LOCALE_O) | BIT_OF(COLONS))) \ goto unknown; \ } while (0) #define NEEDS(n) do if (s >= endp || (n) >= endp - s - 1) goto err; while (0) #define FILL_PADDING(i) do { \ if (!(flags & BIT_OF(LEFT)) && precision > (i)) { \ NEEDS(precision); \ memset(s, padding ? padding : ' ', precision - (i)); \ s += precision - (i); \ } \ else { \ NEEDS(i); \ } \ } while (0); #define FMT(def_pad, def_prec, fmt, val) \ do { \ int l; \ if (precision <= 0) precision = (def_prec); \ if (flags & BIT_OF(LEFT)) precision = 1; \ l = snprintf(s, endp - s, \ ((padding == '0' || (!padding && (def_pad) == '0')) ? \ "%0*"fmt : "%*"fmt), \ precision, (val)); \ if (l < 0) goto err; \ s += l; \ } while (0) #define STRFTIME(fmt) \ do { \ i = date_strftime_with_tmx(s, endp - s, (fmt), tmx); \ if (!i) return 0; \ if (flags & BIT_OF(UPPER)) \ upcase(s, i); \ if (!(flags & BIT_OF(LEFT)) && precision > i) { \ if (start + maxsize < s + precision) { \ errno = ERANGE; \ return 0; \ } \ memmove(s + precision - i, s, i); \ memset(s, padding ? padding : ' ', precision - i); \ s += precision; \ } \ else s += i; \ } while (0) #define FMTV(def_pad, def_prec, fmt, val) \ do { \ VALUE tmp = (val); \ if (FIXNUM_P(tmp)) { \ FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \ } \ else { \ VALUE args[2], result; \ size_t l; \ if (precision <= 0) precision = (def_prec); \ if (flags & BIT_OF(LEFT)) precision = 1; \ args[0] = INT2FIX(precision); \ args[1] = (val); \ if (padding == '0' || (!padding && (def_pad) == '0')) \ result = rb_str_format(2, args, rb_str_new2("%0*"fmt)); \ else \ result = rb_str_format(2, args, rb_str_new2("%*"fmt)); \ l = strlcpy(s, StringValueCStr(result), endp - s); \ if ((size_t)(endp - s) <= l) \ goto err; \ s += l; \ } \ } while (0) if (*format != '%') { *s++ = *format; continue; } tp = tbuf; sp = format; precision = -1; flags = 0; padding = 0; colons = 0; again: switch (*++format) { case '\0': format--; goto unknown; case 'A': /* full weekday name */ case 'a': /* abbreviated weekday name */ if (flags & BIT_OF(CHCASE)) { flags &= ~(BIT_OF(LOWER) | BIT_OF(CHCASE)); flags |= BIT_OF(UPPER); } { int wday = tmx_wday; if (wday < 0 || wday > 6) i = 1, tp = "?"; else { if (*format == 'A') i = strlen(tp = days_l[wday]); else i = 3, tp = days_l[wday]; } } break; case 'B': /* full month name */ case 'b': /* abbreviated month name */ case 'h': /* same as %b */ if (flags & BIT_OF(CHCASE)) { flags &= ~(BIT_OF(LOWER) | BIT_OF(CHCASE)); flags |= BIT_OF(UPPER); } { int mon = tmx_mon; if (mon < 1 || mon > 12) i = 1, tp = "?"; else { if (*format == 'B') i = strlen(tp = months_l[mon - 1]); else i = 3, tp = months_l[mon - 1]; } } break; case 'C': /* century (year/100) */ FMTV('0', 2, "d", div(tmx_year, INT2FIX(100))); continue; case 'c': /* appropriate date and time representation */ STRFTIME("%a %b %e %H:%M:%S %Y"); continue; case 'D': STRFTIME("%m/%d/%y"); continue; case 'd': /* day of the month, 01 - 31 */ case 'e': /* day of month, blank padded */ v = range(1, tmx_mday, 31); FMT((*format == 'd') ? '0' : ' ', 2, "d", v); continue; case 'F': STRFTIME("%Y-%m-%d"); continue; case 'G': /* year of ISO week with century */ case 'Y': /* year with century */ { VALUE year = (*format == 'G') ? tmx_cwyear : tmx_year; if (FIXNUM_P(year)) { long y = FIX2LONG(year); FMT('0', 0 <= y ? 4 : 5, "ld", y); } else { FMTV('0', 4, "d", year); } } continue; case 'g': /* year of ISO week without a century */ case 'y': /* year without a century */ v = NUM2INT(mod((*format == 'g') ? tmx_cwyear : tmx_year, INT2FIX(100))); FMT('0', 2, "d", v); continue; case 'H': /* hour, 24-hour clock, 00 - 23 */ case 'k': /* hour, 24-hour clock, blank pad */ v = range(0, tmx_hour, 23); FMT((*format == 'H') ? '0' : ' ', 2, "d", v); continue; case 'I': /* hour, 12-hour clock, 01 - 12 */ case 'l': /* hour, 12-hour clock, 1 - 12, blank pad */ v = range(0, tmx_hour, 23); if (v == 0) v = 12; else if (v > 12) v -= 12; FMT((*format == 'I') ? '0' : ' ', 2, "d", v); continue; case 'j': /* day of the year, 001 - 366 */ v = range(1, tmx_yday, 366); FMT('0', 3, "d", v); continue; case 'L': /* millisecond */ case 'N': /* nanosecond */ if (*format == 'L') w = 3; else w = 9; if (precision <= 0) precision = w; NEEDS(precision); { VALUE subsec = tmx_sec_fraction; int ww; long n; ww = precision; while (9 <= ww) { subsec = mul(subsec, INT2FIX(1000000000)); ww -= 9; } n = 1; for (; 0 < ww; ww--) n *= 10; if (n != 1) subsec = mul(subsec, INT2FIX(n)); subsec = div(subsec, INT2FIX(1)); if (FIXNUM_P(subsec)) { (void)snprintf(s, endp - s, "%0*ld", precision, FIX2LONG(subsec)); s += precision; } else { VALUE args[2], result; args[0] = INT2FIX(precision); args[1] = subsec; result = rb_str_format(2, args, rb_str_new2("%0*d")); (void)strlcpy(s, StringValueCStr(result), endp - s); s += precision; } } continue; case 'M': /* minute, 00 - 59 */ v = range(0, tmx_min, 59); FMT('0', 2, "d", v); continue; case 'm': /* month, 01 - 12 */ v = range(1, tmx_mon, 12); FMT('0', 2, "d", v); continue; case 'n': /* same as \n */ FILL_PADDING(1); *s++ = '\n'; continue; case 't': /* same as \t */ FILL_PADDING(1); *s++ = '\t'; continue; case 'P': /* am or pm based on 12-hour clock */ case 'p': /* AM or PM based on 12-hour clock */ if ((*format == 'p' && (flags & BIT_OF(CHCASE))) || (*format == 'P' && !(flags & (BIT_OF(CHCASE) | BIT_OF(UPPER))))) { flags &= ~(BIT_OF(UPPER) | BIT_OF(CHCASE)); flags |= BIT_OF(LOWER); } v = range(0, tmx_hour, 23); if (v < 12) tp = ampm[0]; else tp = ampm[1]; i = 2; break; case 'Q': /* milliseconds since Unix epoch */ FMTV('0', 1, "d", tmx_msecs); continue; case 'R': STRFTIME("%H:%M"); continue; case 'r': STRFTIME("%I:%M:%S %p"); continue; case 'S': /* second, 00 - 59 */ v = range(0, tmx_sec, 59); FMT('0', 2, "d", v); continue; case 's': /* seconds since Unix epoch */ FMTV('0', 1, "d", tmx_secs); continue; case 'T': STRFTIME("%H:%M:%S"); continue; case 'U': /* week of year, Sunday is first day of week */ case 'W': /* week of year, Monday is first day of week */ v = range(0, (*format == 'U') ? tmx_wnum0 : tmx_wnum1, 53); FMT('0', 2, "d", v); continue; case 'u': /* weekday, Monday == 1, 1 - 7 */ v = range(1, tmx_cwday, 7); FMT('0', 1, "d", v); continue; case 'V': /* week of year according ISO 8601 */ v = range(1, tmx_cweek, 53); FMT('0', 2, "d", v); continue; case 'v': STRFTIME("%e-%b-%Y"); continue; case 'w': /* weekday, Sunday == 0, 0 - 6 */ v = range(0, tmx_wday, 6); FMT('0', 1, "d", v); continue; case 'X': /* appropriate time representation */ STRFTIME("%H:%M:%S"); continue; case 'x': /* appropriate date representation */ STRFTIME("%m/%d/%y"); continue; case 'Z': /* time zone name or abbreviation */ if (flags & BIT_OF(CHCASE)) { flags &= ~(BIT_OF(UPPER) | BIT_OF(CHCASE)); flags |= BIT_OF(LOWER); } { char *zone = tmx_zone; if (zone == NULL) tp = ""; else tp = zone; i = strlen(tp); } break; case 'z': /* offset from UTC */ { long off, aoff; int hl, hw; off = tmx_offset; aoff = off; if (aoff < 0) aoff = -off; if ((aoff / 3600) < 10) hl = 1; else hl = 2; hw = 2; if (flags & BIT_OF(LEFT) && hl == 1) hw = 1; switch (colons) { case 0: /* %z -> +hhmm */ precision = precision <= (3 + hw) ? hw : precision - 3; NEEDS(precision + 3); break; case 1: /* %:z -> +hh:mm */ precision = precision <= (4 + hw) ? hw : precision - 4; NEEDS(precision + 4); break; case 2: /* %::z -> +hh:mm:ss */ precision = precision <= (7 + hw) ? hw : precision - 7; NEEDS(precision + 7); break; case 3: /* %:::z -> +hh[:mm[:ss]] */ { if (aoff % 3600 == 0) { precision = precision <= (1 + hw) ? hw : precision - 1; NEEDS(precision + 3); } else if (aoff % 60 == 0) { precision = precision <= (4 + hw) ? hw : precision - 4; NEEDS(precision + 4); } else { precision = precision <= (7 + hw) ? hw : precision - 7; NEEDS(precision + 7); } } break; default: format--; goto unknown; } if (padding == ' ' && precision > hl) { i = snprintf(s, endp - s, "%*s", precision - hl, ""); precision = hl; if (i < 0) goto err; s += i; } if (off < 0) { off = -off; *s++ = '-'; } else { *s++ = '+'; } i = snprintf(s, endp - s, "%.*ld", precision, off / 3600); if (i < 0) goto err; s += i; off = off % 3600; if (colons == 3 && off == 0) continue; if (1 <= colons) *s++ = ':'; i = snprintf(s, endp - s, "%02d", (int)(off / 60)); if (i < 0) goto err; s += i; off = off % 60; if (colons == 3 && off == 0) continue; if (2 <= colons) { *s++ = ':'; i = snprintf(s, endp - s, "%02d", (int)off); if (i < 0) goto err; s += i; } } continue; case '+': STRFTIME("%a %b %e %H:%M:%S %Z %Y"); continue; case 'E': /* POSIX locale extensions, ignored for now */ flags |= BIT_OF(LOCALE_E); if (*(format + 1) && strchr("cCxXyY", *(format + 1))) goto again; goto unknown; case 'O': /* POSIX locale extensions, ignored for now */ flags |= BIT_OF(LOCALE_O); if (*(format + 1) && strchr("deHkIlmMSuUVwWy", *(format + 1))) goto again; goto unknown; case ':': flags |= BIT_OF(COLONS); { size_t l = strspn(format, ":"); format += l; if (*format == 'z') { colons = l; format--; goto again; } format -= l; } goto unknown; case '_': FLAG_FOUND(); padding = ' '; goto again; case '-': FLAG_FOUND(); flags |= BIT_OF(LEFT); goto again; case '^': FLAG_FOUND(); flags |= BIT_OF(UPPER); goto again; case '#': FLAG_FOUND(); flags |= BIT_OF(CHCASE); goto again; case '0': FLAG_FOUND(); padding = '0'; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { char *e; precision = (int)strtoul(format, &e, 10); format = e - 1; goto again; } case '%': FILL_PADDING(1); *s++ = '%'; continue; default: unknown: i = format - sp + 1; tp = sp; precision = -1; flags = 0; padding = 0; colons = 0; break; } if (i) { FILL_PADDING(i); memcpy(s, tp, i); switch (flags & (BIT_OF(UPPER) | BIT_OF(LOWER))) { case BIT_OF(UPPER): upcase(s, i); break; case BIT_OF(LOWER): downcase(s, i); break; } s += i; } } if (s >= endp) { goto err; } if (*format == '\0') { *s = '\0'; return (s - start); } return 0; }
VALUE Detect_Contextual_Arguments_traverse_item(VALUE self ){VALUE vals[0]; VALUE it ,__result=Qnil,_autovar=Qnil,_autovar_2=Qnil,_autovar_3=Qnil,_ar=Qnil,_it=Qnil,_autovar_4=Qnil;VALUE bind2=bind_new2(2); cstruct *ptr; Data_Get_Struct(self,cstruct,ptr);switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_2,rb_obj_class(ame_curobj2(ptr))))){case 0/*AmethystAST*/:; switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_3,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; int oldpos1=ptr->pos;int cut1=0; alt1_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=3; it=Detect_Contextual_Arguments_visit(self ); if (it==failobj){it=failobj;goto revert1;} __result=it;; ;goto accept2;revert1:; goto alt1_2; accept2:; ;ptr->branches-=3; goto accept1; alt1_2: ptr->pos=oldpos1;ptr->branches-=1; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar=it;; cstruct oldpass1=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar); it=Detect_Contextual_Arguments_traverse(self ); if (it==failobj){it=failobj;goto pass1;} _autovar_2=it;; goto success1; pass1: *ptr=oldpass1;if (1){it=failobj;goto revert2;} success1: *ptr=oldpass1; it=_autovar_2; __result=it;; ;goto accept3;revert2:; goto alt1_3; accept3:; ;ptr->branches-=2; goto accept1; alt1_3: ptr->pos=oldpos1;ptr->branches-=1; it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto revert3;} __result=it;; ;goto accept4;revert3:; goto alt1_4; accept4:; ;ptr->branches-=1; goto accept1; alt1_4: ptr->pos=oldpos1;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept1:; break; case 1/*Object*/:; int oldpos2=ptr->pos;int cut2=0; alt2_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar=it;; cstruct oldpass2=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar); it=Detect_Contextual_Arguments_traverse(self ); if (it==failobj){it=failobj;goto pass2;} _autovar_2=it;; goto success2; pass2: *ptr=oldpass2;if (1){it=failobj;goto revert4;} success2: *ptr=oldpass2; it=_autovar_2; __result=it;; ;goto accept6;revert4:; goto alt2_2; accept6:; ;ptr->branches-=2; goto accept5; alt2_2: ptr->pos=oldpos2;ptr->branches-=1; it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto revert5;} __result=it;; ;goto accept7;revert5:; goto alt2_3; accept7:; ;ptr->branches-=1; goto accept5; alt2_3: ptr->pos=oldpos2;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept5:; break; } break; case 1/*Array*/:; switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_4,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; int oldpos3=ptr->pos;int cut3=0; alt3_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_visit(self ); if (it==failobj){it=failobj;goto revert6;} __result=it;; ;goto accept9;revert6:; goto alt3_2; accept9:; ;ptr->branches-=2; goto accept8; alt3_2: ptr->pos=oldpos3;ptr->branches-=1; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_3=it;; cstruct oldpass3=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_3); it=rb_ary_new3(0); _ar=it;; int stop1=0; while(!stop1){ int oldpos4=ptr->pos;int cut4=0; alt4_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_traverse_item(self ); if (it==failobj){it=failobj;goto revert8;} _it=it;; bind_aset(bind2,1,_ar);bind_aset(bind2,2,_it);it=rb_funcall(self,sy_Detect_Contextual_Arguments_bind_lb_1_rb__lt__7b20,1,bind2);_ar=bind_aget(bind2,1);;_it=bind_aget(bind2,2);; ;goto accept12;revert8:; goto alt4_2; accept12:; ;ptr->branches-=2; goto accept11; alt4_2: ptr->pos=oldpos4;ptr->branches-=1; stop1=1; ;goto accept13;revert9:; goto alt4_3; accept13:; ;ptr->branches-=1; goto accept11; alt4_3: ptr->pos=oldpos4;ptr->branches-=1;if (1){it=failobj;goto pass3;}; accept11:; } it=_ar; _autovar_4=it;; goto success3; pass3: *ptr=oldpass3;if (1){it=failobj;goto revert7;} success3: *ptr=oldpass3; it=_autovar_4; __result=it;; ;goto accept10;revert7:; goto alt3_3; accept10:; ;ptr->branches-=1; goto accept8; alt3_3: ptr->pos=oldpos3;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept8:; break; case 1/*Object*/:; it=ptr->ary[ptr->pos]; ;ptr->pos++; _autovar_3=it;; cstruct oldpass4=*ptr; ptr->pos=ptr->len=0; ptr->ary=NULL; ame_setsrc2(self,_autovar_3); it=rb_ary_new3(0); _ar=it;; int stop2=0; while(!stop2){ int oldpos5=ptr->pos;int cut5=0; alt5_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_traverse_item(self ); if (it==failobj){it=failobj;goto revert10;} _it=it;; bind_aset(bind2,1,_ar);bind_aset(bind2,2,_it);it=rb_funcall(self,sy_Detect_Contextual_Arguments_bind_lb_1_rb__lt__7b20,1,bind2);_ar=bind_aget(bind2,1);;_it=bind_aget(bind2,2);; ;goto accept15;revert10:; goto alt5_2; accept15:; ;ptr->branches-=2; goto accept14; alt5_2: ptr->pos=oldpos5;ptr->branches-=1; stop2=1; ;goto accept16;revert11:; goto alt5_3; accept16:; ;ptr->branches-=1; goto accept14; alt5_3: ptr->pos=oldpos5;ptr->branches-=1;if (1){it=failobj;goto pass4;}; accept14:; } it=_ar; _autovar_4=it;; goto success4; pass4: *ptr=oldpass4;if (1){it=failobj;goto fail;} success4: *ptr=oldpass4; it=_autovar_4; __result=it;; break; } break; case 2/*Object*/:; switch(FIX2LONG(rb_hash_aref(switchhash_Detect_Contextual_Arguments_5,rb_obj_class(ame_curobj2(ptr))))){case 0/*Contextual_Argument*/:; int oldpos6=ptr->pos;int cut6=0; alt6_1:if(!ptr->branches)ptr->discard=ptr->pos; ptr->branches+=2; it=Detect_Contextual_Arguments_visit(self ); if (it==failobj){it=failobj;goto revert12;} __result=it;; ;goto accept18;revert12:; goto alt6_2; accept18:; ;ptr->branches-=2; goto accept17; alt6_2: ptr->pos=oldpos6;ptr->branches-=1; it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto revert13;} __result=it;; ;goto accept19;revert13:; goto alt6_3; accept19:; ;ptr->branches-=1; goto accept17; alt6_3: ptr->pos=oldpos6;ptr->branches-=1;if (1){it=failobj;goto fail;}; accept17:; break; case 1/*Object*/:; it=AmethystCore_anything(self ); if (it==failobj){it=failobj;goto fail;} __result=it;; break; } break; } fail: return it; }
/* * call-seq: max_nesting=(depth) * * This sets the maximum level of data structure nesting in the generated JSON * to the integer depth, max_nesting = 0 if no maximum should be checked. */ static VALUE cState_max_nesting_set(VALUE self, VALUE depth) { GET_STATE(self); Check_Type(depth, T_FIXNUM); return state->max_nesting = FIX2LONG(depth); }