chiark / gitweb /
fix up opening and closing
authorian <ian>
Thu, 30 Mar 2006 15:53:38 +0000 (15:53 +0000)
committerian <ian>
Thu, 30 Mar 2006 15:53:38 +0000 (15:53 +0000)
cdb/readonly.c
cdb/writeable.c

index 4cf8e2218b1a38dfb68e31fb49aa72650f910de7..3bfa98bbb68bd3a691894e7b4772973938815a96 100644 (file)
@@ -2,17 +2,25 @@
 
 #include "chiark_tcl_cdb.h"
 
 
 #include "chiark_tcl_cdb.h"
 
-static void destroy_cdb_idtabcb(Tcl_Interp *ip, void *val) { abort(); }
-
-const IdDataSpec cdbtcl_databases= {
-  "cdb-db", "cdb-opendatabases-table", destroy_cdb_idtabcb
-};
-
 typedef struct Ro {
   int ix, fd;
   struct cdb cdb;
 } Ro;
 
 typedef struct Ro {
   int ix, fd;
   struct cdb cdb;
 } Ro;
 
+static void ro_close(Ro *ro) {
+  cdb_free(&ro->cdb);
+  close(ro->fd);
+}
+
+static void destroy_cdb_idtabcb(Tcl_Interp *ip, void *ro_v) {
+  ro_close(ro_v);
+  TFREE(ro_v);
+}
+
+const IdDataSpec cdbtcl_databases= {
+  "cdb-db", "cdb-opendatabases-table", destroy_cdb_idtabcb
+};
+
 int cht_do_cdb_open(ClientData cd, Tcl_Interp *ip,
                    const char *path, void **result) {
   Ro *ro;
 int cht_do_cdb_open(ClientData cd, Tcl_Interp *ip,
                    const char *path, void **result) {
   Ro *ro;
@@ -33,10 +41,9 @@ int cht_do_cdb_open(ClientData cd, Tcl_Interp *ip,
 }
 
 int cht_do_cdb_close(ClientData cd, Tcl_Interp *ip, void *ro_v) {
 }
 
 int cht_do_cdb_close(ClientData cd, Tcl_Interp *ip, void *ro_v) {
-  Ro *ro= ro_v;
-  cdb_free(&ro->cdb);
-  close(ro->fd);
-  TFREE(ro);
+  ro_close(ro_v);
+  cht_tabledataid_disposing(ip, ro_v, &cdbtcl_databases);
+  TFREE(ro_v);
   return TCL_OK;
 }
 
   return TCL_OK;
 }
 
index d5c5c5ba8272c4493aa20f0d4fcd62ad1c9fd165..94a7f76a904fd4f7de81477d34c6f8a2985bd85e 100644 (file)
@@ -168,9 +168,9 @@ static int rw_close(Tcl_Interp *ip, Rw *rw) {
   return rc;
 }
 
   return rc;
 }
 
-static void destroy_cdbrw_idtabcb(Tcl_Interp *ip, void *rw) {
-  rw_close(0,rw);
-  TFREE(rw);
+static void destroy_cdbrw_idtabcb(Tcl_Interp *ip, void *rw_v) {
+  rw_close(0,rw_v);
+  TFREE(rw_v);
 }
 const IdDataSpec cdbtcl_rwdatabases= {
   "cdb-rwdb", "cdb-openrwdatabases-table", destroy_cdbrw_idtabcb
 }
 const IdDataSpec cdbtcl_rwdatabases= {
   "cdb-rwdb", "cdb-openrwdatabases-table", destroy_cdbrw_idtabcb
@@ -746,7 +746,7 @@ int cht_do_cdbwr_close(ClientData cd, Tcl_Interp *ip, void *rw_v) {
   else rc= TCL_OK;
 
   if (!rc) {
   else rc= TCL_OK;
 
   if (!rc) {
-    if (!rw->logfile) {
+    if (rw->logfile) {
       logsz= ftello(rw->logfile);
       if (logsz < 0)
        rc= cht_posixerr(ip, errno, "ftell logfile during close info");
       logsz= ftello(rw->logfile);
       if (logsz < 0)
        rc= cht_posixerr(ip, errno, "ftell logfile during close info");
@@ -754,7 +754,8 @@ int cht_do_cdbwr_close(ClientData cd, Tcl_Interp *ip, void *rw_v) {
        rc= infocb(ip, rw, "close", "main=%luby log=%luby",
                   rw->mainsz, logsz);
     } else if (reccount>=0) {
        rc= infocb(ip, rw, "close", "main=%luby log=%luby",
                   rw->mainsz, logsz);
     } else if (reccount>=0) {
-      rc= infocb(ip, rw, "close", "main=%luby nrecs=%l", rw->mainsz, reccount);
+      rc= infocb(ip, rw, "close", "main=%luby nrecs=%ld",
+                rw->mainsz, reccount);
     } else {
       rc= infocb(ip, rw, "close", "main=%luby", rw->mainsz);
     }
     } else {
       rc= infocb(ip, rw, "close", "main=%luby", rw->mainsz);
     }