ports/textproc/ruby-hyperestraier/patches/patch-ext_estraier_c

90 lines
3.7 KiB
Text
Raw Normal View History

2023-08-16 22:26:55 +00:00
Use modern ruby macros for accessing ptr/len for strings and arrays.
Undefine the allocation function for a few constants to prevent
warnings on Ruby 3.2.
Index: ext/estraier.c
--- ext/estraier.c.orig
+++ ext/estraier.c
@@ -154,6 +154,7 @@ int Init_estraier(void){
static void doc_init(void){
cls_doc = rb_define_class_under(mod_estraier, "Document", rb_cObject);
cls_doc_data = rb_define_class_under(mod_estraier, "Document_data", rb_cObject);
+ rb_undef_alloc_func(cls_doc_data);
rb_define_private_method(cls_doc, "initialize", doc_initialize, -1);
rb_define_method(cls_doc, "add_attr", doc_add_attr, 2);
rb_define_method(cls_doc, "add_text", doc_add_text, 1);
@@ -351,7 +352,7 @@ static VALUE doc_make_snippet(VALUE vself, VALUE vword
vdoc = rb_iv_get(vself, VNDATA);
Data_Get_Struct(vdoc, ESTDOC, doc);
Check_Type(vwords, T_ARRAY);
- len = RARRAY(vwords)->len;
+ len = RARRAY_LEN(vwords);
for(i = 0; i < len; i++){
Check_Type(rb_ary_entry(vwords, i), T_STRING);
}
@@ -368,6 +369,7 @@ static VALUE doc_make_snippet(VALUE vself, VALUE vword
static void cond_init(void){
cls_cond = rb_define_class_under(mod_estraier, "Condition", rb_cObject);
cls_cond_data = rb_define_class_under(mod_estraier, "Condition_data", rb_cObject);
+ rb_undef_alloc_func(cls_cond_data);
rb_define_const(cls_cond, "SURE", INT2NUM(ESTCONDSURE));
rb_define_const(cls_cond, "USUAL", INT2NUM(ESTCONDUSUAL));
rb_define_const(cls_cond, "FAST", INT2NUM(ESTCONDFAST));
@@ -519,6 +521,7 @@ static VALUE cond_set_mask(VALUE vself, VALUE vmask){
static void res_init(void){
cls_res = rb_define_class_under(mod_estraier, "Result", rb_cObject);
cls_res_data = rb_define_class_under(mod_estraier, "Result_data", rb_cObject);
+ rb_undef_alloc_func(cls_res_data);
rb_define_private_method(cls_res, "initialize", res_initialize, 0);
rb_define_method(cls_res, "doc_num", res_doc_num, 0);
rb_define_method(cls_res, "get_doc_id", res_get_doc_id, 1);
@@ -662,6 +665,7 @@ static VALUE res_get_shadows(VALUE vself, VALUE vid){
static void db_init(void){
cls_db = rb_define_class_under(mod_estraier, "Database", rb_cObject);
cls_db_data = rb_define_class_under(mod_estraier, "Database_data", rb_cObject);
+ rb_undef_alloc_func(cls_db_data);
rb_define_const(cls_db, "VERSION", rb_str_new2(est_version));
rb_define_const(cls_db, "ERRNOERR", INT2NUM(ESTENOERR));
rb_define_const(cls_db, "ERRINVAL", INT2NUM(ESTEINVAL));
@@ -764,7 +768,7 @@ static VALUE db_search_meta(VALUE vself, VALUE vdbs, V
CBMAP *hints;
int i, dnum, *res, rnum;
Check_Type(vdbs, T_ARRAY);
- dnum = RARRAY(vdbs)->len;
+ dnum = RARRAY_LEN(vdbs);
dbs = cbmalloc(dnum * sizeof(ESTMTDB *) + 1);
for(i = 0; i < dnum; i++){
vdb = rb_ary_entry(vdbs, i);
@@ -1189,10 +1193,10 @@ static CBLIST *objtocblist(VALUE obj){
VALUE str;
int i, len;
list = cblistopen();
- len = RARRAY(obj)->len;
+ len = RARRAY_LEN(obj);
for(i = 0; i < len; i++){
str = rb_ary_entry(obj, i);
- cblistpush(list, RSTRING(str)->ptr, RSTRING(str)->len);
+ cblistpush(list, RSTRING_PTR(str), RSTRING_LEN(str));
}
return list;
}
@@ -1218,14 +1222,14 @@ static CBMAP *objtocbmap(VALUE obj){
int i, len;
map = cbmapopenex(31);
keys = rb_funcall(obj, rb_intern("keys"), 0);
- len = RARRAY(keys)->len;
+ len = RARRAY_LEN(keys);
for(i = 0; i < len; i++){
key = rb_ary_entry(keys, i);
val = rb_hash_aref(obj, key);
key = rb_String(key);
val = rb_String(val);
- cbmapput(map, RSTRING(key)->ptr, RSTRING(key)->len,
- RSTRING(val)->ptr, RSTRING(val)->len, 0);
+ cbmapput(map, RSTRING_PTR(key), RSTRING_LEN(key),
+ RSTRING_PTR(val), RSTRING_LEN(val), 0);
}
return map;
}