http: cleanup assertion for memoized header strings
[unicorn.git] / ext / unicorn_http / ext_help.h
blobbd29cc73da484874abace33a3ee7173e1ce9af04
1 #ifndef ext_help_h
2 #define ext_help_h
4 #ifndef RSTRING_PTR
5 #define RSTRING_PTR(s) (RSTRING(s)->ptr)
6 #endif
7 #ifndef RSTRING_LEN
8 #define RSTRING_LEN(s) (RSTRING(s)->len)
9 #endif
11 #ifndef RUBINIUS
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';
22 rb_str_flush(str);
24 # define rb_str_set_len(str,len) rb_18_str_set_len(str,len)
25 #endif
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
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
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))
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