<commit_before>#include <tokyo_tyrant_db.h>

static VALUE cDB_put_method(VALUE vself, VALUE vkey, VALUE vstr, int method){
  int ecode;
  bool res;
  TCRDB *db;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  vkey = StringValueEx(vkey);
  vstr = StringValueEx(vstr);

  switch(method){
    case TTPUT:
      res = tcrdbput2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    case TTPUTKEEP:
      res = tcrdbputkeep2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    case TTPUTCAT:
      res = tcrdbputcat2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    case TTPUTNR:
      res = tcrdbputnr2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    default:
      res = false;
      break;
  }

  if(!res){
    ecode = tcrdbecode(db);
    rb_raise(eTokyoTyrantError, "put error: %s", tcrdberrmsg(ecode));
  }

  return Qtrue;  
}

static VALUE cDB_put(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUT);
}

static VALUE cDB_mput(VALUE vself, VALUE vhash){
  VALUE vary;
  TCRDB *db;
  TCLIST *list, *args;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  args = vhashtolist(vhash);
  list = tcrdbmisc(db, "putlist", 0, args);
  vary = listtovary(list);
  tclistdel(list);
  return vary;
}

static VALUE cDB_putkeep(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUTKEEP);  
}

static VALUE cDB_putcat(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUTCAT);
}

static VALUE cDB_putnr(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUTNR);
}

static VALUE cDB_putshl(VALUE vself, VALUE vkey, VALUE vstr, VALUE vwidth){
  int ecode;
  TCRDB *db;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  vkey = StringValueEx(vkey);
  vstr = StringValueEx(vstr);

  if(!tcrdbputshl2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr), FIXNUM_P(vwidth))){
    ecode = tcrdbecode(db);
    rb_raise(eTokyoTyrantError, "put error: %s", tcrdberrmsg(ecode));
  }

  return Qtrue;
}<commit_msg>fix another memory leak<commit_after>#include <tokyo_tyrant_db.h>

static VALUE cDB_put_method(VALUE vself, VALUE vkey, VALUE vstr, int method){
  int ecode;
  bool res;
  TCRDB *db;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  vkey = StringValueEx(vkey);
  vstr = StringValueEx(vstr);

  switch(method){
    case TTPUT:
      res = tcrdbput2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    case TTPUTKEEP:
      res = tcrdbputkeep2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    case TTPUTCAT:
      res = tcrdbputcat2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    case TTPUTNR:
      res = tcrdbputnr2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr));
      break;
    default:
      res = false;
      break;
  }

  if(!res){
    ecode = tcrdbecode(db);
    rb_raise(eTokyoTyrantError, "put error: %s", tcrdberrmsg(ecode));
  }

  return Qtrue;  
}

static VALUE cDB_put(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUT);
}

static VALUE cDB_mput(VALUE vself, VALUE vhash){
  VALUE vary;
  TCRDB *db;
  TCLIST *list, *args;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  args = vhashtolist(vhash);
  list = tcrdbmisc(db, "putlist", 0, args);
  vary = listtovary(list);
  tclistdel(args);
  tclistdel(list);
  return vary;
}

static VALUE cDB_putkeep(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUTKEEP);  
}

static VALUE cDB_putcat(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUTCAT);
}

static VALUE cDB_putnr(VALUE vself, VALUE vkey, VALUE vstr){
  return cDB_put_method(vself, vkey, vstr, TTPUTNR);
}

static VALUE cDB_putshl(VALUE vself, VALUE vkey, VALUE vstr, VALUE vwidth){
  int ecode;
  TCRDB *db;
  Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);

  vkey = StringValueEx(vkey);
  vstr = StringValueEx(vstr);

  if(!tcrdbputshl2(db, RSTRING_PTR(vkey), RSTRING_PTR(vstr), FIXNUM_P(vwidth))){
    ecode = tcrdbecode(db);
    rb_raise(eTokyoTyrantError, "put error: %s", tcrdberrmsg(ecode));
  }

  return Qtrue;
}
{'fraction_non_alphanumeric': 0.12365975696926376, 'fraction_numerical': 0.0028591851322373124, 'mean_word_length': 4.361430395913154, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2446584', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1797, 'n_words': 374}