Skip to content

Commit 3a54903

Browse files
committed
Add wiki to the the installed documentation
1 parent 80d8599 commit 3a54903

File tree

4 files changed

+176
-12
lines changed

4 files changed

+176
-12
lines changed

README.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
[![Build Status](https://github.com/cedlemo/OCaml-GObject-Introspection/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/cedlemo/OCaml-GObject-Introspection/actions)
22
[![License: GPL-3.0-or-later](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
33

4-
54
# gobject-introspection OCaml package
65

76
The OCaml bindings to the [GObject-Introspection](https://gi.readthedocs.io/en/latest/index.html) library based on Ctypes.
87

98
## Installation
109

11-
the package gobject-introspection is now published and available in the opam-repository:
10+
The package gobject-introspection is now published and available in the opam-repository:
1211

1312
```
1413
opam install gobject-introspection
1514
```
1615

17-
## API:
16+
## API
1817

19-
https://cedlemo.github.io/OCaml-GObject-Introspection/
18+
<https://cedlemo.github.io/OCaml-GObject-Introspection/>
2019

2120
## Usage
2221

2322
Two ideas to explore:
2423

2524
- Create a generic Ctypes bindings generator, based on ocaml-gobject-introspection,
26-
for the GNOME libraries : https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator
25+
for the GNOME libraries: <https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator>.
2726

2827
- Create a generic FFI bindings generator for bucklescript in order to be able to
2928
use the javascript bindings to the GNOME libraries. (I am not sure if it is
30-
faisable).
29+
feasible).
3130

32-
- https://devdocs.baznga.org/
33-
- https://bucklescript.github.io/bucklescript/Manual.html#_ffi
34-
- https://github.com/glennsl/bucklescript-ffi-cheatsheet
35-
- https://github.com/Place1/node-gir
31+
- <https://devdocs.baznga.org/>
32+
- <https://bucklescript.github.io/bucklescript/Manual.html#_ffi>
33+
- <https://github.com/glennsl/bucklescript-ffi-cheatsheet>
34+
- <https://github.com/Place1/node-gir>
3635

37-
## Wiki :
36+
## Manual
3837

39-
https://github.com/cedlemo/OCaml-GObject-Introspection/wiki#introduction
38+
<https://github.com/cedlemo/OCaml-GObject-Introspection/wiki#introduction>
4039

4140
### table of content.
4241

docs/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(documentation
2+
(mld_files index manual))

docs/index.mld

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{0 gobject-introspection OCaml package}
2+
3+
The OCaml bindings to the {{: https://gi.readthedocs.io/en/latest/index.html} GObject-Introspection}
4+
library based on Ctypes.
5+
6+
{1 Installation}
7+
8+
The package gobject-introspection is now published and available in
9+
the opam-repository:
10+
11+
{[
12+
opam install gobject-introspection
13+
]}
14+
15+
{1 API}
16+
17+
{2 Library gobject-introspection}
18+
19+
The entry point of this library is the module: {!GObject_introspection}.
20+
21+
{2 Library gobject-introspection.bindings}
22+
23+
The entry point of this library is the module: {!Bindings}.
24+
25+
{1 Usage}
26+
27+
Two ideas to explore:
28+
{ul {- Create a generic Ctypes bindings generator, based on
29+
ocaml-gobject-introspection, for the GNOME libraries:
30+
{{: https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator}}.}
31+
32+
{- Create a generic FFI bindings generator for bucklescript in order to be
33+
able to use the javascript bindings to the GNOME libraries. (I am not
34+
sure if it is feasible).
35+
36+
{ul {- {{: https://devdocs.baznga.org/}}}
37+
{- {{: https://bucklescript.github.io/bucklescript/Manual.html#_ffi}}}
38+
{- {{: https://github.com/glennsl/bucklescript-ffi-cheatsheet}}}
39+
{- {{: https://github.com/Place1/node-gir}}}}}}
40+
41+
{1 Manual}
42+
43+
{{!page-manual}Manual}.

docs/manual.mld

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{0 Introduction}
2+
3+
The Ctypes bindings to the GObject-Introspection (all the files/modules named
4+
[GISomething]).
5+
6+
{1 Implementation details}
7+
8+
{2 GObjectIntrospection Info Structures hierarchy and type coercion functions}
9+
10+
{[
11+
GIBaseInfo
12+
+----GIArgInfo
13+
+----GICallableInfo
14+
+----GIFunctionInfo
15+
+----GISignalInfo
16+
+----GIVFuncInfo
17+
+----GIConstantInfo
18+
+----GIFieldInfo
19+
+----GIPropertyInfo
20+
+----GIRegisteredTypeInfo
21+
+----GIEnumInfo
22+
+----GIInterfaceInfo
23+
+----GIObjectInfo
24+
+----GIStructInfo
25+
+----GIUnionInfo
26+
+----GITypeInfo
27+
]}
28+
29+
This hierarchy determines the need to cast structures. For example [GIArgInfo]
30+
needs only to be casted to [GIBaseInfo].
31+
32+
[GIFunctionInfo] needs to be casted to [GICallableInfo] and to [GIBaseInfo].
33+
34+
So each module will (except GIBaseInfo), have functions for type coercion like:
35+
36+
{[
37+
GIArgInfo.to_baseinfo
38+
GIArgInfo.from_baseinfo
39+
GIFunctionInfo.to_baseinfo
40+
GIFunctionInfo.from_baseinfo
41+
GIFunctionInfo.to_callableinfo
42+
GIFunctionInfo.from_callableinfo
43+
]}
44+
45+
{2 How the underlying C structures allocation and deallocation are handled}
46+
47+
When an info structure pointer is returned with full transfert via the C api,
48+
each OCaml value that wraps them is finalised with [Gc.finalise] for example:
49+
50+
{[
51+
let get_field info n =
52+
let get_field_raw =
53+
foreign "g_struct_info_get_field"
54+
(ptr structinfo @-> int @-> returning (ptr GIFieldInfo.fieldinfo)) in
55+
let max = get_n_fields info in
56+
if (n < 0 || n >= max) then raise (Failure "Array Index out of bounds")
57+
else let info' = get_field_raw info n in
58+
GIFieldInfo.add_unref_finaliser info'
59+
]}
60+
61+
So when the [info'] value is garbage collected, the
62+
[GIFieldInfo.add_unref_finaliser] is called. Here is the code of this function:
63+
64+
{[
65+
let add_unref_finaliser info =
66+
let _ = Gc.finalise (fun i ->
67+
let i' = cast_to_baseinfo i in
68+
GIBaseInfo.base_info_unref i') info
69+
in info
70+
]}
71+
72+
Each info module have this kind of function but the end user of the lib should
73+
not use them. When a cast need to be done, each module have the following two
74+
functions:
75+
76+
{ul {- [to_baseinfo]}
77+
{- [from_baseinfo] }}
78+
79+
Those functions allow to transform an OCaml value that represents a [GIInfo] to
80+
another [GIInfo] type while the underlying C structure are ref'ed and linked to
81+
a Gc finaliser that unref them. This should avoid zombies OCaml values (with C
82+
structure already deallocated) and memory leaks.
83+
84+
{1 Progress}
85+
86+
{2 Finished}
87+
88+
{ul {- GIRepository — GObject Introspection repository manager}
89+
{- GIBaseInfo — Base struct for all GITypelib structs}
90+
{- GIFunctionInfo — Struct representing a function}
91+
{- GIStructInfo — Struct representing a C structure}
92+
{- GIFieldInfo — Struct representing a struct or union field}
93+
{- GIUnionInfo — Struct representing a union.}
94+
{- GIEnumInfo — Structs representing an enumeration and its values}
95+
{- GIValueInfo — Struct representing a value}
96+
{- GICallableInfo — Struct representing a callable}
97+
{- GIArgInfo — Struct representing an argument}
98+
{- GITypeInfo — Struct representing a type}
99+
{- GIConstantInfo — Struct representing a constant}
100+
{- GIObjectInfo — Struct representing a GObject}
101+
{- GIInterfaceInfo — Struct representing a GInterface}
102+
{- GIPropertyInfo — Struct representing a property}
103+
{- GISignalInfo — Struct representing a signal}
104+
{- GIVFuncInfo — Struct representing a virtual function}
105+
{- GIRegisteredTypeInfo — Struct representing a struct with a GType}}
106+
107+
{2 Remains}
108+
109+
{ul {- GICallbackInfo — Struct representing a callback (no C API for now).}}
110+
111+
{1 Resources}
112+
113+
{ul {- {{: https://ocaml.org/learn/tutorials/calling_c_libraries.html}}}
114+
{- {{: https://developer.gnome.org/gi/}}}
115+
{- {{: https://developer.gnome.org/gi/1.52/GIRepository.html}}}
116+
{- {{: https://ocaml.org/learn/tutorials/objects.html}}}
117+
{- {{: https://ocaml.org/manual/index.html}}}
118+
{- {{: https://ocaml.org/manual/intfc.html}}}
119+
{- {{: https://web.archive.org/web/20200223115730/http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.html} http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.html} (old)}
120+
{- {{: https://wiki.haskell.org/GObjectIntrospection}}}}

0 commit comments

Comments
 (0)