Skip to content

Commit

Permalink
Bump headers via make update_duckdb_headers, to add back ENTRYPOINT…
Browse files Browse the repository at this point in the history
…_VISIBILITY
  • Loading branch information
carlopi committed Jan 9, 2025
1 parent 8fe9b2b commit b332f18
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
53 changes: 45 additions & 8 deletions duckdb_capi/duckdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ typedef struct {
void *internal_data;
} duckdb_result;

//! A database object. Should be closed with `duckdb_close`.
//! A database instance cache object. Must be destroyed with `duckdb_destroy_instance_cache`.
typedef struct _duckdb_instance_cache {
void *internal_ptr;
} * duckdb_instance_cache;

//! A database object. Must be closed with `duckdb_close`.
typedef struct _duckdb_database {
void *internal_ptr;
} * duckdb_database;
Expand Down Expand Up @@ -680,26 +685,58 @@ struct duckdb_extension_access {
// Open Connect
//===--------------------------------------------------------------------===//

/*!
Creates a new database instance cache.
The instance cache is necessary if a client/program (re)opens multiple databases to the same file within the same
process. Must be destroyed with 'duckdb_destroy_instance_cache'.
* @return The database instance cache.
*/
DUCKDB_API duckdb_instance_cache duckdb_create_instance_cache();

/*!
Creates a new database instance in the instance cache, or retrieves an existing database instance.
Must be closed with 'duckdb_close'.
* @param instance_cache The instance cache in which to create the database, or from which to take the database.
* @param path Path to the database file on disk. Both `nullptr` and `:memory:` open or retrieve an in-memory database.
* @param out_database The resulting cached database.
* @param config (Optional) configuration used to create the database.
* @param out_error If set and the function returns `DuckDBError`, this contains the error message.
Note that the error message must be freed using `duckdb_free`.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_get_or_create_from_cache(duckdb_instance_cache instance_cache, const char *path,
duckdb_database *out_database, duckdb_config config,
char **out_error);

/*!
Destroys an existing database instance cache and de-allocates its memory.
* @param instance_cache The instance cache to destroy.
*/
DUCKDB_API void duckdb_destroy_instance_cache(duckdb_instance_cache *instance_cache);

/*!
Creates a new database or opens an existing database file stored at the given path.
If no path is given a new in-memory database is created instead.
The instantiated database should be closed with 'duckdb_close'.
The database must be closed with 'duckdb_close'.
* @param path Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* @param path Path to the database file on disk. Both `nullptr` and `:memory:` open an in-memory database.
* @param out_database The result database object.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_open(const char *path, duckdb_database *out_database);

/*!
Extended version of duckdb_open. Creates a new database or opens an existing database file stored at the given path.
The instantiated database should be closed with 'duckdb_close'.
The database must be closed with 'duckdb_close'.
* @param path Path to the database file on disk, or `nullptr` or `:memory:` to open an in-memory database.
* @param path Path to the database file on disk. Both `nullptr` and `:memory:` open an in-memory database.
* @param out_database The result database object.
* @param config (Optional) configuration used to start up the database system.
* @param out_error If set and the function returns DuckDBError, this will contain the reason why the start-up failed.
Note that the error must be freed using `duckdb_free`.
* @param config (Optional) configuration used to start up the database.
* @param out_error If set and the function returns `DuckDBError`, this contains the error message.
Note that the error message must be freed using `duckdb_free`.
* @return `DuckDBSuccess` on success or `DuckDBError` on failure.
*/
DUCKDB_API duckdb_state duckdb_open_ext(const char *path, duckdb_database *out_database, duckdb_config config,
Expand Down
24 changes: 22 additions & 2 deletions duckdb_capi/duckdb_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ typedef struct {
duckdb_data_chunk (*duckdb_stream_fetch_chunk)(duckdb_result result);
#endif

// Exposing the instance cache
#ifdef DUCKDB_EXTENSION_API_VERSION_UNSTABLE
duckdb_instance_cache (*duckdb_create_instance_cache)();
duckdb_state (*duckdb_get_or_create_from_cache)(duckdb_instance_cache instance_cache, const char *path,
duckdb_database *out_database, duckdb_config config,
char **out_error);
void (*duckdb_destroy_instance_cache)(duckdb_instance_cache *instance_cache);
#endif

// New append functions that are added
#ifdef DUCKDB_EXTENSION_API_VERSION_UNSTABLE
duckdb_state (*duckdb_append_default_to_chunk)(duckdb_appender appender, duckdb_data_chunk chunk, idx_t col,
Expand Down Expand Up @@ -947,6 +956,11 @@ typedef struct {
#define duckdb_arrow_array_scan duckdb_ext_api.duckdb_arrow_array_scan
#define duckdb_stream_fetch_chunk duckdb_ext_api.duckdb_stream_fetch_chunk

// Version unstable_instance_cache
#define duckdb_create_instance_cache duckdb_ext_api.duckdb_create_instance_cache
#define duckdb_get_or_create_from_cache duckdb_ext_api.duckdb_get_or_create_from_cache
#define duckdb_destroy_instance_cache duckdb_ext_api.duckdb_destroy_instance_cache

// Version unstable_new_append_functions
#define duckdb_append_default_to_chunk duckdb_ext_api.duckdb_append_default_to_chunk

Expand All @@ -966,6 +980,12 @@ typedef struct {
// Place in global scope of any C/C++ file that needs to access the extension API
#define DUCKDB_EXTENSION_EXTERN extern duckdb_ext_api_v1 duckdb_ext_api;

#ifdef _WIN32
#define DUCKDB_CAPI_ENTRY_VISIBILITY __declspec(dllexport)
#else
#define DUCKDB_CAPI_ENTRY_VISIBILITY __attribute__((visibility("default")))
#endif

//===--------------------------------------------------------------------===//
// Entrypoint Macros
//===--------------------------------------------------------------------===//
Expand All @@ -979,7 +999,7 @@ typedef struct {
#define DUCKDB_EXTENSION_ENTRYPOINT \
DUCKDB_EXTENSION_GLOBAL static bool DUCKDB_EXTENSION_GLUE(DUCKDB_EXTENSION_NAME, _init_c_api_internal)( \
duckdb_connection connection, duckdb_extension_info info, struct duckdb_extension_access * access); \
DUCKDB_EXTENSION_EXTERN_C_GUARD_OPEN DUCKDB_EXTENSION_API bool DUCKDB_EXTENSION_GLUE( \
DUCKDB_EXTENSION_EXTERN_C_GUARD_OPEN DUCKDB_CAPI_ENTRY_VISIBILITY DUCKDB_EXTENSION_API bool DUCKDB_EXTENSION_GLUE( \
DUCKDB_EXTENSION_NAME, _init_c_api)(duckdb_extension_info info, struct duckdb_extension_access * access) { \
DUCKDB_EXTENSION_API_INIT(info, access, DUCKDB_EXTENSION_API_VERSION_STRING); \
duckdb_database *db = access->get_database(info); \
Expand All @@ -998,7 +1018,7 @@ typedef struct {
#define DUCKDB_EXTENSION_ENTRYPOINT_CUSTOM \
DUCKDB_EXTENSION_GLOBAL static bool DUCKDB_EXTENSION_GLUE(DUCKDB_EXTENSION_NAME, _init_c_api_internal)( \
duckdb_extension_info info, struct duckdb_extension_access * access); \
DUCKDB_EXTENSION_EXTERN_C_GUARD_OPEN DUCKDB_EXTENSION_API bool DUCKDB_EXTENSION_GLUE( \
DUCKDB_EXTENSION_EXTERN_C_GUARD_OPEN DUCKDB_CAPI_ENTRY_VISIBILITY DUCKDB_EXTENSION_API bool DUCKDB_EXTENSION_GLUE( \
DUCKDB_EXTENSION_NAME, _init_c_api)(duckdb_extension_info info, struct duckdb_extension_access * access) { \
DUCKDB_EXTENSION_API_INIT(info, access, DUCKDB_EXTENSION_API_VERSION_STRING); \
return DUCKDB_EXTENSION_GLUE(DUCKDB_EXTENSION_NAME, _init_c_api_internal)(info, access); \
Expand Down

0 comments on commit b332f18

Please sign in to comment.