2023-05-28 14:00:20 +03:00
|
|
|
#include "parser_st.h"
|
|
|
|
#include "parser_bits.h"
|
|
|
|
|
|
|
|
#ifndef TRUE
|
|
|
|
# define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
# define FALSE 0
|
|
|
|
#endif
|
|
|
|
|
2023-06-17 05:33:12 +03:00
|
|
|
#undef NOT_RUBY
|
2023-05-28 14:00:20 +03:00
|
|
|
#undef RUBY
|
2023-06-17 05:33:12 +03:00
|
|
|
#undef RUBY_EXPORT
|
2023-05-28 14:00:20 +03:00
|
|
|
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef MEMCPY
|
2023-06-16 12:47:36 +03:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
}
|
2023-05-28 14:00:20 +03:00
|
|
|
|
|
|
|
#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
|
|
|
|
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_numcmp
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_numcmp rb_parser_st_numcmp
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_numhash
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_numhash rb_parser_st_numhash
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_free_table
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_free_table rb_parser_st_free_table
|
|
|
|
#define rb_st_hash_start rb_parser_st_hash_start
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_delete
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_delete rb_parser_st_delete
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_foreach
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_foreach rb_parser_st_foreach
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_numtable
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_numtable rb_parser_st_init_numtable
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_table_with_size
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_table_with_size rb_parser_st_init_table_with_size
|
2023-06-17 05:33:12 +03:00
|
|
|
#undef st_init_existing_table_with_size
|
|
|
|
#define st_init_existing_table_with_size rb_parser_st_init_existing_table_with_size
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_insert
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_insert rb_parser_st_insert
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_lookup
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_lookup rb_parser_st_lookup
|
|
|
|
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_table_size
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_table_size rb_parser_st_table_size
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_clear
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_clear rb_parser_st_clear
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_strtable
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_strtable rb_parser_st_init_strtable
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_table
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_table rb_parser_st_init_table
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_strcasetable
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_strcasetable rb_parser_st_init_strcasetable
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_strtable_with_size
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_strtable_with_size rb_parser_st_init_strtable_with_size
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_numtable_with_size
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_numtable_with_size rb_parser_st_init_numtable_with_size
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_init_strcasetable_with_size
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_init_strcasetable_with_size rb_parser_st_init_strcasetable_with_size
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_memsize
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_memsize rb_parser_st_memsize
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_get_key
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_get_key rb_parser_st_get_key
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_add_direct
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_add_direct rb_parser_st_add_direct
|
2023-12-14 21:42:40 +03:00
|
|
|
#define rb_st_add_direct_with_hash rb_parser_st_add_direct_with_hash
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_insert2
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_insert2 rb_parser_st_insert2
|
Fix memory leak when copying ST tables
st_copy allocates a st_table, which is not needed for hashes since it is
allocated by VWA and embedded, so this causes a memory leak.
The following script demonstrates the issue:
```ruby
20.times do
100_000.times do
{a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9}
end
puts `ps -o rss= -p #{$$}`
end
```
2023-06-29 16:21:11 +03:00
|
|
|
#undef st_replace
|
|
|
|
#define st_replace rb_parser_st_replace
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_copy
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_copy rb_parser_st_copy
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_delete_safe
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_delete_safe rb_parser_st_delete_safe
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_shift
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_shift rb_parser_st_shift
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_cleanup_safe
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_cleanup_safe rb_parser_st_cleanup_safe
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_update
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_update rb_parser_st_update
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_foreach_with_replace
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_foreach_with_replace rb_parser_st_foreach_with_replace
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_foreach_check
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_foreach_check rb_parser_st_foreach_check
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_keys
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_keys rb_parser_st_keys
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_keys_check
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_keys_check rb_parser_st_keys_check
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_values
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_values rb_parser_st_values
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_values_check
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_values_check rb_parser_st_values_check
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_hash
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_hash rb_parser_st_hash
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_hash_uint32
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_hash_uint32 rb_parser_st_hash_uint32
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_hash_uint
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_hash_uint rb_parser_st_hash_uint
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_hash_end
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_hash_end rb_parser_st_hash_end
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_locale_insensitive_strcasecmp
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_locale_insensitive_strcasecmp rb_parser_st_locale_insensitive_strcasecmp
|
2023-06-16 11:31:47 +03:00
|
|
|
#undef st_locale_insensitive_strncasecmp
|
2023-05-28 14:00:20 +03:00
|
|
|
#define st_locale_insensitive_strncasecmp rb_parser_st_locale_insensitive_strncasecmp
|
|
|
|
|
2023-06-29 05:44:54 +03:00
|
|
|
#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; \
|
2024-10-08 15:25:15 +03:00
|
|
|
_Pragma("GCC diagnostic pop") \
|
|
|
|
y
|
2023-06-29 05:44:54 +03:00
|
|
|
#endif
|
|
|
|
|
2023-05-28 14:00:20 +03:00
|
|
|
#ifndef NO_SANITIZE
|
|
|
|
# define NO_SANITIZE(x, y) y
|
|
|
|
#endif
|
|
|
|
|
2023-06-17 05:33:12 +03:00
|
|
|
#include "st.c"
|