summaryrefslogtreecommitdiff
path: root/parser_st.c
blob: c7a45d25e6e9749e2b15c32de84bcdd15da273d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "parser_st.h"
#include "parser_bits.h"

#ifndef TRUE
# define TRUE    1
#endif

#ifndef FALSE
# define FALSE   0
#endif

#undef NOT_RUBY
#undef RUBY
#undef RUBY_EXPORT

#undef MEMCPY
#define MEMCPY(p1,p2,type,n) nonempty_memcpy((p1), (p2), (sizeof(type) * (n)))
/* The multiplication should not overflow since this macro is used
 * only with the already allocated size. */
static inline void *
nonempty_memcpy(void *dest, const void *src, size_t n)
{
    if (n) {
        return memcpy(dest, src, n);
    }
    else {
        return dest;
    }
}

#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <string.h>
#include <assert.h>

#ifdef __GNUC__
#define PREFETCH(addr, write_p) __builtin_prefetch(addr, write_p)
#define EXPECT(expr, val) __builtin_expect(expr, val)
#define ATTRIBUTE_UNUSED  __attribute__((unused))
#else
#define PREFETCH(addr, write_p)
#define EXPECT(expr, val) (expr)
#define ATTRIBUTE_UNUSED
#endif


#define st_index_t parser_st_index_t
#define st_hash_t parser_st_hash_t
#define st_data_t parser_st_data_t
#define st_hash_type parser_st_hash_type
#define st_table parser_st_table
#define st_table_entry parser_st_table_entry
#define st_update_callback_func parser_st_update_callback_func
#define st_foreach_check_callback_func parser_st_foreach_check_callback_func
#define st_foreach_callback_func parser_st_foreach_callback_func
#define st_retval parser_st_retval

#define ST_CONTINUE ST2_CONTINUE
#define ST_STOP ST2_STOP
#define ST_DELETE ST2_DELETE
#define ST_CHECK ST2_CHECK
#define ST_REPLACE ST2_REPLACE

#undef st_numcmp
#define st_numcmp rb_parser_st_numcmp
#undef st_numhash
#define st_numhash rb_parser_st_numhash
#undef st_free_table
#define st_free_table rb_parser_st_free_table
#define rb_st_hash_start rb_parser_st_hash_start
#undef st_delete
#define st_delete rb_parser_st_delete
#undef st_foreach
#define st_foreach rb_parser_st_foreach
#undef st_init_numtable
#define st_init_numtable rb_parser_st_init_numtable
#undef st_init_table_with_size
#define st_init_table_with_size rb_parser_st_init_table_with_size
#undef st_init_existing_table_with_size
#define st_init_existing_table_with_size rb_parser_st_init_existing_table_with_size
#undef st_insert
#define st_insert rb_parser_st_insert
#undef st_lookup
#define st_lookup rb_parser_st_lookup

#undef st_table_size
#define st_table_size rb_parser_st_table_size
#undef st_clear
#define st_clear rb_parser_st_clear
#undef st_init_strtable
#define st_init_strtable rb_parser_st_init_strtable
#undef st_init_table
#define st_init_table rb_parser_st_init_table
#undef st_init_strcasetable
#define st_init_strcasetable rb_parser_st_init_strcasetable
#undef st_init_strtable_with_size
#define st_init_strtable_with_size rb_parser_st_init_strtable_with_size
#undef st_init_numtable_with_size
#define st_init_numtable_with_size rb_parser_st_init_numtable_with_size
#undef st_init_strcasetable_with_size
#define st_init_strcasetable_with_size rb_parser_st_init_strcasetable_with_size
#undef st_memsize
#define st_memsize rb_parser_st_memsize
#undef st_get_key
#define st_get_key rb_parser_st_get_key
#undef st_add_direct
#define st_add_direct rb_parser_st_add_direct
#undef st_insert2
#define st_insert2 rb_parser_st_insert2
#undef st_replace
#define st_replace rb_parser_st_replace
#undef st_copy
#define st_copy rb_parser_st_copy
#undef st_delete_safe
#define st_delete_safe rb_parser_st_delete_safe
#undef st_shift
#define st_shift rb_parser_st_shift
#undef st_cleanup_safe
#define st_cleanup_safe rb_parser_st_cleanup_safe
#undef st_update
#define st_update rb_parser_st_update
#undef st_foreach_with_replace
#define st_foreach_with_replace rb_parser_st_foreach_with_replace
#undef st_foreach_check
#define st_foreach_check rb_parser_st_foreach_check
#undef st_keys
#define st_keys rb_parser_st_keys
#undef st_keys_check
#define st_keys_check rb_parser_st_keys_check
#undef st_values
#define st_values rb_parser_st_values
#undef st_values_check
#define st_values_check rb_parser_st_values_check
#undef st_hash
#define st_hash rb_parser_st_hash
#undef st_hash_uint32
#define st_hash_uint32 rb_parser_st_hash_uint32
#undef st_hash_uint
#define st_hash_uint rb_parser_st_hash_uint
#undef st_hash_end
#define st_hash_end rb_parser_st_hash_end
#undef st_locale_insensitive_strcasecmp
#define st_locale_insensitive_strcasecmp rb_parser_st_locale_insensitive_strcasecmp
#undef st_locale_insensitive_strncasecmp
#define st_locale_insensitive_strncasecmp rb_parser_st_locale_insensitive_strncasecmp

#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
/* GCC warns about unknown sanitizer, which is annoying. */
# undef NO_SANITIZE
# define NO_SANITIZE(x, y) \
    _Pragma("GCC diagnostic push") \
    _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
    __attribute__((__no_sanitize__(x))) y; \
    _Pragma("GCC diagnostic pop")
#endif

#ifndef NO_SANITIZE
# define NO_SANITIZE(x, y) y
#endif

#include "st.c"