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 #if !defined(SIZET2NUM)
40 # if SIZEOF_SIZE_T == SIZEOF_LONG
41 # define SIZET2NUM(n) ULONG2NUM(n)
43 # define SIZET2NUM(n) ULL2NUM(n)
45 #endif /* ! defined(SIZET2NUM) */
47 #if !defined(NUM2SIZET)
48 # if SIZEOF_SIZE_T == SIZEOF_LONG
49 # define NUM2SIZET(n) ((size_t)NUM2ULONG(n))
51 # define NUM2SIZET(n) ((size_t)NUM2ULL(n))
53 #endif /* ! defined(NUM2SIZET) */
55 static inline int str_cstr_eq(VALUE val
, const char *ptr
, long len
)
57 return (RSTRING_LEN(val
) == len
&& !memcmp(ptr
, RSTRING_PTR(val
), len
));
60 #define STR_CSTR_EQ(val, const_str) \
61 str_cstr_eq(val, const_str, sizeof(const_str) - 1)
63 /* strcasecmp isn't locale independent */
64 static int str_cstr_case_eq(VALUE val
, const char *ptr
, long len
)
66 if (RSTRING_LEN(val
) == len
) {
67 const char *v
= RSTRING_PTR(val
);
69 for (; len
--; ++ptr
, ++v
) {
70 if ((*ptr
== *v
) || (*v
>= 'A' && *v
<= 'Z' && (*v
| 0x20) == *ptr
))
79 #define STR_CSTR_CASE_EQ(val, const_str) \
80 str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)
82 #endif /* ext_help_h */