improve warning in associate callback function
This commit is contained in:
parent
9e2b2e2abb
commit
865bf435f6
24
ext/bdb.c
24
ext/bdb.c
|
@ -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,15 +1136,15 @@ 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);
|
||||||
if (!NIL_P(keys)) {
|
if (!NIL_P(keys)) {
|
||||||
keys = rb_funcall(keys,fv_uniq,0); /* secondary keys must be uniq */
|
keys = rb_funcall(keys,fv_uniq,0); /* secondary keys must be uniq */
|
||||||
switch(RARRAY(keys)->len) {
|
switch(RARRAY(keys)->len) {
|
||||||
case 0:
|
case 0:
|
||||||
return DB_DONOTINDEX;
|
return DB_DONOTINDEX;
|
||||||
|
@ -1152,7 +1158,7 @@ int assoc_callback(DB *secdb, const DBT* key, const DBT* data, DBT* result)
|
||||||
memset(result->data,0,result->size * sizeof(DBT));
|
memset(result->data,0,result->size * sizeof(DBT));
|
||||||
|
|
||||||
for (i=0; i<result->size; i++) {
|
for (i=0; i<result->size; i++) {
|
||||||
assoc_key(result->data + i*sizeof(DBT), (VALUE)RARRAY(keys)->ptr[i]);
|
assoc_key(result->data + i*sizeof(DBT), (VALUE)RARRAY(keys)->ptr[i]);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue