http: cleanups for latest Rubinius
[unicorn.git] / ext / unicorn_http / ext_help.h
blobcc157cbc14b823549d12950f8b9a9b60020ea770
1 #ifndef ext_help_h
2 #define ext_help_h
4 #ifndef RSTRING_PTR
5 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
6 #endif /* !defined(RSTRING_PTR) */
7 #ifndef RSTRING_LEN
8 #define RSTRING_LEN(s) (RSTRING(s)->len)
9 #endif /* !defined(RSTRING_LEN) */
11 #ifndef RUBINIUS
12 # define rb_str_update(x) do {} while (0)
13 #endif /* !RUBINIUS */
15 #ifndef HAVE_RB_STR_SET_LEN
16 # ifdef RUBINIUS
17 # error we should never get here with current Rubinius (1.x)
18 # endif
19 /* this is taken from Ruby 1.8.7, 1.8.6 may not have it */
20 static void rb_18_str_set_len(VALUE str, long len)
22 RSTRING(str)->len = len;
23 RSTRING(str)->ptr[len] = '\0';
25 #endif /* !defined(HAVE_RB_STR_SET_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")
30 #else
31 # define assert_frozen(f) do {} while (0)
32 #endif /* !defined(OBJ_FROZEN) */
34 #if !defined(OFFT2NUM)
35 # if SIZEOF_OFF_T == SIZEOF_LONG
36 # define OFFT2NUM(n) LONG2NUM(n)
37 # else
38 # define OFFT2NUM(n) LL2NUM(n)
39 # endif
40 #endif /* ! defined(OFFT2NUM) */
42 #ifndef HAVE_RB_STR_MODIFY
43 # define rb_str_modify(x) do {} while (0)
44 #endif /* ! defined(HAVE_RB_STR_MODIFY) */
46 static inline int str_cstr_eq(VALUE val, const char *ptr, long 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, long 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))
62 continue;
63 return 0;
65 return 1;
67 return 0;
70 #define STR_CSTR_CASE_EQ(val, const_str) \
71 str_cstr_case_eq(val, const_str, sizeof(const_str) - 1)
73 #endif /* ext_help_h */