annotate dyncallback/dyncallback.3 @ 425:2d9f1cb06352

- dynload: corrected comparison of size of optional PE header info to what is pointed to (ptr arithmetic was incorrect, only broke ReactOS builds and runtime, though)
author Tassilo Philipp
date Fri, 17 Dec 2021 18:50:58 +0100
parents 7cb8a0aaf638
children e2899b4ff713
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 .\" Copyright (c) 2007-2014 Daniel Adler <dadler AT uni-goettingen DOT de>,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 .\" Tassilo Philipp <tphilipp AT potion-studios DOT com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 .\"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 .\" Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 .\" purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 .\" copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 .\"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 .\"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 .Dd $Mdocdate$
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 .Dt dyncallback 3
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 .Sh NAME
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 .Nm dyncallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 .Nd callback interface of dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 .Sh SYNOPSIS
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 .In dyncall_callback.h
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 .Ft DCCallback *
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 .Fn dcbNewCallback "const char * signature" "DCCallbackHandler * funcptr" "void * userdata"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 .Ft void
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 .Fn dcbInitCallback "DCCallback * pcb" "const char * signature" "DCCallbackHandler * funcptr" "void * userdata"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 .Ft void
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 .Fn dcbFreeCallback "DCCallback * pcb"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 .Ft void
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 .Fn dcbGetUserData "DCCallback * pcb"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 .Sh DESCRIPTION
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 The
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 .Nm
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 dyncall library has an interface to create callback objects, that can be passed
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 to functions as callback arguments. In other words, a pointer to the callback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 object can be "called", directly. The callback handler then allows iterating
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37 dynamically over the arguments once called back.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 .Fn dcbNewCallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 creates a new callback object, where
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 .Ar signature
96
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
42 is a signature string describing the function to be called back (see manual or
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
43 dyncall_signature.h for format). This is needed for
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 .Nm
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 dyncallback to correctly prepare the arguments passed in by the function that
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 calls the callback handler. Note that the handler doesn't return the value
96
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
47 specified in the signature, directly, but a signature character, specifying the
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
48 return value's type.
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
49 The return value itself is stored where the handler's
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
50 3rd parameter points to (see below).
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 .Ar funcptr
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 is a pointer to the
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 .Nm
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 dyncallback callback handler (see below), and
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 .Ar userdata
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 a pointer to arbitrary user data you want to use in the callback handler.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57 Use the returned pointer as callback argument in functions requiring a callback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 function pointer.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 .Fn dcbInitCallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 (re)initialize the callback object.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 .Fn dcbFreeCallback
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 destroys and frees the callback handler.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 .Fn dcbGetUserData
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 returns a pointer to the userdata passed to the callback object on creation or
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68 initialization.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 Declaration of a dyncallback handler (following function pointer definition in
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71 dyncallback/dyncall_callback.h):
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 .Bd -literal -offset indent
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 char cbHandler(DCCallback* cb,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 DCArgs* args,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 DCValue* result,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 void* userdata);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 .Ed
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 .Ar cb is a pointer to the DCCallback object in use
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
80 .Nm
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
81 result is a pointer to a DCValue object in order to store the callback's
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
82 return value (output, to be set by handler). Finally,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
83 .Ar userdata is a pointer to some user defined data that can be
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
84 set when creating the callback object.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
85 The handler itself returns a signature character (see manual for format)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
86 specifying the data type used for
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
87 .Ar result .
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
88 .Sh EXAMPLE
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
89 Let's say, we want to create a callback object and call it. For simplicity, this
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
90 example will omit passing it as a function pointer to a function (e.g. compar
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
91 in qsort(), etc.) and demonstrate calling it, directly. First, we need to define
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
92 our callback handler - the following handler illustrates how to access the passed-
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
93 in arguments:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
94 .Bd -literal -offset indent
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
95 char cbHandler(DCCallback* cb,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
96 DCArgs* args,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
97 DCValue* result,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
98 void* userdata)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
99 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
100 int* ud = (int*)userdata;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
101 int arg1 = dcbArgInt (args);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
102 float arg2 = dcbArgFloat (args);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
103 short arg3 = dcbArgShort (args);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
104 double arg4 = dcbArgDouble (args);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
105 long long arg5 = dcbArgLongLong(args);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
106
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
107 // .. do something ..
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
108
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
109 result->s = 1244;
96
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
110 return 's';
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
111 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
112 .Ed
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
113 .Pp
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
114 Note that the return value of the handler is a signature character, not the
96
95f67e67feb0 - updated dyncallback.3, blurb about handler's retval signature character was outdated
cslag
parents: 93
diff changeset
115 actual return value, itself.
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
116 Now, let's call it through a DCCallback object:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
117 .Bd -literal -offset indent
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
118 DCCallback* cb;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
119 short result = 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
120 int userdata = 1337;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
121 cb = dcbNewCallback("ifsdl)s", &cbHandler, &userdata);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
122 result = ((short(*)(int, float, short, double, long long))cb)
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
123 (123, 23.f, 3, 1.82, 9909ll);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
124 dcbFreeCallback(cb);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
125 .Ed
250
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
126 .Sh CONFORMING TO
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
127 The dyncallback library needs at least a c99 compiler with additional support
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
128 for anonymous structs/unions (which were introduced officially in c11). Given
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
129 that those are generally supported by pretty much all major c99 conforming
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
130 compilers (as default extension), it should build fine with a c99 toolchain.
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
131 Strictly speaking, dyncall conforms to c11, though.
7cb8a0aaf638 - note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents: 96
diff changeset
132 .Ed
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
133 .Sh SEE ALSO
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
134 .Xr dyncall 3 ,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
135 .Xr dynload 3
93
dfde5035d410 - better, more neutral .3 SEE ALSO
cslag
parents: 81
diff changeset
136 and the dyncall manual (available in HTML and PDF format) for more information.
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
137 .Sh AUTHORS
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
138 .An "Daniel Adler" Aq dadler@uni-goettingen.de
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
139 .An "Tassilo Philipp" Aq tphilipp@potion-studios.com