| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE book [ |
| 3 |
<!ENTITY % eclent SYSTEM "../ecl.ent"> |
| 4 |
%eclent; |
| 5 |
]> |
| 6 |
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> |
| 7 |
<reference xml:id="uffi.objects"> |
| 8 |
<title>Objects</title> |
| 9 |
<partintro> |
| 10 |
<title>Overview</title> |
| 11 |
<para> |
| 12 |
Objects are entities that can allocated, referred to by pointers, and |
| 13 |
can be freed.</para> |
| 14 |
</partintro> |
| 15 |
|
| 16 |
|
| 17 |
<refentry xml:id="uffi.allocate-foreign-object"> |
| 18 |
<refnamediv> |
| 19 |
<refname><function>allocate-foreign-object</function></refname> |
| 20 |
<refpurpose>Allocates an instance of a foreign object. |
| 21 |
</refpurpose> |
| 22 |
</refnamediv> |
| 23 |
|
| 24 |
<refsynopsisdiv> |
| 25 |
<title>Macro</title> |
| 26 |
<funcsynopsis> |
| 27 |
<funcprototype> |
| 28 |
<funcdef>allocate-foreign-object</funcdef> |
| 29 |
<paramdef><parameter>type</parameter></paramdef> |
| 30 |
<paramdef>&optional;</paramdef> |
| 31 |
<paramdef><parameter>size</parameter></paramdef> |
| 32 |
</funcprototype> |
| 33 |
</funcsynopsis> |
| 34 |
<variablelist> |
| 35 |
<varlistentry> |
| 36 |
<term><parameter>type</parameter></term> |
| 37 |
<listitem> |
| 38 |
<para>The type of foreign object to allocate. This parameter is evaluated.</para> |
| 39 |
</listitem> |
| 40 |
</varlistentry> |
| 41 |
<varlistentry> |
| 42 |
<term><parameter>size</parameter></term> |
| 43 |
<listitem> |
| 44 |
<para>An optional size parameter that is evaluated. If specified, allocates and returns an |
| 45 |
array of <parameter>type</parameter> that is <parameter>size</parameter> members long. This parameter is evaluated.</para> |
| 46 |
</listitem> |
| 47 |
</varlistentry> |
| 48 |
<varlistentry> |
| 49 |
<term>returns</term> |
| 50 |
<listitem> |
| 51 |
<para>A pointer to the foreign object.</para> |
| 52 |
</listitem> |
| 53 |
</varlistentry> |
| 54 |
</variablelist> |
| 55 |
</refsynopsisdiv> |
| 56 |
|
| 57 |
<refsect1> |
| 58 |
<title>Description</title> |
| 59 |
<para>Allocates an instance of a foreign object. It returns a pointer to |
| 60 |
the object.</para> |
| 61 |
</refsect1> |
| 62 |
<refsect1> |
| 63 |
<title>Examples</title> |
| 64 |
<screen> |
| 65 |
(def-struct ab (a :int) (b :double)) |
| 66 |
(allocate-foreign-object 'ab) |
| 67 |
=> #<ptr></screen> |
| 68 |
</refsect1> |
| 69 |
<refsect1> |
| 70 |
<title>Side Effects</title> |
| 71 |
<para>None.</para> |
| 72 |
</refsect1> |
| 73 |
<refsect1> |
| 74 |
<title>Affected by</title> |
| 75 |
<para>None.</para> |
| 76 |
</refsect1> |
| 77 |
<refsect1> |
| 78 |
<title>Exceptional Situations</title> |
| 79 |
<para>None.</para> |
| 80 |
</refsect1> |
| 81 |
</refentry> |
| 82 |
|
| 83 |
|
| 84 |
<refentry xml:id="uffi.free-foreign-object"> |
| 85 |
<refnamediv> |
| 86 |
<refname><function>free-foreign-object</function></refname> |
| 87 |
<refpurpose>Frees memory that was allocated for a foreign boject. |
| 88 |
</refpurpose> |
| 89 |
</refnamediv> |
| 90 |
|
| 91 |
<refsynopsisdiv> |
| 92 |
<title>Macro</title> |
| 93 |
<funcsynopsis> |
| 94 |
<funcprototype> |
| 95 |
<funcdef>free-foreign-object</funcdef> |
| 96 |
<paramdef><parameter>ptr</parameter></paramdef> |
| 97 |
</funcprototype> |
| 98 |
</funcsynopsis> |
| 99 |
<variablelist> |
| 100 |
<varlistentry> |
| 101 |
<term><parameter>ptr</parameter></term> |
| 102 |
<listitem> |
| 103 |
<para>A pointer to the allocated foreign object to free.</para> |
| 104 |
</listitem> |
| 105 |
</varlistentry> |
| 106 |
</variablelist> |
| 107 |
</refsynopsisdiv> |
| 108 |
|
| 109 |
<refsect1> |
| 110 |
<title>Description</title> |
| 111 |
<para> |
| 112 |
Frees the memory used by the allocation of a foreign object.</para> |
| 113 |
</refsect1> |
| 114 |
<refsect1> |
| 115 |
<title>Side Effects</title> |
| 116 |
<para>None.</para> |
| 117 |
</refsect1> |
| 118 |
<refsect1> |
| 119 |
<title>Affected by</title> |
| 120 |
<para>None.</para> |
| 121 |
</refsect1> |
| 122 |
<refsect1> |
| 123 |
<title>Exceptional Situations</title> |
| 124 |
<para>None.</para> |
| 125 |
</refsect1> |
| 126 |
</refentry> |
| 127 |
|
| 128 |
|
| 129 |
<refentry xml:id="uffi.with-foreign-object"> |
| 130 |
<refnamediv> |
| 131 |
<refname><function>with-foreign-object</function></refname> |
| 132 |
<refpurpose>Wraps the allocation of a foreign object around a body of code. |
| 133 |
</refpurpose> |
| 134 |
</refnamediv> |
| 135 |
|
| 136 |
<refsynopsisdiv> |
| 137 |
<title>Macro</title> |
| 138 |
<funcsynopsis> |
| 139 |
<funcprototype> |
| 140 |
<funcdef>with-foreign-object</funcdef> |
| 141 |
<paramdef><parameter>(var type)</parameter></paramdef> |
| 142 |
<paramdef><parameter>&body;</parameter></paramdef> |
| 143 |
<paramdef><parameter>body</parameter></paramdef> |
| 144 |
</funcprototype> |
| 145 |
</funcsynopsis> |
| 146 |
</refsynopsisdiv> |
| 147 |
<refsect1> |
| 148 |
<title>Arguments and Values</title> |
| 149 |
<variablelist> |
| 150 |
<varlistentry> |
| 151 |
<term><parameter>var</parameter></term> |
| 152 |
<listitem> |
| 153 |
<para>The variable name to bind.</para> |
| 154 |
</listitem> |
| 155 |
</varlistentry> |
| 156 |
<varlistentry> |
| 157 |
<term><parameter>type</parameter></term> |
| 158 |
<listitem> |
| 159 |
<para>The type of foreign object to allocate. This parameter is evaluated.</para> |
| 160 |
</listitem> |
| 161 |
</varlistentry> |
| 162 |
<varlistentry> |
| 163 |
<term>returns</term> |
| 164 |
<listitem> |
| 165 |
<para>The result of evaluating the <parameter>body</parameter>.</para> |
| 166 |
</listitem> |
| 167 |
</varlistentry> |
| 168 |
</variablelist> |
| 169 |
</refsect1> |
| 170 |
<refsect1> |
| 171 |
<title>Description</title> <para> This function wraps the allocation, |
| 172 |
binding, and destruction of a foreign object. On &CMUCL; and &LW; |
| 173 |
platforms the object is stack allocated for efficiency. Benchmarks show |
| 174 |
that &ACL; performs much better with static allocation.</para> |
| 175 |
</refsect1> |
| 176 |
<refsect1> |
| 177 |
<title>Examples</title> |
| 178 |
<screen> |
| 179 |
(defun gethostname2 () |
| 180 |
"Returns the hostname" |
| 181 |
(uffi:with-foreign-object (name '(:array :unsigned-char 256)) |
| 182 |
(if (zerop (c-gethostname (uffi:char-array-to-pointer name) 256)) |
| 183 |
(uffi:convert-from-foreign-string name) |
| 184 |
(error "gethostname() failed."))))</screen> |
| 185 |
</refsect1> |
| 186 |
<refsect1> |
| 187 |
<title>Side Effects</title> |
| 188 |
<para>None.</para> |
| 189 |
</refsect1> |
| 190 |
<refsect1> |
| 191 |
<title>Affected by</title> |
| 192 |
<para>None.</para> |
| 193 |
</refsect1> |
| 194 |
<refsect1> |
| 195 |
<title>Exceptional Situations</title> |
| 196 |
<para>None.</para> |
| 197 |
</refsect1> |
| 198 |
</refentry> |
| 199 |
|
| 200 |
<refentry xml:id="uffi.size-of-foreign-type"> |
| 201 |
<refnamediv> |
| 202 |
<refname><function>size-of-foreign-type</function></refname> |
| 203 |
<refpurpose>Returns the number of data bytes used by a foreign object type. |
| 204 |
</refpurpose> |
| 205 |
</refnamediv> |
| 206 |
|
| 207 |
<refsynopsisdiv> |
| 208 |
<title>Macro</title> |
| 209 |
<funcsynopsis> |
| 210 |
<funcprototype> |
| 211 |
<funcdef>size-of-foreign-type</funcdef> |
| 212 |
<paramdef><parameter>ftype</parameter></paramdef> |
| 213 |
</funcprototype> |
| 214 |
</funcsynopsis> |
| 215 |
<variablelist> |
| 216 |
<varlistentry> |
| 217 |
<term><parameter>ftype</parameter></term> |
| 218 |
<listitem> |
| 219 |
<para>A foreign type specifier. This parameter is evaluated.</para> |
| 220 |
</listitem> |
| 221 |
</varlistentry> |
| 222 |
</variablelist> |
| 223 |
</refsynopsisdiv> |
| 224 |
|
| 225 |
<refsect1> |
| 226 |
<title>Description</title> |
| 227 |
<para> |
| 228 |
Returns the number of data bytes used by a foreign object type. This does not include any Lisp storage overhead.</para> |
| 229 |
</refsect1> |
| 230 |
<refsect1> |
| 231 |
<title>Examples</title> |
| 232 |
<para> |
| 233 |
<screen> |
| 234 |
(size-of-foreign-object :unsigned-byte) |
| 235 |
=> 1 |
| 236 |
(size-of-foreign-object 'my-100-byte-vector-type) |
| 237 |
=> 100</screen></para> |
| 238 |
</refsect1> |
| 239 |
<refsect1> |
| 240 |
<title>Side Effects</title> |
| 241 |
<para>None.</para> |
| 242 |
</refsect1> <refsect1> |
| 243 |
<title>Affected by</title> |
| 244 |
<para>None.</para> |
| 245 |
</refsect1> |
| 246 |
<refsect1> |
| 247 |
<title>Exceptional Situations</title> |
| 248 |
<para>None.</para> |
| 249 |
</refsect1> |
| 250 |
</refentry> |
| 251 |
|
| 252 |
<refentry xml:id="uffi.pointer-address"> |
| 253 |
<refnamediv> |
| 254 |
<refname><function>pointer-address</function></refname> |
| 255 |
<refpurpose>Returns the address of a pointer. |
| 256 |
</refpurpose> |
| 257 |
</refnamediv> |
| 258 |
|
| 259 |
<refsynopsisdiv> |
| 260 |
<title>Macro</title> |
| 261 |
<funcsynopsis> |
| 262 |
<funcprototype> |
| 263 |
<funcdef>pointer-address</funcdef> |
| 264 |
<paramdef><parameter>ptr</parameter></paramdef> |
| 265 |
</funcprototype> |
| 266 |
</funcsynopsis> |
| 267 |
<variablelist> |
| 268 |
<varlistentry> |
| 269 |
<term><parameter>ptr</parameter></term> |
| 270 |
<listitem> |
| 271 |
<para>A pointer to a foreign object.</para> |
| 272 |
</listitem> |
| 273 |
</varlistentry> |
| 274 |
<varlistentry> |
| 275 |
<term>returns</term> |
| 276 |
<listitem> |
| 277 |
<para>An integer representing the pointer's address.</para> |
| 278 |
</listitem> |
| 279 |
</varlistentry> |
| 280 |
</variablelist> |
| 281 |
</refsynopsisdiv> |
| 282 |
|
| 283 |
<refsect1> |
| 284 |
<title>Description</title> |
| 285 |
<para> |
| 286 |
Returns the address as an integer of a pointer.</para> |
| 287 |
</refsect1> |
| 288 |
<refsect1> |
| 289 |
<title>Side Effects</title> |
| 290 |
<para>None.</para> |
| 291 |
</refsect1> |
| 292 |
<refsect1> |
| 293 |
<title>Affected by</title> |
| 294 |
<para>None.</para> |
| 295 |
</refsect1> |
| 296 |
<refsect1> |
| 297 |
<title>Exceptional Situations</title> |
| 298 |
<para>None.</para> |
| 299 |
</refsect1> |
| 300 |
</refentry> |
| 301 |
|
| 302 |
|
| 303 |
<refentry xml:id="uffi.deref-pointer"> |
| 304 |
<refnamediv> |
| 305 |
<refname><function>deref-pointer</function></refname> |
| 306 |
<refpurpose>Deferences a pointer. |
| 307 |
</refpurpose> |
| 308 |
</refnamediv> |
| 309 |
|
| 310 |
<refsynopsisdiv> |
| 311 |
<title>Macro</title> |
| 312 |
<funcsynopsis> |
| 313 |
<funcprototype> |
| 314 |
<funcdef>deref-pointer</funcdef> |
| 315 |
<paramdef><parameter>ptr</parameter></paramdef> |
| 316 |
<paramdef><parameter>type</parameter></paramdef> |
| 317 |
</funcprototype> |
| 318 |
</funcsynopsis> |
| 319 |
<variablelist> |
| 320 |
<varlistentry> |
| 321 |
<term><parameter>ptr</parameter></term> |
| 322 |
<listitem> |
| 323 |
<para>A pointer to a foreign object.</para> |
| 324 |
</listitem> |
| 325 |
</varlistentry> |
| 326 |
<varlistentry> |
| 327 |
<term><parameter>type</parameter></term> |
| 328 |
<listitem> |
| 329 |
<para>A foreign type of the object being pointed to.</para> |
| 330 |
</listitem> |
| 331 |
</varlistentry> |
| 332 |
<varlistentry> |
| 333 |
<term>returns</term> |
| 334 |
<listitem> |
| 335 |
<para>The value of the object where the pointer points.</para> |
| 336 |
</listitem> |
| 337 |
</varlistentry> |
| 338 |
</variablelist> |
| 339 |
</refsynopsisdiv> |
| 340 |
|
| 341 |
<refsect1> |
| 342 |
<title>Description</title> |
| 343 |
<para> |
| 344 |
Returns the object to which a pointer points.</para> |
| 345 |
</refsect1> |
| 346 |
<refsect1> |
| 347 |
<title>Examples</title> |
| 348 |
<para> |
| 349 |
<screen> |
| 350 |
(let ((intp (allocate-foreign-object :int))) |
| 351 |
(setf (deref-pointer intp :int) 10) |
| 352 |
(prog1 |
| 353 |
(deref-pointer intp :int) |
| 354 |
(free-foreign-object intp))) |
| 355 |
=> 10</screen></para> |
| 356 |
</refsect1> |
| 357 |
<refsect1> |
| 358 |
<title>Notes</title> |
| 359 |
<para> |
| 360 |
The TYPE argument is ignored for CL implementations other than |
| 361 |
AllegroCL. If you want to cast a pointer to another type use |
| 362 |
WITH-CAST-POINTER together with DEREF-POINTER/DEREF-ARRAY.</para> |
| 363 |
</refsect1> |
| 364 |
<refsect1> |
| 365 |
<title>Side Effects</title> |
| 366 |
<para>None.</para> |
| 367 |
</refsect1> |
| 368 |
<refsect1> |
| 369 |
<title>Affected by</title> |
| 370 |
<para>None.</para> |
| 371 |
</refsect1> |
| 372 |
<refsect1> |
| 373 |
<title>Exceptional Situations</title> |
| 374 |
<para>None.</para> |
| 375 |
</refsect1> |
| 376 |
</refentry> |
| 377 |
|
| 378 |
<refentry xml:id="uffi.ensure-char-character"> |
| 379 |
<refnamediv> |
| 380 |
<refname><function>ensure-char-character</function></refname> |
| 381 |
<refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is |
| 382 |
a character. |
| 383 |
</refpurpose> |
| 384 |
</refnamediv> |
| 385 |
|
| 386 |
<refsynopsisdiv> |
| 387 |
<title>Macro</title> |
| 388 |
<funcsynopsis> |
| 389 |
<funcprototype> |
| 390 |
<funcdef>ensure-char-character</funcdef> |
| 391 |
<paramdef><parameter>object</parameter></paramdef> |
| 392 |
</funcprototype> |
| 393 |
</funcsynopsis> |
| 394 |
<variablelist> |
| 395 |
<varlistentry> |
| 396 |
<term><parameter>object</parameter></term> |
| 397 |
<listitem> |
| 398 |
<para>Either a character or a integer specifying a character code.</para> |
| 399 |
</listitem> |
| 400 |
</varlistentry> |
| 401 |
<varlistentry> |
| 402 |
<term>returns</term> |
| 403 |
<listitem> |
| 404 |
<para>A character.</para> |
| 405 |
</listitem> |
| 406 |
</varlistentry> |
| 407 |
</variablelist> |
| 408 |
</refsynopsisdiv> |
| 409 |
|
| 410 |
<refsect1> |
| 411 |
<title>Description</title> |
| 412 |
<para> |
| 413 |
Ensures that an objects obtained by dereferencing |
| 414 |
<constant>:char</constant> and <constant>:unsigned-char</constant> |
| 415 |
pointers are a lisp character.</para> |
| 416 |
</refsect1> |
| 417 |
<refsect1> |
| 418 |
<title>Examples</title> |
| 419 |
<para> |
| 420 |
<screen> |
| 421 |
(let ((fs (convert-to-foreign-string "a"))) |
| 422 |
(prog1 |
| 423 |
(ensure-char-character (deref-pointer fs :char)) |
| 424 |
(free-foreign-object fs))) |
| 425 |
=> #\a</screen></para> |
| 426 |
</refsect1> |
| 427 |
<refsect1> |
| 428 |
<title>Side Effects</title> |
| 429 |
<para>None.</para> |
| 430 |
</refsect1> |
| 431 |
<refsect1> |
| 432 |
<title>Affected by</title> |
| 433 |
<para>None.</para> |
| 434 |
</refsect1> |
| 435 |
<refsect1> |
| 436 |
<title>Exceptional Situations</title> |
| 437 |
<para>Depending upon the implementation and what &UFFI; expects, this |
| 438 |
macro may signal an error if the object is not a character or |
| 439 |
integer.</para> |
| 440 |
</refsect1> |
| 441 |
</refentry> |
| 442 |
|
| 443 |
<refentry xml:id="uffi.ensure-char-integer"> |
| 444 |
<refnamediv> |
| 445 |
<refname><function>ensure-char-integer</function></refname> |
| 446 |
<refpurpose>Ensures that a dereferenced <constant>:char</constant> pointer is |
| 447 |
an integer. |
| 448 |
</refpurpose> |
| 449 |
</refnamediv> |
| 450 |
|
| 451 |
<refsynopsisdiv> |
| 452 |
<title>Macro</title> |
| 453 |
<funcsynopsis> |
| 454 |
<funcprototype> |
| 455 |
<funcdef>ensure-char-integer</funcdef> |
| 456 |
<paramdef><parameter>object</parameter></paramdef> |
| 457 |
</funcprototype> |
| 458 |
</funcsynopsis> |
| 459 |
<variablelist> |
| 460 |
<varlistentry> |
| 461 |
<term><parameter>object</parameter></term> |
| 462 |
<listitem> |
| 463 |
<para>Either a character or a integer specifying a character code.</para> |
| 464 |
</listitem> |
| 465 |
</varlistentry> |
| 466 |
<varlistentry> |
| 467 |
<term>returns</term> |
| 468 |
<listitem> |
| 469 |
<para>An integer.</para> |
| 470 |
</listitem> |
| 471 |
</varlistentry> |
| 472 |
</variablelist> |
| 473 |
</refsynopsisdiv> |
| 474 |
|
| 475 |
<refsect1> |
| 476 |
<title>Description</title> |
| 477 |
<para> |
| 478 |
Ensures that an object obtained by dereferencing a |
| 479 |
<constant>:char</constant> pointer is an integer.</para> |
| 480 |
</refsect1> |
| 481 |
<refsect1> |
| 482 |
<title>Examples</title> |
| 483 |
<para> |
| 484 |
<screen> |
| 485 |
(let ((fs (convert-to-foreign-string "a"))) |
| 486 |
(prog1 |
| 487 |
(ensure-char-integer (deref-pointer fs :char)) |
| 488 |
(free-foreign-object fs))) |
| 489 |
=> 96</screen></para> |
| 490 |
</refsect1> |
| 491 |
<refsect1> |
| 492 |
<title>Side Effects</title> |
| 493 |
<para>None.</para> |
| 494 |
</refsect1> |
| 495 |
<refsect1> |
| 496 |
<title>Affected by</title> |
| 497 |
<para>None.</para> |
| 498 |
</refsect1> |
| 499 |
<refsect1> |
| 500 |
<title>Exceptional Situations</title> |
| 501 |
<para>Depending upon the implementation and what &UFFI; expects, this |
| 502 |
macro may signal an error if the object is not a character or |
| 503 |
integer.</para> |
| 504 |
</refsect1> |
| 505 |
</refentry> |
| 506 |
|
| 507 |
<refentry xml:id="uffi.make-null-pointer"> |
| 508 |
<refnamediv> |
| 509 |
<refname><function>make-null-pointer</function></refname> |
| 510 |
<refpurpose>Create a &NULL; pointer. |
| 511 |
</refpurpose> |
| 512 |
</refnamediv> |
| 513 |
<refsynopsisdiv> |
| 514 |
<title>Macro</title> |
| 515 |
<funcsynopsis> |
| 516 |
<funcprototype> |
| 517 |
<funcdef>make-null-pointer</funcdef> |
| 518 |
<paramdef><parameter>type</parameter></paramdef> |
| 519 |
</funcprototype> |
| 520 |
</funcsynopsis> |
| 521 |
<variablelist> |
| 522 |
<varlistentry> |
| 523 |
<term><parameter>type</parameter></term> |
| 524 |
<listitem> |
| 525 |
<para>A type of object to which the pointer refers.</para> |
| 526 |
</listitem> |
| 527 |
</varlistentry> |
| 528 |
<varlistentry> |
| 529 |
<term>returns</term> |
| 530 |
<listitem> |
| 531 |
<para>The &NULL; pointer of type <parameter>type</parameter>.</para> |
| 532 |
</listitem> |
| 533 |
</varlistentry> |
| 534 |
</variablelist> |
| 535 |
</refsynopsisdiv> |
| 536 |
|
| 537 |
<refsect1> |
| 538 |
<title>Description</title> |
| 539 |
<para> |
| 540 |
Creates a &NULL; pointer of a specified type.</para> |
| 541 |
</refsect1> |
| 542 |
<refsect1> |
| 543 |
<title>Side Effects</title> |
| 544 |
<para>None.</para> |
| 545 |
</refsect1> |
| 546 |
<refsect1> |
| 547 |
<title>Affected by</title> |
| 548 |
<para>None.</para> |
| 549 |
</refsect1> |
| 550 |
<refsect1> |
| 551 |
<title>Exceptional Situations</title> |
| 552 |
<para>None.</para> |
| 553 |
</refsect1> |
| 554 |
</refentry> |
| 555 |
|
| 556 |
|
| 557 |
<refentry xml:id="uffi.null-pointer-p"> |
| 558 |
<refnamediv> |
| 559 |
<refname><function>null-pointer-p</function></refname> |
| 560 |
<refpurpose>Tests a pointer for &NULL; value. |
| 561 |
</refpurpose> |
| 562 |
</refnamediv> |
| 563 |
|
| 564 |
<refsynopsisdiv> |
| 565 |
<title>Macro</title> |
| 566 |
<funcsynopsis> |
| 567 |
<funcprototype> |
| 568 |
<funcdef>null-pointer-p</funcdef> |
| 569 |
<paramdef><parameter>ptr</parameter></paramdef> |
| 570 |
</funcprototype> |
| 571 |
</funcsynopsis> |
| 572 |
<variablelist> |
| 573 |
<varlistentry> |
| 574 |
<term><parameter>ptr</parameter></term> |
| 575 |
<listitem> |
| 576 |
<para>A foreign object pointer.</para> |
| 577 |
</listitem> |
| 578 |
</varlistentry> |
| 579 |
<varlistentry> |
| 580 |
<term>returns</term> |
| 581 |
<listitem> |
| 582 |
<para>The boolean flag.</para> |
| 583 |
</listitem> |
| 584 |
</varlistentry> |
| 585 |
</variablelist> |
| 586 |
</refsynopsisdiv> |
| 587 |
|
| 588 |
<refsect1> |
| 589 |
<title>Description</title> |
| 590 |
<para> |
| 591 |
A predicate testing if a pointer is has a &NULL; value.</para> |
| 592 |
</refsect1> |
| 593 |
<refsect1> |
| 594 |
<title>Side Effects</title> |
| 595 |
<para>None.</para> |
| 596 |
</refsect1> |
| 597 |
<refsect1> |
| 598 |
<title>Affected by</title> |
| 599 |
<para>None.</para> |
| 600 |
</refsect1> |
| 601 |
<refsect1> |
| 602 |
<title>Exceptional Situations</title> |
| 603 |
<para>None.</para> |
| 604 |
</refsect1> |
| 605 |
</refentry> |
| 606 |
|
| 607 |
|
| 608 |
<refentry xml:id="uffi.null-cstring-pointer"> |
| 609 |
<refnamediv> |
| 610 |
<refname><varname>+null-cstring-pointer+</varname></refname> |
| 611 |
<refpurpose>A constant &NULL; cstring pointer. |
| 612 |
</refpurpose> |
| 613 |
<refclass>Constant</refclass> |
| 614 |
</refnamediv> |
| 615 |
|
| 616 |
<refsect1> |
| 617 |
<title>Description</title> |
| 618 |
<para> |
| 619 |
A &NULL; cstring pointer. This can be used for testing |
| 620 |
if a cstring returned by a function is &NULL;.</para> |
| 621 |
</refsect1> |
| 622 |
</refentry> |
| 623 |
|
| 624 |
<refentry xml:id="uffi.with-cast-pointer"> |
| 625 |
<refnamediv> |
| 626 |
<refname><function>with-cast-pointer</function></refname> |
| 627 |
<refpurpose>Wraps a body of code with a pointer cast to a new type. |
| 628 |
</refpurpose> |
| 629 |
</refnamediv> |
| 630 |
|
| 631 |
<refsynopsisdiv> |
| 632 |
<title>Macro</title> |
| 633 |
<funcsynopsis> |
| 634 |
<funcprototype> |
| 635 |
<funcdef>with-cast-pointer</funcdef> |
| 636 |
<paramdef>(<parameter>binding-name ptr type</parameter>)</paramdef> |
| 637 |
<paramdef>&body;</paramdef> |
| 638 |
<paramdef><parameter>body</parameter></paramdef> |
| 639 |
</funcprototype> |
| 640 |
</funcsynopsis> |
| 641 |
<variablelist> |
| 642 |
<varlistentry> |
| 643 |
<term><parameter>binding-name</parameter></term> |
| 644 |
<listitem> |
| 645 |
<para>A symbol which will be bound to the casted object.</para> |
| 646 |
</listitem> |
| 647 |
</varlistentry> |
| 648 |
<varlistentry> |
| 649 |
<term><parameter>ptr</parameter></term> |
| 650 |
<listitem> |
| 651 |
<para>A pointer to a foreign object.</para> |
| 652 |
</listitem> |
| 653 |
</varlistentry> |
| 654 |
<varlistentry> |
| 655 |
<term><parameter>type</parameter></term> |
| 656 |
<listitem> |
| 657 |
<para>A foreign type of the object being pointed to.</para> |
| 658 |
</listitem> |
| 659 |
</varlistentry> |
| 660 |
<varlistentry> |
| 661 |
<term>returns</term> |
| 662 |
<listitem> |
| 663 |
<para>The value of the object where the pointer points.</para> |
| 664 |
</listitem> |
| 665 |
</varlistentry> |
| 666 |
</variablelist> |
| 667 |
</refsynopsisdiv> |
| 668 |
|
| 669 |
<refsect1> |
| 670 |
<title>Description</title> |
| 671 |
<para> |
| 672 |
Executes BODY with POINTER cast to be a pointer to type TYPE. |
| 673 |
BINDING-NAME is will be bound to this value during the execution of |
| 674 |
BODY. |
| 675 |
|
| 676 |
This is a no-op in AllegroCL but will wrap BODY in a LET form if |
| 677 |
BINDING-NAME is provided. |
| 678 |
|
| 679 |
This macro is meant to be used in conjunction with DEREF-POINTER or |
| 680 |
DEREF-ARRAY. In Allegro CL the "cast" will actually take place in |
| 681 |
DEREF-POINTER or DEREF-ARRAY.</para> |
| 682 |
</refsect1> |
| 683 |
<refsect1> |
| 684 |
<title>Examples</title> |
| 685 |
<screen> |
| 686 |
(with-foreign-object (size :int) |
| 687 |
;; FOO is a foreign function returning a :POINTER-VOID |
| 688 |
(let ((memory (foo size))) |
| 689 |
(when (mumble) |
| 690 |
;; at this point we know for some reason that MEMORY points |
| 691 |
;; to an array of unsigned bytes |
| 692 |
(with-cast-pointer (memory :unsigned-byte) |
| 693 |
(dotimes (i (deref-pointer size :int)) |
| 694 |
(do-something-with |
| 695 |
(deref-array memory '(:array :unsigned-byte) i)))))))</screen> |
| 696 |
</refsect1> |
| 697 |
<refsect1> |
| 698 |
<title>Side Effects</title> |
| 699 |
<para>None.</para> |
| 700 |
</refsect1> |
| 701 |
<refsect1> |
| 702 |
<title>Affected by</title> |
| 703 |
<para>None.</para> |
| 704 |
</refsect1> |
| 705 |
<refsect1> |
| 706 |
<title>Exceptional Situations</title> |
| 707 |
<para>None.</para> |
| 708 |
</refsect1> |
| 709 |
</refentry> |
| 710 |
|
| 711 |
<refentry xml:id="uffi.def-foreign-var"> |
| 712 |
<refnamediv> |
| 713 |
<refname><function>def-foreign-var</function></refname> |
| 714 |
<refpurpose> |
| 715 |
Defines a symbol macro to access a variable in foreign code |
| 716 |
</refpurpose> |
| 717 |
</refnamediv> |
| 718 |
<refsynopsisdiv> |
| 719 |
<title>Macro</title> |
| 720 |
<funcsynopsis> |
| 721 |
<funcprototype> |
| 722 |
<funcdef>def-foreign-var</funcdef> |
| 723 |
<paramdef><parameter>name</parameter></paramdef> |
| 724 |
<paramdef><parameter>type</parameter></paramdef> |
| 725 |
<paramdef><parameter>module</parameter></paramdef> |
| 726 |
</funcprototype> |
| 727 |
</funcsynopsis> |
| 728 |
<variablelist> |
| 729 |
<varlistentry> |
| 730 |
<term><parameter>name</parameter></term> |
| 731 |
<listitem> |
| 732 |
<para> |
| 733 |
A string or list specificying the symbol macro's name. If it is a |
| 734 |
string, that names the foreign variable. A Lisp name is created |
| 735 |
by translating #\_ to #\- and by converting to upper-case in |
| 736 |
case-insensitive Lisp implementations. If it is a list, the first |
| 737 |
item is a string specifying the foreign variable name and the |
| 738 |
second it is a symbol stating the Lisp name.</para> |
| 739 |
</listitem> |
| 740 |
</varlistentry> |
| 741 |
<varlistentry> |
| 742 |
<term><parameter>type</parameter></term> |
| 743 |
<listitem> |
| 744 |
<para>A foreign type of the foreign variable.</para> |
| 745 |
</listitem> |
| 746 |
</varlistentry> |
| 747 |
<varlistentry> |
| 748 |
<term><returnvalue>module</returnvalue></term> |
| 749 |
<listitem> |
| 750 |
<para> |
| 751 |
A string specifying the module (or library) the foreign variable |
| 752 |
resides in. (Required by Lispworks)</para> |
| 753 |
</listitem> |
| 754 |
</varlistentry> |
| 755 |
</variablelist> |
| 756 |
</refsynopsisdiv> |
| 757 |
<refsect1> |
| 758 |
<title>Description</title> |
| 759 |
<para> |
| 760 |
Defines a symbol macro which can be used to access (get and set) the |
| 761 |
value of a variable in foreign code.</para> |
| 762 |
</refsect1> |
| 763 |
<refsect1> |
| 764 |
<title>Examples</title> |
| 765 |
<refsect2> |
| 766 |
<title>C code</title> |
| 767 |
<screen> |
| 768 |
int baz = 3; |
| 769 |
|
| 770 |
typedef struct { |
| 771 |
int x; |
| 772 |
double y; |
| 773 |
} foo_struct; |
| 774 |
|
| 775 |
foo_struct the_struct = { 42, 3.2 }; |
| 776 |
|
| 777 |
int foo () { |
| 778 |
return baz; |
| 779 |
}</screen> |
| 780 |
</refsect2> |
| 781 |
<refsect2> |
| 782 |
<title>Lisp code</title> |
| 783 |
<screen> |
| 784 |
(uffi:def-struct foo-struct |
| 785 |
(x :int) |
| 786 |
(y :double)) |
| 787 |
|
| 788 |
(uffi:def-function ("foo" foo) |
| 789 |
() |
| 790 |
:returning :int |
| 791 |
:module "foo") |
| 792 |
|
| 793 |
(uffi:def-foreign-var ("baz" *baz*) :int "foo") |
| 794 |
(uffi:def-foreign-var ("the_struct" *the-struct*) foo-struct "foo") |
| 795 |
|
| 796 |
|
| 797 |
*baz* |
| 798 |
=> 3 |
| 799 |
|
| 800 |
(incf *baz*) |
| 801 |
=> 4 |
| 802 |
|
| 803 |
(foo) |
| 804 |
=> 4</screen> |
| 805 |
</refsect2> |
| 806 |
</refsect1> |
| 807 |
<refsect1> |
| 808 |
<title>Side Effects</title> |
| 809 |
<para>None.</para> |
| 810 |
</refsect1> |
| 811 |
<refsect1> |
| 812 |
<title>Affected by</title> |
| 813 |
<para>None.</para> |
| 814 |
</refsect1> |
| 815 |
<refsect1> |
| 816 |
<title>Exceptional Situations</title> |
| 817 |
<para>None.</para> |
| 818 |
</refsect1> |
| 819 |
</refentry> |
| 820 |
|
| 821 |
</reference> |
| 822 |
</book> |
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|