Ruby: parser_st.c Source File

Ruby 3.4.6p54 (2025-09-16 revision dbd83256b1cec76c69756ecb8758b9e1079833de)

parser_st.c
1#include "parser_st.h"
2#include "parser_bits.h"
3
4#ifndef TRUE
5# define TRUE 1
6#endif
7
8#ifndef FALSE
9# define FALSE 0
10#endif
11
12#undef NOT_RUBY
13#undef RUBY
14#undef RUBY_EXPORT
15
16#undef MEMCPY
17#define MEMCPY(p1,p2,type,n) nonempty_memcpy((p1), (p2), (sizeof(type) * (n)))
18/* The multiplication should not overflow since this macro is used
19 * only with the already allocated size. */
20static inline void *
21nonempty_memcpy(void *dest, const void *src, size_t n)
22{
23 if (n) {
24 return memcpy(dest, src, n);
25 }
26 else {
27 return dest;
28 }
29}
30
31#include <stdio.h>
32#ifdef HAVE_STDLIB_H
33#include <stdlib.h>
34#endif
35#include <string.h>
36#include <assert.h>
37
38#ifdef __GNUC__
39#define PREFETCH(addr, write_p) __builtin_prefetch(addr, write_p)
40#define EXPECT(expr, val) __builtin_expect(expr, val)
41#define ATTRIBUTE_UNUSED __attribute__((unused))
42#else
43#define PREFETCH(addr, write_p)
44#define EXPECT(expr, val) (expr)
45#define ATTRIBUTE_UNUSED
46#endif
47
48
49#define st_index_t parser_st_index_t
50#define st_hash_t parser_st_hash_t
51#define st_data_t parser_st_data_t
52#define st_hash_type parser_st_hash_type
53#define st_table parser_st_table
54#define st_table_entry parser_st_table_entry
55#define st_update_callback_func parser_st_update_callback_func
56#define st_foreach_check_callback_func parser_st_foreach_check_callback_func
57#define st_foreach_callback_func parser_st_foreach_callback_func
58#define st_retval parser_st_retval
59
60#define ST_CONTINUE ST2_CONTINUE
61#define ST_STOP ST2_STOP
62#define ST_DELETE ST2_DELETE
63#define ST_CHECK ST2_CHECK
64#define ST_REPLACE ST2_REPLACE
65
66#undef st_numcmp
67#define st_numcmp rb_parser_st_numcmp
68#undef st_numhash
69#define st_numhash rb_parser_st_numhash
70#undef st_free_table
71#define st_free_table rb_parser_st_free_table
72#define rb_st_hash_start rb_parser_st_hash_start
73#undef st_delete
74#define st_delete rb_parser_st_delete
75#undef st_foreach
76#define st_foreach rb_parser_st_foreach
77#undef st_init_numtable
78#define st_init_numtable rb_parser_st_init_numtable
79#undef st_init_table_with_size
80#define st_init_table_with_size rb_parser_st_init_table_with_size
81#undef st_init_existing_table_with_size
82#define st_init_existing_table_with_size rb_parser_st_init_existing_table_with_size
83#undef st_insert
84#define st_insert rb_parser_st_insert
85#undef st_lookup
86#define st_lookup rb_parser_st_lookup
87
88#undef st_table_size
89#define st_table_size rb_parser_st_table_size
90#undef st_clear
91#define st_clear rb_parser_st_clear
92#undef st_init_strtable
93#define st_init_strtable rb_parser_st_init_strtable
94#undef st_init_table
95#define st_init_table rb_parser_st_init_table
96#undef st_init_strcasetable
97#define st_init_strcasetable rb_parser_st_init_strcasetable
98#undef st_init_strtable_with_size
99#define st_init_strtable_with_size rb_parser_st_init_strtable_with_size
100#undef st_init_numtable_with_size
101#define st_init_numtable_with_size rb_parser_st_init_numtable_with_size
102#undef st_init_strcasetable_with_size
103#define st_init_strcasetable_with_size rb_parser_st_init_strcasetable_with_size
104#undef st_memsize
105#define st_memsize rb_parser_st_memsize
106#undef st_get_key
107#define st_get_key rb_parser_st_get_key
108#undef st_add_direct
109#define st_add_direct rb_parser_st_add_direct
110#define rb_st_add_direct_with_hash rb_parser_st_add_direct_with_hash
111#undef st_insert2
112#define st_insert2 rb_parser_st_insert2
113#undef st_replace
114#define st_replace rb_parser_st_replace
115#undef st_copy
116#define st_copy rb_parser_st_copy
117#undef st_delete_safe
118#define st_delete_safe rb_parser_st_delete_safe
119#undef st_shift
120#define st_shift rb_parser_st_shift
121#undef st_cleanup_safe
122#define st_cleanup_safe rb_parser_st_cleanup_safe
123#undef st_update
124#define st_update rb_parser_st_update
125#undef st_foreach_with_replace
126#define st_foreach_with_replace rb_parser_st_foreach_with_replace
127#undef st_foreach_check
128#define st_foreach_check rb_parser_st_foreach_check
129#undef st_keys
130#define st_keys rb_parser_st_keys
131#undef st_keys_check
132#define st_keys_check rb_parser_st_keys_check
133#undef st_values
134#define st_values rb_parser_st_values
135#undef st_values_check
136#define st_values_check rb_parser_st_values_check
137#undef st_hash
138#define st_hash rb_parser_st_hash
139#undef st_hash_uint32
140#define st_hash_uint32 rb_parser_st_hash_uint32
141#undef st_hash_uint
142#define st_hash_uint rb_parser_st_hash_uint
143#undef st_hash_end
144#define st_hash_end rb_parser_st_hash_end
145#undef st_locale_insensitive_strcasecmp
146#define st_locale_insensitive_strcasecmp rb_parser_st_locale_insensitive_strcasecmp
147#undef st_locale_insensitive_strncasecmp
148#define st_locale_insensitive_strncasecmp rb_parser_st_locale_insensitive_strncasecmp
149
150#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
151/* GCC warns about unknown sanitizer, which is annoying. */
152# undef NO_SANITIZE
153# define NO_SANITIZE(x, y) \
154 _Pragma("GCC diagnostic push") \
155 _Pragma("GCC diagnostic ignored \"-Wattributes\"") \
156 __attribute__((__no_sanitize__(x))) y; \
157 _Pragma("GCC diagnostic pop") \
158 y
159#endif
160
161#ifndef NO_SANITIZE
162# define NO_SANITIZE(x, y) y
163#endif
164
165#include "st.c"
assert.h