And finally at six feet, the old cursor api is officially dead
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 20 Apr 2011 12:38:40 +0000 (15:38 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 20 Apr 2011 12:46:36 +0000 (15:46 +0300)
- Inline the last remains into the new api, handling NULL pointers
  more gracefully than the old version

lib/backend/db3.c

index 44c06ac..5b6a826 100644 (file)
@@ -233,64 +233,45 @@ int dbiSync(dbiIndex dbi, unsigned int flags)
     return rc;
 }
 
-static int dbiCclose(dbiIndex dbi, DBC * dbcursor,
-               unsigned int flags)
-{
-    int rc = -2;
-
-    /* XXX dbiCopen error pathways come through here. */
-    if (dbcursor != NULL) {
-       rc = dbcursor->c_close(dbcursor);
-       rc = cvtdberr(dbi, "dbcursor->c_close", rc, _debug);
-    }
-    return rc;
-}
-
-static int dbiCopen(dbiIndex dbi, DBC ** dbcp, unsigned int dbiflags)
-{
-    DB * db = dbi->dbi_db;
-    DBC * dbcursor = NULL;
-    int flags;
-    int rc;
-    uint32_t eflags = db_envflags(db);
-    
-   /* XXX DB_WRITECURSOR cannot be used with sunrpc dbenv. */
-    assert(db != NULL);
-    if ((dbiflags & DB_WRITECURSOR) &&
-       (eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
-    {
-       flags = DB_WRITECURSOR;
-    } else
-       flags = 0;
-
-    rc = db->cursor(db, NULL, &dbcursor, flags);
-    rc = cvtdberr(dbi, "db->cursor", rc, _debug);
-
-    if (dbcp)
-       *dbcp = dbcursor;
-    else
-       (void) dbiCclose(dbi, dbcursor, 0);
-
-    return rc;
-}
-
 dbiCursor dbiCursorInit(dbiIndex dbi, unsigned int flags)
 {
     dbiCursor dbc = NULL;
-    DBC * cursor = NULL;
+    
+    if (dbi && dbi->dbi_db) {
+       DB * db = dbi->dbi_db;
+       DBC * cursor;
+       int cflags;
+       int rc;
+       uint32_t eflags = db_envflags(db);
+       
+       /* DB_WRITECURSOR requires CDB and writable db */
+       if ((flags & DB_WRITECURSOR) &&
+           (eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
+       {
+           cflags = DB_WRITECURSOR;
+       } else
+           cflags = 0;
 
-    if (dbi && dbiCopen(dbi, &cursor, flags) == 0) {
-       dbc = xcalloc(1, sizeof(*dbc));
-       dbc->cursor = cursor;
-       dbc->dbi = dbi;
+       rc = db->cursor(db, NULL, &cursor, cflags);
+       rc = cvtdberr(dbi, "db->cursor", rc, _debug);
+
+       if (rc == 0) {
+           dbc = xcalloc(1, sizeof(*dbc));
+           dbc->cursor = cursor;
+           dbc->dbi = dbi;
+       }
     }
+
     return dbc;
 }
 
 dbiCursor dbiCursorFree(dbiCursor dbc)
 {
     if (dbc) {
-       dbiCclose(dbc->dbi, dbc->cursor, 0);
+       DBC * cursor = dbc->cursor;
+       int rc = cursor->c_close(cursor);
+       cvtdberr(dbc->dbi, "dbcursor->c_close", rc, _debug);
+       free(dbc);
     }
     return NULL;
 }