Skip to content

fix: bind_text and bind_blob string arguments clean up #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
wasi-sdk
wasi-sdk*
# IntelliJ
.idea

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ RUN apt update \
libtinfo6 \
cargo

RUN cargo install marine
RUN cargo install marine --version 0.12.7

VOLUME /code
WORKDIR /code
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@ EXPORT_FUNCS = \
--export=sqlite3_column_name_,$\
--export=sqlite3_step,$\
--export=sqlite3_reset,$\
--export=sqlite3_bind_blob,$\
--export=sqlite3_bind_blob_,$\
--export=sqlite3_bind_double,$\
--export=sqlite3_bind_int64,$\
--export=sqlite3_bind_text,$\
--export=sqlite3_bind_text_,$\
--export=sqlite3_bind_null,$\
--export=sqlite3_column_count,$\
--export=sqlite3_column_double,$\
40 changes: 28 additions & 12 deletions src/vdbeapi.c
Original file line number Diff line number Diff line change
@@ -1528,21 +1528,30 @@ static int bindText(sqlite3_stmt *pStmt, /* The statement to bind against */
/*
** Bind a blob value to an SQL statement variable.
*/
int sqlite3_bind_blob(sqlite3_stmt *pStmt, int i, const void *zData, int nData,
void (*xDel)(void *)) {
#ifndef __sqlite_unmodified_upstream
int sqlite3_bind_blob_(sqlite3_stmt *pStmt, int i, const void *zData, int nData,
void (*xDel)(void *))
__attribute__((export_name("sqlite3_bind_blob"))) {
#ifdef SQLITE_ENABLE_API_ARMOR
if (nData < 0)
return SQLITE_MISUSE_BKPT;
#endif

#ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, 0);
#else
// xDel is a custom deallocator and if it is not SQLITE_STATIC
// due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData,
(xDel==SQLITE_STATIC || xDel==SQLITE_TRANSIENT)?xDel:free, 0);
// However the memory zData uses has to be cleaned up eventually.
add_object_to_release((void*)zData);
return bindText(pStmt, i, zData, nData, xDel, 0);
}
#endif

int sqlite3_bind_blob(sqlite3_stmt *pStmt, int i, const void *zData, int nData,
void (*xDel)(void *)) {
#ifdef SQLITE_ENABLE_API_ARMOR
if (nData < 0) return SQLITE_MISUSE_BKPT;
#endif

return bindText(pStmt, i, zData, nData, xDel, 0);
}
int sqlite3_bind_blob64(sqlite3_stmt *pStmt, int i, const void *zData,
sqlite3_uint64 nData, void (*xDel)(void *)) {
@@ -1594,17 +1603,24 @@ int sqlite3_bind_pointer(sqlite3_stmt *pStmt, int i, void *pPtr,
}
return rc;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a newline here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


int sqlite3_bind_text(sqlite3_stmt *pStmt, int i, const char *zData, int nData,
void (*xDel)(void *)) {
#ifdef __sqlite_unmodified_upstream
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
#else
}

#ifndef __sqlite_unmodified_upstream
int sqlite3_bind_text_(sqlite3_stmt *pStmt, int i, const char *zData, int nData,
void (*xDel)(void *))
__attribute__((export_name("sqlite3_bind_text"))) {
// xDel is a custom deallocator and if it is not SQLITE_STATIC
// due to our IT architecture it can't be provided from other modules.
return bindText(pStmt, i, zData, nData,
(xDel==SQLITE_STATIC || xDel==SQLITE_TRANSIENT)?xDel:free, SQLITE_UTF8);
#endif
// However the memory zData uses has to be cleaned up eventually.
add_object_to_release((void*)zData);
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
}
#endif

int sqlite3_bind_text64(sqlite3_stmt *pStmt, int i, const char *zData,
sqlite3_uint64 nData, void (*xDel)(void *),
unsigned char enc) {
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.18.0
0.18.1