Mercurial > pub > dyncall > dyncall
comparison doc/manual/manual_bindings.tex @ 360:32736025371f
- doc updates with more info about signature string usage
author | Tassilo Philipp |
---|---|
date | Mon, 13 Apr 2020 21:35:43 +0200 |
parents | e932e6331f35 |
children | b47168dacba6 |
comparison
equal
deleted
inserted
replaced
359:e8a13c880399 | 360:32736025371f |
---|---|
57 \subsubsection{Signatures} | 57 \subsubsection{Signatures} |
58 | 58 |
59 A signature is a character string that represents a function's arguments and | 59 A signature is a character string that represents a function's arguments and |
60 return value types. It is used in the scripting language bindings invoke | 60 return value types. It is used in the scripting language bindings invoke |
61 functions to perform automatic type-conversion of the languages' types to the | 61 functions to perform automatic type-conversion of the languages' types to the |
62 low-level C/C++ data types. This is an essential part of mapping the more flexible | 62 low-level C/C++ data types. |
63 and often abstract data types provided in scripting languages conveniently to the | 63 This is an essential part of mapping the more flexible and often abstract data |
64 strict machine-level data types used by C-libraries. | 64 types provided in scripting languages to the strict machine-level data types |
65 used by C-libraries. | |
65 The high-level C interface functions \capi{dcCallF()}, \capi{dcVCallF()}, | 66 The high-level C interface functions \capi{dcCallF()}, \capi{dcVCallF()}, |
66 \capi{dcArgF()} and \capi{dcVArgF()} of the \product{dyncall} library also make | 67 \capi{dcArgF()} and \capi{dcVArgF()} of the \product{dyncall} library also make |
67 use of this signature string format.\\ | 68 use of this signature string format.\\ |
68 \\ | 69 \\ |
69 The format of a \product{dyncall} signature string is as depicted below: | 70 The format of a \product{dyncall} signature string is as depicted below: |
86 \begin{table}[h] | 87 \begin{table}[h] |
87 \begin{center} | 88 \begin{center} |
88 \begin{tabular*}{0.75\textwidth}{cl} | 89 \begin{tabular*}{0.75\textwidth}{cl} |
89 Signature character & C/C++ data type \\ | 90 Signature character & C/C++ data type \\ |
90 \hline | 91 \hline |
92 \sigchar{v} & void \\ | |
91 \sigchar{B} & \_Bool, bool \\ | 93 \sigchar{B} & \_Bool, bool \\ |
92 \sigchar{c} & char \\ | 94 \sigchar{c} & char \\ |
93 \sigchar{C} & unsigned char \\ | 95 \sigchar{C} & unsigned char \\ |
94 \sigchar{s} & short \\ | 96 \sigchar{s} & short \\ |
95 \sigchar{S} & unsigned short \\ | 97 \sigchar{S} & unsigned short \\ |
101 \sigchar{L} & unsigned long long, uint64\_t \\ | 103 \sigchar{L} & unsigned long long, uint64\_t \\ |
102 \sigchar{f} & float \\ | 104 \sigchar{f} & float \\ |
103 \sigchar{d} & double \\ | 105 \sigchar{d} & double \\ |
104 \sigchar{p} & void* \\ | 106 \sigchar{p} & void* \\ |
105 \sigchar{Z} & const char* (pointing to C string) \\ | 107 \sigchar{Z} & const char* (pointing to C string) \\ |
106 \sigchar{v} & void \\ | |
107 \end{tabular*} | 108 \end{tabular*} |
108 \caption{Type signature encoding for function call data types} | 109 \caption{Type signature encoding for function call data types} |
109 \label{sigchar} | 110 \label{sigchar} |
110 \end{center} | 111 \end{center} |
111 \end{table} | 112 \end{table} |
112 | 113 |
113 Please note that using a \sigchar{(} at the beginning of a signature string is possible, | 114 Please note that using a \sigchar{(} at the beginning of a signature string is possible, |
114 although not required. The character doesn't have any meaning and will simply be | 115 although not required. The character doesn't have any meaning and will simply be |
115 ignored. However, using it prevents annoying syntax highlighting problems with some code | 116 ignored. However, using it prevents annoying syntax highlighting problems with some code |
116 editors. | 117 editors. |
118 | |
119 \pagebreak | |
120 | |
121 Calling convention modes can be switched using the signature string, as well. A | |
122 '\_' in the signature string is followed by a character specifying what | |
123 calling convention to use, as this affects how arguments are passed. This makes | |
124 only sense if there are multiple co-existing calling conventions on a single platform. | |
125 Usually, this is done at the beginning of the string, except in special cases, like | |
126 specifying where the varargs part of a variadic function begins. | |
127 The following signature characters exist: | |
128 | |
129 \begin{table}[h] | |
130 \begin{center} | |
131 \begin{tabular*}{0.75\textwidth}{cl} | |
132 Signature character & Calling Convention \\ | |
133 \hline | |
134 \sigchar{:} & platform's default calling convention \\ | |
135 \sigchar{e} & vararg function \\ | |
136 \sigchar{.} & vararg function's variadic/ellipsis part (...), to be specified before first vararg \\ | |
137 \sigchar{c} & only on x86: cdecl \\ | |
138 \sigchar{s} & only on x86: stdcall \\ | |
139 \sigchar{F} & only on x86: fastcall (MS) \\ | |
140 \sigchar{f} & only on x86: fastcall (GNU) \\ | |
141 \sigchar{+} & only on x86: thiscall (MS) \\ | |
142 \sigchar{\#}& only on x86: thiscall (GNU) \\ | |
143 \sigchar{A} & only on ARM: ARM mode \\ | |
144 \sigchar{a} & only on ARM: THUMB mode \\ | |
145 \sigchar{\$}& syscall \\ | |
146 \end{tabular*} | |
147 \caption{Calling convention signature encoding} | |
148 \label{cconvsigchar} | |
149 \end{center} | |
150 \end{table} | |
117 | 151 |
118 \pagebreak | 152 \pagebreak |
119 | 153 |
120 \paragraph{Examples of C function prototypes} | 154 \paragraph{Examples of C function prototypes} |
121 | 155 |
127 void & f1(); & \sigstr{)v}\\ | 161 void & f1(); & \sigstr{)v}\\ |
128 int & f2(int, int); & \sigstr{ii)i}\\ | 162 int & f2(int, int); & \sigstr{ii)i}\\ |
129 long long & f3(void*); & \sigstr{p)L}\\ | 163 long long & f3(void*); & \sigstr{p)L}\\ |
130 void & f3(int**); & \sigstr{p)v}\\ | 164 void & f3(int**); & \sigstr{p)v}\\ |
131 double & f4(int, bool, char, double, const char*); & \sigstr{iBcdZ)d}\\ | 165 double & f4(int, bool, char, double, const char*); & \sigstr{iBcdZ)d}\\ |
166 void & f5(short a, long long b, ...) & \sigstr{\_esl\_.di)v} (for (promoted) varargs: double, int)\\ | |
132 \end{tabular*} | 167 \end{tabular*} |
133 \caption{Type signature examples of C function prototypes} | 168 \caption{Type signature examples of C function prototypes} |
134 \label{sigex} | 169 \label{sigex} |
135 \end{center} | 170 \end{center} |
136 \end{table} | 171 \end{table} |
144 \begin{table}[h] | 179 \begin{table}[h] |
145 \begin{center} | 180 \begin{center} |
146 \begin{tabular*}{0.75\textwidth}{ll} | 181 \begin{tabular*}{0.75\textwidth}{ll} |
147 Signature character & accepted Erlang data types\\ | 182 Signature character & accepted Erlang data types\\ |
148 \hline | 183 \hline |
184 \sigchar{v} & no return type\\ | |
149 \sigchar{B} & atoms 'true' and 'false' converted to bool\\ | 185 \sigchar{B} & atoms 'true' and 'false' converted to bool\\ |
150 \sigchar{c}, \sigchar{C} & integer cast to (unsigned) char\\ | 186 \sigchar{c}, \sigchar{C} & integer cast to (unsigned) char\\ |
151 \sigchar{s}, \sigchar{S} & integer cast to (unsigned) short\\ | 187 \sigchar{s}, \sigchar{S} & integer cast to (unsigned) short\\ |
152 \sigchar{i}, \sigchar{I} & integer cast to (unsigned) int\\ | 188 \sigchar{i}, \sigchar{I} & integer cast to (unsigned) int\\ |
153 \sigchar{j}, \sigchar{J} & integer cast to (unsigned) long\\ | 189 \sigchar{j}, \sigchar{J} & integer cast to (unsigned) long\\ |
154 \sigchar{l}, \sigchar{L} & integer cast to (unsigned) long long\\ | 190 \sigchar{l}, \sigchar{L} & integer cast to (unsigned) long long\\ |
155 \sigchar{f} & decimal cast to float\\ | 191 \sigchar{f} & decimal cast to float\\ |
156 \sigchar{d} & decimal cast to double\\ | 192 \sigchar{d} & decimal cast to double\\ |
157 \sigchar{p} & binary (previously returned from call\_ptr or callf) cast to void*\\ | 193 \sigchar{p} & binary (previously returned from call\_ptr or callf) cast to void*\\ |
158 \sigchar{Z} & string cast to void*\\ | 194 \sigchar{Z} & string cast to void*\\ |
159 \sigchar{v} & no return type\\ | |
160 \end{tabular*} | 195 \end{tabular*} |
161 \caption{Type signature encoding for Erlang bindings} | 196 \caption{Type signature encoding for Erlang bindings} |
162 \label{Erlangsigchar} | 197 \label{Erlangsigchar} |
163 \end{center} | 198 \end{center} |
164 \end{table} | 199 \end{table} |
172 \begin{table}[h] | 207 \begin{table}[h] |
173 \begin{center} | 208 \begin{center} |
174 \begin{tabular*}{0.75\textwidth}{ll} | 209 \begin{tabular*}{0.75\textwidth}{ll} |
175 Signature character & accepted Go data types\\ | 210 Signature character & accepted Go data types\\ |
176 \hline | 211 \hline |
212 \sigchar{v} & no return type\\ | |
177 \sigchar{B} & bool\\ | 213 \sigchar{B} & bool\\ |
178 \sigchar{c}, \sigchar{C} & int8, uint8\\ | 214 \sigchar{c}, \sigchar{C} & int8, uint8\\ |
179 \sigchar{s}, \sigchar{S} & int16, uint16\\ | 215 \sigchar{s}, \sigchar{S} & int16, uint16\\ |
180 \sigchar{i}, \sigchar{I} & int, uint\\ | 216 \sigchar{i}, \sigchar{I} & int, uint\\ |
181 \sigchar{j}, \sigchar{J} & int32, uint32\\ | 217 \sigchar{j}, \sigchar{J} & int32, uint32\\ |
182 \sigchar{l}, \sigchar{L} & int64, uint64\\ | 218 \sigchar{l}, \sigchar{L} & int64, uint64\\ |
183 \sigchar{f} & float32\\ | 219 \sigchar{f} & float32\\ |
184 \sigchar{d} & float64\\ | 220 \sigchar{d} & float64\\ |
185 \sigchar{p}, \sigchar{Z} & uintptr, unsafe.Pointer\\ | 221 \sigchar{p}, \sigchar{Z} & uintptr, unsafe.Pointer\\ |
186 \sigchar{v} & no return type\\ | |
187 \end{tabular*} | 222 \end{tabular*} |
188 \caption{Type signature encoding for Go bindings} | 223 \caption{Type signature encoding for Go bindings} |
189 \label{Gosigchar} | 224 \label{Gosigchar} |
190 \end{center} | 225 \end{center} |
191 \end{table} | 226 \end{table} |
201 The python module {\tt pydc} implements the Python language bindings, | 236 The python module {\tt pydc} implements the Python language bindings, |
202 namely {\tt load}, {\tt find}, {\tt free}, {\tt call}. | 237 namely {\tt load}, {\tt find}, {\tt free}, {\tt call}. |
203 | 238 |
204 \begin{table}[h] | 239 \begin{table}[h] |
205 \begin{center} | 240 \begin{center} |
206 \begin{tabular*}{0.75\textwidth}{ll} | 241 \begin{tabular*}{0.75\textwidth}{lll} |
207 Signature character & accepted Python data types\\ | 242 Signature character & accepted Python 2 types & accepted Python 3 types \\ |
208 \hline | 243 \hline |
209 \sigchar{B} & bool \\ | 244 \sigchar{v} & no return type & no return type \\ |
210 \sigchar{c} & if string, take first item\\ | 245 \sigchar{B} & bool & bool \\ |
211 \sigchar{s} & int, check in range\\ | 246 \sigchar{c}, \sigchar{C} & int, string (with single char) & int, string (with single char) \\ |
212 \sigchar{i} & int\\ | 247 \sigchar{s}, \sigchar{S} & int & int \\ |
213 \sigchar{j} & int\\ | 248 \sigchar{i}, \sigchar{I} & int & int \\ |
214 \sigchar{l} & long, casted to long long\\ | 249 \sigchar{j}, \sigchar{J} & int & int \\ |
215 \sigchar{f} & float\\ | 250 \sigchar{l}, \sigchar{L} & int, long & int \\ |
216 \sigchar{d} & double\\ | 251 \sigchar{f} & float & float \\ |
217 \sigchar{p} & string or long casted to void*\\ | 252 \sigchar{d} & double & double \\ |
218 \sigchar{v} & no return type\\ | 253 \sigchar{p} & bytearray, int, long & bytearray (mutable in C), int \\ |
254 \sigchar{Z} & string, unicode, bytearray & string, bytearray (all immutable) \\ | |
219 \end{tabular*} | 255 \end{tabular*} |
220 \caption{Type signature encoding for Python bindings} | 256 \caption{Type signature encoding for Python bindings} |
221 \label{Pysigchar} | 257 \label{Pysigchar} |
222 \end{center} | 258 \end{center} |
223 \end{table} | 259 \end{table} |
224 | 260 |
261 For more details, refer to the README.txt file of the binding. | |
262 | |
225 \pagebreak | 263 \pagebreak |
226 | 264 |
227 \subsection{R language bindings} | 265 \subsection{R language bindings} |
228 | 266 |
229 The R package {\tt rdyncall} implements the R langugae bindings providing the function | 267 The R package {\tt rdyncall} implements the R langugae bindings providing the function |
232 \begin{table}[h] | 270 \begin{table}[h] |
233 \begin{center} | 271 \begin{center} |
234 \begin{tabular*}{0.75\textwidth}{ll} | 272 \begin{tabular*}{0.75\textwidth}{ll} |
235 Signature character & accepted R data types\\ | 273 Signature character & accepted R data types\\ |
236 \hline | 274 \hline |
275 \sigchar{v} & no return type\\ | |
237 \sigchar{B} & coerced to logical vector, first item\\ | 276 \sigchar{B} & coerced to logical vector, first item\\ |
238 \sigchar{c} & coerced to integer vector, first item truncated char\\ | 277 \sigchar{c} & coerced to integer vector, first item truncated char\\ |
239 \sigchar{C} & coerced to integer vector, first item truncated to unsigned char\\ | 278 \sigchar{C} & coerced to integer vector, first item truncated to unsigned char\\ |
240 \sigchar{s} & coerced to integer vector, first item truncated to short\\ | 279 \sigchar{s} & coerced to integer vector, first item truncated to short\\ |
241 \sigchar{S} & coerced to integer vector, first item truncated to unsigned short\\ | 280 \sigchar{S} & coerced to integer vector, first item truncated to unsigned short\\ |
247 \sigchar{L} & coerced to numeric, first item casted to unsigned long long\\ | 286 \sigchar{L} & coerced to numeric, first item casted to unsigned long long\\ |
248 \sigchar{f} & coerced to numeric, first item casted to float\\ | 287 \sigchar{f} & coerced to numeric, first item casted to float\\ |
249 \sigchar{d} & coerced to numeric, first item\\ | 288 \sigchar{d} & coerced to numeric, first item\\ |
250 \sigchar{p} & external pointer or coerced to string vector, first item\\ | 289 \sigchar{p} & external pointer or coerced to string vector, first item\\ |
251 \sigchar{Z} & coerced to string vector, first item\\ | 290 \sigchar{Z} & coerced to string vector, first item\\ |
252 \sigchar{v} & no return type\\ | |
253 \end{tabular*} | 291 \end{tabular*} |
254 \caption{Type signature encoding for R bindings} | 292 \caption{Type signature encoding for R bindings} |
255 \label{Rsigchar} | 293 \label{Rsigchar} |
256 \end{center} | 294 \end{center} |
257 \end{table} | 295 \end{table} |
272 \begin{table}[h] | 310 \begin{table}[h] |
273 \begin{center} | 311 \begin{center} |
274 \begin{tabular*}{0.75\textwidth}{ll} | 312 \begin{tabular*}{0.75\textwidth}{ll} |
275 Signature character & accepted Ruby data types\\ | 313 Signature character & accepted Ruby data types\\ |
276 \hline | 314 \hline |
315 \sigchar{v} & no return type\\ | |
277 \sigchar{B} & TrueClass, FalseClass, NilClass, Fixnum casted to bool\\ | 316 \sigchar{B} & TrueClass, FalseClass, NilClass, Fixnum casted to bool\\ |
278 \sigchar{c}, \sigchar{C} & Fixnum cast to (unsigned) char\\ | 317 \sigchar{c}, \sigchar{C} & Fixnum cast to (unsigned) char\\ |
279 \sigchar{s}, \sigchar{S} & Fixnum cast to (unsigned) short\\ | 318 \sigchar{s}, \sigchar{S} & Fixnum cast to (unsigned) short\\ |
280 \sigchar{i}, \sigchar{I} & Fixnum cast to (unsigned) int\\ | 319 \sigchar{i}, \sigchar{I} & Fixnum cast to (unsigned) int\\ |
281 \sigchar{j}, \sigchar{J} & Fixnum cast to (unsigned) long\\ | 320 \sigchar{j}, \sigchar{J} & Fixnum cast to (unsigned) long\\ |
282 \sigchar{l}, \sigchar{L} & Fixnum cast to (unsigned) long long\\ | 321 \sigchar{l}, \sigchar{L} & Fixnum cast to (unsigned) long long\\ |
283 \sigchar{f} & Float cast to float\\ | 322 \sigchar{f} & Float cast to float\\ |
284 \sigchar{d} & Float cast to double\\ | 323 \sigchar{d} & Float cast to double\\ |
285 \sigchar{p}, \sigchar{Z} & String cast to void*\\ | 324 \sigchar{p}, \sigchar{Z} & String cast to void*\\ |
286 \sigchar{v} & no return type\\ | |
287 \end{tabular*} | 325 \end{tabular*} |
288 \caption{Type signature encoding for Ruby bindings} | 326 \caption{Type signature encoding for Ruby bindings} |
289 \label{Rubysigchar} | 327 \label{Rubysigchar} |
290 \end{center} | 328 \end{center} |
291 \end{table} | 329 \end{table} |
330 |