Skip to content

Commit

Permalink
Cleaned array.h, analysis.h. Fixed ruby bindings.
Browse files Browse the repository at this point in the history
* Cleaned public symbol table for array.h and finalized cleanup of analysis.h
* Previously broke ruby bindings. They now pass all unit tests.


git-svn-id: svn+ssh://davebalmain.com/home/dave/repos/ferret/trunk@925 06fd6eb0-0002-0410-a719-e5602cce40bc
  • Loading branch information
dave committed Apr 18, 2008
1 parent f7adc45 commit 2eff78c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 59 deletions.
1 change: 1 addition & 0 deletions c/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ testall
search_bench
bench
.rake
.deps
82 changes: 41 additions & 41 deletions c/include/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,51 @@
#include "global.h"

#if defined POSH_OS_SOLARIS || defined POSH_OS_SUNOS
# define ARY_META_CNT 4
# define FRT_ARY_META_CNT 4
#else
# define ARY_META_CNT 3
# define FRT_ARY_META_CNT 3
#endif

#define ARY_INIT_CAPA 8
#define ary_size(ary) ary_sz(ary)
#define ary_sz(ary) (((int *)ary)[-1])
#define ary_capa(ary) (((int *)ary)[-2])
#define ary_type_size(ary) (((int *)ary)[-3])
#define ary_start(ary) ((void **)&(((int *)ary)[-ARY_META_CNT]))
#define ary_free(ary) free(ary_start(ary))
#define FRT_ARY_INIT_CAPA 8
#define frt_ary_size(ary) frt_ary_sz(ary)
#define frt_ary_sz(ary) (((int *)ary)[-1])
#define frt_ary_capa(ary) (((int *)ary)[-2])
#define frt_ary_type_size(ary) (((int *)ary)[-3])
#define frt_ary_start(ary) ((void **)&(((int *)ary)[-FRT_ARY_META_CNT]))
#define frt_ary_free(ary) free(frt_ary_start(ary))

#define ary_new_type_capa(type, init_capa)\
(type *)ary_new_i(sizeof(type), init_capa)
#define ary_new_type(type) (type *)ary_new_i(sizeof(type), 0)
#define ary_new_capa(init_capa) ary_new_i(sizeof(void *), init_capa)
#define ary_new() ary_new_i(sizeof(void *), 0)
#define ary_resize(ary, size) ary_resize_i(((void ***)(void *)&ary), size)
#define ary_set(ary, i, val) ary_set_i(((void ***)(void *)&ary), i, val)
#define ary_get(ary, i) ary_get_i(((void **)ary), i)
#define ary_push(ary, val) ary_push_i(((void ***)(void *)&ary), val)
#define ary_pop(ary) ary_pop_i(((void **)ary))
#define ary_unshift(ary, val) ary_unshift_i(((void ***)(void *)&ary), val)
#define ary_shift(ary) ary_shift_i(((void **)ary))
#define ary_remove(ary, i) ary_remove_i(((void **)ary), i)
#define ary_delete(ary, i, f) ary_delete_i(((void **)ary), i, (free_ft)f)
#define ary_destroy(ary, f) ary_destroy_i(((void **)ary), (free_ft)f)
#define ary_rsz(ary, size) ary_resize(ary, size)
#define ary_grow(ary) ary_resize(ary, ary_sz(ary))
#define ary_last(ary) ary[ary_sz(ary) - 1]
#define ary_sort(ary, cmp) qsort(ary, ary_size(ary), ary_type_size(ary), cmp)
#define ary_each_rev(ary, i) for (i = ary_size(ary) - 1; i >= 0; i--)
#define ary_each(ary, i) for (i = 0; i < ary_size(ary); i++)
#define frt_ary_new_type_capa(type, init_capa)\
(type *)frt_ary_new_i(sizeof(type), init_capa)
#define frt_ary_new_type(type) (type *)frt_ary_new_i(sizeof(type), 0)
#define frt_ary_new_capa(init_capa) frt_ary_new_i(sizeof(void *), init_capa)
#define frt_ary_new() frt_ary_new_i(sizeof(void *), 0)
#define frt_ary_resize(ary, size) frt_ary_resize_i(((void ***)(void *)&ary), size)
#define frt_ary_set(ary, i, val) frt_ary_set_i(((void ***)(void *)&ary), i, val)
#define frt_ary_get(ary, i) frt_ary_get_i(((void **)ary), i)
#define frt_ary_push(ary, val) frt_ary_push_i(((void ***)(void *)&ary), val)
#define frt_ary_pop(ary) frt_ary_pop_i(((void **)ary))
#define frt_ary_unshift(ary, val) frt_ary_unshift_i(((void ***)(void *)&ary), val)
#define frt_ary_shift(ary) frt_ary_shift_i(((void **)ary))
#define frt_ary_remove(ary, i) frt_ary_remove_i(((void **)ary), i)
#define frt_ary_delete(ary, i, f) frt_ary_delete_i(((void **)ary), i, (free_ft)f)
#define frt_ary_destroy(ary, f) frt_ary_destroy_i(((void **)ary), (free_ft)f)
#define frt_ary_rsz(ary, size) frt_ary_resize(ary, size)
#define frt_ary_grow(ary) frt_ary_resize(ary, frt_ary_sz(ary))
#define frt_ary_last(ary) ary[frt_ary_sz(ary) - 1]
#define frt_ary_sort(ary, cmp) qsort(ary, frt_ary_size(ary), frt_ary_type_size(ary), cmp)
#define frt_ary_each_rev(ary, i) for (i = frt_ary_size(ary) - 1; i >= 0; i--)
#define frt_ary_each(ary, i) for (i = 0; i < frt_ary_size(ary); i++)

extern void ary_resize_i(void ***ary, int size);
extern void **ary_new_i(int type_size, int init_capa);
extern void ary_set_i(void ***ary, int index, void *value);
extern void *ary_get_i(void **ary, int index);
extern void ary_push_i(void ***ary, void *value);
extern void *ary_pop_i(void **ary);
extern void ary_unshift_i(void ***ary, void *value);
extern void *ary_shift_i(void **ary);
extern void *ary_remove_i(void **ary, int index);
extern void ary_delete_i(void **ary, int index, void (*free_elem)(void *p));
extern void ary_destroy_i(void **ary, void (*free_elem)(void *p));
extern void frt_ary_resize_i(void ***ary, int size);
extern void **frt_ary_new_i(int type_size, int init_capa);
extern void frt_ary_set_i(void ***ary, int index, void *value);
extern void *frt_ary_get_i(void **ary, int index);
extern void frt_ary_push_i(void ***ary, void *value);
extern void *frt_ary_pop_i(void **ary);
extern void frt_ary_unshift_i(void ***ary, void *value);
extern void *frt_ary_shift_i(void **ary);
extern void *frt_ary_remove_i(void **ary, int index);
extern void frt_ary_delete_i(void **ary, int index, frt_free_ft p);
extern void frt_ary_destroy_i(void **ary, frt_free_ft p);

#endif
39 changes: 39 additions & 0 deletions c/include/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#define ALLOC_AND_ZERO FRT_ALLOC_AND_ZERO
#define ALLOC_AND_ZERO_N FRT_ALLOC_AND_ZERO_N
#define ALLOC_N FRT_ALLOC_N
#define ARY_INIT_CAPA FRT_ARY_INIT_CAPA
#define ARY_META_CNT FRT_ARY_META_CNT
#define BV_INIT_CAPA FRT_BV_INIT_CAPA
#define DEREF FRT_DEREF
#define EMPTY_STRING FRT_EMPTY_STRING
Expand Down Expand Up @@ -82,6 +84,43 @@
#define a_get_ts frt_a_get_ts
#define a_standard_destroy frt_a_standard_destroy
#define analyzer_new frt_analyzer_new
#define ary_capa frt_ary_capa
#define ary_delete frt_ary_delete
#define ary_delete_i frt_ary_delete_i
#define ary_destroy frt_ary_destroy
#define ary_destroy_i frt_ary_destroy_i
#define ary_each frt_ary_each
#define ary_each_rev frt_ary_each_rev
#define ary_free frt_ary_free
#define ary_get frt_ary_get
#define ary_get_i frt_ary_get_i
#define ary_grow frt_ary_grow
#define ary_last frt_ary_last
#define ary_new frt_ary_new
#define ary_new_capa frt_ary_new_capa
#define ary_new_i frt_ary_new_i
#define ary_new_type frt_ary_new_type
#define ary_new_type_capa frt_ary_new_type_capa
#define ary_pop frt_ary_pop
#define ary_pop_i frt_ary_pop_i
#define ary_push frt_ary_push
#define ary_push_i frt_ary_push_i
#define ary_remove frt_ary_remove
#define ary_remove_i frt_ary_remove_i
#define ary_resize frt_ary_resize
#define ary_resize_i frt_ary_resize_i
#define ary_rsz frt_ary_rsz
#define ary_set frt_ary_set
#define ary_set_i frt_ary_set_i
#define ary_shift frt_ary_shift
#define ary_shift_i frt_ary_shift_i
#define ary_size frt_ary_size
#define ary_sort frt_ary_sort
#define ary_start frt_ary_start
#define ary_sz frt_ary_sz
#define ary_type_size frt_ary_type_size
#define ary_unshift frt_ary_unshift
#define ary_unshift_i frt_ary_unshift_i
#define bv_and frt_bv_and
#define bv_and_x frt_bv_and_x
#define bv_clear frt_bv_clear
Expand Down
34 changes: 17 additions & 17 deletions c/src/analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ INLINE Token *tk_set(Token *tk,
return tk;
}

INLINE Token *tk_set_ts(Token *tk,
char *start, char *end, char *text, int pos_inc)
static INLINE Token *tk_set_ts(Token *tk, char *start, char *end,
char *text, int pos_inc)
{
return tk_set(tk, start, (int)(end - start),
(off_t)(start - text), (off_t)(end - text), pos_inc);
Expand All @@ -41,8 +41,8 @@ INLINE Token *tk_set_no_len(Token *tk,
return tk_set(tk, text, (int)strlen(text), start, end, pos_inc);
}

INLINE Token *w_tk_set(Token *tk, wchar_t *text, off_t start, off_t end,
int pos_inc)
static INLINE Token *w_tk_set(Token *tk, wchar_t *text, off_t start,
off_t end, int pos_inc)
{
int len = wcstombs(tk->text, text, MAX_WORD_SIZE - 1);
tk->text[len] = '\0';
Expand Down Expand Up @@ -153,7 +153,7 @@ static TokenStream *cts_new()

#define MBTS(token_stream) ((MultiByteTokenStream *)(token_stream))

INLINE int mb_next_char(wchar_t *wchr, const char *s, mbstate_t *state)
static INLINE int mb_next_char(wchar_t *wchr, const char *s, mbstate_t *state)
{
int num_bytes;
if ((num_bytes = (int)mbrtowc(wchr, s, MB_CUR_MAX, state)) < 0) {
Expand Down Expand Up @@ -181,7 +181,7 @@ static TokenStream *mb_ts_clone_i(TokenStream *orig_ts)
return ts_clone_size(orig_ts, sizeof(MultiByteTokenStream));
}

TokenStream *mb_ts_new()
static TokenStream *mb_ts_new()
{
TokenStream *ts = ts_new(MultiByteTokenStream);
ts->reset = &mb_ts_reset;
Expand Down Expand Up @@ -415,7 +415,7 @@ Analyzer *mb_whitespace_analyzer_new(bool lowercase)
/*
* LetterTokenizer
*/
Token *lt_next(TokenStream *ts)
static Token *lt_next(TokenStream *ts)
{
char *start;
char *t = ts->t;
Expand Down Expand Up @@ -447,7 +447,7 @@ TokenStream *letter_tokenizer_new()
/*
* Multi-byte LetterTokenizer
*/
Token *mb_lt_next(TokenStream *ts)
static Token *mb_lt_next(TokenStream *ts)
{
int i;
char *start;
Expand Down Expand Up @@ -479,7 +479,7 @@ Token *mb_lt_next(TokenStream *ts)
/*
* Lowercasing Multi-byte LetterTokenizer
*/
Token *mb_lt_next_lc(TokenStream *ts)
static Token *mb_lt_next_lc(TokenStream *ts)
{
int i;
char *start;
Expand Down Expand Up @@ -1310,7 +1310,7 @@ TokenStream *hyphen_filter_new(TokenStream *sub_ts)
****************************************************************************/


Token *mb_lcf_next(TokenStream *ts)
static Token *mb_lcf_next(TokenStream *ts)
{
wchar_t wbuf[MAX_WORD_SIZE + 1], *wchr;
Token *tk = TkFilt(ts)->sub_ts->next(TkFilt(ts)->sub_ts);
Expand Down Expand Up @@ -1343,7 +1343,7 @@ TokenStream *mb_lowercase_filter_new(TokenStream *sub_ts)
return ts;
}

Token *lcf_next(TokenStream *ts)
static Token *lcf_next(TokenStream *ts)
{
int i = 0;
Token *tk = TkFilt(ts)->sub_ts->next(TkFilt(ts)->sub_ts);
Expand All @@ -1370,15 +1370,15 @@ TokenStream *lowercase_filter_new(TokenStream *sub_ts)

#define StemFilt(filter) ((StemFilter *)(filter))

void stemf_destroy_i(TokenStream *ts)
static void stemf_destroy_i(TokenStream *ts)
{
sb_stemmer_delete(StemFilt(ts)->stemmer);
free(StemFilt(ts)->algorithm);
free(StemFilt(ts)->charenc);
filter_destroy_i(ts);
}

Token *stemf_next(TokenStream *ts)
static Token *stemf_next(TokenStream *ts)
{
int len;
const sb_symbol *stemmed;
Expand All @@ -1400,7 +1400,7 @@ Token *stemf_next(TokenStream *ts)
return tk;
}

TokenStream *stemf_clone_i(TokenStream *orig_ts)
static TokenStream *stemf_clone_i(TokenStream *orig_ts)
{
TokenStream *new_ts = filter_clone_size(orig_ts, sizeof(StemFilter));
StemFilter *stemf = StemFilt(new_ts);
Expand Down Expand Up @@ -1526,15 +1526,15 @@ Analyzer *mb_standard_analyzer_new(bool lowercase)
*
****************************************************************************/

void pfa_destroy_i(Analyzer *self)
static void pfa_destroy_i(Analyzer *self)
{
h_destroy(PFA(self)->dict);

a_deref(PFA(self)->default_a);
free(self);
}

TokenStream *pfa_get_ts(Analyzer *self, char *field, char *text)
static TokenStream *pfa_get_ts(Analyzer *self, char *field, char *text)
{
Analyzer *a = h_get(PFA(self)->dict, field);
if (a == NULL) {
Expand All @@ -1543,7 +1543,7 @@ TokenStream *pfa_get_ts(Analyzer *self, char *field, char *text)
return a_get_ts(a, field, text);
}

void pfa_sub_a_destroy_i(void *p)
static void pfa_sub_a_destroy_i(void *p)
{
Analyzer *a = (Analyzer *) p;
a_deref(a);
Expand Down
2 changes: 1 addition & 1 deletion ruby/ext/threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define UNTHREADED 1

typedef void * mutex_t;
typedef struct FerretHashTable *thread_key_t;
typedef struct FrtHashTable *thread_key_t;
typedef int thread_once_t;
#define MUTEX_INITIALIZER NULL
#define MUTEX_RECURSIVE_INITIALIZER NULL
Expand Down

0 comments on commit 2eff78c

Please sign in to comment.