annotate doc/manual/manual_dyncallback_api.tex @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents 17287342e273
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
467
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
1 %//////////////////////////////////////////////////////////////////////////////
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
2 %
533
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 490
diff changeset
3 % Copyright (c) 2007,2013-2022 Daniel Adler <dadler@uni-goettingen.de>,
71c884e610f0 - integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents: 490
diff changeset
4 % Tassilo Philipp <tphilipp@potion-studios.com>
467
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
5 %
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
6 % Permission to use, copy, modify, and distribute this software for any
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
7 % purpose with or without fee is hereby granted, provided that the above
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
8 % copyright notice and this permission notice appear in all copies.
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
9 %
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
10 % THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
11 % WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
12 % MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
13 % ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
14 % WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
15 % ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
16 % OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
17 %
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
18 %//////////////////////////////////////////////////////////////////////////////
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
19
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
20 \section{\emph{Dyncallback} C library API}
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
21
490
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
22 See the dyncallback(3) manpage for more information.
467
b47168dacba6 manual:
Tassilo Philipp
parents: 67
diff changeset
23
490
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
24 %@@@ removed, as manpages are more precise and up to date ------------------->
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
25 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
26 %This library extends \product{dyncall} with function callback support, allowing
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
27 %the user to dynamically create a callback object that can be called directly,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
28 %or passed to functions expecting a function-pointer as argument.\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
29 %\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
30 %Invoking a \product{dyncallback} calls into a user-defined unified handler that
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
31 %permits iteration and thus dynamic handling over the called-back-function's
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
32 %parameters.\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
33 %\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
34 %The flexibility is constrained by the set of supported types, though.\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
35 %\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
36 %For style conventions and supported types, see \product{dyncall} API section.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
37 %In order to use \product{dyncallback}, include {\tt "dyncall\_callback.h"}.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
38 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
39 %\subsection{Callback Object}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
40 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
41 %The \emph{Callback Object} is the core component to this library.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
42 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
43 %\paragraph{Types}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
44 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
45 %\begin{lstlisting}[language=c]
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
46 %typedef struct DCCallback DCCallback;
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
47 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
48 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
49 %\paragraph{Details}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
50 %The \emph{Callback Object} is an object that mimics a fully typed function
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
51 %call to another function (a generic callback handler, in this case).\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
52 %\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
53 %This means, a pointer to this object is passed to a function accepting a pointer
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
54 %to a callback function \emph{as the very callback function pointer itself}.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
55 %Or, if called directly, cast a pointer to this object to a function pointer and
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
56 %issue a call.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
57 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
58 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
59 %\subsection{Allocation}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
60 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
61 %\paragraph{Functions}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
62 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
63 %\begin{lstlisting}[language=c]
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
64 %DCCallback* dcbNewCallback(const DCsigchar* signature,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
65 % DCCallbackHandler* funcptr,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
66 % void* userdata,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
67 % DCaggr** aggrs);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
68 %void dcbFreeCallback(DCCallback* pcb);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
69 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
70 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
71 %\lstinline{dcbNewCallback} creates and initializes a new \emph{Callback} object,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
72 %where \lstinline{signature} is the needed function signature (format is the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
73 %one outlined in the language bindings-section of this manual, see Table \ref{sigchar})
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
74 %of the function to mimic, \lstinline{funcptr} is a pointer to a callback handler,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
75 %and \lstinline{userdata} a pointer to custom data that might be useful in the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
76 %handler.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
77 %Use \lstinline{dcbFreeCallback} to destroy the \emph{Callback} object.\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
78 %\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
79 %As with \capi{dcNewCallVM}/\capi{dcFree}, this will allocate memory using the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
80 %system allocators or custom overrides.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
81 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
82 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
83 %\subsection{Callback handler}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
84 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
85 %The unified callback handler's declaration used when creating a \capi{DCCallback}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
86 %is:
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
87 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
88 %\begin{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
89 %DCsigchar cbHandler(DCCallback* cb,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
90 % DCArgs* args,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
91 % DCValue* result,
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
92 % void* userdata);
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
93 %\end{lstlisting}
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
94 %
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
95 %\capi{cb} is a pointer to the \capi{DCCallback} object in use, \capi{args} allows
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
96 %for dynamic iteration over the called-back-function's arguments (input) and
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
97 %\capi{result} is a pointer to a \capi{DCValue} object in order to store the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
98 %callback's return value (output, to be set by handler).\\
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
99 %Finally, \capi{userdata} is a pointer to some user defined data that can be
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
100 %set when creating the callback object.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
101 %The handler itself returns a signature character (see Table \ref{sigchar}) specifying the
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
102 %data type used for \capi{result}.
17287342e273 manual:
Tassilo Philipp
parents: 467
diff changeset
103 %