This commit is contained in:
Nuno Cruces
2023-11-21 09:45:47 +00:00
parent ae1d696cf3
commit 22d1ae0068
7 changed files with 23 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
#include <stddef.h>
#include "include.h"
#include "sqlite3.h"
#include "types.h"
void go_func(sqlite3_context *, int, sqlite3_value **);
void go_step(sqlite3_context *, int, sqlite3_value **);

12
sqlite3/include.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <assert.h>
#include <stddef.h>
// https://github.com/JuliaLang/julia/blob/v1.9.4/src/julia.h#L67-L68
#define container_of(ptr, type, member) \
((type *)((char *)(ptr)-offsetof(type, member)))
typedef void *go_handle;
void go_destroy(go_handle);
static_assert(sizeof(go_handle) == 4, "Unexpected size");

View File

@@ -1,6 +1,6 @@
#include "include.h"
#include "sqlite3.h"
#include "types.h"
#define GO_POINTER_TYPE "github.com/ncruces/go-sqlite3.Pointer"

View File

@@ -82,7 +82,7 @@ int sqlite3_time_init(sqlite3 *db, char **pzErrMsg,
time_collation,
/*destroy=*/NULL);
sqlite3_create_function_v2(
db, "json_time", -1,
db, "json_time", /*nArg=*/-1,
SQLITE_UTF8 | SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS, /*arg=*/NULL,
json_time_func, /*step=*/NULL, /*final=*/NULL, /*destroy=*/NULL);
return SQLITE_OK;

View File

@@ -1,7 +0,0 @@
#pragma once
typedef void *go_handle;
void go_destroy(go_handle);
static_assert(sizeof(go_handle) == 4, "Unexpected size");

View File

@@ -2,8 +2,8 @@
#include <stddef.h>
#include <time.h>
#include "include.h"
#include "sqlite3.h"
#include "types.h"
int go_localtime(struct tm *, sqlite3_int64);
int go_vfs_find(const char *zVfsName);

View File

@@ -1,11 +1,7 @@
#include <stddef.h>
#include "include.h"
#include "sqlite3.h"
#include "types.h"
// https://github.com/JuliaLang/julia/blob/v1.9.4/src/julia.h#L67-L68
#define container_of(ptr, type, member) \
((type *)((char *)(ptr)-offsetof(type, member)))
#define SQLITE_VTAB_CREATOR_GO /******/ 0x01
#define SQLITE_VTAB_DESTROYER_GO /****/ 0x02
@@ -67,7 +63,7 @@ struct go_cursor {
};
static void go_mod_destroy(void *pAux) {
struct go_module *mod = (struct go_module *)pAux;
struct go_module *mod = pAux;
void *handle = mod->handle;
free(mod);
go_destroy(handle);
@@ -80,7 +76,7 @@ static int go_vtab_create_wrapper(sqlite3 *db, void *pAux, int argc,
if (vtab == NULL) return SQLITE_NOMEM;
*ppVTab = &vtab->base;
struct go_module *mod = (struct go_module *)pAux;
struct go_module *mod = pAux;
int rc = go_vtab_create(&mod->base, argc, argv, ppVTab, pzErr);
if (rc) {
if (*pzErr) *pzErr = sqlite3_mprintf("%s", *pzErr);
@@ -96,7 +92,7 @@ static int go_vtab_connect_wrapper(sqlite3 *db, void *pAux, int argc,
if (vtab == NULL) return SQLITE_NOMEM;
*ppVTab = &vtab->base;
struct go_module *mod = (struct go_module *)pAux;
struct go_module *mod = pAux;
int rc = go_vtab_connect(&mod->base, argc, argv, ppVTab, pzErr);
if (rc) {
free(vtab);
@@ -225,6 +221,7 @@ static_assert(offsetof(struct go_module, base) == 4, "Unexpected offset");
static_assert(offsetof(struct go_vtab, base) == 4, "Unexpected offset");
static_assert(offsetof(struct go_cursor, base) == 4, "Unexpected offset");
static_assert(sizeof(struct sqlite3_index_info) == 72, "Unexpected size");
static_assert(sizeof(struct sqlite3_index_orderby) == 8, "Unexpected size");
static_assert(sizeof(struct sqlite3_index_constraint) == 12, "Unexpected size");
static_assert(sizeof(struct sqlite3_index_constraint_usage) == 8, "Unexpected size");
static_assert(sizeof(struct sqlite3_index_orderby) == 8, "Unexpected size");
static_assert(sizeof(struct sqlite3_index_constraint_usage) == 8,
"Unexpected size");