From f4ec50bf72a40f66dd013c560078256d7b8dfc40 Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 16:50:10 -1000 Subject: [PATCH 1/8] option call to epoll_ctl --- lib/polly.ml | 37 ++++++++++++++++++++++++------------- lib/polly_stubs.c | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index bd05aac..5e7cb66 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -96,16 +96,16 @@ module Events = struct let test x y = x land y <> empty end -type t = Unix.file_descr (* epoll fd *) +type t = int (* epoll fd *) -external caml_polly_add : t -> Unix.file_descr -> Events.t -> unit - = "caml_polly_add" +external caml_polly_add : (t [@untagged]) -> (int [@untagged]) -> (Events.t [@untagged]) -> (int [@untagged]) [@noalloc] + = "caml_polly_add" "caml_untagged_polly_add" -external caml_polly_del : t -> Unix.file_descr -> Events.t -> unit - = "caml_polly_del" +external caml_polly_del : (t [@untagged]) -> (int [@untagged]) -> (Events.t [@untagged]) -> (int [@untagged]) [@noalloc] + = "caml_polly_del" "caml_untagged_polly_del" -external caml_polly_mod : t -> Unix.file_descr -> Events.t -> unit - = "caml_polly_mod" +external caml_polly_mod : (t [@untagged]) -> (int [@untagged]) -> (Events.t [@untagged]) -> (int [@untagged]) [@noalloc] + = "caml_polly_mod" "caml_untagged_polly_mod" external caml_polly_create1 : unit -> t = "caml_polly_create1" @@ -113,7 +113,7 @@ external caml_polly_wait : t (* epoll fd *) -> int (* max number of fds handled *) -> int (* timeout in ms *) - -> (Unix.file_descr -> Unix.file_descr -> Events.t -> unit) + -> (t -> Unix.file_descr -> Events.t -> unit) -> int (* actual number of ready fds; 0 = timeout *) = "caml_polly_wait" external caml_polly_wait_fold : @@ -121,18 +121,29 @@ external caml_polly_wait_fold : -> int (* max number of fds handled *) -> int (* timeout in ms *) -> 'a (* initial value *) - -> (Unix.file_descr -> Unix.file_descr -> Events.t -> 'a -> 'a) + -> (t -> Unix.file_descr -> Events.t -> 'a -> 'a) -> 'a (* final value *) = "caml_polly_wait_fold" let create = caml_polly_create1 -let close t = Unix.close t +let close t = Unix.close (Obj.magic t : Unix.file_descr) -let add = caml_polly_add +external uerror : string -> 'a -> 'b = "caml_uerror" -let del t fd = caml_polly_del t fd Events.empty +let add : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> + let __FUNCTION__ = "Polly.add" in + let r = caml_polly_add t (Obj.magic fd) evt in + if r = -1 then uerror __FUNCTION__ None -let upd = caml_polly_mod +let del : t -> Unix.file_descr -> unit = fun t fd -> + let __FUNCTION__ = "Polly.del" in + let r = caml_polly_del t (Obj.magic fd) Events.empty in + if r = -1 then uerror __FUNCTION__ None + +let upd : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> + let __FUNCTION__ = "Polly.upd" in + let r = caml_polly_mod t (Obj.magic fd) evt in + if r = -1 then uerror __FUNCTION__ None let wait = caml_polly_wait diff --git a/lib/polly_stubs.c b/lib/polly_stubs.c index 24393fb..4bd6783 100644 --- a/lib/polly_stubs.c +++ b/lib/polly_stubs.c @@ -60,16 +60,13 @@ CAMLprim value caml_polly_create1(value val_unit) static value caml_polly_ctl(value val_epfd, value val_fd, value val_events, int op) { - CAMLparam3(val_epfd, val_fd, val_events); - struct epoll_event event = { - .events = (uint32_t) Int_val(val_events), - .data.fd = Int_val(val_fd) - }; + CAMLparam0(); /* no need to register int */ + struct epoll_event event = { + .events = (uint32_t) Int_val(val_events), + .data.fd = Int_val(val_fd) + }; - if (epoll_ctl(Int_val(val_epfd), op, Int_val(val_fd), &event) == -1) - uerror(__FUNCTION__, Nothing); - - CAMLreturn(Val_unit); + CAMLreturn(Val_int(epoll_ctl(Int_val(val_epfd), op, Int_val(val_fd), &event))); } CAMLprim value caml_polly_add(value val_epfd, value val_fd, value val_events) @@ -77,16 +74,40 @@ CAMLprim value caml_polly_add(value val_epfd, value val_fd, value val_events) return caml_polly_ctl(val_epfd, val_fd, val_events, EPOLL_CTL_ADD); } +int caml_untagged_polly_add(int epfd, int fd, int events) { + struct epoll_event event = { + .events = (uint32_t) events, + .data.fd = fd + }; + return epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &event); +} + CAMLprim value caml_polly_mod(value val_epfd, value val_fd, value val_events) { return caml_polly_ctl(val_epfd, val_fd, val_events, EPOLL_CTL_MOD); } +int caml_untagged_polly_mod(int epfd, int fd, int events) { + struct epoll_event event = { + .events = (uint32_t) events, + .data.fd = fd + }; + return epoll_ctl(epfd, EPOLL_CTL_MOD, fd, &event); +} + CAMLprim value caml_polly_del(value val_epfd, value val_fd, value val_events) { return caml_polly_ctl(val_epfd, val_fd, val_events, EPOLL_CTL_DEL); } +int caml_untagged_polly_del(int epfd, int fd, int events) { + struct epoll_event event = { + .events = (uint32_t) events, + .data.fd = fd + }; + return epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &event); +} + CAMLprim value caml_polly_wait(value val_epfd, value val_max, value val_timeout, value val_f) { From ddba25be37bd1f648df5d15ad4dceaced4f190a5 Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 17:10:37 -1000 Subject: [PATCH 2/8] restore compilation with 4.X --- lib/polly.ml | 8 ++++---- lib/polly_stubs.c | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index 5e7cb66..0a6778b 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -128,22 +128,22 @@ let create = caml_polly_create1 let close t = Unix.close (Obj.magic t : Unix.file_descr) -external uerror : string -> 'a -> 'b = "caml_uerror" +external uerror : string -> 'a = "caml_raise_unix_error" let add : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> let __FUNCTION__ = "Polly.add" in let r = caml_polly_add t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ None + if r = -1 then uerror __FUNCTION__ let del : t -> Unix.file_descr -> unit = fun t fd -> let __FUNCTION__ = "Polly.del" in let r = caml_polly_del t (Obj.magic fd) Events.empty in - if r = -1 then uerror __FUNCTION__ None + if r = -1 then uerror __FUNCTION__ let upd : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> let __FUNCTION__ = "Polly.upd" in let r = caml_polly_mod t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ None + if r = -1 then uerror __FUNCTION__ let wait = caml_polly_wait diff --git a/lib/polly_stubs.c b/lib/polly_stubs.c index 4bd6783..f3a17c8 100644 --- a/lib/polly_stubs.c +++ b/lib/polly_stubs.c @@ -43,6 +43,13 @@ CONSTANT(EPOLLET); CONSTANT(EPOLLEXCLUSIVE); #endif +/* necessary because of changes from 4.X to 5.X in ocaml, + uerror is a macro in 5.0 */ +CAMLprim void caml_raise_unix_error(value funname) { + CAMLparam1(funname); + uerror(String_val(funname),Nothing); +} + CAMLprim value caml_polly_create1(value val_unit) { CAMLparam1(val_unit); From 3954132194857d08960798a5149596e8e3de954f Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 17:31:24 -1000 Subject: [PATCH 3/8] lint --- lib/polly.ml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index 0a6778b..bf31a74 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -130,20 +130,23 @@ let close t = Unix.close (Obj.magic t : Unix.file_descr) external uerror : string -> 'a = "caml_raise_unix_error" -let add : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> - let __FUNCTION__ = "Polly.add" in - let r = caml_polly_add t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ - -let del : t -> Unix.file_descr -> unit = fun t fd -> - let __FUNCTION__ = "Polly.del" in - let r = caml_polly_del t (Obj.magic fd) Events.empty in - if r = -1 then uerror __FUNCTION__ - -let upd : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> - let __FUNCTION__ = "Polly.upd" in - let r = caml_polly_mod t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ +let add : t -> Unix.file_descr -> Events.t -> unit = + fun t fd evt -> + let __FUNCTION__ = "Polly.add" in + let r = caml_polly_add t (Obj.magic fd) evt in + if r = -1 then uerror __FUNCTION__ + +let del : t -> Unix.file_descr -> unit = + fun t fd -> + let __FUNCTION__ = "Polly.del" in + let r = caml_polly_del t (Obj.magic fd) Events.empty in + if r = -1 then uerror __FUNCTION__ + +let upd : t -> Unix.file_descr -> Events.t -> unit = + fun t fd evt -> + let __FUNCTION__ = "Polly.upd" in + let r = caml_polly_mod t (Obj.magic fd) evt in + if r = -1 then uerror __FUNCTION__ let wait = caml_polly_wait From 420bb4a1ea1333ad095528e4791e4b7273a465cb Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 17:39:54 -1000 Subject: [PATCH 4/8] lint --- lib/polly.ml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index bf31a74..8f634a1 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -131,22 +131,22 @@ let close t = Unix.close (Obj.magic t : Unix.file_descr) external uerror : string -> 'a = "caml_raise_unix_error" let add : t -> Unix.file_descr -> Events.t -> unit = - fun t fd evt -> - let __FUNCTION__ = "Polly.add" in - let r = caml_polly_add t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ + fun t fd evt -> + let __FUNCTION__ = "Polly.add" in + let r = caml_polly_add t (Obj.magic fd) evt in + if r = -1 then uerror __FUNCTION__ let del : t -> Unix.file_descr -> unit = - fun t fd -> - let __FUNCTION__ = "Polly.del" in - let r = caml_polly_del t (Obj.magic fd) Events.empty in - if r = -1 then uerror __FUNCTION__ + fun t fd -> + let __FUNCTION__ = "Polly.del" in + let r = caml_polly_del t (Obj.magic fd) Events.empty in + if r = -1 then uerror __FUNCTION__ let upd : t -> Unix.file_descr -> Events.t -> unit = - fun t fd evt -> - let __FUNCTION__ = "Polly.upd" in - let r = caml_polly_mod t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ + fun t fd evt -> + let __FUNCTION__ = "Polly.upd" in + let r = caml_polly_mod t (Obj.magic fd) evt in + if r = -1 then uerror __FUNCTION__ let wait = caml_polly_wait From b30dd644093cee007ca033bcc9918325675fbd59 Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 17:45:55 -1000 Subject: [PATCH 5/8] lint --- lib/polly.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/polly.ml b/lib/polly.ml index 8f634a1..609694c 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -146,7 +146,7 @@ let upd : t -> Unix.file_descr -> Events.t -> unit = fun t fd evt -> let __FUNCTION__ = "Polly.upd" in let r = caml_polly_mod t (Obj.magic fd) evt in - if r = -1 then uerror __FUNCTION__ + if r = -1 then uerror __FUNCTION__ let wait = caml_polly_wait From 38484c96a4c02d273de1ee36a819c5f58d860e06 Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 18:03:07 -1000 Subject: [PATCH 6/8] lint --- lib/polly.ml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index 609694c..f840475 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -98,13 +98,28 @@ end type t = int (* epoll fd *) -external caml_polly_add : (t [@untagged]) -> (int [@untagged]) -> (Events.t [@untagged]) -> (int [@untagged]) [@noalloc] +external caml_polly_add : + ( (t [@untagged]) + -> (int [@untagged]) + -> (Events.t [@untagged]) + -> (int [@untagged]) + [@noalloc]) = "caml_polly_add" "caml_untagged_polly_add" -external caml_polly_del : (t [@untagged]) -> (int [@untagged]) -> (Events.t [@untagged]) -> (int [@untagged]) [@noalloc] +external caml_polly_del : + ( (t [@untagged]) + -> (int [@untagged]) + -> (Events.t [@untagged]) + -> (int [@untagged]) + [@noalloc]) = "caml_polly_del" "caml_untagged_polly_del" -external caml_polly_mod : (t [@untagged]) -> (int [@untagged]) -> (Events.t [@untagged]) -> (int [@untagged]) [@noalloc] +external caml_polly_mod : + ( (t [@untagged]) + -> (int [@untagged]) + -> (Events.t [@untagged]) + -> (int [@untagged]) + [@noalloc]) = "caml_polly_mod" "caml_untagged_polly_mod" external caml_polly_create1 : unit -> t = "caml_polly_create1" From c6fcf1f8cba5bc96d26207ae62fc4fe85b734893 Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 18:15:50 -1000 Subject: [PATCH 7/8] lint --- lib/polly.ml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index f840475..264a03a 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -99,26 +99,26 @@ end type t = int (* epoll fd *) external caml_polly_add : - ( (t [@untagged]) - -> (int [@untagged]) - -> (Events.t [@untagged]) - -> (int [@untagged]) + ( (t[@untagged]) + -> (int[@untagged]) + -> (Events.t[@untagged]) + -> (int[@untagged]) [@noalloc]) = "caml_polly_add" "caml_untagged_polly_add" external caml_polly_del : - ( (t [@untagged]) - -> (int [@untagged]) - -> (Events.t [@untagged]) - -> (int [@untagged]) + ( (t[@untagged]) + -> (int[@untagged]) + -> (Events.t[@untagged]) + -> (int[@untagged]) [@noalloc]) = "caml_polly_del" "caml_untagged_polly_del" external caml_polly_mod : - ( (t [@untagged]) - -> (int [@untagged]) - -> (Events.t [@untagged]) - -> (int [@untagged]) + ( (t[@untagged]) + -> (int[@untagged]) + -> (Events.t[@untagged]) + -> (int[@untagged]) [@noalloc]) = "caml_polly_mod" "caml_untagged_polly_mod" From 6cea054c7b76c87bbc6265abb7c7bc1319482465 Mon Sep 17 00:00:00 2001 From: Christophe Raffalli Date: Fri, 4 Aug 2023 18:33:14 -1000 Subject: [PATCH 8/8] lint --- lib/polly.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/polly.ml b/lib/polly.ml index 264a03a..a59c03b 100644 --- a/lib/polly.ml +++ b/lib/polly.ml @@ -103,24 +103,24 @@ external caml_polly_add : -> (int[@untagged]) -> (Events.t[@untagged]) -> (int[@untagged]) - [@noalloc]) - = "caml_polly_add" "caml_untagged_polly_add" + [@noalloc] + ) = "caml_polly_add" "caml_untagged_polly_add" external caml_polly_del : ( (t[@untagged]) -> (int[@untagged]) -> (Events.t[@untagged]) -> (int[@untagged]) - [@noalloc]) - = "caml_polly_del" "caml_untagged_polly_del" + [@noalloc] + ) = "caml_polly_del" "caml_untagged_polly_del" external caml_polly_mod : ( (t[@untagged]) -> (int[@untagged]) -> (Events.t[@untagged]) -> (int[@untagged]) - [@noalloc]) - = "caml_polly_mod" "caml_untagged_polly_mod" + [@noalloc] + ) = "caml_polly_mod" "caml_untagged_polly_mod" external caml_polly_create1 : unit -> t = "caml_polly_create1"