8 #define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries) 12 #define RFLOAT_VALUE(val) (RFLOAT(val)->value) 16 #define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len 19 #define RSTRING_PTR(string) RSTRING(string)->ptr 22 #define RSTRING_LEN(string) RSTRING(string)->len 26 # define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj) 27 # define RB_OBJ_STRING(obj) (obj) 29 # define PRIsVALUE "s" 30 # define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj) 31 # define RB_OBJ_STRING(obj) StringValueCStr(obj) 34 #ifdef HAVE_RUBY_ENCODING_H 36 #define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding()) 38 #define FORCE_UTF8(obj) 43 #define RB_GC_GUARD(object) 53 #define FBUFFER_INITIAL_LENGTH_DEFAULT 1024 55 #define FBUFFER_PTR(fb) (fb->ptr) 56 #define FBUFFER_LEN(fb) (fb->len) 57 #define FBUFFER_CAPA(fb) (fb->capa) 58 #define FBUFFER_PAIR(fb) FBUFFER_PTR(fb), FBUFFER_LEN(fb) 61 static void fbuffer_free(
FBuffer *fb);
62 static void fbuffer_clear(
FBuffer *fb);
63 static void fbuffer_append(
FBuffer *fb,
const char *newstr,
unsigned long len);
65 static void fbuffer_append_long(
FBuffer *fb,
long number);
67 static void fbuffer_append_char(
FBuffer *fb,
char newchr);
78 memset((
void *) fb, 0,
sizeof(
FBuffer));
83 static void fbuffer_free(
FBuffer *fb)
89 static void fbuffer_clear(
FBuffer *fb)
94 static void fbuffer_inc_capa(
FBuffer *fb,
unsigned long requested)
96 unsigned long required;
103 for (required = fb->
capa; requested > required - fb->
len; required <<= 1);
105 if (required > fb->
capa) {
111 static void fbuffer_append(
FBuffer *fb,
const char *newstr,
unsigned long len)
114 fbuffer_inc_capa(fb, len);
120 #ifdef JSON_GENERATOR 128 fbuffer_append(fb, newstr, len);
132 static void fbuffer_append_char(
FBuffer *fb,
char newchr)
134 fbuffer_inc_capa(fb, 1);
135 *(fb->
ptr + fb->
len) = newchr;
139 #ifdef JSON_GENERATOR 140 static void freverse(
char *start,
char *end)
144 while (end > start) {
145 c = *end, *end-- = *start, *start++ = c;
149 static long fltoa(
long number,
char *
buf)
151 static char digits[] =
"0123456789";
155 if (sign < 0) number = -number;
156 do *tmp++ = digits[number % 10];
while (number /= 10);
157 if (sign < 0) *tmp++ =
'-';
158 freverse(buf, tmp - 1);
162 static void fbuffer_append_long(
FBuffer *fb,
long number)
165 unsigned long len = fltoa(number, buf);
166 fbuffer_append(fb, buf, len);
171 unsigned long len = fb->
len;
174 result = fbuffer_alloc(len);
#define FBUFFER_INITIAL_LENGTH_DEFAULT
unsigned long initial_length
struct FBufferStruct FBuffer
#define MEMCPY(p1, p2, type, n)
#define REALLOC_N(var, type, n)
unsigned char buf[MIME_BUF_SIZE]
#define StringValuePtr(v)
VALUE rb_str_new(const char *, long)