123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include "store.h"
- #define ENTRY(a, b) case LSUP_STORE_##a: return &b;
- static inline const LSUP_StoreInt *
- select_interface (LSUP_StoreType be) {
- switch (be) {
- BACKEND_TBL
- default: return NULL;
- }
- }
- #undef ENTRY
- const LSUP_StoreInt *
- LSUP_store_int (LSUP_StoreType type) {
- switch (type) {
- #define ENTRY(a, b) \
- case LSUP_STORE_##a: return &b;
- BACKEND_TBL
- #undef ENTRY
- default: return NULL;
- }
- }
- LSUP_Store *
- LSUP_store_new (
- const LSUP_StoreType store_type, const char *store_id, size_t size)
- {
- if (UNLIKELY (!LSUP_IS_INIT)) {
- log_error (
- "Environment is not initialized. Did you call LSUP_init()?");
- return NULL;
- }
- const LSUP_StoreInt *sif = select_interface (store_type);
- if (UNLIKELY (!sif)) {
- log_error ("Not a valid store type: %d", store_type);
- return NULL;
- }
- LSUP_Store *store;
- MALLOC_GUARD (store, NULL);
- store->type = store_type;
- store->sif = sif;
- store->id = store_id ? strdup (store_id) : NULL;
- // TODO implement custom default context.
- store->data = store->sif->new_fn (store_id, size);
- return store;
- }
- void
- LSUP_store_free (LSUP_Store *store)
- {
- store->sif->free_fn (store->data);
- free (store);
- }
|