package ctypes-foreign

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

Install

Authors

Maintainers

Sources

0.21.1.tar.gz
md5=8b201d932741c5096854e5eb39139b90

Description

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

Tags

org:mirage

Published: 21 Jul 2023

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 (89)

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

Conflicts

None