Skip to content

Commit

Permalink
modify stubs so they build on < 4.08
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Nov 25, 2019
1 parent 70a38c1 commit 9975b2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/sqlite3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ module Data = struct
let to_string_coerce = function
| NONE | NULL -> ""
| INT n -> Int64.to_string n
| FLOAT n -> Float.to_string n
| FLOAT n -> string_of_float n
| TEXT t | BLOB t -> t
end (* Data *)

Expand Down
16 changes: 15 additions & 1 deletion src/sqlite3_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>

#include <caml/version.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/fail.h>
Expand Down Expand Up @@ -420,7 +421,9 @@ static struct custom_operations db_wrap_ops = {
custom_serialize_default,
custom_deserialize_default,
custom_compare_ext_default,
custom_fixed_length_default
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
custom_fixed_length_default,
#endif
};

#ifdef SQLITE_HAS_OPEN_V2
Expand Down Expand Up @@ -540,7 +543,11 @@ CAMLprim value caml_sqlite3_open(
int mem, hiwtr;
int rc = sqlite3_db_status(db, SQLITE_DBSTATUS_CACHE_USED, &mem, &hiwtr, 0);
mem = db_wrap_size + (rc ? 8192 : mem);
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
v_res = caml_alloc_custom_mem(&db_wrap_ops, sizeof(db_wrap *), mem);
#else
v_res = caml_alloc_custom(&db_wrap_ops, sizeof(db_wrap *), 1, 1000);
#endif
dbw->db = db;
dbw->rc = SQLITE_OK;
dbw->ref_count = 1;
Expand Down Expand Up @@ -875,7 +882,9 @@ static struct custom_operations stmt_wrap_ops = {
custom_serialize_default,
custom_deserialize_default,
custom_compare_ext_default,
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
custom_fixed_length_default
#endif
};

static inline value prepare_it(
Expand All @@ -897,11 +906,16 @@ static inline value prepare_it(
if (rc != SQLITE_OK) raise_sqlite3_current(dbw->db, loc);
raise_sqlite3_Error("No code compiled from %s", sql);
} else {
#if (OCAML_VERSION_MAJOR >= 4 && OCAML_VERSION_MINOR >= 8)
size_t mem =
sizeof(stmt_wrap) + sql_len + 1 +
sqlite3_stmt_status(stmtw->stmt, SQLITE_STMTSTATUS_MEMUSED, 0);
value v_stmt =
caml_alloc_custom_mem(&stmt_wrap_ops, sizeof(stmt_wrap *), mem);
#else
value v_stmt =
caml_alloc_custom(&stmt_wrap_ops, sizeof(stmt_wrap *), 1, 1000);
#endif
Sqlite3_stmtw_val(v_stmt) = stmtw;
return v_stmt;
}
Expand Down

0 comments on commit 9975b2b

Please sign in to comment.