Skip to content

Commit 175ed4b

Browse files
committed
Used new OCaml 4.12 C-macros
1 parent 3fafb45 commit 175ed4b

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(description "\
2323
Postgresql offers library functions for accessing PostgreSQL databases.")
2424
(depends
25-
(ocaml (>= 4.08))
25+
(ocaml (>= 4.12))
2626
dune-configurator
2727
(conf-postgresql :build)
2828
base-bytes

postgresql.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ doc: "https://mmottl.github.io/postgresql-ocaml/api"
1515
bug-reports: "https://github.com/mmottl/postgresql-ocaml/issues"
1616
depends: [
1717
"dune" {>= "2.7"}
18-
"ocaml" {>= "4.08"}
18+
"ocaml" {>= "4.12"}
1919
"dune-configurator"
2020
"conf-postgresql" {build}
2121
"base-bytes"

src/postgresql_stubs.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,6 @@
118118
#define ANYELEMENTOID 2283
119119
#define JSONBOID 3802
120120

121-
static value v_None = Val_int(0);
122-
123-
static inline value make_some(value v)
124-
{
125-
CAMLparam1(v);
126-
value v_res = caml_alloc_small(1, 0);
127-
Field(v_res, 0) = v;
128-
CAMLreturn(v_res);
129-
}
130-
131121
/* Cache for OCaml-values */
132122
static value v_empty_string = Val_unit;
133123
static const value *v_exc_Oid = NULL; /* Exception [Oid] */
@@ -338,13 +328,14 @@ CAMLprim value PQconndefaults_stub(value __unused v_unit)
338328

339329
for (i = 0; i < n; i++, p++) {
340330
v_el = caml_alloc_small(7, 0);
341-
for (j = 0; j < 7; j++) Field(v_el, j) = v_None;
331+
for (j = 0; j < 7; j++) Field(v_el, j) = Val_none;
342332
Store_field(v_res, i, v_el);
343333
Store_field(v_el, 0, caml_copy_string(p->keyword));
344-
if (p->envvar) Store_field(v_el, 1, make_some(caml_copy_string(p->envvar)));
334+
if (p->envvar)
335+
Store_field(v_el, 1, caml_alloc_some(caml_copy_string(p->envvar)));
345336
if (p->compiled)
346-
Store_field(v_el, 2, make_some(caml_copy_string(p->compiled)));
347-
if (p->val) Store_field(v_el, 3, make_some(caml_copy_string(p->val)));
337+
Store_field(v_el, 2, caml_alloc_some(caml_copy_string(p->compiled)));
338+
if (p->val) Store_field(v_el, 3, caml_alloc_some(caml_copy_string(p->val)));
348339
Store_field(v_el, 4, caml_copy_string(p->label));
349340
Store_field(v_el, 5, caml_copy_string(p->dispchar));
350341
Store_field(v_el, 6, Val_int(p->dispsize));
@@ -1158,16 +1149,16 @@ CAMLprim value PQCancel_stub(value v_conn)
11581149
{
11591150
CAMLparam1(v_conn);
11601151
PGconn *conn = get_conn(v_conn);
1161-
if (conn == NULL) CAMLreturn(v_None);
1152+
if (conn == NULL) CAMLreturn(Val_none);
11621153
else {
11631154
PGcancel *cancel = get_cancel_obj(v_conn);
11641155
char errbuf[256];
11651156
int res;
11661157
caml_enter_blocking_section();
11671158
res = PQcancel(cancel, errbuf, 256);
11681159
caml_leave_blocking_section();
1169-
if (res == 0) CAMLreturn(make_some(caml_copy_string(errbuf)));
1170-
else CAMLreturn(v_None);
1160+
if (res == 0) CAMLreturn(caml_alloc_some(caml_copy_string(errbuf)));
1161+
else CAMLreturn(Val_none);
11711162
}
11721163
}
11731164

@@ -1259,9 +1250,9 @@ CAMLprim value PQnotifies_stub(value v_conn)
12591250
Field(v_notif, 1) = Val_int(notif->be_pid);
12601251
Field(v_notif, 2) = v_extra;
12611252
PQfreemem(notif);
1262-
CAMLreturn(make_some(v_notif));
1253+
CAMLreturn(caml_alloc_some(v_notif));
12631254
}
1264-
else CAMLreturn(v_None);
1255+
else CAMLreturn(Val_none);
12651256
}
12661257

12671258
/* Functions Associated with the COPY Command */

0 commit comments

Comments
 (0)