5 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
6 #endif /* !defined(RSTRING_PTR) */
8 #define RSTRING_LEN(s) (RSTRING(s)->len)
9 #endif /* !defined(RSTRING_LEN) */
11 #ifndef HAVE_RB_STR_SET_LEN
13 # error we should never get here with current Rubinius (1.x)
15 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
16 static void rb_18_str_set_len(VALUE str
, long len
)
18 RSTRING(str
)->len
= len
;
19 RSTRING(str
)->ptr
[len
] = '\0';
21 # define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
22 #endif /* !defined(HAVE_RB_STR_SET_LEN) */
24 /* not all Ruby implementations support frozen objects (Rubinius does not) */
25 #if defined(OBJ_FROZEN)
26 # define assert_frozen(f) assert(OBJ_FROZEN(f) && "unfrozen object")
28 # define assert_frozen(f) do {} while (0)
29 #endif /* !defined(OBJ_FROZEN) */
31 #if !defined(OFFT2NUM)
32 # if SIZEOF_OFF_T == SIZEOF_LONG
33 # define OFFT2NUM(n) LONG2NUM(n)
35 # define OFFT2NUM(n) LL2NUM(n)
37 #endif /* ! defined(OFFT2NUM) */
39 #ifndef HAVE_RB_STR_MODIFY
40 # define rb_str_modify(x) do {} while (0)
41 #endif /* ! defined(HAVE_RB_STR_MODIFY) */
43 static inline int str_cstr_eq(VALUE val
, const char *ptr
, long len
)
45 return (RSTRING_LEN(val
) == len
&& !memcmp(ptr
, RSTRING_PTR(val
), len
));
48 #define STR_CSTR_EQ(val, const_str) \
49 str_cstr_eq(val, const_str, sizeof(const_str) - 1)
51 /* strcasecmp isn't locale independent */
52 static int str_cstr_case_eq(VALUE val
, const char *ptr
, long len
)
54 if (RSTRING_LEN(val
) == len
) {
55 const char *v
= RSTRING_PTR(val
);
57 for (; len
--; ++ptr
, ++v
) {
58 if ((*ptr
== *v
) || (*v
>= 'A' && *v
<= 'Z' && (*v
| 0x20) == *ptr
))
67 #define STR_CSTR_CASE_EQ(val, const_str) \
68 str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)
70 #endif /* ext_help_h */