1 <!-- -*- DocBook -*- -->
5 <title>Declarations</title>
9 <title>Overview</title>
10 <para>Declarations are used to give the compiler optimizing
11 information about foreign types. Currently, only &cmucl;
12 supports declarations. On &acl; and &lw;, these expressions
13 declare the type generically as &t;
18 <refentry id="def-type">
20 <refname>def-type</refname>
21 <refpurpose>Defines a Common Lisp type.
23 <refclass>Macro</refclass>
28 <function>def-type</function> <replaceable>name type</replaceable>
32 <title>Arguments and Values</title>
35 <term><parameter>name</parameter></term>
37 <para>A symbol naming the type</para>
41 <term><parameter>type</parameter></term>
43 <para>A form that is evaluated that specifies the &uffi; type.
50 <title>Description</title>
51 <para>Defines a Common Lisp type based on a &uffi; type.
55 <title>Examples</title>
57 (def-type char-ptr '(* :char))
60 (declare (type char-ptr ptr))
65 <title>Side Effects</title>
66 <para>Defines a new &cl; type.</para>
69 <title>Affected by</title>
73 <title>Exceptional Situations</title>
81 <title>Primitive Types</title>
83 <title>Overview</title>
85 Primitive types have a single value, these include
86 characters, numbers, and pointers. They are all symbols in
91 <para><constant>:char</constant> - Signed 8-bits</para>
94 <para><constant>:unsigned-char</constant> - Unsigned 8-bits</para>
97 <para><constant>:short</constant> - Signed 16-bits</para>
100 <para><constant>:unsigned-short</constant> - Unsigned 16-bits</para>
103 <para><constant>:int</constant> - Signed 32-bits</para>
106 <para><constant>:unsigned-int</constant> - Unsigned 32-bits</para>
109 <para><constant>:long</constant> - Signed 32-bits</para>
112 <para><constant>:unsigned-long</constant> - Unsigned 32-bits</para>
115 <para><constant>:float</constant> - 32-bit floating point</para>
118 <para><constant>:double</constant> - 64-bit floating point</para>
121 <para><constant>:cstring</constant> -
122 A null-terminated string used for passing and returning with a function.
126 <para><constant>:void</constant> -
127 The absence of a value. Used in generic pointers and in return types from functions.</para>
130 <para><constant>*</constant> - Used to declare a pointer to an object</para>
135 <refentry id="def-constant">
137 <refname>def-constant</refname>
138 <refpurpose>Binds a symbol to a constant.
140 <refclass>Macro</refclass>
143 <title>Syntax</title>
145 <function>def-constant</function> <replaceable>name value &key export</replaceable>
149 <title>Arguments and Values</title>
152 <term><parameter>name</parameter></term>
154 <para>A symbol that will be bound to the value.
159 <term><parameter>value</parameter></term>
161 <para>An evaluated form that is bound the the name.
166 <term><parameter>export</parameter></term>
168 <para>When &t;, the name is exported from the current package. The default is &nil;</para>
174 <title>Description</title>
176 This is a thin wrapper around
177 <function>defconstant</function>. It evaluates at
178 compile-time and optionally exports the symbol from the package.
182 <title>Examples</title>
184 (def-constant pi2 (* 2 pi))
185 (def-constant exported-pi2 (* 2 pi) :export t)
189 <title>Side Effects</title>
190 <para>Creates a new special variable..</para>
193 <title>Affected by</title>
197 <title>Exceptional Situations</title>
202 <refentry id="def-foreign-type">
204 <refname>def-foreign-type</refname>
205 <refpurpose>Defines a new foreign type.
207 <refclass>Macro</refclass>
210 <title>Syntax</title>
212 <function>def-foreign-type</function> <replaceable>name type</replaceable>
216 <title>Arguments and Values</title>
219 <term><parameter>name</parameter></term>
221 <para>A symbol naming the new foreign type.
226 <term><parameter>value</parameter></term>
228 <para>A form that is not evaluated that defines the new
236 <title>Description</title>
237 <para>Defines a new foreign type.
241 <title>Examples</title>
243 (def-foreign-type my-generic-pointer :pointer-void)
244 (def-foreign-type a-double-float :double-float)
245 (def-foreign-type char-ptr (* :char))
249 <title>Side Effects</title>
250 <para>Defines a new foreign type.
254 <title>Affected by</title>
258 <title>Exceptional Situations</title>
263 <refentry id="null-char-p">
265 <refname>null-char-p</refname>
266 <refpurpose>Tests a character for &null; value.
268 <refclass>Macro</refclass>
271 <title>Syntax</title>
273 <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
277 <title>Arguments and Values</title>
280 <term><parameter>char</parameter></term>
282 <para>A character or integer.
287 <term><parameter>is-null</parameter></term>
289 <para>A boolean flag indicating if char is a &null; value.
296 <title>Description</title>
298 A predicate testing if a character or integer is &null;. This
299 abstracts the difference in implementations where some return a
300 <computeroutput>character</computeroutput> and some return a
301 <computeroutput>integer</computeroutput> whence dereferencing a
302 <computeroutput>C</computeroutput> character pointer.
306 <title>Examples</title>
309 (let ((fs (convert-to-foreign-string "ab")))
310 (values (null-char-p (deref-array fs 'ca 0))
311 (null-char-p (deref-array fs 'ca 2))))
317 <title>Side Effects</title>
322 <title>Affected by</title>
326 <title>Exceptional Situations</title>
331 <refentry id="ensure-char">
333 <refname>ensure-char</refname>
334 <refpurpose>Ensures value is a character.
336 <refclass>Macro</refclass>
339 <title>Syntax</title>
341 <function>ensure-char</function> <replaceable>obj</replaceable> => <returnvalue>char</returnvalue>
345 <title>Arguments and Values</title>
348 <term><parameter>obj</parameter></term>
350 <para>A character or integer.
355 <term><parameter>char</parameter></term>
357 <para>A character value.
364 <title>Description</title>
366 Enscapsulates the fact that some implementations return a character
367 and others return an integer when dereferencing a character pointer.
371 <title>Examples</title>
374 (let ((fs (convert-to-foreign-string "a")))
376 (ensure-char (deref-pointer fs :char))
377 (free-foreign-object fs)))
383 <title>Side Effects</title>
387 <title>Affected by</title>
391 <title>Exceptional Situations</title>
392 <para>Signals an error if <parameter>obj</parameter> is not
393 an integer or character.</para>
399 <title>Aggregate Types</title>
401 <title>Overview</title>
403 Aggregate types are comprised of one or more primitive types.
407 <refentry id="def-enum">
409 <refname>def-enum</refname>
410 <refpurpose>Defines a &c; enumeration.
412 <refclass>Macro</refclass>
415 <title>Syntax</title>
417 <function>def-enum</function> <replaceable>name fields &key separator-string</replaceable>
421 <title>Arguments and Values</title>
424 <term><parameter>name</parameter></term>
426 <para>A symbol that names the enumeration.
431 <term><parameter>fields</parameter></term>
433 <para>A list of field defintions. Each definition can be
434 a symbol or a list of two elements. Symbols get assigned a value of the
435 current counter which starts at <computeroutput>0</computeroutput> and
436 increments by <computeroutput>1</computeroutput> for each subsequent symbol. It the field definition is a list, the first position is the symbol and the second
437 position is the value to assign the the symbol. The current counter gets set
438 to <computeroutput>1+</computeroutput> this value.
443 <term><parameter>separator-string</parameter></term>
445 <para>A string that governs the creation of constants. The
446 default is <computeroutput>"#"</computeroutput>.</para>
452 <title>Description</title>
454 Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
455 values are created by the <function>concatenation</function> of the
456 enumeration name, separator-string, and field symbol. Also creates
457 a foreign type with the name <parameter>name</parameter> of type
458 <constant>:int</constant>.
462 <title>Examples</title>
464 (def-enum abc (:a :b :c))
465 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
466 ;; the foreign type "abc" to be :int
468 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
469 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
470 ;; the foreign type efoo to be :int
474 <title>Side Effects</title>
475 <para>Creates a :int foreign type, defines constants.</para>
478 <title>Affected by</title>
482 <title>Exceptional Situations</title>
488 <refentry id="def-struct">
490 <refname>def-struct</refname>
491 <refpurpose>Defines a &c; structure.
493 <refclass>Macro</refclass>
496 <title>Syntax</title>
498 <function>def-struct</function> <replaceable>name &rest fields</replaceable>
502 <title>Arguments and Values</title>
505 <term><parameter>name</parameter></term>
507 <para>A symbol that names the structure.
512 <term><parameter>fields</parameter></term>
514 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
521 <title>Description</title>
523 Declares a structure. A special type is available as a slot
524 in the field. It is a pointer that points to an instance of the parent
525 structure. It's type is <constant>:pointer-self</constant>.
530 <title>Examples</title>
532 (def-struct foo (a :unsigned-int)
535 (next :pointer-self))
539 <title>Side Effects</title>
540 <para>Creates a foreign type.</para>
543 <title>Affected by</title>
547 <title>Exceptional Situations</title>
553 <refentry id="get-slot-value">
555 <refname>def-slot-value</refname>
556 <refpurpose>Retrieves a value from a slot of a structure.
558 <refclass>Macro</refclass>
561 <title>Syntax</title>
563 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
567 <title>Arguments and Values</title>
570 <term><parameter>obj</parameter></term>
572 <para>A pointer to foreign structure.
577 <term><parameter>type</parameter></term>
579 <para>A name of the foreign structure.
584 <term><parameter>field</parameter></term>
586 <para>A name of the desired field in foreign structure.
591 <term><returnvalue>value</returnvalue></term>
593 <para>The value of the field in the structure.
600 <title>Description</title>
602 Accesses a slot value from a structure.
606 <title>Examples</title>
608 (get-slot-value foo-ptr 'foo-structure 'field-name)
612 <title>Side Effects</title>
616 <title>Affected by</title>
620 <title>Exceptional Situations</title>
625 <refentry id="get-slot-pointer">
627 <refname>get-slot-pointer</refname>
628 <refpurpose>Retrieves a pointer from a slot of a structure.
630 <refclass>Macro</refclass>
633 <title>Syntax</title>
635 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
639 <title>Arguments and Values</title>
642 <term><parameter>obj</parameter></term>
644 <para>A pointer to foreign structure.
649 <term><parameter>type</parameter></term>
651 <para>A name of the foreign structure.
656 <term><parameter>field</parameter></term>
658 <para>A name of the desired field in foreign structure.
663 <term><returnvalue>pointer</returnvalue></term>
665 <para>The value of the field in the structure.
672 <title>Description</title>
674 This is similar to <function>get-slot-value</function>. It
675 is used when the value of a slot is a pointer type.
679 <title>Examples</title>
681 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
685 <title>Side Effects</title>
689 <title>Affected by</title>
693 <title>Exceptional Situations</title>
699 <refentry id="def-array">
701 <refname>def-array</refname>
702 <refpurpose>Defines a foreign array type.
704 <refclass>Macro</refclass>
707 <title>Syntax</title>
709 <function>def-array</function> <replaceable>name type</replaceable>
713 <title>Arguments and Values</title>
716 <term><parameter>name</parameter></term>
718 <para>A name of the new foreign type.
723 <term><parameter>type</parameter></term>
725 <para>The foreign type of the array elements.
732 <title>Description</title>
734 Defines a foreign array type.
738 <title>Examples</title>
740 (def-array byte-array :unsigned-char)
744 <title>Side Effects</title>
745 <para>Defines a new foreign type.</para>
748 <title>Affected by</title>
752 <title>Exceptional Situations</title>
758 <refentry id="deref-array">
760 <refname>deref-array</refname>
761 <refpurpose>Deference an array.
763 <refclass>Macro</refclass>
766 <title>Syntax</title>
768 <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
772 <title>Arguments and Values</title>
775 <term><parameter>array</parameter></term>
777 <para>A foreign array.
782 <term><parameter>type</parameter></term>
784 <para>The foreign type of the array.
789 <term><parameter>position</parameter></term>
791 <para>An integer specifying the position to retrieve from
797 <term><returnvalue>value</returnvalue></term>
799 <para>The value stored in the position of the array.
806 <title>Description</title>
808 Dereferences (retrieves) the value of an array element.
812 <title>Examples</title>
815 (let ((fs (convert-to-foreign-string "ab")))
816 (values (null-char-p (deref-array fs 'ca 0))
817 (null-char-p (deref-array fs 'ca 2))))
823 <title>Side Effects</title>
827 <title>Affected by</title>
831 <title>Exceptional Situations</title>
838 <title>Objects</title>
840 <title>Overview</title>
842 Objects are entities that can allocated and freed.
847 <refentry id="allocate-foreign-object">
849 <refname>allocate-foreign-object</refname>
850 <refpurpose>Allocates an instance of a foreign object.
852 <refclass>Macro</refclass>
855 <title>Syntax</title>
857 <function>allocate-foreign-object</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
861 <title>Arguments and Values</title>
864 <term><parameter>type</parameter></term>
866 <para>A type of foreign object to allocate.
871 <term><returnvalue>ptr</returnvalue></term>
873 <para>A pointer to the foreign object.
880 <title>Description</title>
882 Allocates an instance of a foreign object. It returns a pointer to the object.
886 <title>Examples</title>
888 (def-struct ab (a :int) (b :double))
889 (allocate-foreign-object 'ab)
894 <title>Side Effects</title>
898 <title>Affected by</title>
902 <title>Exceptional Situations</title>
908 <refentry id="free-foreign-object">
910 <refname>free-foreign-object</refname>
911 <refpurpose>Frees memory that was allocated for a foreign boject.
913 <refclass>Macro</refclass>
916 <title>Syntax</title>
918 <function>free-foreign-object</function> <replaceable>ptr</replaceable>
922 <title>Arguments and Values</title>
925 <term><parameter>ptr</parameter></term>
927 <para>A pointer to the allocated foreign object to free.
934 <title>Description</title>
936 Frees the memory used by the allocation of a foreign object.
940 <title>Side Effects</title>
944 <title>Affected by</title>
948 <title>Exceptional Situations</title>
954 <refentry id="pointer-address">
956 <refname>pointer-address</refname>
957 <refpurpose>Returns the address of a pointer.
959 <refclass>Macro</refclass>
962 <title>Syntax</title>
964 <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
968 <title>Arguments and Values</title>
971 <term><parameter>ptr</parameter></term>
973 <para>A pointer to a foreign object.
978 <term><parameter>address</parameter></term>
980 <para>An integer representing the pointer's address.
987 <title>Description</title>
989 Returns the address as an integer of a pointer.
993 <title>Side Effects</title>
997 <title>Affected by</title>
1001 <title>Exceptional Situations</title>
1007 <refentry id="deref-pointer">
1009 <refname>deref-pointer</refname>
1010 <refpurpose>Deferences a pointer.
1012 <refclass>Macro</refclass>
1015 <title>Syntax</title>
1017 <function>def-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
1021 <title>Arguments and Values</title>
1024 <term><parameter>ptr</parameter></term>
1026 <para>A pointer to a foreign object.
1031 <term><parameter>type</parameter></term>
1033 <para>A foreign type of the object being pointed to.
1038 <term><parameter>value</parameter></term>
1040 <para>The value of the object where the pointer points.
1047 <title>Description</title>
1049 Returns the object to which a pointer points.
1053 <title>Examples</title>
1056 (let ((fs (convert-to-foreign-string "a")))
1058 (ensure-char (deref-pointer fs :char))
1059 (free-foreign-object fs)))
1065 <title>Side Effects</title>
1069 <title>Affected by</title>
1073 <title>Exceptional Situations</title>
1078 <refentry id="make-null-pointer">
1080 <refname>make-null-pointer</refname>
1081 <refpurpose>Create a &null; pointer.
1083 <refclass>Macro</refclass>
1086 <title>Syntax</title>
1088 <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
1092 <title>Arguments and Values</title>
1095 <term><parameter>type</parameter></term>
1097 <para>A type of object to which the pointer refers.
1102 <term><parameter>ptr</parameter></term>
1104 <para>The &null; pointer of type <parameter>type</parameter>.
1111 <title>Description</title>
1113 Creates a &null; pointer of a specified type.
1117 <title>Side Effects</title>
1121 <title>Affected by</title>
1125 <title>Exceptional Situations</title>
1131 <refentry id="null-pointer-p">
1133 <refname>null-pointer-p</refname>
1134 <refpurpose>Tests a pointer for &null; value.
1136 <refclass>Macro</refclass>
1139 <title>Syntax</title>
1141 <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
1145 <title>Arguments and Values</title>
1148 <term><parameter>ptr</parameter></term>
1150 <para>A foreign object pointer.
1155 <term><returnvalue>is-null</returnvalue></term>
1157 <para>The boolean flag.
1164 <title>Description</title>
1166 A predicate testing if a pointer is has a &null; value.
1170 <title>Side Effects</title>
1174 <title>Affected by</title>
1178 <title>Exceptional Situations</title>
1184 <refentry id="null-cstring-pointer">
1186 <refname>+null-cstring-pointer+</refname>
1187 <refpurpose>A constant &null; cstring pointer.
1189 <refclass>Constant</refclass>
1192 <title>Description</title>
1194 A &null; cstring pointer. This can be used for testing
1195 if a cstring returned by a function is &null;.
1203 <title>Strings</title>
1205 <title>Overview</title>
1207 &uffi; has functions to two types of <varname>C</varname>-compatible
1208 strings, <emphasis>cstring</emphasis> and <emphasis>foreign</emphasis> strings.
1209 cstrings are used as parameters to and from functions. An implementation, such as CMUCL,
1210 may not convert these to a foreign type for efficiency sake. Thus, it is not
1211 possible to "allocate" a cstring. In contrast, foreign strings
1212 always need to have memory for them.
1216 <refentry id="convert-from-cstring">
1218 <refname>convert-from-cstring</refname>
1219 <refpurpose>Converts a cstring to a Lisp string.
1221 <refclass>Macro</refclass>
1224 <title>Syntax</title>
1226 <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
1230 <title>Arguments and Values</title>
1233 <term><parameter>cstring</parameter></term>
1240 <term><returnvalue>string</returnvalue></term>
1242 <para>A Lisp string.
1249 <title>Description</title>
1251 Converts a Lisp string to a <constant>cstring</constant>. This is
1252 most often used when processing the results of a foreign function
1253 that returns a cstring.
1257 <title>Side Effects</title>
1261 <title>Affected by</title>
1265 <title>Exceptional Situations</title>
1271 <refentry id="convert-to-cstring">
1273 <refname>convert-to-cstring</refname>
1274 <refpurpose>Converts a Lisp string to a cstring.
1276 <refclass>Macro</refclass>
1279 <title>Syntax</title>
1281 <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
1285 <title>Arguments and Values</title>
1288 <term><parameter>string</parameter></term>
1290 <para>A Lisp string.
1295 <term><returnvalue>cstring</returnvalue></term>
1304 <title>Description</title>
1306 Converts a Lisp string to a
1307 <varname>cstring</varname>. The
1308 <varname>cstring</varname> should be freed with
1309 <function>free-cstring</function>.
1313 <title>Side Effects</title>
1317 <title>Affected by</title>
1321 <title>Exceptional Situations</title>
1327 <refentry id="free-cstring">
1329 <refname>free-cstring</refname>
1330 <refpurpose>Free memory used by cstring.
1332 <refclass>Macro</refclass>
1335 <title>Syntax</title>
1337 <function>free-cstring</function> <replaceable>cstring</replaceable>
1341 <title>Arguments and Values</title>
1344 <term><parameter>cstring</parameter></term>
1353 <title>Description</title>
1355 Frees any memory possibly allocated by
1356 <function>convert-to-cstring</function>.
1360 <title>Side Effects</title>
1364 <title>Affected by</title>
1368 <title>Exceptional Situations</title>
1374 <refentry id="with-cstring">
1376 <refname>with-cstring</refname>
1377 <refpurpose>Binds a newly created cstring.
1379 <refclass>Macro</refclass>
1382 <title>Syntax</title>
1384 <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
1388 <title>Arguments and Values</title>
1391 <term><parameter>cstring</parameter></term>
1393 <para>A symbol naming the cstring to be created.
1398 <term><parameter>string</parameter></term>
1400 <para>A Lisp string that will be translated to a cstring.
1405 <term><parameter>body</parameter></term>
1407 <para>The body of where the cstring will be bound.
1414 <title>Description</title>
1416 Binds a lexical variable to a newly allocated <varname>cstring</varname>. Automatically frees <varname>cstring</varname>.
1420 <title>Examples</title>
1423 (def-function ("getenv" c-getenv)
1425 :returning :cstring)
1428 "Returns an environment variable, or NIL if it does not exist"
1429 (check-type key string)
1430 (with-cstring (key-cstring key)
1431 (convert-from-cstring (c-getenv key-cstring))))
1436 <title>Side Effects</title>
1440 <title>Affected by</title>
1444 <title>Exceptional Situations</title>
1450 <refentry id="convert-from-foreign-string">
1452 <refname>convert-from-foreign-string</refname>
1453 <refpurpose>Converts a foreign string into a Lisp string.
1455 <refclass>Macro</refclass>
1458 <title>Syntax</title>
1460 <function>convert-from-foreign-string</function> <replaceable>foreign-string &key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
1464 <title>Arguments and Values</title>
1467 <term><parameter>foreign-string</parameter></term>
1469 <para>A foreign string.
1474 <term><parameter>length</parameter></term>
1476 <para>The length of the foreign string to
1477 convert. The default is the length of the string until a &null;
1478 character is reached.
1483 <term><parameter>null-terminated-p</parameter></term>
1485 <para>A boolean flag with a default value of &t; When true,
1486 the string is converted until the first &null; character is reached.
1491 <term><returnvalue>string</returnvalue></term>
1493 <para>A Lisp string.
1500 <title>Description</title>
1502 Returns a Lisp string from a foreign string.
1503 Can translated ASCII and binary strings.
1507 <title>Side Effects</title>
1511 <title>Affected by</title>
1515 <title>Exceptional Situations</title>
1521 <refentry id="convert-to-foreign-string">
1523 <refname>convert-to-foreign-string</refname>
1524 <refpurpose>Converts a Lisp string to a foreign string.
1526 <refclass>Macro</refclass>
1529 <title>Syntax</title>
1531 <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
1535 <title>Arguments and Values</title>
1538 <term><parameter>string</parameter></term>
1540 <para>A Lisp string.
1545 <term><returnvalue>foreign-string</returnvalue></term>
1547 <para>A foreign string.
1554 <title>Description</title>
1556 Converts a Lisp string to a foreign string. Memory should be
1557 freed with <function>free-foreign-object</function>.
1561 <title>Side Effects</title>
1565 <title>Affected by</title>
1569 <title>Exceptional Situations</title>
1576 <refentry id="allocate-foreign-string">
1578 <refname>allocate-foreign-string</refname>
1579 <refpurpose>Allocates space for a foreign string.
1581 <refclass>Macro</refclass>
1584 <title>Syntax</title>
1586 <function>allocate-foreign-string</function> <replaceable>size &key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
1590 <title>Arguments and Values</title>
1593 <term><parameter>size</parameter></term>
1595 <para>The size of the space to be allocated in bytes.
1600 <term><parameter>unsigned</parameter></term>
1602 <para>A boolean flag with a default value of &nil;. When true,
1603 marks the pointer as an <constant>:unsigned-char</constant>.
1608 <term><returnvalue>foreign-string</returnvalue></term>
1610 <para>A foreign string which has undefined contents.
1617 <title>Description</title>
1619 Allocates space for a foreign string. Memory should
1620 be freed with <function>free-foreign-object</function>.
1624 <title>Side Effects</title>
1628 <title>Affected by</title>
1632 <title>Exceptional Situations</title>
1640 <title>Functions & Libraries</title>
1642 <refentry id="def-function">
1644 <refname>def-function</refname>
1645 <refpurpose>Declares a function.
1647 <refclass>Macro</refclass>
1650 <title>Syntax</title>
1652 <function>def-function</function> <replaceable>name args &key module returning</replaceable>
1656 <title>Arguments and Values</title>
1659 <term><parameter>name</parameter></term>
1661 <para>A string or list specificying the function name. If it is a string, that names the foreign function. A Lisp name is created by translating #\_ to #\- and by converting to upper-case in case-insensitive Lisp implementations. If it is a list, the first item is a string specifying the foreign function name and the second it is a symbol stating the Lisp name.
1666 <term><parameter>args</parameter></term>
1668 <para>A list of argument declarations. Use &nil; to specify no arguments.
1673 <term><parameter>module</parameter></term>
1675 <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
1679 <term><returnvalue>returning</returnvalue></term>
1681 <para>A declaration specifying the result type of the
1689 <title>Description</title>
1690 <para>Declares a foreign function.
1694 <title>Examples</title>
1696 (def-function "gethostname"
1703 <title>Side Effects</title>
1707 <title>Affected by</title>
1711 <title>Exceptional Situations</title>
1716 <refentry id="load-foreign-library">
1718 <refname>load-foreign-library</refname>
1719 <refpurpose>Loads a foreign library.
1721 <refclass>Function</refclass>
1724 <title>Syntax</title>
1726 <function>load-foreign-library</function> <replaceable>filename &key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
1730 <title>Arguments and Values</title>
1733 <term><parameter>filename</parameter></term>
1735 <para>A string or pathname specifying the library location
1736 in the filesystem. At least one implementation (&lw;) can not
1737 accept a logical pathname.
1742 <term><parameter>module</parameter></term>
1744 <para>A string designating the name of the module to apply
1745 to functions in this library. (Required for Lispworks)
1750 <term><parameter>supporting-libraries</parameter></term>
1752 <para>A list of strings naming the libraries required to
1753 link the foreign library. (Required by CMUCL)
1758 <term><returnvalue>success</returnvalue></term>
1760 <para>A boolean flag, &t; if the library was able to be
1761 loaded successfully or if the library has been previously loaded,
1769 <title>Description</title>
1770 <para>Loads a foreign library. Applies a module name to functions
1771 within the library. Ensures that a library is only loaded once during
1776 <title>Examples</title>
1778 (load-foreign-library #p"/usr/lib/libmysqlclient.so"
1780 :supporting-libraries '("c"))
1785 <title>Side Effects</title>
1786 <para>Loads the foreign code into the Lisp system.
1790 <title>Affected by</title>
1791 <para>Ability to load the file.</para>
1794 <title>Exceptional Situations</title>