Skip to content

Commit 9975b2b

Browse files
committed
modify stubs so they build on < 4.08
1 parent 70a38c1 commit 9975b2b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/sqlite3.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ module Data = struct
233233
let to_string_coerce = function
234234
| NONE | NULL -> ""
235235
| INT n -> Int64.to_string n
236-
| FLOAT n -> Float.to_string n
236+
| FLOAT n -> string_of_float n
237237
| TEXT t | BLOB t -> t
238238
end (* Data *)
239239

src/sqlite3_stubs.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <stdio.h>
2929
#include <string.h>
3030

31+
#include <caml/version.h>
3132
#include <caml/mlvalues.h>
3233
#include <caml/memory.h>
3334
#include <caml/fail.h>
@@ -420,7 +421,9 @@ static struct custom_operations db_wrap_ops = {
420421
custom_serialize_default,
421422
custom_deserialize_default,
422423
custom_compare_ext_default,
423-
custom_fixed_length_default
424+
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
425+
custom_fixed_length_default,
426+
#endif
424427
};
425428

426429
#ifdef SQLITE_HAS_OPEN_V2
@@ -540,7 +543,11 @@ CAMLprim value caml_sqlite3_open(
540543
int mem, hiwtr;
541544
int rc = sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &mem, &hiwtr, 0);
542545
mem = db_wrap_size + (rc ? 8192 : mem);
546+
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
543547
v_res = caml_alloc_custom_mem(&db_wrap_ops, sizeof(db_wrap *), mem);
548+
#else
549+
v_res = caml_alloc_custom(&db_wrap_ops, sizeof(db_wrap *), 1, 1000);
550+
#endif
544551
dbw->db = db;
545552
dbw->rc = SQLITE_OK;
546553
dbw->ref_count = 1;
@@ -875,7 +882,9 @@ static struct custom_operations stmt_wrap_ops = {
875882
custom_serialize_default,
876883
custom_deserialize_default,
877884
custom_compare_ext_default,
885+
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
878886
custom_fixed_length_default
887+
#endif
879888
};
880889

881890
static inline value prepare_it(
@@ -897,11 +906,16 @@ static inline value prepare_it(
897906
if (rc != SQLITE_OK) raise_sqlite3_current(dbw->db, loc);
898907
raise_sqlite3_Error("No code compiled from %s", sql);
899908
} else {
909+
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
900910
size_t mem =
901911
sizeof(stmt_wrap) + sql_len + 1 +
902912
sqlite3_stmt_status(stmtw->stmt, SQLITE_STMTSTATUS_MEMUSED, 0);
903913
value v_stmt =
904914
caml_alloc_custom_mem(&stmt_wrap_ops, sizeof(stmt_wrap *), mem);
915+
#else
916+
value v_stmt =
917+
caml_alloc_custom(&stmt_wrap_ops, sizeof(stmt_wrap *), 1, 1000);
918+
#endif
905919
Sqlite3_stmtw_val(v_stmt) = stmtw;
906920
return v_stmt;
907921
}

0 commit comments

Comments
 (0)