Skip to content

Commit 369033d

Browse files
committed
Clarify which runtime interactions are allowed in custom ops
1 parent 7ceab32 commit 369033d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

manual/src/cmds/intf-c.etex

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,10 +1984,10 @@ block (as given by the "identifier" field) to the output stream,
19841984
then call the user-provided "serialize" function. That function is
19851985
responsible for writing the data contained in the custom block, using
19861986
the "serialize_..." functions defined in "<caml/intext.h>" and listed
1987-
below. The user-provided "serialize" function must then store in its
1988-
"bsize_32" and "bsize_64" parameters the sizes in bytes of the data
1989-
part of the custom block on a 32-bit architecture and on a 64-bit
1990-
architecture, respectively.
1987+
in section~\ref{ss:c-custom-serialization}. The user-provided "serialize"
1988+
function must then store in its "bsize_32" and "bsize_64" parameters the sizes
1989+
in bytes of the data part of the custom block on a 32-bit architecture and on a
1990+
64-bit architecture, respectively.
19911991

19921992
The "serialize" field can be set to "custom_serialize_default",
19931993
in which case the "Failure" exception is raised when attempting to
@@ -2000,12 +2000,12 @@ be deserialized (un-marshaled) using the OCaml functions "input_value"
20002000
or "Marshal.from_...". This user-provided function is responsible for
20012001
reading back the data written by the "serialize" operation, using the
20022002
"deserialize_..." functions defined in "<caml/intext.h>" and listed
2003-
below. It must then rebuild the data part of the custom block
2004-
and store it at the pointer given as the "dst" argument. Finally, it
2005-
returns the size in bytes of the data part of the custom block.
2006-
This size must be identical to the "wsize_32" result of
2007-
the "serialize" operation if the architecture is 32 bits, or
2008-
"wsize_64" if the architecture is 64 bits.
2003+
in section~\ref{ss:c-custom-serialization}. It must then rebuild the data part
2004+
of the custom block and store it at the pointer given as the "dst" argument.
2005+
Finally, it returns the size in bytes of the data part of the custom block.
2006+
This size must be identical to the "wsize_32" result of the "serialize"
2007+
operation if the architecture is 32 bits, or "wsize_64" if the architecture is
2008+
64 bits.
20092009

20102010
The "deserialize" field can be set to "custom_deserialize_default"
20112011
to indicate that deserialization is not supported. In this case,
@@ -2023,13 +2023,16 @@ specified in the "fixed_length" structure, and do not consume space in
20232023
the serialized output.
20242024
\end{itemize}
20252025

2026-
Note: the "finalize", "compare", "hash", "serialize" and "deserialize"
2027-
functions attached to custom block descriptors must never access the
2028-
OCaml runtime. Within these functions, do not call any of the OCaml
2029-
allocation functions, and do not perform a callback into OCaml code.
2030-
Do not use "CAMLparam" to register the parameters to these functions,
2031-
and do not use "CAMLreturn" to return the result. Do not raise
2032-
exceptions, do not remove global roots, etc.
2026+
Note: the "finalize", "compare", "hash", "serialize", and "deserialize"
2027+
functions attached to custom blocks descriptors are only allowed limited
2028+
interactions with the OCaml runtime. Within these functions, do not call any of
2029+
the OCaml allocation functions, and do not perform any callback into OCaml
2030+
code. Do not use "CAMLparam" to register the parameters to these functions, and
2031+
do not use "CAMLreturn" to return the result. Do not raise exceptions (to
2032+
signal an error during deserialization, use "caml_deserialize_error"). Do not
2033+
remove global roots. When in doubt, err on the side of caution. Within
2034+
"serialize" and "deserialize" functions, use of the corresponding functions
2035+
from section~\ref{ss:c-custom-serialization} is allowed (and even recommended).
20332036

20342037
\subsection{ss:c-custom-alloc}{Allocating custom blocks}
20352038

0 commit comments

Comments
 (0)