Skip to content

Commit

Permalink
st: Modify for non-Ruby environments
Browse files Browse the repository at this point in the history
  • Loading branch information
k-takata committed Mar 15, 2020
1 parent 5c287ca commit 90a42a2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 22 deletions.
34 changes: 17 additions & 17 deletions regint.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@

# define CHECK_INTERRUPT_IN_MATCH_AT

# define st_init_table onig_st_init_table
# define st_init_table_with_size onig_st_init_table_with_size
# define st_init_numtable onig_st_init_numtable
# define st_init_numtable_with_size onig_st_init_numtable_with_size
# define st_init_strtable onig_st_init_strtable
# define st_init_strtable_with_size onig_st_init_strtable_with_size
# define st_delete onig_st_delete
# define st_delete_safe onig_st_delete_safe
# define st_insert onig_st_insert
# define st_lookup onig_st_lookup
# define st_foreach onig_st_foreach
# define st_add_direct onig_st_add_direct
# define st_free_table onig_st_free_table
# define st_cleanup_safe onig_st_cleanup_safe
# define st_copy onig_st_copy
# define st_nothing_key_clone onig_st_nothing_key_clone
# define st_nothing_key_free onig_st_nothing_key_free
# define rb_st_init_table onig_st_init_table
# define rb_st_init_table_with_size onig_st_init_table_with_size
# define rb_st_init_numtable onig_st_init_numtable
# define rb_st_init_numtable_with_size onig_st_init_numtable_with_size
# define rb_st_init_strtable onig_st_init_strtable
# define rb_st_init_strtable_with_size onig_st_init_strtable_with_size
# define rb_st_delete onig_st_delete
# define rb_st_delete_safe onig_st_delete_safe
# define rb_st_insert onig_st_insert
# define rb_st_lookup onig_st_lookup
# define rb_st_foreach onig_st_foreach
# define rb_st_add_direct onig_st_add_direct
# define rb_st_free_table onig_st_free_table
# define rb_st_cleanup_safe onig_st_cleanup_safe
# define rb_st_copy onig_st_copy
# define rb_st_nothing_key_clone onig_st_nothing_key_clone
# define rb_st_nothing_key_free onig_st_nothing_key_free
/* */
# define onig_st_is_member st_is_member

Expand Down
23 changes: 21 additions & 2 deletions st.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,17 @@

*/

#if !defined(RUBY) && defined(RUBY_EXPORT)
#define RUBY
#endif

#ifdef RUBY
#include "internal.h"
#include "internal/bits.h"
#include "internal/hash.h"
#include "internal/sanitizers.h"
#else
#include "regint.h"
#include "st.h"
#endif

Expand Down Expand Up @@ -171,7 +176,14 @@ static const struct st_hash_type type_strcasehash = {
#define realloc ruby_xrealloc
#define free ruby_xfree
#else /* RUBY */
#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
#define NO_SANITIZE(s,decl) decl
#endif /* RUBY */

#define EQUAL(tab,x,y) ((x) == (y) || (*(tab)->type->compare)((x),(y)) == 0)
Expand Down Expand Up @@ -343,7 +355,14 @@ do_hash(st_data_t key, st_table *tab)
static int
get_power2(st_index_t size)
{
unsigned int n = ST_INDEX_BITS - nlz_intptr(size);
unsigned int n;

#ifdef RUBY
n = ST_INDEX_BITS - nlz_intptr(size);
#else
for (n = 0; size != 0; n++)
size >>= 1;
#endif
if (n <= MAX_POWER2)
return n < MINIMAL_POWER2 ? MINIMAL_POWER2 : n;
#ifdef RUBY
Expand Down
17 changes: 14 additions & 3 deletions st.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@ extern "C" {
#endif
#endif

#if !defined(RUBY) && defined(RUBY_EXPORT)
#define RUBY
#endif

#ifdef RUBY
#include "ruby/defines.h"
#else /* RUBY */
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifndef RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_END
#endif
#ifndef CONSTFUNC
#define CONSTFUNC(decl) decl
#define PUREFUNC(decl) decl
#endif
#endif /* RUBY */

RUBY_SYMBOL_EXPORT_BEGIN
Expand All @@ -41,9 +55,6 @@ typedef unsigned LONG_LONG st_data_t;
# define CHAR_BIT 8
# endif
#endif
#ifndef _
# define _(args) args
#endif
#ifndef ANYARGS
# ifdef __cplusplus
# define ANYARGS ...
Expand Down

0 comments on commit 90a42a2

Please sign in to comment.