Movatterモバイル変換


[0]ホーム

URL:


packagectypes-foreign

  1. Overview
  2. Docs

You can search for identifiers within the package.

in-package search v0.2.0

Dynamic access to foreign C libraries using Ctypes

Install

Dune Dependency

Authors

Maintainers

Sources

0.23.0.tar.gz
sha256=cae47d815b27dd4c824a007f1145856044542fe2588d23a443ef4eefec360bf1
md5=b1af973ec9cf7867a63714e92df82f2a

Description

This installs thectypes-foreign interface whichuseslibffi to provide dynamic access to foreign libraries.

Tags

org:mirage

Published:16 Aug 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 theusual 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 ofsigset_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. odocwith-doc
  2. conf-ftswith-test & os != "win32"
  3. stdlib-shimswith-test
  4. conf-ncurseswith-test
  5. ounit2with-test
  6. lwtwith-test & >= "2.4.7"
  7. integerswith-test & >= "0.2.2"

Used by (84)

  1. argon2
  2. arrayjit
  3. async_ssl
  4. bimage-unix
  5. bls12-381= "0.3.15"
  6. bls12-381-legacy< "0.4.4"
  7. bls12-381-unix< "1.0.2"
  8. camlkit-base
  9. cf
  10. checked_oint< "0.4.1"
  11. cmark
  12. cmarker
  13. corosync
  14. ctypes< "0.21.1"
  15. ctypes-zarith
  16. cudajit
  17. directories< "0.3"
  18. extism
  19. flock
  20. gccjit
  21. gdal
  22. gobject-introspection
  23. gpiod
  24. gr
  25. guile
  26. hacl-star-raw< "0.4.4"
  27. hardcaml_c
  28. hardcaml_verilator
  29. hdr_histogram
  30. imguiml
  31. libbpf_maps
  32. libdash
  33. libirmin
  34. libudev
  35. lilv
  36. llama-cpp-ocaml
  37. lmdb< "1.0"
  38. lp-glpk< "0.4.0"
  39. lp-gurobi
  40. memtrace_viewer< "v0.15.0"
  41. mmdb
  42. mpg123
  43. netlink
  44. ocephes
  45. octez-l2-libs
  46. opasswd
  47. opencc< "transition"
  48. opencc0
  49. opencc1
  50. opencc1_1
  51. orocksdb
  52. osx-cf
  53. osx-secure-transport
  54. pari
  55. pari-bindings
  56. pg_query
  57. pkcs11-driver
  58. pkcs11-rev
  59. portaudio_c_bindings
  60. portmidi
  61. posix-getopt< "2.0.0"
  62. py
  63. qcstm>= "0.1.1"
  64. reed-solomon-erasure
  65. sarek
  66. sattools
  67. sodium< "0.6.0"
  68. spoc
  69. srt>= "0.2.2"
  70. stk_iconv
  71. swipl
  72. tensorflow
  73. tezos-wasmer
  74. tgls
  75. torch
  76. tsdl
  77. tsdl-image
  78. tsdl-mixer
  79. tsdl-ttf
  80. unix-type-representations< "0.1.1"
  81. wasmer
  82. wasmtime
  83. yara
  84. yices2_bindings

Conflicts

None


[8]ページ先頭

©2009-2025 Movatter.jp