Skip to content

Commit

Permalink
Use mlvalue convenience macros
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA committed Feb 6, 2022
1 parent dab566f commit dc5b105
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/unix/lwt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@
#define CAML_NAME_SPACE
#endif

#if OCAML_VERSION < 41200
#define Val_none Val_int(0)
#define Some_val(v) Field(v, 0)
#define Tag_some 0
#define Is_none(v) ((v) == Val_none)
#define Is_some(v) Is_block(v)
#endif

#endif // #ifndef _LWT_CONFIG_H_
4 changes: 2 additions & 2 deletions src/unix/lwt_process_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

static HANDLE get_handle(value opt) {
value fd;
if (Is_block(opt)) {
fd = Field(opt, 0);
if (Is_some(opt)) {
fd = Some_val(opt);
if (Descr_kind_val(fd) == KIND_SOCKET) {
win32_maperr(ERROR_INVALID_HANDLE);
uerror("CreateProcess", Nothing);
Expand Down
2 changes: 1 addition & 1 deletion src/unix/unix_c/unix_accept4.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CAMLprim value lwt_unix_accept4(value vcloexec, value vnonblock, value vsock)

union sock_addr_union addr;
socklen_param_type addr_len;
int cloexec = Is_block(vcloexec) && Bool_val(Field(vcloexec, 0)) ? SOCK_CLOEXEC : 0;
int cloexec = Is_some(vcloexec) && Bool_val(Some_val(vcloexec)) ? SOCK_CLOEXEC : 0;
int nonblock = Bool_val(vnonblock) ? SOCK_NONBLOCK : 0;
addr_len = sizeof(addr);

Expand Down
2 changes: 1 addition & 1 deletion src/unix/unix_c/unix_access_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static int access_permission_table[] = {
static int int_of_access_permissions(value list)
{
int result = 0;
while (Is_block(list)) {
while (list != Val_emptylist) {
result |= access_permission_table[Int_val(Field(list, 0))];
list = Field(list, 1);
};
Expand Down
2 changes: 1 addition & 1 deletion src/unix/unix_c/unix_getaddrinfo_job.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ CAMLprim value lwt_unix_getaddrinfo_job(value node, value service, value hints)
job->info = NULL;
memset(&job->hints, 0, sizeof(struct addrinfo));
job->hints.ai_family = PF_UNSPEC;
for (/*nothing*/; Is_block(hints); hints = Field(hints, 1)) {
for (/*nothing*/; hints != Val_emptylist; hints = Field(hints, 1)) {
value v = Field(hints, 0);
if (Is_block(v)) switch (Tag_val(v)) {
case 0: /* AI_FAMILY of socket_domain */
Expand Down
7 changes: 3 additions & 4 deletions src/unix/unix_c/unix_recv_send_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,10 @@ value wrapper_send_msg(int fd, int n_iovs, struct iovec *iovs,
msg.msg_iov = iovs;
msg.msg_iovlen = n_iovs;

/* dest: Unix.sockaddr option */
if (Is_block(dest)) {
if (Is_some(dest)) {
union sock_addr_union addr;
socklen_t addr_len;
get_sockaddr(Field(dest, 0), &addr, &addr_len);
get_sockaddr(Some_val(dest), &addr, &addr_len);

msg.msg_name = &addr.s_gen;
msg.msg_namelen = addr_len;
Expand All @@ -97,7 +96,7 @@ value wrapper_send_msg(int fd, int n_iovs, struct iovec *iovs,
cm->cmsg_len = CMSG_LEN(n_fds * sizeof(int));

int *fds = (int *)CMSG_DATA(cm);
for (; Is_block(val_fds); val_fds = Field(val_fds, 1), fds++)
for (/*nothing*/; val_fds != Val_emptylist; val_fds = Field(val_fds, 1), fds++)
*fds = Int_val(Field(val_fds, 0));
};
#else
Expand Down
2 changes: 1 addition & 1 deletion src/unix/unix_c/unix_set_affinity.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CAMLprim value lwt_unix_set_affinity(value val_pid, value val_cpus)
{
cpu_set_t cpus;
CPU_ZERO(&cpus);
for (; Is_block(val_cpus); val_cpus = Field(val_cpus, 1))
for (/*nothing*/; val_cpus != Val_emptylist; val_cpus = Field(val_cpus, 1))
CPU_SET(Int_val(Field(val_cpus, 0)), &cpus);
if (sched_setaffinity(Int_val(val_pid), sizeof(cpu_set_t), &cpus) < 0)
uerror("sched_setaffinity", Nothing);
Expand Down

0 comments on commit dc5b105

Please sign in to comment.