Commit d07590a2 authored by gwenn's avatar gwenn

Clean cgo parts

parent b499e7c0
......@@ -10,18 +10,18 @@ void goSqlite3SetAuxdata(sqlite3_context *ctx, int N, void *ad) {
sqlite3_set_auxdata(ctx, N, ad, goXAuxDataDestroy);
}
static void cXFunc(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
static inline void cXFunc(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
void *goctx = sqlite3_get_auxdata(ctx, 0);
goXFunc(ctx, udf, goctx, argc, argv);
}
static void cXStep(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
static inline void cXStep(sqlite3_context *ctx, int argc, sqlite3_value **argv) {
void *udf = sqlite3_user_data(ctx);
goXStep(ctx, udf, argc, argv);
}
static void cXFinal(sqlite3_context *ctx) {
static inline void cXFinal(sqlite3_context *ctx) {
void *udf = sqlite3_user_data(ctx);
goXFinal(ctx, udf);
}
......
......@@ -10,39 +10,39 @@ package sqlite
// These wrappers are necessary because SQLITE_TRANSIENT
// is a pointer constant, and cgo doesn't translate them correctly.
static void my_result_text(sqlite3_context *ctx, char *p, int np) {
static inline void my_result_text(sqlite3_context *ctx, char *p, int np) {
sqlite3_result_text(ctx, p, np, SQLITE_TRANSIENT);
}
static void my_result_blob(sqlite3_context *ctx, void *p, int np) {
static inline void my_result_blob(sqlite3_context *ctx, void *p, int np) {
sqlite3_result_blob(ctx, p, np, SQLITE_TRANSIENT);
}
static void my_result_value(sqlite3_context *ctx, sqlite3_value **argv, int i) {
static inline void my_result_value(sqlite3_context *ctx, sqlite3_value **argv, int i) {
sqlite3_result_value(ctx, argv[i]);
}
static const void *my_value_blob(sqlite3_value **argv, int i) {
static inline const void *my_value_blob(sqlite3_value **argv, int i) {
return sqlite3_value_blob(argv[i]);
}
static int my_value_bytes(sqlite3_value **argv, int i) {
static inline int my_value_bytes(sqlite3_value **argv, int i) {
return sqlite3_value_bytes(argv[i]);
}
static double my_value_double(sqlite3_value **argv, int i) {
static inline double my_value_double(sqlite3_value **argv, int i) {
return sqlite3_value_double(argv[i]);
}
static int my_value_int(sqlite3_value **argv, int i) {
static inline int my_value_int(sqlite3_value **argv, int i) {
return sqlite3_value_int(argv[i]);
}
static sqlite3_int64 my_value_int64(sqlite3_value **argv, int i) {
static inline sqlite3_int64 my_value_int64(sqlite3_value **argv, int i) {
return sqlite3_value_int64(argv[i]);
}
static const unsigned char *my_value_text(sqlite3_value **argv, int i) {
static inline const unsigned char *my_value_text(sqlite3_value **argv, int i) {
return sqlite3_value_text(argv[i]);
}
static int my_value_type(sqlite3_value **argv, int i) {
static inline int my_value_type(sqlite3_value **argv, int i) {
return sqlite3_value_type(argv[i]);
}
static int my_value_numeric_type(sqlite3_value **argv, int i) {
static inline int my_value_numeric_type(sqlite3_value **argv, int i) {
return sqlite3_value_numeric_type(argv[i]);
}
......
......@@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.
#include <sqlite3.h>
// warning: incompatible pointer types passing
//#include "_cgo_export.h"
extern int goXCommitHook(void *udp);
......
......@@ -7,23 +7,6 @@ package sqlite
/*
#include <sqlite3.h>
#include <stdlib.h>
// just to get ride of warning
static int my_table_column_metadata(
sqlite3 *db,
const char *zDbName,
const char *zTableName,
const char *zColumnName,
char **pzDataType,
char **pzCollSeq,
int *pNotNull,
int *pPrimaryKey,
int *pAutoinc
) {
return sqlite3_table_column_metadata(db, zDbName, zTableName, zColumnName,
(char const **)pzDataType, (char const **)pzCollSeq, pNotNull, pPrimaryKey, pAutoinc);
}
*/
import "C"
......@@ -199,7 +182,7 @@ func (c *Conn) Column(dbName, tableName, columnName string) (*Column, error) {
defer C.free(unsafe.Pointer(zColumnName))
var zDataType, zCollSeq *C.char
var notNull, primaryKey, autoinc C.int
rv := C.my_table_column_metadata(c.db, zDbName, zTableName, zColumnName, &zDataType, &zCollSeq,
rv := C.sqlite3_table_column_metadata(c.db, zDbName, zTableName, zColumnName, &zDataType, &zCollSeq,
&notNull, &primaryKey, &autoinc)
if rv != C.SQLITE_OK {
return nil, c.error(rv, fmt.Sprintf("Conn.Column(db: %q, tbl: %q, col: %q)", dbName, tableName, columnName))
......
......@@ -12,7 +12,7 @@ package sqlite
#include <stdlib.h>
// cgo doesn't support varargs
static int my_db_config(sqlite3 *db, int op, int v, int *ok) {
static inline int my_db_config(sqlite3 *db, int op, int v, int *ok) {
return sqlite3_db_config(db, op, v, ok);
}
*/
......
......@@ -17,17 +17,12 @@ package sqlite
// #define SQLITE_STATIC ((sqlite3_destructor_type)0)
// #define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
static int my_bind_text(sqlite3_stmt *stmt, int n, const char *p, int np) {
static inline int my_bind_text(sqlite3_stmt *stmt, int n, const char *p, int np) {
return sqlite3_bind_text(stmt, n, p, np, SQLITE_TRANSIENT);
}
static int my_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) {
static inline int my_bind_blob(sqlite3_stmt *stmt, int n, void *p, int np) {
return sqlite3_bind_blob(stmt, n, p, np, SQLITE_TRANSIENT);
}
// just to get ride of "warning: passing argument 5 of ‘sqlite3_prepare_v2’ from incompatible pointer type [...] ‘const char **’ but argument is of type ‘char **’"
static int my_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, char **pzTail) {
return sqlite3_prepare_v2(db, zSql, nByte, ppStmt, (const char**)pzTail);
}
*/
import "C"
......@@ -102,7 +97,7 @@ func (c *Conn) prepare(cmd string, args ...interface{}) (*Stmt, error) {
var stmt *C.sqlite3_stmt
var tail *C.char
// If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes as this saves SQLite from having to make a copy of the input string.
rv := C.my_prepare_v2(c.db, cmdstr, C.int(len(cmd)+1), &stmt, &tail)
rv := C.sqlite3_prepare_v2(c.db, cmdstr, C.int(len(cmd)+1), &stmt, &tail)
if rv != C.SQLITE_OK {
return nil, c.error(rv, cmd)
}
......@@ -148,7 +143,6 @@ func (c *Conn) Prepare(cmd string, args ...interface{}) (*Stmt, error) {
// The Stmt is reset at each call.
// (See http://sqlite.org/c3ref/bind_blob.html, http://sqlite.org/c3ref/step.html)
func (s *Stmt) Exec(args ...interface{}) error {
// TODO Check column count == 0
err := s.Bind(args...)
if err != nil {
return err
......
......@@ -15,7 +15,7 @@ int goSqlite3BusyHandler(sqlite3 *db, void *udp);
void goSqlite3ProgressHandler(sqlite3 *db, int numOps, void *udp);
// cgo doesn't support varargs
static void my_log(int iErrCode, char *msg) {
static inline void my_log(int iErrCode, char *msg) {
sqlite3_log(iErrCode, msg);
}
......
......@@ -9,10 +9,10 @@ package sqlite
#include <stdlib.h>
// cgo doesn't support varargs
static char *my_mprintf(char *zFormat, char *arg) {
static inline char *my_mprintf(char *zFormat, char *arg) {
return sqlite3_mprintf(zFormat, arg);
}
static char *my_mprintf2(char *zFormat, char *arg1, char *arg2) {
static inline char *my_mprintf2(char *zFormat, char *arg1, char *arg2) {
return sqlite3_mprintf(zFormat, arg1, arg2);
}
*/
......
......@@ -31,14 +31,14 @@ static int cXInit(sqlite3 *db, void *pAux, int argc, const char *const*argv, sql
return SQLITE_OK;
}
static int cXCreate(sqlite3 *db, void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVTab, char **pzErr) {
static inline int cXCreate(sqlite3 *db, void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVTab, char **pzErr) {
return cXInit(db, pAux, argc, argv, ppVTab, pzErr, 1);
}
static int cXConnect(sqlite3 *db, void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVTab, char **pzErr) {
static inline int cXConnect(sqlite3 *db, void *pAux, int argc, const char *const*argv, sqlite3_vtab **ppVTab, char **pzErr) {
return cXInit(db, pAux, argc, argv, ppVTab, pzErr, 0);
}
static int cXBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *info) {
static inline int cXBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *info) {
// TODO
return SQLITE_OK;
}
......@@ -57,10 +57,10 @@ static int cXRelease(sqlite3_vtab *pVTab, int isDestroy) {
return SQLITE_OK;
}
static int cXDisconnect(sqlite3_vtab *pVTab) {
static inline int cXDisconnect(sqlite3_vtab *pVTab) {
return cXRelease(pVTab, 0);
}
static int cXDestroy(sqlite3_vtab *pVTab) {
static inline int cXDestroy(sqlite3_vtab *pVTab) {
return cXRelease(pVTab, 1);
}
......@@ -113,7 +113,7 @@ static int cXNext(sqlite3_vtab_cursor *pCursor) {
}
return SQLITE_OK;
}
static int cXEof(sqlite3_vtab_cursor *pCursor) {
static inline int cXEof(sqlite3_vtab_cursor *pCursor) {
return goVEof(((goVTabCursor*)pCursor)->vTabCursor);
}
static int cXColumn(sqlite3_vtab_cursor *pCursor, sqlite3_context *ctx, int i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment