Skip to content

Commit b7ab278

Browse files
committed
Used new OCaml 4.12 C-macros
1 parent fd1dd42 commit b7ab278

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sqlite3-ocaml is an OCaml library with bindings to the SQLite3 client API.
2323
Sqlite3 is a self-contained, serverless, zero-configuration, transactional SQL
2424
database engine with outstanding performance for many use cases.")
2525
(depends
26-
(ocaml (>= 4.06))
26+
(ocaml (>= 4.12))
2727
dune-configurator
2828
(conf-sqlite3 :build)
2929
(ppx_inline_test :with-test)

sqlite3.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ doc: "https://mmottl.github.io/sqlite3-ocaml/api"
1717
bug-reports: "https://github.com/mmottl/sqlite3-ocaml/issues"
1818
depends: [
1919
"dune" {>= "2.7"}
20-
"ocaml" {>= "4.06"}
20+
"ocaml" {>= "4.12"}
2121
"dune-configurator"
2222
"conf-sqlite3" {build}
2323
"ppx_inline_test" {with-test}

src/sqlite3_stubs.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,8 @@ static int pthread_setspecific(pthread_key_t key, void *value)
109109

110110
/* Utility definitions */
111111

112-
static const value Val_None = Val_int(0);
113-
114-
static inline value Val_Some(value v_arg)
115-
{
116-
CAMLparam1(v_arg);
117-
value v_res = caml_alloc_small(1, 0);
118-
Field(v_res, 0) = v_arg;
119-
CAMLreturn(v_res);
120-
}
121-
122112
static inline value Val_string_option(const char *str)
123-
{ return (str == NULL) ? Val_None : Val_Some(caml_copy_string(str)); }
113+
{ return (str == NULL) ? Val_none : caml_alloc_some(caml_copy_string(str)); }
124114

125115

126116
/* Type definitions */
@@ -340,14 +330,8 @@ static inline value copy_string_option_array(const char** strs, int len)
340330

341331
for (i = 0; i < len; ++i) {
342332
const char *str = strs[i];
343-
if (str == NULL) Field(v_res, i) = Val_None;
344-
else {
345-
value v_opt;
346-
v_str = caml_copy_string(str);
347-
v_opt = caml_alloc_small(1, 0);
348-
Field(v_opt, 0) = v_str;
349-
Store_field(v_res, i, v_opt);
350-
}
333+
if (str == NULL) Field(v_res, i) = Val_none;
334+
else Store_field(v_res, i, caml_alloc_some(caml_copy_string(str)));
351335
}
352336

353337
CAMLreturn(v_res);
@@ -483,7 +467,7 @@ CAMLprim value caml_sqlite3_open(
483467
char *file;
484468

485469
#ifdef SQLITE_HAS_OPEN_V2
486-
if (v_vfs_opt == Val_None) vfs = NULL;
470+
if (Is_none(v_vfs_opt)) vfs = NULL;
487471
else {
488472
value v_vfs = Field(v_vfs_opt, 0);
489473
int vfs_len = caml_string_length(v_vfs) + 1;
@@ -499,7 +483,7 @@ CAMLprim value caml_sqlite3_open(
499483
Int_val(v_cache)
500484
)
501485
caml_failwith("SQLite3 version < 3.5 does not support open flags");
502-
if (v_vfs_opt != Val_None)
486+
if (Is_some(v_vfs_opt))
503487
caml_failwith("SQLite3 version < 3.5 does not support VFS modules");
504488
#endif
505489

@@ -665,7 +649,7 @@ CAMLprim value caml_sqlite3_exec(value v_db, value v_maybe_cb, value v_sql)
665649
cbx.cbp = &v_cb;
666650
cbx.exn = &v_exn;
667651

668-
if (v_maybe_cb != Val_None) {
652+
if (Is_some(v_maybe_cb)) {
669653
v_cb = Field(v_maybe_cb, 0);
670654
cb = exec_callback;
671655
}
@@ -947,9 +931,9 @@ CAMLprim value caml_sqlite3_prepare_tail(value v_stmt)
947931
if (stmtw->sql && stmtw->tail && *(stmtw->tail)) {
948932
db_wrap *dbw = stmtw->db_wrap;
949933
int tail_len = stmtw->sql_len - (stmtw->tail - stmtw->sql);
950-
CAMLreturn(Val_Some(prepare_it(dbw, stmtw->tail, tail_len, loc)));
934+
CAMLreturn(caml_alloc_some(prepare_it(dbw, stmtw->tail, tail_len, loc)));
951935
}
952-
else CAMLreturn(Val_None);
936+
else CAMLreturn(Val_none);
953937
}
954938

955939
CAMLprim value caml_sqlite3_recompile(value v_stmt)
@@ -1391,7 +1375,7 @@ static inline value caml_sqlite3_wrap_values(int argc, sqlite3_value **args)
13911375
v_res = Val_int(1);
13921376
break;
13931377
default:
1394-
v_res = Val_None;
1378+
v_res = Val_none;
13951379
}
13961380
Store_field(v_arr, i, v_res);
13971381
}
@@ -1588,8 +1572,8 @@ CAMLprim value caml_sqlite3_create_aggregate_function(
15881572
sqlite3_create_window_function(
15891573
dbw->db, String_val(v_name), n_args, SQLITE_UTF8, param,
15901574
caml_sqlite3_user_function_step, caml_sqlite3_user_function_final,
1591-
v_valuefn == Val_None ? NULL : caml_sqlite3_user_function_value,
1592-
v_inversefn == Val_None ? NULL : caml_sqlite3_user_function_inverse,
1575+
Is_none(v_valuefn) ? NULL : caml_sqlite3_user_function_value,
1576+
Is_none(v_inversefn) ? NULL : caml_sqlite3_user_function_inverse,
15931577
NULL);
15941578
#else
15951579
rc = sqlite3_create_function(dbw->db, String_val(v_name),

0 commit comments

Comments
 (0)