Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the Esperanto support for lwt #945

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/unix/config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,19 @@ struct
Output.{name = feature.macro_name; found}
end

let compiles ?(werror = false) ?(link_flags = []) context code =
let c_flags = C_library_flags.c_flags () in
let compiles ?(werror = false) ?c_flags ?link_flags context code =
let c_flags = match c_flags with
| None -> C_library_flags.c_flags ()
| Some c_flags -> c_flags in
let c_flags =
if werror then
"-Werror"::c_flags
else
c_flags
in
let link_flags = link_flags @ (C_library_flags.link_flags ()) in
let link_flags = match link_flags with
| None -> C_library_flags.link_flags ()
| Some link_flags -> link_flags in
Configurator.c_test context ~c_flags ~link_flags code
|> fun result -> Some result

Expand Down Expand Up @@ -469,11 +473,14 @@ struct
When targeting Android, compiling without -lpthread is the only way
to link with pthread, and we don't to search for libpthread, because
if we find it, it is likely the host's libpthread. *)
match compiles context code with
| Some true -> Some true
| no ->
match compiles ~c_flags:[] ~link_flags:[] context code,
compiles context code with
| Some true, Some true -> Some true
| Some false, Some true
| Some true, Some false -> Some true
| _no ->
if !Arguments.android_target = Some true then
no
Some false
else begin
match compiles context code ~link_flags:["-lpthread"] with
| Some true ->
Expand Down Expand Up @@ -516,6 +523,7 @@ struct
struct msghdr msg;
msg.msg_controllen = 0;
msg.msg_control = 0;
unsigned char *data = CMSG_DATA(CMSG_FIRSTHDR(&msg));
return 0;
}
|}
Expand Down
10 changes: 3 additions & 7 deletions src/unix/unix_c/unix_get_network_information_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,12 @@ value alloc_host_entry(struct hostent *entry)
res = caml_alloc_small(4, 0);
Field(res, 0) = name;
Field(res, 1) = aliases;
switch (entry->h_addrtype) {
case PF_UNIX:
if (entry->h_addrtype == PF_UNIX) {
Field(res, 2) = Val_int(0);
break;
case PF_INET:
} else if (entry->h_addrtype == PF_INET) {
Field(res, 2) = Val_int(1);
break;
default: /*PF_INET6 */
} else {
Field(res, 2) = Val_int(2);
break;
}
Field(res, 3) = addr_list;
End_roots();
Expand Down
12 changes: 6 additions & 6 deletions src/unix/unix_c/unix_madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#include <caml/bigarray.h>
#include <sys/mman.h>

static int advise_table[] = {
MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL, MADV_WILLNEED, MADV_DONTNEED,
CAMLprim value lwt_unix_madvise(value val_buffer, value val_offset,
value val_length, value val_advice)
{
int advise_table[] = {
MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL, MADV_WILLNEED, MADV_DONTNEED,
#if defined(MADV_MERGEABLE)
MADV_MERGEABLE,
#else
Expand All @@ -34,11 +37,8 @@ static int advise_table[] = {
#else
0,
#endif
};
};

CAMLprim value lwt_unix_madvise(value val_buffer, value val_offset,
value val_length, value val_advice)
{
int ret =
madvise((char *)Caml_ba_data_val(val_buffer) + Long_val(val_offset),
Long_val(val_length), advise_table[Int_val(val_advice)]);
Expand Down
8 changes: 3 additions & 5 deletions src/unix/unix_c/unix_mcast_modify_membership.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ CAMLprim value lwt_unix_mcast_modify_membership(value fd, value v_action,
t = socket_domain(fd_sock);
r = 0;

switch (t) {
case PF_INET: {
if (t == PF_INET) {
struct ip_mreq mreq;

if (caml_string_length(group_addr) != 4 ||
Expand All @@ -55,11 +54,10 @@ CAMLprim value lwt_unix_mcast_modify_membership(value fd, value v_action,

r = setsockopt(fd_sock, IPPROTO_IP, optname, (void *)&mreq,
sizeof(mreq));
break;
}
default:
else {
caml_invalid_argument("lwt_unix_mcast_modify_membership");
};
}

if (r == -1) uerror("setsockopt", Nothing);

Expand Down
8 changes: 3 additions & 5 deletions src/unix/unix_c/unix_mcast_set_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ CAMLprim value lwt_unix_mcast_set_loop(value fd, value flag)
f = Bool_val(flag);
r = 0;

switch (t) {
case PF_INET:
if (t == PF_INET) {
r = setsockopt(Int_val(fd), IPPROTO_IP, IP_MULTICAST_LOOP,
(void *)&f, sizeof(f));
break;
default:
} else {
caml_invalid_argument("lwt_unix_mcast_set_loop");
};
}

if (r == -1) uerror("setsockopt", Nothing);

Expand Down
8 changes: 3 additions & 5 deletions src/unix/unix_c/unix_mcast_set_ttl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ CAMLprim value lwt_unix_mcast_set_ttl(value fd, value ttl)
v = Int_val(ttl);
r = 0;

switch (t) {
case PF_INET:
if (t == PF_INET) {
r = setsockopt(fd_sock, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&v,
sizeof(v));
break;
default:
} else {
caml_invalid_argument("lwt_unix_mcast_set_ttl");
};
}

if (r == -1) uerror("setsockopt", Nothing);

Expand Down
7 changes: 3 additions & 4 deletions src/unix/unix_c/unix_mcast_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ int socket_domain(int fd)
l = sizeof(addr);
if (getsockname(fd, &addr.s_gen, &l) == -1) uerror("getsockname", Nothing);

switch (addr.s_gen.sa_family) {
case AF_INET:
if (addr.s_gen.sa_family == AF_INET) {
return PF_INET;
case AF_INET6:
} else if (addr.s_gen.sa_family == AF_INET6) {
return PF_INET6;
default:
} else {
caml_invalid_argument("Not an Internet socket");
}

Expand Down
32 changes: 16 additions & 16 deletions src/unix/unix_c/unix_tcflow_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@
#include <termios.h>
#include <unistd.h>

/* +-----------------------------------------------------------------+
| Converters |
+-----------------------------------------------------------------+ */

/* Table mapping constructors of ocaml type Unix.flow_action to C values. */
static int flow_action_table[] = {
/* Constructor TCOOFF. */
TCOOFF,
/* Constructor TCOON. */
TCOON,
/* Constructor TCIOFF. */
TCIOFF,
/* Constructor TCION. */
TCION
};

/* +-----------------------------------------------------------------+
| Asynchronous job |
+-----------------------------------------------------------------+ */
Expand Down Expand Up @@ -94,6 +78,22 @@ static value result_tcflow(struct job_tcflow* job)
/* The stub creating the job structure. */
CAMLprim value lwt_unix_tcflow_job(value fd, value action)
{
/* +-----------------------------------------------------------------+
| Converters |
+-----------------------------------------------------------------+ */

/* Table mapping constructors of ocaml type Unix.flow_action to C values. */
int flow_action_table[] = {
/* Constructor TCOOFF. */
TCOOFF,
/* Constructor TCOON. */
TCOON,
/* Constructor TCIOFF. */
TCIOFF,
/* Constructor TCION. */
TCION
};

/* Allocate a new job. */
struct job_tcflow* job = lwt_unix_new(struct job_tcflow);
/* Initializes function fields. */
Expand Down
28 changes: 14 additions & 14 deletions src/unix/unix_c/unix_tcflush_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@
#include <termios.h>
#include <unistd.h>

/* +-----------------------------------------------------------------+
| Converters |
+-----------------------------------------------------------------+ */

/* Table mapping constructors of ocaml type Unix.flush_queue to C values. */
static int flush_queue_table[] = {
/* Constructor TCIFLUSH. */
TCIFLUSH,
/* Constructor TCOFLUSH. */
TCOFLUSH,
/* Constructor TCIOFLUSH. */
TCIOFLUSH
};

/* +-----------------------------------------------------------------+
| Asynchronous job |
+-----------------------------------------------------------------+ */
Expand Down Expand Up @@ -92,6 +78,20 @@ static value result_tcflush(struct job_tcflush* job)
/* The stub creating the job structure. */
CAMLprim value lwt_unix_tcflush_job(value fd, value queue)
{
/* +-----------------------------------------------------------------+
| Converters |
+-----------------------------------------------------------------+ */

/* Table mapping constructors of ocaml type Unix.flush_queue to C values. */
int flush_queue_table[] = {
/* Constructor TCIFLUSH. */
TCIFLUSH,
/* Constructor TCOFLUSH. */
TCOFLUSH,
/* Constructor TCIOFLUSH. */
TCIOFLUSH
};

/* Allocate a new job. */
struct job_tcflush* job = lwt_unix_new(struct job_tcflush);
/* Initializes function fields. */
Expand Down
Loading