Mercurial > pub > dyncall > dyncall
annotate dyncall/dyncall.3 @ 250:7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
author | Tassilo Philipp |
---|---|
date | Sun, 14 May 2017 00:19:15 +0200 |
parents | dfde5035d410 |
children | 32736025371f |
rev | line source |
---|---|
0 | 1 .\" Copyright (c) 2007-2013 Daniel Adler <dadler AT uni-goettingen DOT de>, |
2 .\" Tassilo Philipp <tphilipp AT potion-studios DOT com> | |
3 .\" | |
4 .\" Permission to use, copy, modify, and distribute this software for any | |
5 .\" purpose with or without fee is hereby granted, provided that the above | |
6 .\" copyright notice and this permission notice appear in all copies. | |
7 .\" | |
8 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 .\" | |
16 .Dd $Mdocdate$ | |
17 .Dt dyncall 3 | |
18 .Sh NAME | |
19 .Nm dyncall | |
20 .Nd encapsulation of architecture-, OS- and compiler-specific function call | |
21 semantics | |
22 .Sh SYNOPSIS | |
23 .In dyncall.h | |
24 .Ft DCCallVM * | |
25 .Fn dcNewCallVM "DCsize size" | |
26 .Ft void | |
27 .Fn dcFree "DCCallVM * vm" | |
28 .Ft void | |
29 .Fn dcMode "DCCallVM * vm" "DCint mode" | |
30 .Ft void | |
31 .Fn dcReset "DCCallVM * vm" | |
32 .Ft void | |
33 .Fn dcArgBool "DCCallVM * vm" "DCbool arg" | |
34 .Ft void | |
35 .Fn dcArgChar "DCCallVM * vm" "DCchar arg" | |
36 .Ft void | |
37 .Fn dcArgShort "DCCallVM * vm" "DCshort arg" | |
38 .Ft void | |
39 .Fn dcArgInt "DCCallVM * vm" "DCint arg" | |
40 .Ft void | |
41 .Fn dcArgLong "DCCallVM * vm" "DClong arg" | |
42 .Ft void | |
43 .Fn dcArgLongLong "DCCallVM * vm" "DClonglong arg" | |
44 .Ft void | |
45 .Fn dcArgFloat "DCCallVM * vm" "DCfloat arg" | |
46 .Ft void | |
47 .Fn dcArgDouble "DCCallVM * vm" "DCdouble arg" | |
48 .Ft void | |
49 .Fn dcArgPointer "DCCallVM * vm" "DCpointer arg" | |
50 .Ft DCvoid | |
51 .Fn dcCallVoid "DCCallVM * vm" "DCpointer funcptr" | |
52 .Ft DCbool | |
53 .Fn dcCallBool "DCCallVM * vm" "DCpointer funcptr" | |
54 .Ft DCchar | |
55 .Fn dcCallChar "DCCallVM * vm" "DCpointer funcptr" | |
56 .Ft DCshort | |
57 .Fn dcCallShort "DCCallVM * vm" "DCpointer funcptr" | |
58 .Ft DCint | |
59 .Fn dcCallInt "DCCallVM * vm" "DCpointer funcptr" | |
60 .Ft DClong | |
61 .Fn dcCallLong "DCCallVM * vm" "DCpointer funcptr" | |
62 .Ft DClonglong | |
63 .Fn dcCallLongLong "DCCallVM * vm" "DCpointer funcptr" | |
64 .Ft DCfloat | |
65 .Fn dcCallFloat "DCCallVM * vm" "DCpointer funcptr" | |
66 .Ft DCdouble | |
67 .Fn dcCallDouble "DCCallVM * vm" "DCpointer funcptr" | |
68 .Ft DCpointer | |
69 .Fn dcCallPointer "DCCallVM * vm" "DCpointer funcptr" | |
70 .Ft void | |
71 .Fn dcArgF "DCCallVM * vm" "const DCsigchar * signature" "..." | |
72 .Ft void | |
73 .Fn dcVArgF "DCCallVM * vm" "const DCsigchar * signature" "va_list args" | |
74 .Ft void | |
75 .Fn dcCallF "DCCallVM * vm" "DCValue * result" "DCpointer funcptr" "const DCsigchar * signature" "..." | |
76 .Ft void | |
77 .Fn dcVCallF "DCCallVM * vm" "DCValue * result" "DCpointer funcptr" "const DCsigchar * signature" "va_list args" | |
78 .Sh DESCRIPTION | |
79 The | |
80 .Nm | |
81 library encapsulates architecture-, OS- and compiler-specific function call | |
82 semantics in a virtual "bind argument parameters from left to right and then | |
83 call" interface allowing programmers to call C functions in a completely | |
84 dynamic manner. | |
85 .Pp | |
86 In other words, instead of calling a function directly, the | |
87 .Nm | |
88 library provides a mechanism to push the function parameters manually and to | |
89 issue the call afterwards. | |
90 .Pp | |
91 Since the idea behind this concept is similar to call dispatching mechanisms | |
92 of virtual machines, the object that can be dynamically loaded with arguments, | |
93 and then used to actually invoke the call, is called CallVM. It is possible to | |
94 change the calling convention used by the CallVM at run-time. Due to the fact | |
95 that nearly every platform comes with one or more distinct calling conventions, the | |
96 .Nm | |
97 library project intends to be a portable and open-source approach to the variety of | |
98 compiler-specific binary interfaces, platform specific subtleties, and so on... | |
99 .Pp | |
100 .Fn dcNewCallVM | |
101 creates a new CallVM object, where | |
102 .Ar size | |
103 specifies the max size of the internal stack that will be allocated and used to | |
104 bind the arguments to. Use | |
105 .Fn dcFree | |
106 to destroy the CallVM object. | |
107 .Pp | |
108 .Fn dcMode | |
109 sets the calling convention to use. See dyncall.h for a list of | |
110 available modes. Note that some mode/platform combinations don't make any | |
111 sense (e.g. using a PowerPC calling convention on a MIPS platform) and are | |
112 silently ignored. | |
113 .Pp | |
114 .Fn dcReset | |
50 | 115 resets the internal stack of arguments and prepares it for a new call. |
0 | 116 This function should be called after setting the call mode (using dcMode), but |
117 prior to binding arguments to the CallVM. Use it also when reusing a CallVM, as | |
118 arguments don't get flushed automatically after a function call invocation. | |
50 | 119 Note: you should also call this function after initial creation of the a CallVM |
120 object, as dcNewCallVM doesn't do this, implicitly. | |
0 | 121 .Pp |
122 .Fn dcArgBool , | |
123 .Fn dcArgChar , | |
124 .Fn dcArgShort , | |
125 .Fn dcArgInt , | |
126 .Fn dcArgLong , | |
127 .Fn dcArgLongLong , | |
128 .Fn dcArgFloat , | |
129 .Fn dcArgDouble | |
130 and | |
131 .Fn dcArgPointer | |
132 are used to bind arguments of the named types to the CallVM object. Arguments should | |
133 be bound in | |
134 .Em "left to right" | |
135 order regarding the C function prototype. | |
136 .Pp | |
137 .Fn dcCallVoid , | |
138 .Fn dcCallBool , | |
139 .Fn dcCallChar , | |
140 .Fn dcCallShort , | |
141 .Fn dcCallInt , | |
142 .Fn dcCallLong , | |
143 .Fn dcCallLongLong , | |
144 .Fn dcCallFloat , | |
145 .Fn dcCallDouble | |
146 and | |
147 .Fn dcCallPointer | |
148 call the function with the bound arguments and returning the named type, where | |
149 .Ar funcptr | |
150 is a pointer to the function to call. After the invocation of the function | |
151 call, the argument values are still bound to the CallVM and a second call | |
152 using the same arguments can be issued. Call | |
153 .Fn reset | |
154 to clear the internal argument stack. | |
155 .Pp | |
156 .Fn dcArgF , | |
157 .Fn dcVArgF , | |
158 .Fn dcCallF | |
159 and | |
160 .Fn dcVCallF | |
161 can be used to bind arguments in a printf-style call, using a signature | |
162 string encoding the argument types and return type. The former 2 only bind | |
163 the arguments to the | |
164 .Ar vm | |
165 object (and ignore return types specified in the | |
166 signature), whereas the latter two issue a call to the given function pointer, | |
167 afterwards. The return value will be stored in | |
168 .Ar result . | |
169 For information about the signature format, refer to the | |
170 .Nm | |
171 manual in PDF format. | |
172 .Sh EXAMPLE | |
173 Let's say, we want to make a call to the function: | |
174 .Bd -literal -offset indent | |
175 double sqrt(double x); | |
176 .Ed | |
177 .Pp | |
178 Using the | |
179 .Nm | |
180 library, this function would be called as follows: | |
181 .Bd -literal -offset indent | |
182 double r; | |
183 DCCallVM* vm = dcNewCallVM(4096); | |
184 dcMode(vm, DC_CALL_C_DEFAULT); | |
185 dcReset(vm); | |
186 dcArgDouble(vm, 4.2373); | |
187 r = dcCallDouble(vm, (DCpointer)&sqrt); | |
188 dcFree(vm); | |
189 .Ed | |
250
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
190 .Sh CONFORMING TO |
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
191 The dyncall library needs at least a c99 compiler with additional support for |
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
192 anonymous structs/unions (which were introduced officially in c11). Given that |
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
193 those are generally supported by pretty much all major c99 conforming compilers |
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
194 (as default extension), it should build fine with a c99 toolchain. Strictly |
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
195 speaking, dyncall conforms to c11, though. |
7cb8a0aaf638
- note about c99 (+ anon struct/union) requirements in doc
Tassilo Philipp
parents:
93
diff
changeset
|
196 .Ed |
0 | 197 .Sh SEE ALSO |
198 .Xr dyncallback 3 , | |
199 .Xr dynload 3 | |
200 and the | |
201 .Nm | |
93 | 202 manual (available in HTML and PDF format) for more information. |
0 | 203 .Sh AUTHORS |
204 .An "Daniel Adler" Aq dadler@uni-goettingen.de | |
205 .An "Tassilo Philipp" Aq tphilipp@potion-studios.com |