Added test cases related to database operations#11
Open
wu-zhao-min wants to merge 1 commit into
Open
Conversation
gburd
requested changes
Jun 16, 2026
gburd
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the contribution, and for thinking about boundary/cursor/stat coverage — that kind of testing is welcome.
Unfortunately I can't merge this as-is: it won't compile. test/c/test_db185.c exercises the DB 1.85 compatibility API (it #includes db_185.h and dbp is the 1.85 DB). That handle is defined in src/dbinc/db_185.in and has only these methods:
typedef struct __db {
DBTYPE type;
int (*close)(struct __db *);
int (*del)(const struct __db *, const DBT *, u_int);
int (*get)(const struct __db *, const DBT *, DBT *, u_int);
int (*put)(const struct __db *, DBT *, const DBT *, u_int);
int (*seq)(const struct __db *, DBT *, DBT *, u_int);
int (*sync)(const struct __db *, u_int);
void *internal;
int (*fd)(const struct __db *);
} DB;So the new code can't build here:
dbp->cursor(...)anddbp->stat(...)— no such members on the 1.85DB.cursor->c_get/c_put/c_close(DBC), and constantsDB_NEXT,DB_SET,DB_KEYFIRST,DB_NOTFOUND,DB_BTREE_STAT/DB_HASH_STAT/DB_RECNO_STAT— these are the modern API, not indb_185.h(the 1.85 API iterates withseq()+R_NEXT/R_FIRSTand has no cursors or stat).
A couple of other issues to flag regardless:
char large_key[1024*1024]is a 1 MB stack array (stack overflow risk).- In
test_db_cursor,sprintf((char *)key.data, ...)writes into the buffer returned byc_get, which is owned by Berkeley DB — that's a write into library-owned memory.
Two good ways forward:
- Best: add these cursor/stat/boundary tests against the modern API — e.g. a new
test/c/program (or extend one that usesdb.h/DB_ENV), whereDB->cursor,DBC->get, andDB->statexist. That's where this coverage belongs. - If you specifically want to extend the 1.85 path, use only
get/put/del/seq/syncwith theR_*flags, and keep buffers caller-owned.
Happy to review a revised version. Closing for changes, not merging.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added the processing of boundary conditions for the new database, the complete operation process of cursors, and the test cases for database statistics information.