improve warning in associate callback function

This commit is contained in:
Justin Balthrop 2009-08-27 17:49:32 -07:00
parent 9e2b2e2abb
commit 865bf435f6

View file

@ -1102,17 +1102,23 @@ void assoc_key(DBT* result, VALUE obj) {
result->flags=LMEMFLAG; result->flags=LMEMFLAG;
} }
VALUE VALUE assoc_call(VALUE *args)
assoc_callback2(VALUE *args)
{ {
return rb_funcall(args[0],fv_call,3,args[1],args[2],args[3]); return rb_funcall(args[0],fv_call,3,args[1],args[2],args[3]);
} }
VALUE assoc_rescue(VALUE *error, VALUE e)
{
VALUE message = StringValue(e);
rb_warn(RSTRING_PTR(message));
*error = e;
}
int assoc_callback(DB *secdb, const DBT* key, const DBT* data, DBT* result) int assoc_callback(DB *secdb, const DBT* key, const DBT* data, DBT* result)
{ {
t_dbh *dbh; t_dbh *dbh;
VALUE proc; VALUE proc;
int status; VALUE error = Qnil;
VALUE retv; VALUE retv;
VALUE args[4]; VALUE args[4];
VALUE keys; VALUE keys;
@ -1130,10 +1136,10 @@ int assoc_callback(DB *secdb, const DBT* key, const DBT* data, DBT* result)
fprintf(stderr,"assoc_data %*s", data->size, data->data); fprintf(stderr,"assoc_data %*s", data->size, data->data);
#endif #endif
retv=rb_protect((VALUE(*)_((VALUE)))assoc_callback2,(VALUE)args,&status); retv=rb_rescue((VALUE(*)_((VALUE)))assoc_call,(VALUE)args,(VALUE(*)_((VALUE)))assoc_rescue,(VALUE)&error);
if (status) return 99999; if (!NIL_P(error)) return 99999;
if ( NIL_P(retv) ) if (NIL_P(retv))
return DB_DONOTINDEX; return DB_DONOTINDEX;
keys = rb_check_array_type(retv); keys = rb_check_array_type(retv);