14 #include "ruby/internal/config.h"
25 #include "internal/error.h"
26 #include "internal/hash.h"
27 #include "internal/numeric.h"
28 #include "internal/object.h"
29 #include "internal/sanitizers.h"
30 #include "internal/symbol.h"
35 #define BIT_DIGITS(N) (((N)*146)/485 + 1)
37 static char *fmt_setup(
char*,
size_t,
int,
int,
int,
int);
38 static char *ruby_ultoa(
unsigned long val,
char *endp,
int base,
int octzero);
41 sign_bits(
int base,
const char *p)
47 if (*p ==
'X') c =
'F';
68 #define CHECK(l) do {\
69 int cr = ENC_CODERANGE(result);\
70 while ((l) >= bsiz - blen) {\
72 if (bsiz<0) rb_raise(rb_eArgError, "too big specifier");\
74 rb_str_resize(result, bsiz);\
75 ENC_CODERANGE_SET(result, cr);\
76 buf = RSTRING_PTR(result);\
79 #define PUSH(s, l) do { \
84 #define PUSH_(s, l) do { \
85 memcpy(&buf[blen], (s), (l));\
89 #define FILL(c, l) do { \
95 #define FILL_(c, l) do { \
96 memset(&buf[blen], (c), (l));\
100 #define GETARG() (!UNDEF_P(nextvalue) ? nextvalue : \
103 #define GETNEXTARG() ( \
104 check_next_arg(posarg, nextarg), \
105 (posarg = nextarg++, GETNTHARG(posarg)))
107 #define GETPOSARG(n) ( \
108 check_pos_arg(posarg, (n)), \
109 (posarg = -1, GETNTHARG(n)))
111 #define GETNTHARG(nth) \
112 (((nth) >= argc) ? (rb_raise(rb_eArgError, "too few arguments"), 0) : argv[(nth)])
114 #define CHECKNAMEARG(name, len, enc) ( \
115 check_name_arg(posarg, name, len, enc), \
118 #define GETNUM(n, val) \
119 (!(p = get_num(p, end, enc, &(n))) ? \
120 rb_raise(rb_eArgError, #val " too big") : (void)0)
122 #define GETASTER(val) do { \
127 tmp = GETPOSARG(n); \
130 tmp = GETNEXTARG(); \
133 (val) = NUM2INT(tmp); \
137 get_num(
const char *p,
const char *end,
rb_encoding *enc,
int *valp)
141 if (MUL_OVERFLOW_INT_P(10, next_n))
144 if (INT_MAX - (*p -
'0') < next_n)
156 check_next_arg(
int posarg,
int nextarg)
167 check_pos_arg(
int posarg,
int n)
181 check_name_arg(
int posarg,
const char *name,
int len,
rb_encoding *enc)
192 get_hash(
volatile VALUE *hash,
int argc,
const VALUE *argv)
196 if (!UNDEF_P(*hash))
return *hash;
204 return (*hash = tmp);
216 enum {default_float_precision = 6};
225 int width, prec, flags = FNONE;
234 #define CHECK_FOR_WIDTH(f) \
235 if ((f) & FWIDTH) { \
236 rb_raise(rb_eArgError, "width given twice"); \
238 if ((f) & FPREC0) { \
239 rb_raise(rb_eArgError, "width after precision"); \
241 #define CHECK_FOR_FLAGS(f) \
242 if ((f) & FWIDTH) { \
243 rb_raise(rb_eArgError, "flag after width"); \
245 if ((f) & FPREC0) { \
246 rb_raise(rb_eArgError, "flag after precision"); \
249 #define update_coderange(partial) do { \
250 if (coderange != ENC_CODERANGE_BROKEN && scanned < blen \
251 && rb_enc_to_index(enc) ) { \
252 int cr = coderange; \
253 scanned += rb_str_coderange_scan_restartable(buf+scanned, buf+blen, enc, &cr); \
254 ENC_CODERANGE_SET(result, \
255 (partial && cr == ENC_CODERANGE_UNKNOWN ? \
256 ENC_CODERANGE_BROKEN : (coderange = cr))); \
265 fmt = rb_str_tmp_frozen_acquire(fmt);
273 memset(buf, 0, bsiz);
276 for (; p < end; p++) {
281 for (t = p; t < end && *t !=
'%'; t++) ;
286 update_coderange(FALSE);
305 CHECK_FOR_FLAGS(flags);
311 CHECK_FOR_FLAGS(flags);
317 CHECK_FOR_FLAGS(flags);
323 CHECK_FOR_FLAGS(flags);
329 CHECK_FOR_FLAGS(flags);
334 case '1':
case '2':
case '3':
case '4':
335 case '5':
case '6':
case '7':
case '8':
case '9':
339 if (!UNDEF_P(nextvalue)) {
342 nextvalue = GETPOSARG(n);
346 CHECK_FOR_WIDTH(flags);
354 const char *start = p;
355 char term = (*p ==
'<') ?
'>' :
'}';
358 for (; p < end && *p != term; ) {
364 #if SIZEOF_INT < SIZEOF_SIZE_T
365 if ((
size_t)(p - start) >= INT_MAX) {
366 const int message_limit = 20;
369 "too long name (%"PRIuSIZE
" bytes) - %.*s...%c",
370 (
size_t)(p - start - 2),
len, start, term);
373 len = (int)(p - start + 1);
378 CHECKNAMEARG(start,
len, enc);
379 get_hash(&hash, argc, argv);
384 if (UNDEF_P(nextvalue)) {
386 sym = rb_sym_intern(start + 1,
390 nextvalue = rb_hash_default_value(hash, sym);
391 if (
NIL_P(nextvalue)) {
392 rb_key_err_raise(
rb_enc_sprintf(enc,
"key%.*s not found",
len, start), hash, sym);
395 if (term ==
'}')
goto format_s;
401 CHECK_FOR_WIDTH(flags);
413 if (flags & FPREC0) {
416 flags |= FPREC|FPREC0;
429 GETNUM(prec, precision);
433 if (flags != FNONE) {
441 VALUE val = GETARG();
458 int encidx = rb_ascii8bit_appendable_encoding_index(enc, c);
465 if (!(flags & FWIDTH)) {
470 else if ((flags & FMINUS)) {
472 CHECK(n + (width > 0 ? width : 0));
475 if (width > 0) FILL_(
' ', width);
479 CHECK(n + (width > 0 ? width : 0));
480 if (width > 0) FILL_(
' ', width);
491 VALUE arg = GETARG();
503 update_coderange(TRUE);
505 if (flags&(FPREC|FWIDTH)) {
510 if ((flags&FPREC) && (prec < slen)) {
517 if ((flags&FWIDTH) && (width > slen)) {
520 if (!(flags&FMINUS)) {
549 volatile VALUE val = GETARG();
551 char nbuf[BIT_DIGITS(SIZEOF_LONG*CHAR_BIT)+2], *s;
552 const char *prefix = 0;
553 int sign = 0, dots = 0;
556 int base, bignum = 0;
569 if (flags&(FPLUS|FSPACE)) sign = 1;
572 if (flags & FSHARP) {
577 prefix =
"0x";
break;
579 prefix =
"0X";
break;
581 prefix =
"0b";
break;
583 prefix =
"0B";
break;
629 int numbits = ffs(base)-1;
633 if (INT_MAX-1 < numdigits)
648 else if (flags & FPLUS) {
652 else if (flags & FSPACE) {
667 if (numdigits == 0 ||
668 ((abs_nlz_bits != (
size_t)(numbits-1) ||
670 (!bignum ? v < 0 : BIGNUM_NEGATIVE_P(val))))
690 else if (flags & FPLUS) {
694 else if (flags & FSPACE) {
698 s = ruby_ultoa((
unsigned long)v, nbuf +
sizeof(nbuf), 10, 0);
699 len = (int)(nbuf +
sizeof(nbuf) - s);
711 else if (flags & FPLUS) {
715 else if (flags & FSPACE) {
730 while ((c = (
int)(
unsigned char)*pp) != 0) {
735 if (prefix && !prefix[1]) {
739 else if (
len == 1 && *s ==
'0') {
741 if (flags & FPREC) prec--;
743 else if ((flags & FPREC) && (prec >
len)) {
747 else if (
len == 1 && *s ==
'0') {
751 width -= (int)strlen(prefix);
753 if ((flags & (FZERO|FMINUS|FPREC)) == FZERO) {
759 if (!prefix && prec == 0 &&
len == 1 && *s ==
'0')
len = 0;
764 if (!(flags&FMINUS)) {
768 if (sc) PUSH(&sc, 1);
770 int plen = (int)strlen(prefix);
773 if (dots) PUSH(
"..", 2);
776 if (!sign && valsign < 0) {
777 char c = sign_bits(base, p);
778 FILL_(c, prec -
len);
780 else if ((flags & (FMINUS|FPREC)) != FMINUS) {
781 FILL_(
'0', prec -
len);
792 VALUE val = GETARG(), num, den;
793 int sign = (flags&FPLUS) ? 1 : 0, zero = 0;
807 if (!(flags&FPREC)) prec = default_float_precision;
815 else if (BIGNUM_NEGATIVE_P(num)) {
817 num = rb_big_uminus(num);
821 num = rb_int_plus(num, rb_int_idiv(den,
INT2FIX(2)));
822 num = rb_int_idiv(num, den);
824 else if (prec >= 0) {
827 val = rb_int2str(num, 10);
829 if (prec >=
len)
len = prec + 1;
830 if (sign || (flags&FSPACE)) ++
len;
832 fill = width >
len ? width -
len : 0;
834 if (fill && !(flags&(FMINUS|FZERO))) {
837 if (sign || (flags&FSPACE)) {
838 buf[blen++] = sign > 0 ?
'+' : sign < 0 ?
'-' :
' ';
840 if (fill && (flags&(FMINUS|FZERO)) == FZERO) {
846 PUSH_(t,
len - prec);
857 else if (prec >
len) {
858 FILL_(
'0', prec -
len);
862 PUSH_(t +
len - prec, prec);
864 if (fill && (flags&FMINUS)) {
879 VALUE val = GETARG();
883 if (!isfinite(fval)) {
895 need = (int)strlen(expr);
897 if (!isnan(fval) && fval < 0.0)
899 else if (flags & (FPLUS|FSPACE))
900 sign = (flags & FPLUS) ?
'+' :
' ';
903 if ((flags & FWIDTH) && need < width)
907 if (flags & FMINUS) {
909 buf[blen - need--] = sign;
910 memcpy(&buf[blen - need], expr, elen);
914 buf[blen - elen - 1] = sign;
915 memcpy(&buf[blen - elen], expr, elen);
921 char fbuf[2*BIT_DIGITS(SIZEOF_INT*CHAR_BIT)+10];
922 char *fmt = fmt_setup(fbuf,
sizeof(fbuf), *p, flags, width, prec);
935 update_coderange(FALSE);
937 rb_str_tmp_frozen_release(orig, fmt);
940 if (posarg >= 0 && nextarg < argc && !(argc == 2 &&
RB_TYPE_P(argv[1],
T_HASH))) {
941 const char *mesg =
"too many arguments for format string";
951 fmt_setup(
char *buf,
size_t size,
int c,
int flags,
int width,
int prec)
958 buf = ruby_ultoa(prec, buf, 10, 0);
962 if (flags & FWIDTH) {
963 buf = ruby_ultoa(width, buf, 10, 0);
966 if (flags & FSPACE) *--buf =
' ';
967 if (flags & FZERO) *--buf =
'0';
968 if (flags & FMINUS) *--buf =
'-';
969 if (flags & FPLUS) *--buf =
'+';
970 if (flags & FSHARP) *--buf =
'#';
976 #define FILE rb_printf_buffer
977 #define __sbuf rb_printf_sbuf
978 #define __sFILE rb_printf_sfile
983 #if SIZEOF_LONG < SIZEOF_LONG_LONG
984 # if SIZEOF_LONG_LONG == SIZEOF_VOIDP
987 # define _HAVE_LLP64_
989 # define _HAVE_SANE_QUAD_
990 # define quad_t LONG_LONG
991 # define u_quad_t unsigned LONG_LONG
993 #define FLOATING_POINT 1
994 #define BSD__dtoa ruby_dtoa
995 #define BSD__hdtoa ruby_hdtoa
996 #ifdef RUBY_PRI_VALUE_MARK
997 # define PRI_EXTRA_MARK RUBY_PRI_VALUE_MARK
999 #define lower_hexdigits (ruby_hexdigits+0)
1000 #define upper_hexdigits (ruby_hexdigits+16)
1001 #include "vsnprintf.c"
1004 ruby_ultoa(
unsigned long val,
char *endp,
int base,
int flags)
1006 const char *xdigs = lower_hexdigits;
1007 int octzero = flags & FSHARP;
1008 return BSD__ultoa(val, endp, base, octzero, xdigs);
1011 static int ruby_do_vsnprintf(
char *str,
size_t n,
const char *fmt, va_list ap);
1016 if (str && (ssize_t)n < 1)
1018 return ruby_do_vsnprintf(str, n, fmt, ap);
1022 ruby_do_vsnprintf(
char *str,
size_t n,
const char *fmt, va_list ap)
1027 f._flags = __SWR | __SSTR;
1028 f._bf._base = f._p = (
unsigned char *)str;
1029 f._bf._size = f._w = str ? (n - 1) : 0;
1030 f.vwrite = BSD__sfvwrite;
1032 ret = BSD_vfprintf(&f, fmt, ap);
1034 #if SIZEOF_SIZE_T > SIZEOF_INT
1035 if (n > INT_MAX)
return INT_MAX;
1046 if (str && (ssize_t)n < 1)
1050 ret = ruby_do_vsnprintf(str, n, fmt, ap);
1056 rb_printf_buffer base;
1057 volatile VALUE value;
1061 ruby__sfvwrite(
register rb_printf_buffer *fp,
register struct __suio *uio)
1065 char *buf = (
char*)fp->_p;
1067 long blen = buf -
RSTRING_PTR(result), bsiz = fp->_w;
1069 if (
RBASIC(result)->klass) {
1072 if (uio->uio_resid == 0)
1074 #if SIZE_MAX > LONG_MAX
1075 if (uio->uio_resid >= LONG_MAX)
1078 len = (long)uio->uio_resid;
1082 for (iov = uio->uio_iov;
len > 0; ++iov) {
1083 MEMCPY(buf, iov->iov_base,
char, n = iov->iov_len);
1087 fp->_p = (
unsigned char *)buf;
1093 ruby__sfvextra(rb_printf_buffer *fp,
size_t valsize,
void *valp,
long *sz,
int sign)
1099 if (valsize !=
sizeof(
VALUE))
return 0;
1100 value = *(
VALUE *)valp;
1101 if (
RBASIC(result)->klass) {
1105 # define LITERAL(str) (*sz = rb_strlen_lit(str), str)
1108 # define LITERAL_CASE(x) case Q##x: return LITERAL(#x)
1111 LITERAL_CASE(
false);
1112 # undef LITERAL_CASE
1119 if (sign ==
' ' && !rb_str_symname_p(value)) {
1120 value = rb_str_escape(value);
1125 if (sign ==
' ') value = QUOTE(value);
1136 *(
volatile VALUE *)valp = value;
1145 ruby_vsprintf0(
VALUE result,
char *p,
const char *fmt, va_list ap)
1148 #define f buffer.base
1155 f._flags = __SWR | __SSTR;
1158 f._bf._base = (
unsigned char *)result;
1159 f._p = (
unsigned char *)p;
1160 RBASIC_CLEAR_CLASS(result);
1161 f.vwrite = ruby__sfvwrite;
1162 f.vextra = ruby__sfvextra;
1164 BSD_vfprintf(&f, fmt, ap);
1165 RBASIC_SET_CLASS_RAW(result, klass);
1167 long blen = (
char *)f._p - p;
1181 const int initial_len = 120;
1193 ruby_vsprintf0(result,
RSTRING_PTR(result), fmt, ap);
1203 va_start(ap, format);
1222 va_start(ap, format);
1244 va_start(ap, format);
ruby_coderange_type
What rb_enc_str_coderange() returns.
static bool rb_enc_isprint(OnigCodePoint c, rb_encoding *enc)
Identical to rb_isprint(), except it additionally takes an encoding.
int rb_enc_toupper(int c, rb_encoding *enc)
Identical to rb_toupper(), except it additionally takes an encoding.
static bool rb_enc_isdigit(OnigCodePoint c, rb_encoding *enc)
Identical to rb_isdigit(), except it additionally takes an encoding.
VALUE rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap)
Identical to rb_enc_sprintf(), except it takes a va_list instead of variadic arguments.
VALUE rb_enc_sprintf(rb_encoding *enc, const char *fmt,...)
Identical to rb_sprintf(), except it additionally takes an encoding.
#define TYPE(_)
Old name of rb_type.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define ENC_CODERANGE_7BIT
Old name of RUBY_ENC_CODERANGE_7BIT.
#define ENC_CODERANGE_VALID
Old name of RUBY_ENC_CODERANGE_VALID.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define T_BIGNUM
Old name of RUBY_T_BIGNUM.
#define ECONV_UNDEF_REPLACE
Old name of RUBY_ECONV_UNDEF_REPLACE.
#define T_FIXNUM
Old name of RUBY_T_FIXNUM.
#define ENC_CODERANGE(obj)
Old name of RB_ENC_CODERANGE.
#define ENC_CODERANGE_UNKNOWN
Old name of RUBY_ENC_CODERANGE_UNKNOWN.
#define FIXABLE
Old name of RB_FIXABLE.
#define LONG2FIX
Old name of RB_INT2FIX.
#define ECONV_INVALID_REPLACE
Old name of RUBY_ECONV_INVALID_REPLACE.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define T_HASH
Old name of RUBY_T_HASH.
#define NUM2INT
Old name of RB_NUM2INT.
#define Qnil
Old name of RUBY_Qnil.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define NIL_P
Old name of RB_NIL_P.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define ENC_CODERANGE_SET(obj, cr)
Old name of RB_ENC_CODERANGE_SET.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
#define ruby_debug
This variable controls whether the interpreter is in debug mode.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eRuntimeError
RuntimeError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eArgError
ArgumentError exception.
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Identical to rb_raise(), except it additionally takes an encoding.
VALUE rb_Float(VALUE val)
This is the logic behind Kernel#Float.
VALUE rb_Integer(VALUE val)
This is the logic behind Kernel#Integer.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
Identical to rb_enc_associate_index(), except it takes an encoding itself instead of its index.
int rb_enc_codelen(int code, rb_encoding *enc)
Queries the number of bytes requested to represent the passed code point using the passed encoding.
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
Look for the "common" encoding between the two.
int rb_enc_to_index(rb_encoding *enc)
Queries the index of the encoding.
static char * rb_enc_right_char_head(const char *s, const char *p, const char *e, rb_encoding *enc)
Queries the right boundary of a character.
rb_encoding * rb_enc_check(VALUE str1, VALUE str2)
Identical to rb_enc_compatible(), except it raises an exception instead of returning NULL.
static int rb_enc_mbcput(unsigned int c, void *buf, rb_encoding *enc)
Identical to rb_enc_uint_chr(), except it writes back to the passed buffer instead of allocating one.
rb_encoding * rb_enc_from_index(int idx)
Identical to rb_find_encoding(), except it takes an encoding index instead of a Ruby object.
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
Queries the number of bytes of the character at the passed pointer.
VALUE rb_enc_associate_index(VALUE obj, int encindex)
Identical to rb_enc_set_index(), except it additionally does contents fix-up depending on the passed ...
rb_encoding * rb_enc_get(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
static const char * rb_enc_name(rb_encoding *enc)
Queries the (canonical) name of the passed encoding.
static int rb_enc_mbminlen(rb_encoding *enc)
Queries the minimum number of bytes that the passed encoding needs to represent a character.
char * rb_enc_nth(const char *head, const char *tail, long nth, rb_encoding *enc)
Queries the n-th character.
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
Identical to rb_str_conv_enc(), except it additionally takes IO encoder options.
long rb_enc_strlen(const char *head, const char *tail, rb_encoding *enc)
Counts the number of characters of the passed string, according to the passed encoding.
long rb_str_coderange_scan_restartable(const char *str, const char *end, rb_encoding *enc, int *cr)
Scans the passed string until it finds something odd.
VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id_cstr(), except for the return type.
int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags)
Exports an integer into a buffer.
VALUE rb_str_to_inum(VALUE str, int base, int badcheck)
Identical to rb_cstr2inum(), except it takes Ruby's strings instead of C's.
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret)
Calculates the number of words needed represent the absolute value of the passed integer.
int rb_absint_singlebit_p(VALUE val)
Tests abs(val) consists only of a bit or not.
VALUE rb_big2str(VALUE x, int base)
Generates a place-value representation of the passed integer.
#define INTEGER_PACK_BIG_ENDIAN
Big endian combination.
VALUE rb_dbl2big(double d)
Converts a C's double into a bignum.
#define INTEGER_PACK_2COMP
Uses 2's complement representation.
VALUE rb_check_hash_type(VALUE obj)
Try converting an object to its hash representation using its to_hash method, if any.
VALUE rb_hash_lookup2(VALUE hash, VALUE key, VALUE def)
Identical to rb_hash_lookup(), except you can specify what to return on misshits.
VALUE rb_int_positive_pow(long x, unsigned long y)
Raises the passed x to the power of y.
VALUE rb_rational_num(VALUE rat)
Queries the numerator of the passed Rational.
VALUE rb_rational_den(VALUE rat)
Queries the denominator of the passed Rational.
size_t rb_str_capacity(VALUE str)
Queries the capacity of the given string.
void rb_str_modify(VALUE str)
Declares that the string is about to be modified.
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_str_new(const char *ptr, long len)
Allocates an instance of rb_cString.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_resize(VALUE str, long len)
Overwrites the length of the string.
VALUE rb_str_buf_new(long capa)
Allocates a "string buffer".
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
int len
Length of the buffer.
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt)
Formats a string.
VALUE rb_f_sprintf(int argc, const VALUE *argv)
Identical to rb_str_format(), except how the arguments are arranged.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
VALUE rb_str_vcatf(VALUE dst, const char *fmt, va_list ap)
Identical to rb_str_catf(), except it takes a va_list.
VALUE rb_vsprintf(const char *fmt, va_list ap)
Identical to rb_sprintf(), except it takes a va_list.
VALUE rb_str_catf(VALUE dst, const char *fmt,...)
Identical to rb_sprintf(), except it renders the output to the specified object rather than creating ...
#define rb_long2int
Just another name of rb_long2int_inline.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
#define RBASIC(obj)
Convenient casting macro.
#define StringValue(v)
Ensures that the parameter object is a String.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
#define RSTRING_GETMEM(str, ptrvar, lenvar)
Convenient macro to obtain the contents and length at once.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#define StringValueCStr(v)
Identical to StringValuePtr, except it additionally checks for the contents for viability as a C stri...
int ruby_vsnprintf(char *str, size_t n, char const *fmt, va_list ap)
Identical to ruby_snprintf(), except it takes a va_list.
int ruby_snprintf(char *str, size_t n, char const *fmt,...)
Our own locale-insensitive version of snprintf(3).
#define RTEST
This is an old name of RB_TEST.
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.