diff --git a/README.md b/README.md index 5650ec34..d8320d39 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,8 @@ Once you get the REPL prompt, try running `Luv.Env.environ ();;` You can tell Luv to ignore its vendored libuv, and build against an external one by setting `LUV_USE_SYSTEM_LIBUV=yes` during the build. This requires libuv to be findable by `-luv`, `uv.h` to be in the header path, and the Luv version to -be at least 0.5.7. +be at least 0.5.7. Alternatively, to use `pkg-config` to probe for the +appropriate build and link flags, set `LUV_USE_SYSTEM_LIBUV=pkg_config`. The external libuv can be considerably older than what Luv vendors — at the moment, Luv supports compilation against libuv versions all the way down to diff --git a/dune-project b/dune-project index 929c696e..cb1438a6 100644 --- a/dune-project +++ b/dune-project @@ -1 +1,5 @@ -(lang dune 2.0) +(lang dune 3.0) + +(using ctypes 0.1) + +(use_standard_c_and_cxx_flags true) diff --git a/src/c.ml b/src/c.ml index 8c0e11c2..0299970e 100644 --- a/src/c.ml +++ b/src/c.ml @@ -2,11 +2,6 @@ details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - -module Types = Luv_c_types -module Functions = - Luv_c_function_descriptions.Descriptions - (Luv_c_generated_functions.Non_blocking) -module Blocking = - Luv_c_function_descriptions.Blocking - (Luv_c_generated_functions.Blocking) +module Types = Luv_c.C.Types +module Functions = Luv_c.C.Non_blocking +module Blocking = Luv_c.C.Blocking diff --git a/src/c/blocking_function_description.ml b/src/c/blocking_function_description.ml new file mode 100644 index 00000000..a4c1adcd --- /dev/null +++ b/src/c/blocking_function_description.ml @@ -0,0 +1,423 @@ +(* This file is part of Luv, released under the MIT license. See LICENSE.md for + details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) + + +module Types = Types_generated + +(* We want to be able to call some of the libuv functions with the OCaml + runtime lock released, in some circumstances. For that, we have Ctypes + generate separate stubs that release the lock. + + The functions in this module are called with the runtime lock RELEASED. *) + +module Functions(F : Ctypes.FOREIGN) = struct + open Ctypes + open F + + let error_code = int + + module Loop = + struct + let run = + foreign "uv_run" + (ptr Types.Loop.t @-> Types.Loop.Run_mode.t @-> returning bool) + end + + (* See https://github.com/ocsigen/lwt/issues/230. *) + module Pipe = + struct + let bind = + foreign "uv_pipe_bind" + (ptr Types.Pipe.t @-> string @-> returning error_code) + end + + (* Synchronous (callback = NULL) calls to these functions are blocking, so we + have to release the OCaml runtime lock. Technically, asychronous calls are + non-blocking, and we don't have to release the lock. However, supporting + both variants would take a bit of extra code to implement, so it's best to + see if there is a need. For now, we release the runtime lock during the + asychronous calls as well. *) + module File = + struct + let t = int + let uid = int + let gid = int + let request = Types.File.Request.t + + type trampoline = (Types.File.Request.t ptr -> unit) static_funptr + + let trampoline : trampoline typ = + static_funptr + Ctypes.(ptr request @-> returning void) + + let get_trampoline = + foreign "luv_get_fs_trampoline" + (void @-> returning trampoline) + + let get_null_callback = + foreign "luv_null_fs_callback_pointer" + (void @-> returning trampoline) + + let req_cleanup = + foreign "uv_fs_req_cleanup" + (ptr request @-> returning void) + + let close = + foreign "uv_fs_close" + (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> + returning error_code) + + let open_ = + foreign "uv_fs_open" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + int @-> + int @-> + trampoline @-> + returning error_code) + + let read = + foreign "uv_fs_read" + (ptr Types.Loop.t @-> + ptr request @-> + t @-> + ptr Types.Buf.t @-> + uint @-> + int64_t @-> + trampoline @-> + returning error_code) + + let write = + foreign "uv_fs_write" + (ptr Types.Loop.t @-> + ptr request @-> + t @-> + ptr Types.Buf.t @-> + uint @-> + int64_t @-> + trampoline @-> + returning error_code) + + let unlink = + foreign "uv_fs_unlink" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let mkdir = + foreign "uv_fs_mkdir" + (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> + returning error_code) + + let mkdtemp = + foreign "uv_fs_mkdtemp" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let mkstemp = + foreign "uv_fs_mkstemp" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let rmdir = + foreign "uv_fs_rmdir" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let opendir = + foreign "uv_fs_opendir" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let closedir = + foreign "uv_fs_closedir" + (ptr Types.Loop.t @-> + ptr request @-> + ptr Types.File.Dir.t @-> + trampoline @-> + returning error_code) + + let readdir = + foreign "uv_fs_readdir" + (ptr Types.Loop.t @-> + ptr request @-> + ptr Types.File.Dir.t @-> + trampoline @-> + returning error_code) + + let scandir = + foreign "uv_fs_scandir" + (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> + returning error_code) + + let scandir_next = + foreign "uv_fs_scandir_next" + (ptr request @-> ptr Types.File.Dirent.t @-> returning error_code) + + let stat = + foreign "uv_fs_stat" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let lstat = + foreign "uv_fs_lstat" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let fstat = + foreign "uv_fs_fstat" + (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> + returning error_code) + + let statfs = + foreign "uv_fs_statfs" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let rename = + foreign "uv_fs_rename" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + string @-> + trampoline @-> + returning error_code) + + let fsync = + foreign "uv_fs_fsync" + (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> + returning error_code) + + let fdatasync = + foreign "uv_fs_fdatasync" + (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> + returning error_code) + + let ftruncate = + foreign "uv_fs_ftruncate" + (ptr Types.Loop.t @-> ptr request @-> t @-> int64_t @-> trampoline @-> + returning error_code) + + let copyfile = + foreign "uv_fs_copyfile" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + string @-> + int @-> + trampoline @-> + returning error_code) + + let sendfile = + foreign "uv_fs_sendfile" + (ptr Types.Loop.t @-> + ptr request @-> + t @-> + t @-> + int64_t @-> + size_t @-> + trampoline @-> + returning error_code) + + let access = + foreign "uv_fs_access" + (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> + returning error_code) + + let chmod = + foreign "uv_fs_chmod" + (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> + returning error_code) + + let fchmod = + foreign "uv_fs_fchmod" + (ptr Types.Loop.t @-> ptr request @-> t @-> int @-> trampoline @-> + returning error_code) + + let utime = + foreign "uv_fs_utime" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + float @-> + float @-> + trampoline @-> + returning error_code) + + let futime = + foreign "uv_fs_futime" + (ptr Types.Loop.t @-> + ptr request @-> + t @-> + float @-> + float @-> + trampoline @-> + returning error_code) + + let lutime = + foreign "uv_fs_lutime" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + float @-> + float @-> + trampoline @-> + returning error_code) + + let link = + foreign "uv_fs_link" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + string @-> + trampoline @-> + returning error_code) + + let symlink = + foreign "uv_fs_symlink" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + string @-> + int @-> + trampoline @-> + returning error_code) + + let readlink = + foreign "uv_fs_readlink" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let realpath = + foreign "uv_fs_realpath" + (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> + returning error_code) + + let chown = + foreign "uv_fs_chown" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + uid @-> + gid @-> + trampoline @-> + returning error_code) + + let fchown = + foreign "uv_fs_fchown" + (ptr Types.Loop.t @-> + ptr request @-> + t @-> + uid @-> + gid @-> + trampoline @-> + returning error_code) + + let lchown = + foreign "uv_fs_lchown" + (ptr Types.Loop.t @-> + ptr request @-> + string @-> + uid @-> + gid @-> + trampoline @-> + returning error_code) + + let get_result = + foreign "uv_fs_get_result" + (ptr request @-> returning PosixTypes.ssize_t) + + let get_ptr = + foreign "uv_fs_get_ptr" + (ptr request @-> returning (ptr void)) + + let get_ptr_as_string = + foreign "uv_fs_get_ptr" + (ptr request @-> returning string) + + let get_path = + foreign "luv_fs_get_path" + (ptr request @-> returning string) + + let get_statbuf = + foreign "uv_fs_get_statbuf" + (ptr request @-> returning (ptr Types.File.Stat.t)) + end + + module Thread = + struct + let join = + foreign "uv_thread_join" + (ptr Types.Thread.t @-> returning error_code) + end + + module Mutex = + struct + let lock = + foreign "uv_mutex_lock" + (ptr Types.Mutex.t @-> returning void) + end + + module Rwlock = + struct + let rdlock = + foreign "uv_rwlock_rdlock" + (ptr Types.Rwlock.t @-> returning void) + + let wrlock = + foreign "uv_rwlock_wrlock" + (ptr Types.Rwlock.t @-> returning void) + end + + module Semaphore = + struct + let wait = + foreign "uv_sem_wait" + (ptr Types.Semaphore.t @-> returning void) + end + + module Condition = + struct + let wait = + foreign "uv_cond_wait" + (ptr Types.Condition.t @-> ptr Types.Mutex.t @-> returning void) + + let timedwait = + foreign "uv_cond_timedwait" + (ptr Types.Condition.t @-> ptr Types.Mutex.t @-> uint64_t @-> + returning error_code) + end + + module Barrier = + struct + let wait = + foreign "uv_barrier_wait" + (ptr Types.Barrier.t @-> returning bool) + end + + module Time = + struct + let sleep = + foreign "uv_sleep" + (int @-> returning void) + end + + module Random = + struct + let request = Types.Random.Request.t + + let trampoline = + static_funptr + Ctypes.(ptr request @-> error_code @-> ptr void @-> size_t @-> + returning void) + let random = + foreign "uv_random" + (ptr Types.Loop.t @-> + ptr request @-> + ptr char @-> + size_t @-> + uint @-> + trampoline @-> + returning error_code) + end +end diff --git a/src/c/dune b/src/c/dune index 4bc017fc..22d779b3 100644 --- a/src/c/dune +++ b/src/c/dune @@ -1,41 +1,78 @@ (* -*- tuareg -*- *) -let foreign_archives, uv_library_flag, include_dirs, i_option, install_h = - let use_system_libuv = - match Sys.getenv "LUV_USE_SYSTEM_LIBUV" with - | "yes" -> true - | _ -> false - | exception Not_found -> false - in - - if use_system_libuv then - "", - "-luv", - "", - "", - false - else - "(foreign_archives uv)", - "", - "(include_dirs vendor/libuv/include)", - "-I vendor/libuv/include", - true +let libuv_resolve = + match Sys.getenv "LUV_USE_SYSTEM_LIBUV" with + | "pkg_config" | "pkg-config" -> `pkg_config + | "yes" -> `system_luv + | _ -> `vendored + | exception Not_found -> `vendored + +let build_flags_resolver_stanza = + match libuv_resolve with + | `pkg_config -> "(build_flags_resolver (pkg_config))" + | `vendored -> + {|(build_flags_resolver + (vendored + (c_flags (-fPIC -I vendor/libuv/include -I src/c/vendor/libuv/include)) + (c_library_flags ())))|} + | `system_luv -> + (* older, non-pkg-config way of using the system luv *) + {|(build_flags_resolver + (vendored + (c_flags ()) + (c_library_flags (-luv))))|} + +let foreign_archives_stanza = + match libuv_resolve with + | `vendored -> "(foreign_archives uv)" + | `pkg_config -> "" + | `system_luv -> "" + +let include_dirs_stanza = + match libuv_resolve with + | `vendored -> "(include_dirs vendor/libuv/include)" + | `pkg_config -> "" + | `system_luv -> "" + +let install_h = + match libuv_resolve with + | `vendored -> true + | `pkg_config -> false + | `system_luv -> false let () = Jbuild_plugin.V1.send @@ {| - -; The final FFI module, containing all the OCaml bits, and linked with libuv. (library - (name luv_c) - (public_name luv.c) - (wrapped false) - (modules Luv_c_generated_functions) - (libraries ctypes luv_c_function_descriptions threads) - (foreign_stubs - (language c) - (names c_generated_functions helpers) - |}^ include_dirs ^{|) - |}^ foreign_archives ^{| - (c_library_flags |}^ uv_library_flag ^{| (:include extra_libs.sexp))) + (name luv_c) + (public_name luv.c) + (libraries threads) + ; ctypes code-gen produces code that warns due to backward compatibility + (flags (:standard -w -9-11-27)) + (foreign_stubs + (language c) + (names helpers)|} + ^ include_dirs_stanza ^ {|) + |} ^ foreign_archives_stanza ^ {| + (ctypes + (external_library_name libuv) + |} ^ build_flags_resolver_stanza ^ {| + (type_description + (instance Types) + (functor Type_description)) + (function_description + (concurrency unlocked) + (instance Blocking) + (functor Blocking_function_description)) + (function_description + (concurrency sequential) + (instance Non_blocking) + (functor Non_blocking_function_description)) + (generated_entry_point C) + (headers (preamble "#include \"windows_version.h\" +#include +#include +#include +#include \"helpers.h\" +")))) |}^ (if not install_h then "" else {| @@ -61,9 +98,6 @@ let () = Jbuild_plugin.V1.send @@ {| (vendor/libuv/include/uv/win.h as uv/win.h))) |}) ^{| - - - ; The vendored libuv. (rule (targets libuv.a dlluv%{ext_dll}) @@ -94,68 +128,4 @@ let () = Jbuild_plugin.V1.send @@ {| else \ echo '()' > extra_libs.sexp; \ fi")))) - - - -; Everything below is the bindings generation process using ctypes. It produces -; two OCaml modules, Luv_c_generated_functions and Luv_c_generated_types. - -; Type bindings (Luv_c_generated_types). -(library - (name luv_c_type_descriptions) - (public_name luv.c_type_descriptions) - (modules Luv_c_type_descriptions) - (libraries ctypes)) - -(executable - (name generate_types_start) - (modules Generate_types_start) - (libraries ctypes.stubs luv_c_type_descriptions)) - -(rule - (with-stdout-to generate_types_step_2.c - (run ./generate_types_start.exe))) - -; Based partially on -; https://github.com/avsm/ocaml-yaml/blob/master/types/stubgen/jbuild#L20 -(rule - (targets generate_types_step_2.exe) - (deps (:c generate_types_step_2.c) helpers.h shims.h) - (action (bash "\ - %{cc} %{c} \ - -I '%{lib:ctypes:.}' \ - -I %{ocaml_where} \ - |}^ i_option ^{| -o %{targets}"))) - -(rule - (with-stdout-to luv_c_generated_types.ml - (run ./generate_types_step_2.exe))) - -; Function bindings. -(library - (name luv_c_function_descriptions) - (public_name luv.c_function_descriptions) - (flags (:standard -w -9-16-27)) - (wrapped false) - (modules Luv_c_generated_types Luv_c_function_descriptions Luv_c_types) - (libraries ctypes luv_c_type_descriptions)) - -(executable - (name generate_c_functions) - (modules Generate_c_functions) - (libraries ctypes.stubs luv_c_function_descriptions)) - -(executable - (name generate_ml_functions) - (modules Generate_ml_functions) - (libraries ctypes.stubs luv_c_function_descriptions)) - -(rule - (with-stdout-to c_generated_functions.c - (run ./generate_c_functions.exe luv_stub))) - -(rule - (with-stdout-to luv_c_generated_functions.ml - (run ./generate_ml_functions.exe luv_stub))) - |} diff --git a/src/c/generate_c_functions.ml b/src/c/generate_c_functions.ml deleted file mode 100644 index 468fa204..00000000 --- a/src/c/generate_c_functions.ml +++ /dev/null @@ -1,24 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -let () = - print_endline "#include \"windows_version.h\""; - print_endline "#include "; - print_endline "#include "; - print_endline "#include "; - print_endline "#include "; - print_endline "#include "; - print_endline "#include \"helpers.h\""; - - Cstubs.write_c - Format.std_formatter - ~prefix:Sys.argv.(1) - (module Luv_c_function_descriptions.Descriptions); - - Cstubs.write_c - ~concurrency:Cstubs.unlocked - Format.std_formatter - ~prefix:(Sys.argv.(1) ^ "_blocking") - (module Luv_c_function_descriptions.Blocking) diff --git a/src/c/generate_ml_functions.ml b/src/c/generate_ml_functions.ml deleted file mode 100644 index 051aaac7..00000000 --- a/src/c/generate_ml_functions.ml +++ /dev/null @@ -1,26 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -let () = - print_endline "module Non_blocking ="; - print_endline "struct"; - - Cstubs.write_ml - Format.std_formatter - ~prefix:Sys.argv.(1) - (module Luv_c_function_descriptions.Descriptions); - - print_endline "end"; - print_newline (); - print_endline "module Blocking ="; - print_endline "struct"; - - Cstubs.write_ml - ~concurrency:Cstubs.unlocked - Format.std_formatter - ~prefix:Sys.(argv.(1) ^ "_blocking") - (module Luv_c_function_descriptions.Blocking); - - print_endline "end" diff --git a/src/c/generate_types_start.ml b/src/c/generate_types_start.ml deleted file mode 100644 index 8fcc92c7..00000000 --- a/src/c/generate_types_start.ml +++ /dev/null @@ -1,14 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -let () = - print_endline "#include \"windows_version.h\""; - print_endline "#include "; - print_endline "#include "; - print_endline "#include "; - print_endline "#include \"helpers.h\""; - - Cstubs_structs.write_c - Format.std_formatter (module Luv_c_type_descriptions.Descriptions) diff --git a/src/c/luv_c_types.ml b/src/c/luv_c_types.ml deleted file mode 100644 index 16da4a63..00000000 --- a/src/c/luv_c_types.ml +++ /dev/null @@ -1,6 +0,0 @@ -(* This file is part of Luv, released under the MIT license. See LICENSE.md for - details, or visit https://github.com/aantron/luv/blob/master/LICENSE.md. *) - - - -include Luv_c_type_descriptions.Descriptions (Luv_c_generated_types) diff --git a/src/c/luv_c_function_descriptions.ml b/src/c/non_blocking_function_description.ml similarity index 73% rename from src/c/luv_c_function_descriptions.ml rename to src/c/non_blocking_function_description.ml index 89e18203..0dcd2f66 100644 --- a/src/c/luv_c_function_descriptions.ml +++ b/src/c/non_blocking_function_description.ml @@ -3,437 +3,15 @@ -(* Everything is in one file to cut down on Dune boilerplate, as it would grow - proportionally in the number of files the bindings are spread over. - https://github.com/ocaml/dune/issues/135. *) +module Types = Types_generated -module Types = Luv_c_types +module Functions(F : Ctypes.FOREIGN) = struct + (* We want to be able to call some of the libuv functions with the OCaml + runtime lock released, in some circumstances. For that, we have Ctypes + generate separate stubs that release the lock. -(* We want to be able to call some of the libuv functions with the OCaml runtime - lock released, in some circumstances. For that, we have Ctypes generate - separate stubs that release the lock. + The functions in this file are called with the runtime lock HELD. *) - However, releasing the lock is not possible for some kinds of arguments. So, - we can't blindly generate lock-releasing and lock-retaining versions of each - binding. - - Instead, we group the lock-releasing bindings in this module [Blocking]. *) -module Blocking (F : Ctypes.FOREIGN) = -struct - open Ctypes - open F - - let error_code = int - - module Loop = - struct - let run = - foreign "uv_run" - (ptr Types.Loop.t @-> Types.Loop.Run_mode.t @-> returning bool) - end - - (* See https://github.com/ocsigen/lwt/issues/230. *) - module Pipe = - struct - let bind = - foreign "uv_pipe_bind" - (ptr Types.Pipe.t @-> string @-> returning error_code) - end - - (* Synchronous (callback = NULL) calls to these functions are blocking, so we - have to release the OCaml runtime lock. Technically, asychronous calls are - non-blocking, and we don't have to release the lock. However, supporting - both variants would take a bit of extra code to implement, so it's best to - see if there is a need. For now, we release the runtime lock during the - asychronous calls as well. *) - module File = - struct - let t = int - let uid = int - let gid = int - let request = Types.File.Request.t - - type trampoline = (Types.File.Request.t ptr -> unit) static_funptr - - let trampoline : trampoline typ = - static_funptr - Ctypes.(ptr request @-> returning void) - - let get_trampoline = - foreign "luv_get_fs_trampoline" - (void @-> returning trampoline) - - let get_null_callback = - foreign "luv_null_fs_callback_pointer" - (void @-> returning trampoline) - - let req_cleanup = - foreign "uv_fs_req_cleanup" - (ptr request @-> returning void) - - let close = - foreign "uv_fs_close" - (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> - returning error_code) - - let open_ = - foreign "uv_fs_open" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - int @-> - int @-> - trampoline @-> - returning error_code) - - let read = - foreign "uv_fs_read" - (ptr Types.Loop.t @-> - ptr request @-> - t @-> - ptr Types.Buf.t @-> - uint @-> - int64_t @-> - trampoline @-> - returning error_code) - - let write = - foreign "uv_fs_write" - (ptr Types.Loop.t @-> - ptr request @-> - t @-> - ptr Types.Buf.t @-> - uint @-> - int64_t @-> - trampoline @-> - returning error_code) - - let unlink = - foreign "uv_fs_unlink" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let mkdir = - foreign "uv_fs_mkdir" - (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> - returning error_code) - - let mkdtemp = - foreign "uv_fs_mkdtemp" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let mkstemp = - foreign "uv_fs_mkstemp" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let rmdir = - foreign "uv_fs_rmdir" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let opendir = - foreign "uv_fs_opendir" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let closedir = - foreign "uv_fs_closedir" - (ptr Types.Loop.t @-> - ptr request @-> - ptr Types.File.Dir.t @-> - trampoline @-> - returning error_code) - - let readdir = - foreign "uv_fs_readdir" - (ptr Types.Loop.t @-> - ptr request @-> - ptr Types.File.Dir.t @-> - trampoline @-> - returning error_code) - - let scandir = - foreign "uv_fs_scandir" - (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> - returning error_code) - - let scandir_next = - foreign "uv_fs_scandir_next" - (ptr request @-> ptr Types.File.Dirent.t @-> returning error_code) - - let stat = - foreign "uv_fs_stat" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let lstat = - foreign "uv_fs_lstat" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let fstat = - foreign "uv_fs_fstat" - (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> - returning error_code) - - let statfs = - foreign "uv_fs_statfs" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let rename = - foreign "uv_fs_rename" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - string @-> - trampoline @-> - returning error_code) - - let fsync = - foreign "uv_fs_fsync" - (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> - returning error_code) - - let fdatasync = - foreign "uv_fs_fdatasync" - (ptr Types.Loop.t @-> ptr request @-> t @-> trampoline @-> - returning error_code) - - let ftruncate = - foreign "uv_fs_ftruncate" - (ptr Types.Loop.t @-> ptr request @-> t @-> int64_t @-> trampoline @-> - returning error_code) - - let copyfile = - foreign "uv_fs_copyfile" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - string @-> - int @-> - trampoline @-> - returning error_code) - - let sendfile = - foreign "uv_fs_sendfile" - (ptr Types.Loop.t @-> - ptr request @-> - t @-> - t @-> - int64_t @-> - size_t @-> - trampoline @-> - returning error_code) - - let access = - foreign "uv_fs_access" - (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> - returning error_code) - - let chmod = - foreign "uv_fs_chmod" - (ptr Types.Loop.t @-> ptr request @-> string @-> int @-> trampoline @-> - returning error_code) - - let fchmod = - foreign "uv_fs_fchmod" - (ptr Types.Loop.t @-> ptr request @-> t @-> int @-> trampoline @-> - returning error_code) - - let utime = - foreign "uv_fs_utime" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - float @-> - float @-> - trampoline @-> - returning error_code) - - let futime = - foreign "uv_fs_futime" - (ptr Types.Loop.t @-> - ptr request @-> - t @-> - float @-> - float @-> - trampoline @-> - returning error_code) - - let lutime = - foreign "uv_fs_lutime" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - float @-> - float @-> - trampoline @-> - returning error_code) - - let link = - foreign "uv_fs_link" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - string @-> - trampoline @-> - returning error_code) - - let symlink = - foreign "uv_fs_symlink" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - string @-> - int @-> - trampoline @-> - returning error_code) - - let readlink = - foreign "uv_fs_readlink" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let realpath = - foreign "uv_fs_realpath" - (ptr Types.Loop.t @-> ptr request @-> string @-> trampoline @-> - returning error_code) - - let chown = - foreign "uv_fs_chown" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - uid @-> - gid @-> - trampoline @-> - returning error_code) - - let fchown = - foreign "uv_fs_fchown" - (ptr Types.Loop.t @-> - ptr request @-> - t @-> - uid @-> - gid @-> - trampoline @-> - returning error_code) - - let lchown = - foreign "uv_fs_lchown" - (ptr Types.Loop.t @-> - ptr request @-> - string @-> - uid @-> - gid @-> - trampoline @-> - returning error_code) - - let get_result = - foreign "uv_fs_get_result" - (ptr request @-> returning PosixTypes.ssize_t) - - let get_ptr = - foreign "uv_fs_get_ptr" - (ptr request @-> returning (ptr void)) - - let get_ptr_as_string = - foreign "uv_fs_get_ptr" - (ptr request @-> returning string) - - let get_path = - foreign "luv_fs_get_path" - (ptr request @-> returning string) - - let get_statbuf = - foreign "uv_fs_get_statbuf" - (ptr request @-> returning (ptr Types.File.Stat.t)) - end - - module Thread = - struct - let join = - foreign "uv_thread_join" - (ptr Types.Thread.t @-> returning error_code) - end - - module Mutex = - struct - let lock = - foreign "uv_mutex_lock" - (ptr Types.Mutex.t @-> returning void) - end - - module Rwlock = - struct - let rdlock = - foreign "uv_rwlock_rdlock" - (ptr Types.Rwlock.t @-> returning void) - - let wrlock = - foreign "uv_rwlock_wrlock" - (ptr Types.Rwlock.t @-> returning void) - end - - module Semaphore = - struct - let wait = - foreign "uv_sem_wait" - (ptr Types.Semaphore.t @-> returning void) - end - - module Condition = - struct - let wait = - foreign "uv_cond_wait" - (ptr Types.Condition.t @-> ptr Types.Mutex.t @-> returning void) - - let timedwait = - foreign "uv_cond_timedwait" - (ptr Types.Condition.t @-> ptr Types.Mutex.t @-> uint64_t @-> - returning error_code) - end - - module Barrier = - struct - let wait = - foreign "uv_barrier_wait" - (ptr Types.Barrier.t @-> returning bool) - end - - module Time = - struct - let sleep = - foreign "uv_sleep" - (int @-> returning void) - end - - module Random = - struct - let request = Types.Random.Request.t - - let trampoline = - static_funptr - Ctypes.(ptr request @-> error_code @-> ptr void @-> size_t @-> - returning void) - - let random = - foreign "uv_random" - (ptr Types.Loop.t @-> - ptr request @-> - ptr char @-> - size_t @-> - uint @-> - trampoline @-> - returning error_code) - end -end - -module Descriptions (F : Ctypes.FOREIGN) = -struct open Ctypes open F @@ -627,7 +205,7 @@ struct let start = foreign "uv_timer_start" (ptr t @-> trampoline @-> uint64_t @-> uint64_t @-> - returning error_code) + returning error_code) let stop = foreign "uv_timer_stop" @@ -811,7 +389,7 @@ struct let trampoline = static_funptr Ctypes.(ptr Types.Stream.Connect_request.t @-> error_code @-> - returning void) + returning void) let get_trampoline = foreign "luv_get_connect_trampoline" @@ -823,7 +401,7 @@ struct let trampoline = static_funptr Ctypes.(ptr Types.Stream.Shutdown_request.t @-> error_code @-> - returning void) + returning void) let get_trampoline = foreign "luv_get_shutdown_trampoline" @@ -835,7 +413,7 @@ struct let trampoline = static_funptr Ctypes.(ptr Types.Stream.Write_request.t @-> error_code @-> - returning void) + returning void) let get_trampoline = foreign "luv_get_write_trampoline" @@ -851,7 +429,7 @@ struct let read_trampoline = static_funptr Ctypes.(ptr t @-> PosixTypes.ssize_t @-> ptr Types.Buf.t @-> - returning void) + returning void) let get_connection_trampoline = foreign "luv_get_connection_trampoline" @@ -866,7 +444,7 @@ struct (ptr Types.Stream.Shutdown_request.t @-> ptr t @-> Shutdown_request.trampoline @-> - returning error_code) + returning error_code) let listen = foreign "uv_listen" @@ -879,7 +457,7 @@ struct let read_start = foreign "luv_read_start" (ptr t @-> Handle.alloc_trampoline @-> read_trampoline @-> - returning error_code) + returning error_code) let read_stop = foreign "uv_read_stop" @@ -893,7 +471,7 @@ struct uint @-> ptr t @-> Write_request.trampoline @-> - returning error_code) + returning error_code) let try_write = foreign "uv_try_write" @@ -935,7 +513,7 @@ struct let socketpair = foreign "uv_socketpair" (int @-> int @-> ptr Types.Os_socket.t @-> int @-> int @-> - returning error_code) + returning error_code) let nodelay = foreign "uv_tcp_nodelay" @@ -967,7 +545,7 @@ struct ptr t @-> ptr Types.Sockaddr.t @-> Stream.Connect_request.trampoline @-> - returning error_code) + returning error_code) let close_reset = foreign "uv_tcp_close_reset" @@ -996,7 +574,7 @@ struct ptr t @-> ocaml_string @-> Stream.Connect_request.trampoline @-> - returning void) + returning void) let getsockname = foreign "uv_pipe_getsockname" @@ -1087,7 +665,7 @@ struct let set_membership = foreign "uv_udp_set_membership" (ptr t @-> ocaml_string @-> ocaml_string @-> Types.UDP.Membership.t @-> - returning error_code) + returning error_code) let set_source_membership = foreign "uv_udp_set_source_membership" @@ -1096,7 +674,7 @@ struct ocaml_string @-> ocaml_string @-> Types.UDP.Membership.t @-> - returning error_code) + returning error_code) let set_multicast_loop = foreign "uv_udp_set_multicast_loop" @@ -1123,7 +701,7 @@ struct let trampoline = static_funptr Ctypes.(ptr Types.UDP.Send_request.t @-> error_code @-> - returning void) + returning void) let get_trampoline = foreign "luv_get_send_trampoline" @@ -1138,12 +716,12 @@ struct uint @-> ptr Types.Sockaddr.t @-> Send_request.trampoline @-> - returning error_code) + returning error_code) let try_send = foreign "uv_udp_try_send" (ptr t @-> ptr Types.Buf.t @-> uint @-> ptr Types.Sockaddr.t @-> - returning error_code) + returning error_code) let recv_trampoline = static_funptr @@ -1153,7 +731,7 @@ struct ptr Types.Buf.t @-> ptr Types.Sockaddr.t @-> uint @-> - returning void) + returning void) let get_recv_trampoline = foreign "luv_get_recv_trampoline" @@ -1162,7 +740,7 @@ struct let recv_start = foreign "luv_udp_recv_start" (ptr t @-> Handle.alloc_trampoline @-> recv_trampoline @-> - returning error_code) + returning error_code) let recv_stop = foreign "uv_udp_recv_stop" @@ -1219,7 +797,7 @@ struct ptr Types.Process.Redirection.t @-> int @-> int @-> - returning error_code) + returning error_code) let process_kill = foreign "uv_process_kill" @@ -1270,7 +848,7 @@ struct error_code @-> ptr Types.File.Stat.t @-> ptr Types.File.Stat.t @-> - returning void) + returning void) let get_trampoline = foreign "luv_get_fs_poll_trampoline" @@ -1312,7 +890,7 @@ struct string_opt @-> string_opt @-> ptr addrinfo @-> - returning error_code) + returning error_code) let free = foreign "uv_freeaddrinfo" @@ -1338,7 +916,7 @@ struct trampoline @-> ptr Types.Sockaddr.t @-> int @-> - returning error_code) + returning error_code) end end @@ -1420,7 +998,7 @@ struct let queue = foreign "uv_queue_work" (ptr Loop.t @-> ptr t @-> work_trampoline @-> after_work_trampoline @-> - returning error_code) + returning error_code) end module Thread = @@ -1439,12 +1017,12 @@ struct let create = foreign "uv_thread_create_ex" (ptr t @-> ptr options @-> trampoline @-> ptr void @-> - returning error_code) + returning error_code) let create_c = foreign "luv_thread_create_c" (ptr t @-> ptr options @-> nativeint @-> nativeint @-> - returning error_code) + returning error_code) let self = foreign "uv_thread_self" @@ -1611,27 +1189,27 @@ struct let ip4_addr = foreign "uv_ip4_addr" (ocaml_string @-> int @-> ptr Types.Sockaddr.in_ @-> - returning error_code) + returning error_code) let ip6_addr = foreign "uv_ip6_addr" (ocaml_string @-> int @-> ptr Types.Sockaddr.in6 @-> - returning error_code) + returning error_code) let ip4_name = foreign "uv_ip4_name" (ptr Types.Sockaddr.in_ @-> ocaml_bytes @-> size_t @-> - returning error_code) + returning error_code) let ip6_name = foreign "uv_ip6_name" (ptr Types.Sockaddr.in6 @-> ocaml_bytes @-> size_t @-> - returning error_code) + returning error_code) let memcpy_from_sockaddr = foreign "memcpy" (ptr Types.Sockaddr.storage @-> ptr Types.Sockaddr.t @-> int @-> - returning void) + returning void) let ntohs = foreign "ntohs" @@ -1706,7 +1284,7 @@ struct let interface_addresses = foreign "uv_interface_addresses" (ptr (ptr Types.Network.Interface_address.t) @-> ptr int @-> - returning error_code) + returning error_code) let free_interface_addresses = foreign "uv_free_interface_addresses" @@ -1809,7 +1387,7 @@ struct let trampoline = static_funptr Ctypes.(ptr request @-> error_code @-> ptr void @-> size_t @-> - returning void) + returning void) let get_trampoline = foreign "luv_get_random_trampoline" @@ -1827,7 +1405,7 @@ struct size_t @-> uint @-> trampoline @-> - returning error_code) + returning error_code) end module Metrics = diff --git a/src/c/luv_c_type_descriptions.ml b/src/c/type_description.ml similarity index 99% rename from src/c/luv_c_type_descriptions.ml rename to src/c/type_description.ml index d2047f06..f24035b1 100644 --- a/src/c/luv_c_type_descriptions.ml +++ b/src/c/type_description.ml @@ -7,7 +7,7 @@ proportionally in the number of files the bindings are spread over. https://github.com/ocaml/dune/issues/135. *) -module Descriptions (F : Ctypes.TYPE) = +module Types (F : Ctypes.TYPE) = struct open Ctypes open F diff --git a/src/feature/detect_features.ml b/src/feature/detect_features.ml index 2c31040e..0145747c 100644 --- a/src/feature/detect_features.ml +++ b/src/feature/detect_features.ml @@ -215,7 +215,7 @@ let () = let ml_buffer = Buffer.create 4096 in fixed_ml max_int ml_buffer; - let version = Luv_c_types.Version.minor in + let version = Luv_c.C.Types.Version.minor in let context = mli_buffer, ml_buffer in let int = int context in