Multiple changes.

- Raise an error if invalid options are passed to the constructor.
- Bugfix: Ensure drop() only removes the specified collection.
- Fix initializer double memory allocation.
- Fix key/data object allocation: make garbage collection safe.
- Move common macros to the global header file.

FossilOrigin-Name: 98d3016bd25921dead39d9c5474712766b56519d575bc8cd960932b3fbc16b69
This commit is contained in:
Mahlon E. Smith 2021-06-28 23:39:46 +00:00
parent b7e515d51e
commit e9b476a4d7
10 changed files with 605 additions and 517 deletions

View file

@ -4,12 +4,23 @@
#include "mdbx.h"
#ifndef MDBX_EXT_0_9_3
#define MDBX_EXT_0_9_3
#ifndef RBMDBX_EXT
#define RBMDBX_EXT
#define RMDBX_TXN_ROLLBACK 0
#define RMDBX_TXN_COMMIT 1
/* Shortcut for fetching wrapped data structure.
*/
#define UNWRAP_DB( self, db ) \
rmdbx_db_t *db; \
TypedData_Get_Struct( self, rmdbx_db_t, &rmdbx_db_data, db )
/* Raise if current DB is not open. */
#define CHECK_HANDLE() \
if ( ! db->state.open ) rb_raise( rmdbx_eDatabaseError, "Closed database." )
/*
* A struct encapsulating an instance's DB
* state and settings.
@ -21,7 +32,8 @@ struct rmdbx_db {
MDBX_cursor *cursor;
struct {
int env_flags;
unsigned int env_flags;
unsigned int db_flags;
int mode;
int open;
int max_collections;
@ -40,12 +52,11 @@ struct rmdbx_db {
typedef struct rmdbx_db rmdbx_db_t;
static const rb_data_type_t rmdbx_db_data;
extern void rmdbx_free( void *db ); /* forward declaration for the allocator */
/* ------------------------------------------------------------
* Globals
* ------------------------------------------------------------ */
extern VALUE rmdbx_mMDBX;
extern VALUE rmdbx_cDatabase;
extern VALUE rmdbx_eDatabaseError;
@ -55,13 +66,15 @@ extern VALUE rmdbx_eRollback;
/* ------------------------------------------------------------
* Functions
* ------------------------------------------------------------ */
extern void rmdbx_free( void *db ); /* forward declaration for the allocator */
extern void Init_rmdbx ( void );
extern void rmdbx_init_database ( void );
extern void rmdbx_close_all( rmdbx_db_t* );
extern void rmdbx_open_txn( rmdbx_db_t*, int );
extern void rmdbx_close_txn( rmdbx_db_t*, int );
extern void rmdbx_open_cursor( rmdbx_db_t* );
extern VALUE rmdbx_gather_stats( rmdbx_db_t* );
#endif /* define MDBX_EXT_0_9_3 */
#endif /* define RBMDBX_EXT */