3 #include "chiark_tcl_cdb.h"
8 /*---------- Forward declarations ----------*/
12 /*---------- Useful routines ----------*/
14 static void maybe_close(int fd) {
19 rc= cht_posixerr(ip, errno, "failed to " m); goto x_rc; \
22 /*==================== Subsystems and subtypes ====================*/
24 /*---------- Pathbuf ----------*/
26 typedef struct Pathbuf {
32 static void pathbuf_init(Pathbuf *pb, const char *pathb) {
34 pb->buf= TALLOC(l + 4);
35 memcpy(pb->buf, pathb, l);
39 static const char *pathbuf_sfx(Pathbuf *pb, const char *suffix) {
40 assert(strlen(suffix) <= MAX_SUFFIX);
41 strcpy(pb->sfx, suffix);
44 static void pathbuf_free(Pathbuf *pb) {
49 /*---------- Our hash table ----------*/
51 typedef struct HashTable {
53 Byte padding[128]; /* allow for expansion by Tcl, urgh */
57 typedef struct HashValue {
62 static HashValue *htv_prep(int len) {
64 hd= TALLOC((hd->data - (Byte*)hd) + len);
68 static Byte *htv_fillptr(HashValue *hd) {
72 static void ht_setup(HashTable *ht) {
73 Tcl_InitHashTable(&ht->t, TCL_STRING_KEYS);
75 static void ht_update(HashTable *ht, const char *key, HashValue *val_eat) {
79 he= Tcl_CreateHashEntry(&ht->t, (char*)key, &new);
80 if (!new) TFREE(Tcl_GetHashValue(he));
81 Tcl_SetHashValue(he, val_eat);
82 /* eats the value since the data structure owns the memory */
84 static void ht_maybeupdate(HashTable *ht, const char *key,
86 /* like ht_update except does not overwrite existing values */
90 he= Tcl_CreateHashEntry(&ht->t, (char*)key, &new);
91 if (!new) { TFREE(val_eat); return; }
92 Tcl_SetHashValue(he, val_eat);
95 static const HashValue *ht_lookup(HashTable *ht, const char *key) {
98 he= Tcl_FindHashEntry(&ht->t, key);
101 return Tcl_GetHashValue(he);
104 static int ht_forall(HashTable *ht,
105 int (*fn)(const char *key, HashValue *val,
106 struct ht_forall_ctx *ctx),
107 struct ht_forall_ctx *ctx) {
108 /* Returns first positive value returned by any call to fn, or 0. */
115 for (he= Tcl_FirstHashEntry(&ht->t, &sp);
117 he= Tcl_NextHashEntry(&sp)) {
118 val= Tcl_GetHashValue(he);
119 if (!val->len) continue;
121 key= Tcl_GetHashKey(&ht->t, he);
123 r= fn(key, val, ctx);
129 static void ht_destroy(HashTable *ht) {
133 for (he= Tcl_FirstHashEntry(&ht->t, &sp);
135 he= Tcl_NextHashEntry(&sp)) {
136 /* ht_forall skips empty (deleted) entries so is no good for this */
137 TFREE(Tcl_GetHashValue(he));
139 Tcl_DeleteHashTable(&ht->t);
142 /*==================== Existential ====================*/
144 /*---------- Rw data structure ----------*/
149 struct cdb cdb; /* valid iff cdb_fd >= 0 */
152 Pathbuf pbsome, pbother;
154 ScriptToInvoke on_info, on_lexminval;
157 static int rw_close(Tcl_Interp *ip, Rw *rw) {
161 ht_destroy(&rw->logincore);
162 if (rw->cdb_fd >= 0) cdb_free(&rw->cdb);
163 maybe_close(rw->cdb_fd);
164 maybe_close(rw->lock_fd);
167 r= fclose(rw->logfile);
168 if (r && ip) { rc= cht_posixerr(ip, errno, "probable data loss! failed to"
169 " fclose logfile during untidy close"); }
172 pathbuf_free(&rw->pbsome); pathbuf_free(&rw->pbother);
177 static void destroy_cdbrw_idtabcb(Tcl_Interp *ip, void *rw) { rw_close(0,rw); }
178 const IdDataSpec cdbtcl_rwdatabases= {
179 "cdb-rwdb", "cdb-openrwdatabases-table", destroy_cdbrw_idtabcb
182 /*---------- File handling ----------*/
184 static int acquire_lock(Tcl_Interp *ip, Pathbuf *pb, int *lockfd_r) {
185 /* *lockfd_r must be -1 on entry. If may be set to >=0 even
186 * on error, and must be closed by the caller. */
191 um= umask(~(mode_t)0);
194 lockmode= 0666 & ~((um & 0444)>>1);
195 /* Remove r where umask would remove w;
196 * eg umask intending 0664 here gives 0660 */
198 *lockfd_r= open(pathbuf_sfx(pb,".lock"), O_RDONLY|O_CREAT, lockmode);
200 return cht_posixerr(ip, errno, "could not open/create lockfile");
203 fl.l_whence= SEEK_SET;
208 r= fcntl(*lockfd_r, F_SETLK, &fl);
210 if (errno == EACCES || errno == EAGAIN)
211 return cht_staticerr(ip, "lock held by another process", "CDB LOCKED");
212 else return cht_posixerr(ip, errno, "unexpected error from fcntl while"
219 /*---------- Log reading and writing ----------*/
221 static int readlognum(FILE *f, int delim, int *num_r) {
223 char numbuf[20], *p, *ep;
228 c= getc(f); if (c==EOF) return -2;
229 if (c == delim) break;
230 if (!isdigit((unsigned char)c)) return -2;
232 if (p == numbuf+sizeof(numbuf)) return -2;
234 if (p == numbuf) return -2;
237 errno=0; ul= strtoul(numbuf, &ep, 10);
238 if (*ep || errno || ul >= INT_MAX/2) return -2;
243 static int readstorelogrecord(FILE *f, HashTable *ht,
244 int (*omitfn)(const HashValue*,
245 struct ht_forall_ctx *ctx),
246 struct ht_forall_ctx *ctx,
247 void (*updatefn)(HashTable*, const char*,
252 * -2 corrupt or error
253 * -3 got newline indicating end
254 * >0 value from omitfn
262 if (c==EOF) { if (feof(f)) return -1; return -2; }
263 if (c=='\n') return -3;
264 if (c!='+') return -2;
266 rc= readlognum(f, ',', &keylen); if (rc) return rc;
267 rc= readlognum(f, ':', &vallen); if (rc) return rc;
269 key= TALLOC(keylen+1);
270 val= htv_prep(vallen);
272 r= fread(key, 1,keylen, f);
273 if (r!=keylen) goto x2_free_keyval;
274 if (memchr(key,0,keylen)) goto x2_free_keyval;
277 c= getc(f); if (c!='-') goto x2_free_keyval;
278 c= getc(f); if (c!='>') goto x2_free_keyval;
280 r= fread(htv_fillptr(val), 1,vallen, f);
281 if (r!=vallen) goto x2_free_keyval;
283 rc= omitfn ? omitfn(val, ctx) : TCL_OK;
284 if (rc) { assert(rc>0); TFREE(val); }
285 else updatefn(ht, key, val);
296 static int writerecord(FILE *f, const char *key, const HashValue *val) {
299 r= fprintf(f, "+%d,%d:%s->", strlen(key), val->len, key);
302 r= fwrite(val->data, 1, val->len, f);
303 if (r != val->len) return -1;
308 /*---------- Creating ----------*/
310 int cht_do_cdbwr_create_empty(ClientData cd, Tcl_Interp *ip,
312 static const char *const toremoves[]= {
313 ".main", ".cdb", ".log", ".tmp", 0
317 int lock_fd=-1, fd=-1, rc, r;
318 const char *const *toremove;
320 pathbuf_init(&pb, pathb);
321 rc= acquire_lock(ip, &pb, &lock_fd); if (rc) goto x_rc;
323 fd= open(pathbuf_sfx(&pb, ".main"), O_RDWR|O_CREAT|O_EXCL, 0666);
324 if (fd <= 0) PE("create new database file");
326 for (toremove=toremoves; *toremove; toremove++) {
327 r= remove(*toremove);
328 if (r && errno != ENOENT)
329 PE("delete possible spurious file during creation");
336 maybe_close(lock_fd);
341 /*---------- Info callbacks ----------*/
343 static int infocbv3(Tcl_Interp *ip, Rw *rw, const char *arg1,
344 const char *arg2fmt, const char *arg3, va_list al) {
348 vsnprintf(buf, sizeof(buf), arg2fmt, al);
351 aa[na++]= cht_ret_string(ip, arg1);
352 aa[na++]= cht_ret_string(ip, buf);
353 if (arg3) aa[na++]= cht_ret_string(ip, arg3);
355 return cht_scriptinv_invoke_fg(&rw->on_info, na, aa);
358 static int infocb3(Tcl_Interp *ip, Rw *rw, const char *arg1,
359 const char *arg2fmt, const char *arg3, ...) {
363 rc= infocbv3(ip,rw,arg1,arg2fmt,arg3,al);
368 static int infocb(Tcl_Interp *ip, Rw *rw, const char *arg1,
369 const char *arg2fmt, ...) {
372 va_start(al, arg2fmt);
373 rc= infocbv3(ip,rw,arg1,arg2fmt,0,al);
378 /*---------- Opening ----------*/
380 static int cdbinit(Tcl_Interp *ip, Rw *rw) {
381 /* On entry, cdb_fd >=0 but cdb is _undefined_/
382 * On exit, either cdb_fd<0 or cdb is initialised */
385 r= cdb_init(&rw->cdb, rw->cdb_fd);
387 rc= cht_posixerr(ip, errno, "failed to initialise cdb reader");
388 close(rw->cdb_fd); rw->cdb_fd= -1; return rc;
393 int cht_do_cdbwr_open(ClientData cd, Tcl_Interp *ip, const char *pathb,
394 Tcl_Obj *on_info, Tcl_Obj *on_lexminval,
396 const Cdbwr_SubCommand *subcmd= cd;
397 int r, rc, mainfd=-1;
400 off_t logrecstart, logjunkpos;
402 rw= TALLOC(sizeof(*rw));
403 ht_setup(&rw->logincore);
404 cht_scriptinv_init(&rw->on_info);
405 cht_scriptinv_init(&rw->on_lexminval);
406 rw->cdb_fd= rw->lock_fd= -1; rw->logfile= 0;
407 pathbuf_init(&rw->pbsome, pathb);
408 pathbuf_init(&rw->pbother, pathb);
412 rc= cht_scriptinv_set(&rw->on_lexminval, ip, on_lexminval, 0);
415 rw->on_lexminval.llength= 0;
418 mainfd= open(pathbuf_sfx(&rw->pbsome,".main"), O_RDONLY);
419 if (mainfd<0) PE("open exist3ing database file .main");
420 rc= acquire_lock(ip, &rw->pbsome, &rw->lock_fd); if (rc) goto x_rc;
422 r= fstat(mainfd, &stab); if (r) PE("fstat .main");
423 rw->mainsz= stab.st_size;
425 rw->cdb_fd= open(pathbuf_sfx(&rw->pbsome,".cdb"), O_RDONLY);
426 if (rw->cdb_fd >=0) {
427 rc= cdbinit(ip, rw); if (rc) goto x_rc;
428 } else if (errno == ENOENT) {
430 rc= cht_staticerr(ip, ".cdb does not exist but .main is nonempty -"
431 " .cdb must have been accidentally deleted!",
440 rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".log"), "r+");
442 if (errno != ENOENT) PE("failed to open .log during open");
443 rw->logfile= fopen(rw->pbsome.buf, "w");
444 if (!rw->logfile) PE("create .log during (clean) open");
445 } else { /* rw->logfile */
446 r= fstat(fileno(rw->logfile), &stab);
447 if (r==-1) PE("fstat .log during open");
448 rc= infocb(ip, rw, "open-dirty-start", "log=%luby",
449 (unsigned long)stab.st_size);
453 logrecstart= ftello(rw->logfile);
454 if (logrecstart < 0) PE("ftello .log during (dirty) open");
455 r= readstorelogrecord(rw->logfile, &rw->logincore, 0,0, ht_update);
456 if (ferror(rw->logfile)) {
457 rc= cht_posixerr(ip, errno, "error reading .log during (dirty) open");
462 } else if (r==-2 || r==-3) {
464 logjunkpos= ftello(rw->logfile);
465 if(logjunkpos<0) PE("ftello .log during report of junk in dirty open");
467 snprintf(buf,sizeof(buf), "CDB SYNTAX LOG %lu %lu",
468 (unsigned long)logjunkpos, (unsigned long)logrecstart);
470 if (!(subcmd->flags & RWSCF_OKJUNK)) {
471 Tcl_SetObjErrorCode(ip, Tcl_NewStringObj(buf,-1));
472 snprintf(buf,sizeof(buf),"%lu",(unsigned long)logjunkpos);
474 Tcl_AppendResult(ip, "syntax error (junk) in .log during"
475 " (dirty) open, at file position ", buf, (char*)0);
479 rc= infocb3(ip, rw, "open-dirty-junk", "errorfpos=%luby", buf,
480 (unsigned long)logjunkpos);
483 r= fseeko(rw->logfile, logrecstart, SEEK_SET);
484 if (r) PE("failed to fseeko .log before junk during dirty open");
486 r= ftruncate(fileno(rw->logfile), logrecstart);
487 if (r) PE("ftruncate .log to chop junk during dirty open");
493 /* now log is positioned for appending and everything is read */
505 int cht_do_cdbwr_open_okjunk(ClientData cd, Tcl_Interp *ip, const char *pathb,
506 Tcl_Obj *on_info, Tcl_Obj *on_lexminval,
508 return cht_do_cdbwr_open(cd,ip,pathb,on_info,on_lexminval,result);
511 /*==================== COMPACTION ====================*/
513 struct ht_forall_ctx {
514 struct cdb_make cdbm;
518 const char *lexminval;
521 /*---------- helper functions ----------*/
523 static int expiredp(const HashValue *val, struct ht_forall_ctx *a) {
525 if (!val->len) return 0;
526 l= val->len < a->lexminvall ? val->len : a->lexminvall;
527 r= memcmp(val->data, a->lexminval, l);
530 return val->len < a->lexminvall;
533 static int delete_ifexpired(const char *key, HashValue *val,
534 struct ht_forall_ctx *a) {
535 if (!expiredp(val, a)) return 0;
537 /* we don't actually need to realloc it to free the memory because
538 * this will shortly all be deleted as part of the compaction */
542 static int addto_cdb(const char *key, HashValue *val,
543 struct ht_forall_ctx *a) {
544 return cdb_make_add(&a->cdbm, key, strlen(key), val->data, val->len);
547 static int addto_main(const char *key, HashValue *val,
548 struct ht_forall_ctx *a) {
550 return writerecord(a->mainfile, key, val);
553 /*---------- compact main entrypoint ----------*/
555 static int compact_core(Tcl_Interp *ip, Rw *rw, unsigned long logsz,
557 /* creates new .cdb and .main
559 * leaves .log with old data
560 * leaves cdb fd open onto old db
561 * leaves logincore full of crap
564 int cdbfd, cdbmaking;
565 off_t errpos, newmainsz;
568 struct ht_forall_ctx a;
574 a.reccount= reccount_r;
576 r= fclose(rw->logfile);
577 if (r) { rc= cht_posixerr(ip, errno, "probable data loss! failed to fclose"
578 " logfile during compact"); goto x_rc; }
581 rc= infocb(ip, rw, "compact-start", "log=%luby main=%luby",
582 logsz, (unsigned long)rw->mainsz);
585 if (rw->on_lexminval.llength) {
586 rc= cht_scriptinv_invoke_fg(&rw->on_lexminval, 0,0);
589 res= Tcl_GetObjResult(ip); assert(res);
590 a.lexminval= Tcl_GetStringFromObj(res, &a.lexminvall);
593 /* we rely not calling Tcl_Eval during the actual compaction;
594 * if we did Tcl_Eval then the interp result would be trashed.
596 rc= ht_forall(&rw->logincore, delete_ifexpired, &a);
602 /* merge unsuperseded records from main into hash table */
604 a.mainfile= fopen(pathbuf_sfx(&rw->pbsome,".main"), "r");
605 if (!a.mainfile) PE("failed to open .main for reading during compact");
608 r= readstorelogrecord(a.mainfile, &rw->logincore,
611 if (ferror(a.mainfile)) { rc= cht_posixerr(ip, errno, "error reading"
612 " .main during compact"); goto x_rc;
616 } else if (r==-1 || r==-2) {
617 errpos= ftello(a.mainfile);
618 if (errpos<0) PE("ftello .main during report of syntax error");
619 snprintf(buf,sizeof(buf), "CDB SYNTAX MAIN %lu", (unsigned long)errpos);
620 Tcl_SetObjErrorCode(ip, Tcl_NewStringObj(buf,-1));
621 snprintf(buf,sizeof(buf), "%lu", (unsigned long)errpos);
623 Tcl_AppendResult(ip, "syntax error in .main during"
624 " compact, at file position ", buf, (char*)0);
636 cdbfd= open(pathbuf_sfx(&rw->pbsome,".tmp"), O_WRONLY|O_CREAT|O_TRUNC, 0666);
637 if (cdbfd<0) PE("create .tmp for new cdb during compact");
639 r= cdb_make_start(&a.cdbm, cdbfd);
640 if (r) PE("cdb_make_start during compact");
643 r= ht_forall(&rw->logincore, addto_cdb, &a);
644 if (r) PE("cdb_make_add during compact");
646 r= cdb_make_finish(&a.cdbm);
647 if(r) PE("cdb_make_finish during compact");
650 r= fdatasync(cdbfd); if (r) PE("fdatasync new cdb during compact");
651 r= close(cdbfd); if (r) PE("close new cdb during compact");
654 r= rename(rw->pbsome.buf, pathbuf_sfx(&rw->pbother,".cdb"));
655 if (r) PE("install new .cdb during compact");
657 /* create new main */
659 a.mainfile= fopen(pathbuf_sfx(&rw->pbsome,".tmp"), "w");
660 if (!a.mainfile) PE("create .tmp for new main during compact");
662 r= ht_forall(&rw->logincore, addto_main, &a);
663 if (r) { rc= cht_posixerr(ip, r, "error writing to new .main"
664 " during compact"); goto x_rc; }
666 r= fflush(a.mainfile); if (r) PE("fflush new main during compact");
667 r= fdatasync(fileno(a.mainfile));
668 if (r) PE("fdatasync new main during compact");
670 newmainsz= ftello(a.mainfile);
671 if (newmainsz<0) PE("ftello new main during compact");
673 r= fclose(a.mainfile); if (r) PE("fclose new main during compact");
676 r= rename(rw->pbsome.buf, pathbuf_sfx(&rw->pbother,".main"));
677 if (r) PE("install new .main during compact");
679 rw->mainsz= newmainsz;
683 rc= infocb(ip, rw, "compact-end", "main=%luby nrecs=%l",
684 (unsigned long)rw->mainsz, *a.reccount);
690 if (a.mainfile) fclose(a.mainfile);
691 if (cdbmaking) cdb_make_finish(&a.cdbm);
693 remove(pathbuf_sfx(&rw->pbsome,".tmp")); /* for tidyness */
697 /*---------- Closing ----------*/
699 static int compact_forclose(Tcl_Interp *ip, Rw *rw, long *reccount_r) {
703 logsz= ftello(rw->logfile);
704 if (logsz < 0) PE("ftello logfile (during tidy close)");
706 rc= compact_core(ip, rw, logsz, reccount_r); if (rc) goto x_rc;
708 r= remove(pathbuf_sfx(&rw->pbsome,".log"));
709 if (r) PE("remove .log (during tidy close)");
716 int cht_do_cdbwr_close(ClientData cd, Tcl_Interp *ip, void *rw_v) {
722 if (rw->autocompact) rc= compact_forclose(ip, rw, &reccount);
727 logsz= ftello(rw->logfile);
729 rc= cht_posixerr(ip, errno, "ftell logfile during close info");
731 rc= infocb(ip, rw, "close", "main=%luby log=%luby",
733 } else if (reccount>=0) {
734 rc= infocb(ip, rw, "close", "main=%luby nrecs=%l", rw->mainsz, reccount);
736 rc= infocb(ip, rw, "close", "main=%luby", rw->mainsz);
739 rc_close= rw_close(ip,rw);
740 if (rc_close) rc= rc_close;
742 cht_tabledataid_disposing(ip, rw_v, &cdbtcl_rwdatabases);
746 /*---------- Other compaction-related entrypoints ----------*/
748 static int compact_keepopen(Tcl_Interp *ip, Rw *rw, int force) {
753 logsz= ftello(rw->logfile);
754 if (logsz < 0) return cht_posixerr(ip, errno, "ftell .log"
755 " during compact check or force");
757 if (!force && logsz < rw->mainsz / 10 + 1000) return TCL_OK;
759 rc= compact_core(ip, rw, logsz, &reccount); if (rc) goto x_rc;
761 maybe_close(rw->cdb_fd);
763 ht_destroy(&rw->logincore);
764 ht_setup(&rw->logincore);
766 rw->cdb_fd= open(pathbuf_sfx(&rw->pbsome,".cdb"), O_RDONLY);
767 if (rw->cdb_fd < 0) PE("reopen .cdb after compact");
769 rc= cdbinit(ip, rw); if (rc) goto x_rc;
771 rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".log"), "w");
772 if (!rw->logfile) PE("reopen .log after compact");
774 r= fsync(fileno(rw->logfile)); if (r) PE("fsync .log after compact reopen");
779 /* doom! all updates fail after this (because rw->logfile is 0), and
780 * we may be using a lot more RAM than would be ideal. Program will
781 * have to reopen if it really wants sanity. */
785 int cht_do_cdbwr_compact_force(ClientData cd, Tcl_Interp *ip, void *rw_v) {
786 return compact_keepopen(ip, rw_v, 1);
788 int cht_do_cdbwr_compact_check(ClientData cd, Tcl_Interp *ip, void *rw_v) {
789 return compact_keepopen(ip, rw_v, 0);
792 int cht_do_cdbwr_compact_explicit(ClientData cd, Tcl_Interp *ip, void *rw_v) {
797 int cht_do_cdbwr_compact_auto(ClientData cd, Tcl_Interp *ip, void *rw_v) {
803 /*---------- Updateing ----------*/
805 static int update(Tcl_Interp *ip, Rw *rw, const char *key,
806 const Byte *data, int dlen) {
810 if (!rw->logfile) return cht_staticerr
811 (ip, "previous compact failed; cdbwr must be closed and reopened "
812 "before any further updates", "CDB BROKEN");
814 val= htv_prep(dlen); assert(val);
815 memcpy(htv_fillptr(val), data, dlen);
817 r= writerecord(rw->logfile, key, val);
818 if (!r) r= fflush(rw->logfile);
819 if (r) PE("write update to logfile");
821 ht_update(&rw->logincore, key, val);
822 return compact_keepopen(ip, rw, 0);
829 int cht_do_cdbwr_update(ClientData cd, Tcl_Interp *ip,
830 void *rw_v, const char *key, Tcl_Obj *value) {
833 data= Tcl_GetStringFromObj(value, &dlen); assert(data);
834 return update(ip, rw_v, key, data, dlen);
837 int cht_do_cdbwr_update_hb(ClientData cd, Tcl_Interp *ip,
838 void *rw_v, const char *key, HBytes_Value value) {
839 return update(ip, rw_v, key, cht_hb_data(&value), cht_hb_len(&value));
842 int cht_do_cdbwr_delete(ClientData cd, Tcl_Interp *ip, void *rw_v,
844 return update(ip, rw_v, key, 0, 0);
847 /*---------- Lookups ----------*/
849 static int lookup_rw(Tcl_Interp *ip, void *rw_v, const char *key,
850 const Byte **data_r, int *len_r /* -1 => notfound */) {
852 const HashValue *val;
855 val= ht_lookup(&rw->logincore, key);
857 if (val->len) { *data_r= val->data; *len_r= val->len; return TCL_OK; }
858 else { *data_r= 0; *len_r= -1; return TCL_OK; }
861 r= cdb_find(&rw->cdb, key, strlen(key));
862 if (!r) { *data_r= 0; *len_r= -1; return TCL_OK; }
863 if (r<0) return cht_posixerr(ip, errno, "cdb_find failed");
865 *len_r= cdb_datalen(&rw->cdb);
867 *data_r= cdb_getdata(&rw->cdb);
868 if (!*data_r) return cht_posixerr(ip, errno, "cdb_getdata failed");
872 int cht_do_cdbwr_lookup(ClientData cd, Tcl_Interp *ip, void *rw_v,
873 const char *key, Tcl_Obj *def,
875 return cht_cdb_dosomelookup(ip, rw_v, key, def, result,
876 lookup_rw, cht_cdb_storeanswer_string);
879 int cht_do_cdbwr_lookup_hb(ClientData cd, Tcl_Interp *ip, void *rw_v,
880 const char *key, Tcl_Obj *def,
882 return cht_cdb_dosomelookup(ip, rw_v, key, def, result,
883 lookup_rw, cht_cdb_storeanswer_hb);