Skip to content

Commit 2aca12b

Browse files
committed
build bundles
1 parent ac6a89b commit 2aca12b

2 files changed

Lines changed: 60 additions & 104 deletions

File tree

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -85264,7 +85264,7 @@ struct Vector {
8526485264
size_t vectorDataSize(VectorType, VectorDims);
8526585265
Vector *vectorAlloc(VectorType, VectorDims);
8526685266
void vectorFree(Vector *v);
85267-
int vectorParse(sqlite3_value *, Vector *, char **);
85267+
int vectorParseWithType(sqlite3_value *, Vector *, char **);
8526885268
void vectorInit(Vector *, VectorType, VectorDims, void *);
8526985269

8527085270
/*
@@ -85319,7 +85319,7 @@ void vectorSerializeWithType(sqlite3_context *, const Vector *);
8531985319
/*
8532085320
* Parses Vector content from the blob; vector type and dimensions must be filled already
8532185321
*/
85322-
int vectorParseSqliteBlob (sqlite3_value *, Vector *, char **);
85322+
int vectorParseSqliteBlobWithType(sqlite3_value *, Vector *, char **);
8532385323

8532485324
void vectorF32DeserializeFromBlob(Vector *, const unsigned char *, size_t);
8532585325
void vectorF64DeserializeFromBlob(Vector *, const unsigned char *, size_t);
@@ -210988,6 +210988,7 @@ size_t vectorDataSize(VectorType type, VectorDims dims){
210988210988
case VECTOR_TYPE_FLOAT64:
210989210989
return dims * sizeof(double);
210990210990
case VECTOR_TYPE_1BIT:
210991+
assert( dims > 0 );
210991210992
return (dims + 7) / 8;
210992210993
default:
210993210994
assert(0);
@@ -211198,7 +211199,7 @@ static int vectorParseSqliteText(
211198211199
return -1;
211199211200
}
211200211201

211201-
int vectorParseSqliteBlob(
211202+
int vectorParseSqliteBlobWithType(
211202211203
sqlite3_value *arg,
211203211204
Vector *pVector,
211204211205
char **pzErrMsg
@@ -211308,14 +211309,14 @@ int detectVectorParameters(sqlite3_value *arg, int typeHint, int *pType, int *pD
211308211309
}
211309211310
}
211310211311

211311-
int vectorParse(
211312+
int vectorParseWithType(
211312211313
sqlite3_value *arg,
211313211314
Vector *pVector,
211314211315
char **pzErrMsg
211315211316
){
211316211317
switch( sqlite3_value_type(arg) ){
211317211318
case SQLITE_BLOB:
211318-
return vectorParseSqliteBlob(arg, pVector, pzErrMsg);
211319+
return vectorParseSqliteBlobWithType(arg, pVector, pzErrMsg);
211319211320
case SQLITE_TEXT:
211320211321
return vectorParseSqliteText(arg, pVector, pzErrMsg);
211321211322
default:
@@ -211477,7 +211478,7 @@ static void vectorFuncHintedType(
211477211478
if( pVector==NULL ){
211478211479
return;
211479211480
}
211480-
if( vectorParse(argv[0], pVector, &pzErrMsg) != 0 ){
211481+
if( vectorParseWithType(argv[0], pVector, &pzErrMsg) != 0 ){
211481211482
sqlite3_result_error(context, pzErrMsg, -1);
211482211483
sqlite3_free(pzErrMsg);
211483211484
goto out_free_vec;
@@ -211527,7 +211528,7 @@ static void vectorExtractFunc(
211527211528
if( pVector==NULL ){
211528211529
return;
211529211530
}
211530-
if( vectorParse(argv[0], pVector, &pzErrMsg)<0 ){
211531+
if( vectorParseWithType(argv[0], pVector, &pzErrMsg)<0 ){
211531211532
sqlite3_result_error(context, pzErrMsg, -1);
211532211533
sqlite3_free(pzErrMsg);
211533211534
goto out_free;
@@ -211582,12 +211583,12 @@ static void vectorDistanceCosFunc(
211582211583
if( pVector2==NULL ){
211583211584
goto out_free;
211584211585
}
211585-
if( vectorParse(argv[0], pVector1, &pzErrMsg)<0 ){
211586+
if( vectorParseWithType(argv[0], pVector1, &pzErrMsg)<0 ){
211586211587
sqlite3_result_error(context, pzErrMsg, -1);
211587211588
sqlite3_free(pzErrMsg);
211588211589
goto out_free;
211589211590
}
211590-
if( vectorParse(argv[1], pVector2, &pzErrMsg)<0 ){
211591+
if( vectorParseWithType(argv[1], pVector2, &pzErrMsg)<0 ){
211591211592
sqlite3_result_error(context, pzErrMsg, -1);
211592211593
sqlite3_free(pzErrMsg);
211593211594
goto out_free;
@@ -211673,10 +211674,11 @@ void vector1BitDump(const Vector *pVec){
211673211674

211674211675
assert( pVec->type == VECTOR_TYPE_1BIT );
211675211676

211677+
printf("f1bit: [");
211676211678
for(i = 0; i < pVec->dims; i++){
211677-
printf("%d ", ((elems[i / 8] >> (i & 7)) & 1) ? +1 : -1);
211679+
printf("%s%d", i == 0 ? "" : ", ", ((elems[i / 8] >> (i & 7)) & 1) ? +1 : -1);
211678211680
}
211679-
printf("\n");
211681+
printf("]\n");
211680211682
}
211681211683

211682211684
/**************************************************************************
@@ -211808,7 +211810,6 @@ int vector1BitDistanceHamming(const Vector *v1, const Vector *v2){
211808211810
** diskAnnInsert() Insert single new(!) vector in an opened index
211809211811
** diskAnnDelete() Delete row by key from an opened index
211810211812
*/
211811-
/* #include "vectorInt.h" */
211812211813
#ifndef SQLITE_OMIT_VECTOR
211813211814

211814211815
/* #include "math.h" */
@@ -211845,7 +211846,8 @@ typedef struct VectorPair VectorPair;
211845211846
typedef struct DiskAnnSearchCtx DiskAnnSearchCtx;
211846211847
typedef struct DiskAnnNode DiskAnnNode;
211847211848

211848-
// VectorPair represents single vector where pNode is an exact representation and pEdge - compressed representation (always NULL if pNodeType == pEdgeType)
211849+
// VectorPair represents single vector where pNode is an exact representation and pEdge - compressed representation
211850+
// (pEdge pointer always equals to pNode if pNodeType == pEdgeType)
211849211851
struct VectorPair {
211850211852
int nodeType;
211851211853
int edgeType;
@@ -212727,15 +212729,13 @@ static int diskAnnSearchCtxInit(const DiskAnnIndex *pIndex, DiskAnnSearchCtx *pC
212727212729
pCtx->nUnvisited = 0;
212728212730
pCtx->blobMode = blobMode;
212729212731
if( initVectorPair(pIndex->nNodeVectorType, pIndex->nEdgeVectorType, pIndex->nVectorDims, &pCtx->query) != 0 ){
212730-
goto out_oom;
212732+
return SQLITE_NOMEM_BKPT;
212731212733
}
212732212734
loadVectorPair(&pCtx->query, pQuery);
212733212735

212734-
if( pCtx->aDistances == NULL || pCtx->aCandidates == NULL || pCtx->aTopDistances == NULL || pCtx->aTopCandidates == NULL ){
212735-
goto out_oom;
212736+
if( pCtx->aDistances != NULL && pCtx->aCandidates != NULL && pCtx->aTopDistances != NULL && pCtx->aTopCandidates != NULL ){
212737+
return SQLITE_OK;
212736212738
}
212737-
return SQLITE_OK;
212738-
out_oom:
212739212739
if( pCtx->aDistances != NULL ){
212740212740
sqlite3_free(pCtx->aDistances);
212741212741
}
@@ -212748,6 +212748,7 @@ static int diskAnnSearchCtxInit(const DiskAnnIndex *pIndex, DiskAnnSearchCtx *pC
212748212748
if( pCtx->aTopCandidates != NULL ){
212749212749
sqlite3_free(pCtx->aTopCandidates);
212750212750
}
212751+
deinitVectorPair(&pCtx->query);
212751212752
return SQLITE_NOMEM_BKPT;
212752212753
}
212753212754

@@ -213557,10 +213558,11 @@ void vectorF32Dump(const Vector *pVec){
213557213558

213558213559
assert( pVec->type == VECTOR_TYPE_FLOAT32 );
213559213560

213561+
printf("f32: [");
213560213562
for(i = 0; i < pVec->dims; i++){
213561-
printf("%f ", elems[i]);
213563+
printf("%s%f", i == 0 ? "" : ", ", elems[i]);
213562213564
}
213563-
printf("\n");
213565+
printf("]\n");
213564213566
}
213565213567

213566213568
/**************************************************************************
@@ -213610,34 +213612,6 @@ size_t vectorF32SerializeToBlob(
213610213612
return sizeof(float) * pVector->dims;
213611213613
}
213612213614

213613-
void vectorF32Serialize(
213614-
sqlite3_context *context,
213615-
const Vector *pVector
213616-
){
213617-
float *elems = pVector->data;
213618-
unsigned char *pBlob;
213619-
size_t nBlobSize;
213620-
213621-
assert( pVector->type == VECTOR_TYPE_FLOAT32 );
213622-
assert( pVector->dims <= MAX_VECTOR_SZ );
213623-
213624-
nBlobSize = vectorDataSize(pVector->type, pVector->dims);
213625-
213626-
if( nBlobSize == 0 ){
213627-
sqlite3_result_zeroblob(context, 0);
213628-
return;
213629-
}
213630-
213631-
pBlob = sqlite3_malloc64(nBlobSize);
213632-
if( pBlob == NULL ){
213633-
sqlite3_result_error_nomem(context);
213634-
return;
213635-
}
213636-
213637-
vectorF32SerializeToBlob(pVector, pBlob, nBlobSize);
213638-
sqlite3_result_blob(context, (char*)pBlob, nBlobSize, sqlite3_free);
213639-
}
213640-
213641213615
#define SINGLE_FLOAT_CHAR_LIMIT 32
213642213616
void vectorF32MarshalToText(
213643213617
sqlite3_context *context,
@@ -213778,10 +213752,14 @@ void vectorF32DeserializeFromBlob(
213778213752
void vectorF64Dump(const Vector *pVec){
213779213753
double *elems = pVec->data;
213780213754
unsigned i;
213755+
213756+
assert( pVec->type == VECTOR_TYPE_FLOAT64 );
213757+
213758+
printf("f64: [");
213781213759
for(i = 0; i < pVec->dims; i++){
213782-
printf("%lf ", elems[i]);
213760+
printf("%s%lf", i == 0 ? "" : ", ", elems[i]);
213783213761
}
213784-
printf("\n");
213762+
printf("]\n");
213785213763
}
213786213764

213787213765
/**************************************************************************
@@ -214201,7 +214179,7 @@ int vectorInRowAlloc(sqlite3 *db, const UnpackedRecord *pRecord, VectorInRow *pV
214201214179
vectorInitFromBlob(pVectorInRow->pVector, sqlite3_value_blob(pVectorValue), sqlite3_value_bytes(pVectorValue));
214202214180
} else if( sqlite3_value_type(pVectorValue) == SQLITE_TEXT ){
214203214181
// users can put strings (e.g. '[1,2,3]') in the table and we should process them correctly
214204-
if( vectorParse(pVectorValue, pVectorInRow->pVector, pzErrMsg) != 0 ){
214182+
if( vectorParseWithType(pVectorValue, pVectorInRow->pVector, pzErrMsg) != 0 ){
214205214183
rc = SQLITE_ERROR;
214206214184
goto out;
214207214185
}
@@ -214922,7 +214900,7 @@ int vectorIndexSearch(
214922214900
rc = SQLITE_NOMEM_BKPT;
214923214901
goto out;
214924214902
}
214925-
if( vectorParse(argv[1], pVector, pzErrMsg) != 0 ){
214903+
if( vectorParseWithType(argv[1], pVector, pzErrMsg) != 0 ){
214926214904
rc = SQLITE_ERROR;
214927214905
goto out;
214928214906
}

0 commit comments

Comments
 (0)