5 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
8 #define RSTRING_LEN(s) (RSTRING(s)->len)
12 # define rb_str_update(x) do {} while (0)
13 # define rb_str_flush(x) do {} while (0)
14 #endif /* !RUBINIUS */
16 #ifndef HAVE_RB_STR_SET_LEN
17 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
18 static void rb_18_str_set_len(VALUE str
, long len
)
20 RSTRING(str
)->len
= len
;
21 RSTRING(str
)->ptr
[len
] = '\0';
24 # define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
27 /* not all Ruby implementations support frozen objects (Rubinius does not) */
28 #if defined(OBJ_FROZEN)
29 # define assert_frozen(f) assert(OBJ_FROZEN(f) && "unfrozen object")
31 # define assert_frozen(f) do {} while (0)
34 #if !defined(OFFT2NUM)
35 # if SIZEOF_OFF_T == SIZEOF_LONG
36 # define OFFT2NUM(n) LONG2NUM(n)
38 # define OFFT2NUM(n) LL2NUM(n)
40 #endif /* ! defined(OFFT2NUM) */
42 #ifndef HAVE_RB_STR_MODIFY
43 # define rb_str_modify(x) do {} while (0)
46 static inline int str_cstr_eq(VALUE val
, const char *ptr
, size_t len
)
48 return (RSTRING_LEN(val
) == len
&& !memcmp(ptr
, RSTRING_PTR(val
), len
));
51 #define STR_CSTR_EQ(val, const_str) \
52 str_cstr_eq(val, const_str, sizeof(const_str) - 1)
54 /* strcasecmp isn't locale independent */
55 static int str_cstr_case_eq(VALUE val
, const char *ptr
, size_t len
)
57 if (RSTRING_LEN(val
) == len
) {
58 const char *v
= RSTRING_PTR(val
);
60 for (; len
--; ++ptr
, ++v
) {
61 if ((*ptr
== *v
) || (*v
>= 'A' && *v
<= 'Z' && (*v
| 0x20) == *ptr
))
70 #define STR_CSTR_CASE_EQ(val, const_str) \
71 str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)