Add patches to use modern Ruby's API. Most of them are based on

patches of http://cvs.pld-linux.org/.

Bump PKGREVISION.
This commit is contained in:
taca 2011-06-19 16:01:52 +00:00
parent 820075baf2
commit 2b14500c27
8 changed files with 728 additions and 5 deletions

View file

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.6 2011/02/21 16:01:20 taca Exp $
# $NetBSD: Makefile,v 1.7 2011/06/19 16:01:52 taca Exp $
DISTNAME= ferret-0.11.6
PKGREVISION= 2
PKGREVISION= 3
CATEGORIES= textproc
MAINTAINER= minskim@NetBSD.org
@ -9,7 +9,5 @@ HOMEPAGE= http://ferret.davebalmain.com/
COMMENT= Text search engine library written for Ruby
LICENSE= mit
RUBY_VERSION_SUPPORTED= 18
.include "../../lang/ruby/gem.mk"
.include "../../mk/bsd.pkg.mk"

View file

@ -1,5 +1,11 @@
$NetBSD: distinfo,v 1.2 2008/04/04 15:21:28 jlam Exp $
$NetBSD: distinfo,v 1.3 2011/06/19 16:01:52 taca Exp $
SHA1 (ferret-0.11.6.gem) = 83e0fada54e20445fe4ed7cd1dcdf9ffe74bb953
RMD160 (ferret-0.11.6.gem) = 8f3fb148dafea297468fdc277c94f13fd4c4e164
Size (ferret-0.11.6.gem) = 473600 bytes
SHA1 (patch-ext_ferret.c) = 97e5ee20b63f9940a897cb7e98775e39798fd67b
SHA1 (patch-ext_lang.h) = 1c1b04b8420a9d0e610e725ca9237d9924076c4e
SHA1 (patch-ext_r__analysis.c) = 9e072327eddedb7f97a9f0b112246c97ac76c3ad
SHA1 (patch-ext_r__index.c) = 9f695ab78e3e7fdb0f0c29f72e11632ab77ad69d
SHA1 (patch-ext_r__qparser.c) = 1dfd71b0e690af23d31f6e8d2d0d77622e85200a
SHA1 (patch-ext_r__search.c) = 88bb96400a8c9fce888c8caddb7ae07741c47c38

View file

@ -0,0 +1,32 @@
$NetBSD: patch-ext_ferret.c,v 1.1 2011/06/19 16:01:52 taca Exp $
* Switch to modern Ruby's API: http://cvs.pld-linux.org/
--- ext/ferret.c.orig 2011-06-10 06:23:08.000000000 +0000
+++ ext/ferret.c
@@ -162,14 +162,14 @@ void *frt_rb_data_ptr(VALUE val)
char *
rs2s(VALUE rstr)
{
- return (char *)(RSTRING(rstr)->ptr ? RSTRING(rstr)->ptr : EMPTY_STRING);
+ return (char *)(RSTRING_PTR(rstr) ? RSTRING_PTR(rstr) : EMPTY_STRING);
}
char *
nstrdup(VALUE rstr)
{
char *old = rs2s(rstr);
- int len = RSTRING(rstr)->len;
+ int len = RSTRING_LEN(rstr);
char *new = ALLOC_N(char, len + 1);
memcpy(new, old, len + 1);
return new;
@@ -295,7 +295,7 @@ static VALUE frt_term_to_s(VALUE self)
char *field = StringValuePtr(rfield);
char *text = StringValuePtr(rtext);
char *term_str = ALLOC_N(char,
- 5 + RSTRING(rfield)->len + RSTRING(rtext)->len);
+ 5 + RSTRING_LEN(rfield) + RSTRING_LEN(rtext));
sprintf(term_str, "%s:%s", field, text);
rstr = rb_str_new2(term_str);
free(term_str);

View file

@ -0,0 +1,17 @@
$NetBSD: patch-ext_lang.h,v 1.1 2011/06/19 16:01:52 taca Exp $
* Switch to modern Ruby's API: http://cvs.pld-linux.org/
--- ext/lang.h.orig 2011-06-10 06:23:08.000000000 +0000
+++ ext/lang.h
@@ -6,6 +6,10 @@
#include <stdarg.h>
#include <ruby.h>
+#ifndef RUBY_RUBY_H
+#define RUBY18
+#endif
+
#undef close
#undef rename
#undef read

View file

@ -0,0 +1,195 @@
$NetBSD: patch-ext_r__analysis.c,v 1.1 2011/06/19 16:01:52 taca Exp $
* Switch to modern Ruby's API: http://cvs.pld-linux.org/
--- ext/r_analysis.c.orig 2011-06-10 06:23:08.000000000 +0000
+++ ext/r_analysis.c
@@ -1,6 +1,11 @@
+#include "lang.h"
+#ifdef RUBY18
#include <regex.h>
+#else
+#include <ruby/regex.h>
+#endif
#include <locale.h>
-#include <st.h>
+#include <ruby/st.h>
#include "ferret.h"
#include "analysis.h"
@@ -47,13 +52,15 @@ static ID id_token_stream;
static VALUE object_space;
+#ifdef RUBY18
extern int ruby_re_search(struct re_pattern_buffer *, const char *, int, int,
int, struct re_registers *);
+#endif
int
frt_rb_hash_size(VALUE hash)
{
- return RHASH(hash)->tbl->num_entries;
+ return RHASH_SIZE(hash);
}
/****************************************************************************
@@ -69,11 +76,11 @@ get_stopwords(VALUE rstop_words)
int i, len;
VALUE rstr;
Check_Type(rstop_words, T_ARRAY);
- len = RARRAY(rstop_words)->len;
- stop_words = ALLOC_N(char *, RARRAY(rstop_words)->len + 1);
+ len = RARRAY_LEN(rstop_words);
+ stop_words = ALLOC_N(char *, RARRAY_LEN(rstop_words) + 1);
stop_words[len] = NULL;
for (i = 0; i < len; i++) {
- rstr = rb_obj_as_string(RARRAY(rstop_words)->ptr[i]);
+ rstr = rb_obj_as_string(RARRAY_PTR(rstop_words)[i]);
stop_words[i] = rs2s(rstr);
}
return stop_words;
@@ -132,7 +139,7 @@ frt_set_token(Token *tk, VALUE rt)
if (rt == Qnil) return NULL;
Data_Get_Struct(rt, RToken, rtk);
- tk_set(tk, rs2s(rtk->text), RSTRING(rtk->text)->len,
+ tk_set(tk, rs2s(rtk->text), RSTRING_LEN(rtk->text),
rtk->start, rtk->end, rtk->pos_inc);
return tk;
}
@@ -372,7 +379,7 @@ frt_token_to_s(VALUE self)
RToken *token;
char *buf;
GET_TK(token, self);
- buf = alloca(RSTRING(token->text)->len + 80);
+ buf = alloca(RSTRING_LEN(token->text) + 80);
sprintf(buf, "token[\"%s\":%d:%d:%d]", rs2s(token->text),
token->start, token->end, token->pos_inc);
return rb_str_new2(buf);
@@ -621,7 +628,7 @@ typedef struct RegExpTokenStream {
VALUE rtext;
VALUE regex;
VALUE proc;
- int curr_ind;
+ long curr_ind;
} RegExpTokenStream;
static void
@@ -689,16 +696,20 @@ frt_rets_get_text(VALUE self)
return RETS(ts)->rtext;
}
+#ifdef RUBY18
+
static Token *
rets_next(TokenStream *ts)
{
static struct re_registers regs;
int ret, beg, end;
- struct RString *rtext = RSTRING(RETS(ts)->rtext);
+ struct RString *rtext = RSTRING_PTR(RETS(ts));
+ long rtext_len = RSTRING_LEN(RETS(ts)->rtext);
+ char *rtext_ptr = RSTRING_PTR(RETS(ts)->rtext);
Check_Type(RETS(ts)->regex, T_REGEXP);
ret = ruby_re_search(RREGEXP(RETS(ts)->regex)->ptr,
- rtext->ptr, rtext->len,
- RETS(ts)->curr_ind, rtext->len - RETS(ts)->curr_ind,
+ rtext_ptr, rtext_len,
+ RETS(ts)->curr_ind, rtext_len - RETS(ts)->curr_ind,
&regs);
if (ret == -2) rb_raise(rb_eStandardError, "regexp buffer overflow");
@@ -707,15 +718,78 @@ rets_next(TokenStream *ts)
beg = regs.beg[0];
RETS(ts)->curr_ind = end = regs.end[0];
if (NIL_P(RETS(ts)->proc)) {
- return tk_set(&(CachedTS(ts)->token), rtext->ptr + beg, end - beg,
+ return tk_set(&(CachedTS(ts)->token), rtext_ptr + beg, end - beg,
beg, end, 1);
} else {
- VALUE rtok = rb_str_new(rtext->ptr + beg, end - beg);
+ VALUE rtok = rb_str_new(rtext_ptr + beg, end - beg);
rtok = rb_funcall(RETS(ts)->proc, id_call, 1, rtok);
return tk_set(&(CachedTS(ts)->token), rs2s(rtok),
- RSTRING(rtok)->len, beg, end, 1);
+ RSTRING_LEN(rtok), beg, end, 1);
+ }
+}
+#else
+
+// partly lifted from ruby 1.9 string.c
+#include <ruby/encoding.h>
+#define BEG(no) regs->beg[no]
+#define END(no) regs->end[no]
+#define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
+static VALUE
+ scan_once(VALUE str, VALUE pat, long *start)
+{
+ VALUE match;
+ struct re_registers *regs;
+
+ if (rb_reg_search(pat, str, *start, 0) >= 0) {
+ match = rb_backref_get();
+ regs = RMATCH_REGS(match);
+ if (BEG(0) == END(0)) {
+ rb_encoding *enc = STR_ENC_GET(str);
+ /*
+ * Always consume at least one character of the input string
+ */
+ if (RSTRING_LEN(str) > END(0))
+ *start = END(0)+rb_enc_mbclen(RSTRING_PTR(str)+END(0),
+ RSTRING_END(str), enc);
+ else
+ *start = END(0)+1;
+ }
+ else {
+ *start = END(0);
}
+ return rb_reg_nth_match(0, match);
+ }
+ return Qnil;
}
+//
+
+static Token *
+ rets_next(TokenStream *ts)
+{
+ VALUE ret;
+ long rtok_len;
+ int beg, end;
+ Check_Type(RETS(ts)->regex, T_REGEXP);
+ ret = scan_once(RETS(ts)->rtext, RETS(ts)->regex, &(RETS(ts)->curr_ind));
+ if (NIL_P(ret)) return NULL;
+
+ Check_Type(ret, T_STRING);
+ rtok_len = RSTRING_LEN(ret);
+ beg = RETS(ts)->curr_ind - rtok_len;
+ end = RETS(ts)->curr_ind;
+
+ if (NIL_P(RETS(ts)->proc)) {
+ return tk_set(&(CachedTS(ts)->token), rs2s(ret), rtok_len,
+ beg, end, 1);
+ } else {
+ VALUE rtok;
+ rtok = rb_funcall(RETS(ts)->proc, id_call, 1, ret);
+ return tk_set(&(CachedTS(ts)->token), rs2s(rtok),
+ RSTRING_LEN(rtok), beg, end, 1);
+ }
+}
+
+#endif
static TokenStream *
rets_reset(TokenStream *ts, char *text)
@@ -1029,8 +1103,8 @@ static int frt_add_mappings_i(VALUE key,
}
if (TYPE(key) == T_ARRAY) {
int i;
- for (i = RARRAY(key)->len - 1; i >= 0; i--) {
- frt_add_mapping_i(mf, RARRAY(key)->ptr[i], to);
+ for (i = RARRAY_LEN(key) - 1; i >= 0; i--) {
+ frt_add_mapping_i(mf, RARRAY_PTR(key)[i], to);
}
}
else {

View file

@ -0,0 +1,244 @@
$NetBSD: patch-ext_r__index.c,v 1.1 2011/06/19 16:01:52 taca Exp $
* Switch to modern Ruby's API: http://cvs.pld-linux.org/
--- ext/r_index.c.orig 2011-06-10 06:23:08.000000000 +0000
+++ ext/r_index.c
@@ -1,6 +1,6 @@
#include "ferret.h"
#include "index.h"
-#include <st.h>
+#include <ruby/st.h>
VALUE mIndex;
@@ -765,8 +765,8 @@ frt_te_each(VALUE self)
char *term;
int term_cnt = 0;
VALUE vals = rb_ary_new2(2);
- RARRAY(vals)->len = 2;
- rb_mem_clear(RARRAY(vals)->ptr, 2);
+ rb_ary_store(vals, 0, Qnil);
+ rb_ary_store(vals, 1, Qnil);
/* each is being called so there will be no current term */
@@ -775,8 +775,8 @@ frt_te_each(VALUE self)
while (NULL != (term = te->next(te))) {
term_cnt++;
- RARRAY(vals)->ptr[0] = rb_str_new(term, te->curr_term_len);
- RARRAY(vals)->ptr[1] = INT2FIX(te->curr_ti.doc_freq);
+ RARRAY_PTR(vals)[0] = rb_str_new(term, te->curr_term_len);
+ RARRAY_PTR(vals)[1] = INT2FIX(te->curr_ti.doc_freq);
rb_yield(vals);
}
return INT2FIX(term_cnt);
@@ -1040,13 +1040,13 @@ frt_tde_each(VALUE self)
int doc_cnt = 0;
TermDocEnum *tde = (TermDocEnum *)DATA_PTR(self);
VALUE vals = rb_ary_new2(2);
- RARRAY(vals)->len = 2;
- rb_mem_clear(RARRAY(vals)->ptr, 2);
+ rb_ary_store(vals, 0, Qnil);
+ rb_ary_store(vals, 1, Qnil);
while (tde->next(tde)) {
doc_cnt++;
- RARRAY(vals)->ptr[0] = INT2FIX(tde->doc_num(tde));
- RARRAY(vals)->ptr[1] = INT2FIX(tde->freq(tde));
+ RARRAY_PTR(vals)[0] = INT2FIX(tde->doc_num(tde));
+ RARRAY_PTR(vals)[1] = INT2FIX(tde->freq(tde));
rb_yield(vals);
}
@@ -1212,14 +1212,11 @@ frt_get_tv_term(TVTerm *tv_term)
VALUE rpositions = Qnil;
rtext = rb_str_new2(tv_term->text);
if (tv_term->positions) {
- VALUE *rpos;
int *positions = tv_term->positions;
rpositions = rb_ary_new2(freq);
- rpos = RARRAY(rpositions)->ptr;
for (i = 0; i < freq; i++) {
- rpos[i] = INT2FIX(positions[i]);
+ rb_ary_store(rpositions, i, NT2FIX(positions[i]));
}
- RARRAY(rpositions)->len = freq;
}
return rb_struct_new(cTVTerm, rtext, rpositions, NULL);
}
@@ -1237,25 +1234,20 @@ frt_get_tv(TermVector *tv)
TVTerm *terms = tv->terms;
const int t_cnt = tv->term_cnt;
const int o_cnt = tv->offset_cnt;
- VALUE rfield, rterms, *rts;
+ VALUE rfield, rterms;
VALUE roffsets = Qnil;
rfield = ID2SYM(rb_intern(tv->field));
rterms = rb_ary_new2(t_cnt);
- rts = RARRAY(rterms)->ptr;
for (i = 0; i < t_cnt; i++) {
- rts[i] = frt_get_tv_term(&terms[i]);
- RARRAY(rterms)->len++;
+ rb_ary_store(rterms, i, frt_get_tv_term(&terms[i]));
}
if (tv->offsets) {
- VALUE *ros;
Offset *offsets = tv->offsets;
roffsets = rb_ary_new2(o_cnt);
- ros = RARRAY(roffsets)->ptr;
for (i = 0; i < o_cnt; i++) {
- ros[i] = frt_get_tv_offsets(&offsets[i]);
- RARRAY(roffsets)->len++;
+ rb_ary_store(roffsets, i, frt_get_tv_offsets(&offsets[i]));
}
}
@@ -1458,19 +1450,19 @@ frt_hash_to_doc_i(VALUE key, VALUE value
{
int i;
df->destroy_data = true;
- for (i = 0; i < RARRAY(value)->len; i++) {
- val = rb_obj_as_string(RARRAY(value)->ptr[i]);
- df_add_data_len(df, nstrdup(val), RSTRING(val)->len);
+ for (i = 0; i < RARRAY_LEN(value); i++) {
+ val = rb_obj_as_string(RARRAY_PTR(value)[i]);
+ df_add_data_len(df, nstrdup(val), RSTRING_LEN(val));
}
}
break;
case T_STRING:
- df_add_data_len(df, rs2s(value), RSTRING(value)->len);
+ df_add_data_len(df, rs2s(value), RSTRING_LEN(value));
break;
default:
val = rb_obj_as_string(value);
df->destroy_data = true;
- df_add_data_len(df, nstrdup(val), RSTRING(val)->len);
+ df_add_data_len(df, nstrdup(val), RSTRING_LEN(val));
break;
}
doc_add_field(doc, df);
@@ -1498,9 +1490,9 @@ frt_get_doc(VALUE rdoc)
int i;
df = df_new("content");
df->destroy_data = true;
- for (i = 0; i < RARRAY(rdoc)->len; i++) {
- val = rb_obj_as_string(RARRAY(rdoc)->ptr[i]);
- df_add_data_len(df, nstrdup(val), RSTRING(val)->len);
+ for (i = 0; i < RARRAY_LEN(rdoc); i++) {
+ val = rb_obj_as_string(RARRAY_PTR(rdoc)[i]);
+ df_add_data_len(df, nstrdup(val), RSTRING_LEN(val));
}
doc_add_field(doc, df);
}
@@ -1511,13 +1503,13 @@ frt_get_doc(VALUE rdoc)
break;
case T_STRING:
df = df_add_data_len(df_new("content"), rs2s(rdoc),
- RSTRING(rdoc)->len);
+ RSTRING_LEN(rdoc));
doc_add_field(doc, df);
break;
default:
val = rb_obj_as_string(rdoc);
df = df_add_data_len(df_new("content"), nstrdup(val),
- RSTRING(val)->len);
+ RSTRING_LEN(val));
df->destroy_data = true;
doc_add_field(doc, df);
break;
@@ -1597,14 +1589,14 @@ frt_iw_add_readers(VALUE self, VALUE rre
IndexReader **irs;
Check_Type(rreaders, T_ARRAY);
- irs = ALLOC_N(IndexReader *, RARRAY(rreaders)->len);
- i = RARRAY(rreaders)->len;
+ irs = ALLOC_N(IndexReader *, RARRAY_LEN(rreaders));
+ i = RARRAY_LEN(rreaders);
while (i-- > 0) {
IndexReader *ir;
- Data_Get_Struct(RARRAY(rreaders)->ptr[i], IndexReader, ir);
+ Data_Get_Struct(RARRAY_PTR(rreaders)[i], IndexReader, ir);
irs[i] = ir;
}
- iw_add_readers(iw, irs, RARRAY(rreaders)->len);
+ iw_add_readers(iw, irs, RARRAY_LEN(rreaders));
free(irs);
return self;
}
@@ -1953,9 +1945,7 @@ frt_lazy_df_load(VALUE self, VALUE rkey,
rdata = rb_ary_new2(lazy_df->size);
for (i = 0; i < lazy_df->size; i++) {
char *data = lazy_df_get_data(lazy_df, i);
- RARRAY(rdata)->ptr[i] =
- rb_str_new(data, lazy_df->data[i].length);
- RARRAY(rdata)->len++;
+ rb_ary_store(rdata, i, rb_str_new(data, lazy_df->data[i].length));
}
}
rb_hash_aset(self, rkey, rdata);
@@ -2038,8 +2028,7 @@ frt_get_lazy_doc(LazyDoc *lazy_doc)
rb_ivar_set(self, id_data, rdata);
for (i = 0; i < lazy_doc->size; i++) {
- RARRAY(rfields)->ptr[i] = ID2SYM(rb_intern(lazy_doc->fields[i]->name));
- RARRAY(rfields)->len++;
+ rb_ary_store(rfields, i, ID2SYM(rb_intern(lazy_doc->fields[i]->name)));
}
rb_ivar_set(self, id_fields, rfields);
@@ -2115,11 +2104,11 @@ frt_ir_init(VALUE self, VALUE rdir)
if (TYPE(rdir) == T_ARRAY) {
VALUE rdirs = rdir;
- const int reader_cnt = RARRAY(rdir)->len;
+ const int reader_cnt = RARRAY_LEN(rdir);
IndexReader **sub_readers = ALLOC_N(IndexReader *, reader_cnt);
int i;
for (i = 0; i < reader_cnt; i++) {
- rdir = RARRAY(rdirs)->ptr[i];
+ rdir = RARRAY_PTR(rdirs)[i];
switch (TYPE(rdir)) {
case T_DATA:
if (CLASS_OF(rdir) == cIndexReader) {
@@ -2235,11 +2224,11 @@ frt_ir_get_norms_into(VALUE self, VALUE
int offset;
offset = FIX2INT(roffset);
Check_Type(rnorms, T_STRING);
- if (RSTRING(rnorms)->len < offset + ir->max_doc(ir)) {
- rb_raise(rb_eArgError, "supplied a string of length:%d to "
+ if (RSTRING_LEN(rnorms) < offset + ir->max_doc(ir)) {
+ rb_raise(rb_eArgError, "supplied a string of length:%ld to "
"IndexReader#get_norms_into but needed a string of length "
"offset:%d + maxdoc:%d",
- RSTRING(rnorms)->len, offset, ir->max_doc(ir));
+ RSTRING_LEN(rnorms), offset, ir->max_doc(ir));
}
ir_get_norms_into(ir, frt_field(rfield),
@@ -2382,8 +2371,7 @@ frt_get_doc_range(IndexReader *ir, int p
len = max - pos;
ary = rb_ary_new2(len);
for (i = 0; i < len; i++) {
- RARRAY(ary)->ptr[i] = frt_get_lazy_doc(ir->get_lazy_doc(ir, i + pos));
- RARRAY(ary)->len++;
+ rb_ary_store(ary, i, frt_get_lazy_doc(ir->get_lazy_doc(ir, i + pos)));
}
return ary;
}
@@ -2410,9 +2398,8 @@ frt_ir_get_doc(int argc, VALUE *argv, VA
pos = FIX2INT(arg1);
pos = (pos < 0) ? (max + pos) : pos;
if (pos < 0 || pos >= max) {
- rb_raise(rb_eArgError, ":%d is out of range [%d..%d] for "
- "IndexReader#[]", pos, 0, max,
- rb_id2name(SYM2ID(argv)));
+ rb_raise(rb_eArgError, ":%ld is out of range [%d..%ld] for "
+ "IndexReader#[]", pos, 0, max);
}
return frt_get_lazy_doc(ir->get_lazy_doc(ir, pos));
}

View file

@ -0,0 +1,17 @@
$NetBSD: patch-ext_r__qparser.c,v 1.1 2011/06/19 16:01:52 taca Exp $
* Switch to modern Ruby's API: http://cvs.pld-linux.org/
--- ext/r_qparser.c.orig 2011-06-10 06:23:08.000000000 +0000
+++ ext/r_qparser.c
@@ -53,8 +53,8 @@ frt_get_fields(VALUE rfields)
fields = hs_new_str(&free);
if (TYPE(rfields) == T_ARRAY) {
int i;
- for (i = 0; i < RARRAY(rfields)->len; i++) {
- rval = rb_obj_as_string(RARRAY(rfields)->ptr[i]);
+ for (i = 0; i < RARRAY_LEN(rfields); i++) {
+ rval = rb_obj_as_string(RARRAY_PTR(rfields)[i]);
hs_add(fields, nstrdup(rval));
}
} else {

View file

@ -0,0 +1,214 @@
$NetBSD: patch-ext_r__search.c,v 1.1 2011/06/19 16:01:52 taca Exp $
* Switch to modern Ruby's API: http://cvs.pld-linux.org/
--- ext/r_search.c.orig 2011-06-10 05:02:24.000000000 +0000
+++ ext/r_search.c
@@ -161,8 +161,7 @@ frt_get_td(TopDocs *td, VALUE rsearcher)
VALUE hit_ary = rb_ary_new2(td->size);
for (i = 0; i < td->size; i++) {
- RARRAY(hit_ary)->ptr[i] = frt_get_hit(td->hits[i]);
- RARRAY(hit_ary)->len++;
+ rb_ary_store(hit_ary, i, frt_get_hit(td->hits[i]));
}
rtop_docs = rb_struct_new(cTopDocs,
@@ -187,7 +186,7 @@ frt_td_to_s(int argc, VALUE *argv, VALUE
int i;
VALUE rhits = rb_funcall(self, id_hits, 0);
Searcher *sea = (Searcher *)DATA_PTR(rb_funcall(self, id_searcher, 0));
- const int len = RARRAY(rhits)->len;
+ const int len = RARRAY_LEN(rhits);
char *str = ALLOC_N(char, len * 64 + 100);
char *s = str;
char *field = "id";
@@ -197,13 +196,13 @@ frt_td_to_s(int argc, VALUE *argv, VALUE
field = frt_field(argv[0]);
}
- sprintf(s, "TopDocs: total_hits = %ld, max_score = %f [\n",
+ sprintf(s, "TopDocs: total_hits = %d, max_score = %f [\n",
FIX2INT(rb_funcall(self, id_total_hits, 0)),
NUM2DBL(rb_funcall(self, id_max_score, 0)));
s += strlen(s);
for (i = 0; i < len; i++) {
- VALUE rhit = RARRAY(rhits)->ptr[i];
+ VALUE rhit = RARRAY_PTR(rhits)[i];
int doc_id = FIX2INT(rb_funcall(rhit, id_doc, 0));
char *value = "";
LazyDoc *lzd = sea->get_lazy_doc(sea, doc_id);
@@ -280,7 +279,7 @@ frt_td_to_json(VALUE self)
VALUE rhit;
LazyDoc *lzd;
Searcher *sea = (Searcher *)DATA_PTR(rb_funcall(self, id_searcher, 0));
- const int num_hits = RARRAY(rhits)->len;
+ const int num_hits = RARRAY_LEN(rhits);
int doc_id;
int len = 32768;
char *str = ALLOC_N(char, len);
@@ -291,7 +290,7 @@ frt_td_to_json(VALUE self)
for (i = 0; i < num_hits; i++) {
if (i) *(s++) = ',';
*(s++) = '{';
- rhit = RARRAY(rhits)->ptr[i];
+ rhit = RARRAY_PTR(rhits)[i];
doc_id = FIX2INT(rb_funcall(rhit, id_doc, 0));
lzd = sea->get_lazy_doc(sea, doc_id);
s = frt_lzd_load_to_json(lzd, &str, s, &len);
@@ -623,7 +622,7 @@ frt_mtq_set_dmt(VALUE self, VALUE rnum_t
rb_raise(rb_eArgError,
"%d <= 0. @@max_terms must be > 0", max_terms);
}
- rb_cvar_set(cMultiTermQuery, id_default_max_terms, rnum_terms, Qfalse);
+ rb_cvar_set(cMultiTermQuery, id_default_max_terms, rnum_terms);
return rnum_terms;
}
@@ -1165,15 +1164,15 @@ frt_phq_add(int argc, VALUE *argv, VALUE
{
int i;
char *t;
- if (RARRAY(rterm)->len < 1) {
+ if (RARRAY_LEN(rterm) < 1) {
rb_raise(rb_eArgError, "Cannot add empty array to a "
"PhraseQuery. You must add either a string or "
"an array of strings");
}
- t = StringValuePtr(RARRAY(rterm)->ptr[0]);
+ t = StringValuePtr(RARRAY_PTR(rterm)[0]);
phq_add_term(q, t, pos_inc);
- for (i = 1; i < RARRAY(rterm)->len; i++) {
- t = StringValuePtr(RARRAY(rterm)->ptr[i]);
+ for (i = 1; i < RARRAY_LEN(rterm); i++) {
+ t = StringValuePtr(RARRAY_PTR(rterm)[i]);
phq_append_multi_term(q, t);
}
break;
@@ -1426,7 +1425,7 @@ frt_fq_set_dms(VALUE self, VALUE val)
"%f < 0.0. :min_similarity must be > 0.0", min_sim);
}
qp_default_fuzzy_min_sim = (float)min_sim;
- rb_cvar_set(cFuzzyQuery, id_default_min_similarity, val, Qfalse);
+ rb_cvar_set(cFuzzyQuery, id_default_min_similarity, val);
return val;
}
@@ -1458,7 +1457,7 @@ frt_fq_set_dpl(VALUE self, VALUE val)
"%d < 0. :prefix_length must be >= 0", pre_len);
}
qp_default_fuzzy_pre_len = pre_len;
- rb_cvar_set(cFuzzyQuery, id_default_prefix_length, val, Qfalse);
+ rb_cvar_set(cFuzzyQuery, id_default_prefix_length, val);
return val;
}
@@ -1591,8 +1590,8 @@ frt_spanmtq_init(VALUE self, VALUE rfiel
{
Query *q = spanmtq_new(frt_field(rfield));
int i;
- for (i = RARRAY(rterms)->len - 1; i >= 0; i--) {
- spanmtq_add_term(q, StringValuePtr(RARRAY(rterms)->ptr[i]));
+ for (i = RARRAY_LEN(rterms) - 1; i >= 0; i--) {
+ spanmtq_add_term(q, StringValuePtr(RARRAY_PTR(rterms)[i]));
}
Frt_Wrap_Struct(self, NULL, &frt_q_free, q);
object_add(q, self);
@@ -1716,8 +1715,8 @@ frt_spannq_init(int argc, VALUE *argv, V
int i;
Query *clause;
Check_Type(v, T_ARRAY);
- for (i = 0; i < RARRAY(v)->len; i++) {
- Data_Get_Struct(RARRAY(v)->ptr[i], Query, clause);
+ for (i = 0; i < RARRAY_LEN(v); i++) {
+ Data_Get_Struct(RARRAY_PTR(v)[i], Query, clause);
spannq_add_clause(q, clause);
}
}
@@ -1782,8 +1781,8 @@ frt_spanoq_init(int argc, VALUE *argv, V
int i;
Query *clause;
Check_Type(rclauses, T_ARRAY);
- for (i = 0; i < RARRAY(rclauses)->len; i++) {
- Data_Get_Struct(RARRAY(rclauses)->ptr[i], Query, clause);
+ for (i = 0; i < RARRAY_LEN(rclauses); i++) {
+ Data_Get_Struct(RARRAY_PTR(rclauses)[i], Query, clause);
spanoq_add_clause(q, clause);
}
}
@@ -2277,8 +2276,8 @@ frt_sort_init(int argc, VALUE *argv, VAL
case 1:
if (TYPE(rfields) == T_ARRAY) {
int i;
- for (i = 0; i < RARRAY(rfields)->len; i++) {
- frt_sort_add(sort, RARRAY(rfields)->ptr[i], reverse);
+ for (i = 0; i < RARRAY_LEN(rfields); i++) {
+ frt_sort_add(sort, RARRAY_PTR(rfields)[i], reverse);
}
} else {
frt_sort_add(sort, rfields, reverse);
@@ -2632,8 +2631,6 @@ frt_sea_search_each(int argc, VALUE *arg
rb_scan_args(argc, argv, "11", &rquery, &roptions);
- rb_thread_critical = Qtrue;
-
Data_Get_Struct(rquery, Query, q);
td = frt_sea_search_internal(q, roptions, sea);
@@ -2648,8 +2645,6 @@ frt_sea_search_each(int argc, VALUE *arg
rtotal_hits = INT2FIX(td->total_hits);
td_destroy(td);
- rb_thread_critical = 0;
-
return rtotal_hits;
}
@@ -2753,8 +2748,7 @@ frt_sea_highlight(int argc, VALUE *argv,
VALUE rexcerpts = rb_ary_new2(size);
for (i = 0; i < size; i++) {
- RARRAY(rexcerpts)->ptr[i] = rb_str_new2(excerpts[i]);
- RARRAY(rexcerpts)->len++;
+ rbary_store(rexcerpts, i, rb_str_new2(excerpts[i]));
}
ary_destroy(excerpts, &free);
return rexcerpts;
@@ -2870,10 +2864,10 @@ frt_ms_init(int argc, VALUE *argv, VALUE
rsearcher = argv[i];
switch (TYPE(rsearcher)) {
case T_ARRAY:
- capa += RARRAY(rsearcher)->len;
+ capa += RARRAY_LEN(rsearcher);
REALLOC_N(searchers, Searcher *, capa);
- for (j = 0; j < RARRAY(rsearcher)->len; j++) {
- VALUE rs = RARRAY(rsearcher)->ptr[j];
+ for (j = 0; j < RARRAY_LEN(rsearcher); j++) {
+ VALUE rs = RARRAY_PTR(rsearcher)[j];
Data_Get_Struct(rs, Searcher, s);
searchers[top++] = s;
}
@@ -3107,7 +3101,7 @@ Init_MultiTermQuery(void)
cMultiTermQuery = rb_define_class_under(mSearch, "MultiTermQuery", cQuery);
rb_define_alloc_func(cMultiTermQuery, frt_data_alloc);
- rb_cvar_set(cMultiTermQuery, id_default_max_terms, INT2FIX(512), Qfalse);
+ rb_cvar_set(cMultiTermQuery, id_default_max_terms, INT2FIX(512));
rb_define_singleton_method(cMultiTermQuery, "default_max_terms",
frt_mtq_get_dmt, 0);
rb_define_singleton_method(cMultiTermQuery, "default_max_terms=",
@@ -3415,10 +3409,8 @@ Init_FuzzyQuery(void)
cFuzzyQuery = rb_define_class_under(mSearch, "FuzzyQuery", cQuery);
rb_define_alloc_func(cFuzzyQuery, frt_data_alloc);
- rb_cvar_set(cFuzzyQuery, id_default_min_similarity,
- rb_float_new(0.5), Qfalse);
- rb_cvar_set(cFuzzyQuery, id_default_prefix_length,
- INT2FIX(0), Qfalse);
+ rb_cvar_set(cFuzzyQuery, id_default_min_similarity, rb_float_new(0.5));
+ rb_cvar_set(cFuzzyQuery, id_default_prefix_length, INT2FIX(0));
rb_define_singleton_method(cFuzzyQuery, "default_min_similarity",
frt_fq_get_dms, 0);