package ctypes-foreign

  1. Overview
  2. Docs
Dynamic access to foreign C libraries using Ctypes

Install

Dune Dependency

Authors

Maintainers

Sources

0.22.0.tar.gz
sha256=aa797c5d6bcaee8883aece2d1d9a524fc1f63c78c1538b0fe69969c0e989419f
md5=8a301a3e3b79156448a6659859ad506c

Description

This installs the ctypes-foreign interface which uses libffi to provide dynamic access to foreign libraries.

Tags

org:mirage

Published: 19 Feb 2024

README

README.md

ctypes is a library for binding to C libraries using pure OCaml. The primary aim is to make writing C extensions as straightforward as possible.

The core of ctypes is a set of combinators for describing the structure of C types -- numeric types, arrays, pointers, structs, unions and functions. You can use these combinators to describe the types of the functions that you want to call, then bind directly to those functions -- all without writing or generating any C!

Usage

Suppose you want to bind to the following C functions:

   int sigemptyset(sigset_t *set);
   int sigfillset(sigset_t *set);
   int sigaddset(sigset_t *set, int signum);
   int sigdelset(sigset_t *set, int signum);
   int sigismember(const sigset_t *set, int signum);

Using ctypes you can describe the interfaces to these functions as follows:

   let sigemptyset = foreign "sigemptyset" (ptr sigset_t @-> returning int)
   let sigfillset = foreign "sigfillset" (ptr sigset_t @-> returning int)
   let sigaddset = foreign "sigaddset" (ptr sigset_t @-> int @-> returning int)
   let sigdelset = foreign "sigdelset" (ptr sigset_t @-> int @-> returning int)
   let sigismember = foreign "sigismember" (ptr sigset_t @-> int @-> returning int)

The names bound by this code have the types you might expect:

   val sigemptyset : sigset_t ptr -> int
   val sigfillset : sigset_t ptr -> int
   val sigaddset : sigset_t ptr -> int -> int
   val sigdelset : sigset_t ptr -> int -> int
   val sigismember : sigset_t ptr -> int -> int

That's all there is to it. Unlike the usual way of writing C extensions, there are no C "stub" functions to write, so there's much less opportunity for error.

The documentation and source distribution contain more complex examples, involving structs, unions, arrays, callback functions, and so on, and show how to create and use C values (like instances of sigset_t ptr) in OCaml.

Links

Dependencies (6)

  1. conf-libffi >= "2.0.0"
  2. conf-pkg-config
  3. dune-configurator
  4. ctypes = version
  5. ocaml >= "4.03.0"
  6. dune >= "2.9"

Dev Dependencies (7)

  1. odoc with-doc
  2. conf-fts with-test & os != "win32"
  3. stdlib-shims with-test
  4. conf-ncurses with-test
  5. ounit2 with-test
  6. lwt with-test & >= "2.4.7"
  7. integers with-test & >= "0.2.2"

Used by (97)

  1. arakoon >= "1.8.6" & < "1.8.12"
  2. argon2
  3. arrayjit
  4. async_ssl != "112.24.02" & < "113.33.05" | >= "v0.10.0"
  5. avroc
  6. bimage-unix
  7. bls12-381 = "0.3.15"
  8. bls12-381-legacy < "0.4.4"
  9. bls12-381-unix < "1.0.2"
  10. camlkit-base
  11. cf
  12. checked_oint
  13. cmark
  14. cmarker
  15. corosync
  16. ctypes >= "0.7.0" & < "0.21.1"
  17. ctypes-zarith
  18. cudajit
  19. directories < "0.3"
  20. extism
  21. flock
  22. gccjit
  23. gdal >= "0.3.0"
  24. gobject-introspection
  25. gpiod
  26. gr
  27. gsasl
  28. guile
  29. hacl-star-raw < "0.4.4"
  30. hardcaml-llvmsim
  31. hardcaml-vpi
  32. hardcaml_c
  33. hardcaml_verilator
  34. hdr_histogram
  35. imguiml
  36. iocaml >= "0.4.3"
  37. iocaml-kernel >= "0.4.4"
  38. libbpf_maps
  39. libdash
  40. libirmin
  41. libudev
  42. lilv
  43. llama-cpp-ocaml
  44. lmdb < "1.0"
  45. lp-glpk < "0.4.0"
  46. lp-gurobi
  47. mariadb < "1.1.4"
  48. memtrace_viewer < "v0.15.0"
  49. mmdb
  50. mpg123
  51. nanomsg
  52. nebula
  53. netlink >= "0.2.1"
  54. ocephes >= "0.8.1"
  55. octez-l2-libs
  56. opasswd >= "0.9.3"
  57. opencc < "transition"
  58. opencc0
  59. opencc1
  60. opencc1_1
  61. orocksdb
  62. osbx < "1.1.1"
  63. osx-cf
  64. osx-secure-transport
  65. pari
  66. pari-bindings
  67. pg_query
  68. pkcs11 < "0.9.0"
  69. pkcs11-driver
  70. pkcs11-rev
  71. portaudio_c_bindings
  72. portmidi
  73. posix-getopt < "2.0.0"
  74. py
  75. qcstm >= "0.1.1"
  76. reed-solomon-erasure
  77. sarek >= "20210823"
  78. sattools
  79. sodium >= "0.2.0" & < "0.3.0"
  80. spoc >= "20170724"
  81. srt >= "0.2.2"
  82. stk_iconv
  83. swipl
  84. tensorflow
  85. tezos-sapling >= "10.2" & < "13.0"
  86. tezos-wasmer
  87. tgls >= "0.8.3"
  88. torch
  89. tsdl >= "0.8.1"
  90. tsdl-image
  91. tsdl-mixer
  92. tsdl-ttf
  93. unix-type-representations < "0.1.1"
  94. wasmer
  95. wasmtime
  96. yara
  97. yices2_bindings

Conflicts

None

OCaml

Innovation. Community. Security.