From ac87b06b023827e2fa79ac7de3127e44f32822ca Mon Sep 17 00:00:00 2001 From: Alex Garcia Date: Fri, 9 Aug 2024 10:44:39 -0700 Subject: [PATCH] Add SQLITE_VEC_STATIC option, prefix json function --- sqlite-vec.c | 29 +++++++++-------------------- sqlite-vec.h.tmpl | 10 ++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/sqlite-vec.c b/sqlite-vec.c index d5120b7..addf191 100644 --- a/sqlite-vec.c +++ b/sqlite-vec.c @@ -546,10 +546,9 @@ static f32 distance_hamming(const void *a, const void *b, const void *d) { return distance_hamming_u8((u8 *)a, (u8 *)b, dimensions / CHAR_BIT); } -#if !defined(SQLITE_CORE) || (defined(SQLITE_AMALGAMATION) && defined(SQLITE_OMIT_JSON)) // from SQLite source: // https://github.com/sqlite/sqlite/blob/a509a90958ddb234d1785ed7801880ccb18b497e/src/json.c#L153 -static const char jsonIsSpaceX[] = { +static const char vecJsonIsSpaceX[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -565,8 +564,7 @@ static const char jsonIsSpaceX[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; -#define jsonIsspace(x) (jsonIsSpaceX[(unsigned char)x]) -#endif +#define vecJsonIsspace(x) (vecJsonIsSpaceX[(unsigned char)x]) typedef void (*vector_cleanup)(void *p); @@ -711,7 +709,7 @@ static int fvec_from_value(sqlite3_value *value, f32 **vector, // advance leading whitespace to first '[' while (i < source_len) { - if (jsonIsspace(source[i])) { + if (vecJsonIsspace(source[i])) { i++; continue; } @@ -761,7 +759,7 @@ static int fvec_from_value(sqlite3_value *value, f32 **vector, offset += (endptr - ptr); while (offset < source_len) { - if (jsonIsspace(source[offset])) { + if (vecJsonIsspace(source[offset])) { offset++; continue; } @@ -849,7 +847,7 @@ static int int8_vec_from_value(sqlite3_value *value, i8 **vector, // advance leading whitespace to first '[' while (i < source_len) { - if (jsonIsspace(source[i])) { + if (vecJsonIsspace(source[i])) { i++; continue; } @@ -904,7 +902,7 @@ static int int8_vec_from_value(sqlite3_value *value, i8 **vector, offset += (endptr - ptr); while (offset < source_len) { - if (jsonIsspace(source[offset])) { + if (vecJsonIsspace(source[offset])) { offset++; continue; } @@ -6931,10 +6929,7 @@ static sqlite3_module vec_static_blob_entriesModule = { "Build flags: " SQLITE_VEC_DEBUG_BUILD -#ifdef _WIN32 -__declspec(dllexport) -#endif - int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg, +SQLITE_VEC_API int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) { SQLITE_EXTENSION_INIT2(pApi); int rc = SQLITE_OK; @@ -7018,10 +7013,7 @@ __declspec(dllexport) } #ifndef SQLITE_VEC_OMIT_FS -#ifdef _WIN32 -__declspec(dllexport) -#endif - int sqlite3_vec_fs_read_init(sqlite3 *db, char **pzErrMsg, +SQLITE_VEC_API int sqlite3_vec_fs_read_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) { UNUSED_PARAMETER(pzErrMsg); SQLITE_EXTENSION_INIT2(pApi); @@ -7033,10 +7025,7 @@ __declspec(dllexport) #endif -#ifdef _WIN32 -__declspec(dllexport) -#endif - int sqlite3_vec_static_blobs_init(sqlite3 *db, char **pzErrMsg, +SQLITE_VEC_API int sqlite3_vec_static_blobs_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) { UNUSED_PARAMETER(pzErrMsg); SQLITE_EXTENSION_INIT2(pApi); diff --git a/sqlite-vec.h.tmpl b/sqlite-vec.h.tmpl index 2496d63..ca2f164 100644 --- a/sqlite-vec.h.tmpl +++ b/sqlite-vec.h.tmpl @@ -3,6 +3,16 @@ #include "sqlite3ext.h" +#ifdef SQLITE_VEC_STATIC + #define SQLITE_VEC_API +#else + #ifdef _WIN32 + #define SQLITE_VEC_API __declspec(dllexport) + #else + #define SQLITE_VEC_API + #endif +#endif + #define SQLITE_VEC_VERSION "v${VERSION}" #define SQLITE_VEC_DATE "${DATE}" #define SQLITE_VEC_SOURCE "${SOURCE}"