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. A
92 dereferenced :char pointer returns an character.</para>
95 <para><constant>:unsigned-char</constant> - Unsigned 8-bits. A dereferenced :unsigned-char
96 pointer returns an character.</para>
99 <para><constant>:byte</constant> - Unsigned 8-bits. A
100 dereferenced :byte pointer returns an integer.</para>
103 <para><constant>:short</constant> - Signed 16-bits.</para>
106 <para><constant>:unsigned-short</constant> - Unsigned 16-bits.</para>
109 <para><constant>:int</constant> - Signed 32-bits.</para>
112 <para><constant>:unsigned-int</constant> - Unsigned 32-bits.</para>
115 <para><constant>:long</constant> - Signed 32-bits.</para>
118 <para><constant>:unsigned-long</constant> - Unsigned 32-bits.</para>
121 <para><constant>:float</constant> - 32-bit floating point.</para>
124 <para><constant>:double</constant> - 64-bit floating point.</para>
127 <para><constant>:cstring</constant> -
128 A &null; terminated string used for passing and returning characters strings with a &c; function.
132 <para><constant>:void</constant> -
133 The absence of a value. Used to indicate that a function does not return a value.</para>
136 <para><constant>:pointer-void</constant> -
137 Points to a generic object.</para>
140 <para><constant>*</constant> - Used to declare a pointer to an object</para>
145 <refentry id="def-constant">
147 <refname>def-constant</refname>
148 <refpurpose>Binds a symbol to a constant.
150 <refclass>Macro</refclass>
153 <title>Syntax</title>
155 <function>def-constant</function> <replaceable>name value &key export</replaceable>
159 <title>Arguments and Values</title>
162 <term><parameter>name</parameter></term>
164 <para>A symbol that will be bound to the value.
169 <term><parameter>value</parameter></term>
171 <para>An evaluated form that is bound the the name.
176 <term><parameter>export</parameter></term>
178 <para>When &t;, the name is exported from the current package. The default is &nil;</para>
184 <title>Description</title>
186 This is a thin wrapper around
187 <function>defconstant</function>. It evaluates at
188 compile-time and optionally exports the symbol from the package.
192 <title>Examples</title>
194 (def-constant pi2 (* 2 pi))
195 (def-constant exported-pi2 (* 2 pi) :export t)
199 <title>Side Effects</title>
200 <para>Creates a new special variable..</para>
203 <title>Affected by</title>
207 <title>Exceptional Situations</title>
212 <refentry id="def-foreign-type">
214 <refname>def-foreign-type</refname>
215 <refpurpose>Defines a new foreign type.
217 <refclass>Macro</refclass>
220 <title>Syntax</title>
222 <function>def-foreign-type</function> <replaceable>name type</replaceable>
226 <title>Arguments and Values</title>
229 <term><parameter>name</parameter></term>
231 <para>A symbol naming the new foreign type.
236 <term><parameter>value</parameter></term>
238 <para>A form that is not evaluated that defines the new
246 <title>Description</title>
247 <para>Defines a new foreign type.
251 <title>Examples</title>
253 (def-foreign-type my-generic-pointer :pointer-void)
254 (def-foreign-type a-double-float :double-float)
255 (def-foreign-type char-ptr (* :char))
259 <title>Side Effects</title>
260 <para>Defines a new foreign type.
264 <title>Affected by</title>
268 <title>Exceptional Situations</title>
273 <refentry id="null-char-p">
275 <refname>null-char-p</refname>
276 <refpurpose>Tests a character for &null; value.
278 <refclass>Macro</refclass>
281 <title>Syntax</title>
283 <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
287 <title>Arguments and Values</title>
290 <term><parameter>char</parameter></term>
292 <para>A character or integer.
297 <term><parameter>is-null</parameter></term>
299 <para>A boolean flag indicating if char is a &null; value.
306 <title>Description</title>
308 A predicate testing if a character or integer is &null;. This
309 abstracts the difference in implementations where some return a
310 <computeroutput>character</computeroutput> and some return a
311 <computeroutput>integer</computeroutput> whence dereferencing a
312 <computeroutput>C</computeroutput> character pointer.
316 <title>Examples</title>
319 (let ((fs (convert-to-foreign-string "ab")))
320 (values (null-char-p (deref-array fs 'ca 0))
321 (null-char-p (deref-array fs 'ca 2))))
327 <title>Side Effects</title>
332 <title>Affected by</title>
336 <title>Exceptional Situations</title>
343 <title>Aggregate Types</title>
345 <title>Overview</title>
347 Aggregate types are comprised of one or more primitive types.
351 <refentry id="def-enum">
353 <refname>def-enum</refname>
354 <refpurpose>Defines a &c; enumeration.
356 <refclass>Macro</refclass>
359 <title>Syntax</title>
361 <function>def-enum</function> <replaceable>name fields &key separator-string</replaceable>
365 <title>Arguments and Values</title>
368 <term><parameter>name</parameter></term>
370 <para>A symbol that names the enumeration.
375 <term><parameter>fields</parameter></term>
377 <para>A list of field defintions. Each definition can be
378 a symbol or a list of two elements. Symbols get assigned a value of the
379 current counter which starts at <computeroutput>0</computeroutput> and
380 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
381 position is the value to assign the the symbol. The current counter gets set
382 to <computeroutput>1+</computeroutput> this value.
387 <term><parameter>separator-string</parameter></term>
389 <para>A string that governs the creation of constants. The
390 default is <computeroutput>"#"</computeroutput>.</para>
396 <title>Description</title>
398 Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
399 values are created by the <function>concatenation</function> of the
400 enumeration name, separator-string, and field symbol. Also creates
401 a foreign type with the name <parameter>name</parameter> of type
402 <constant>:int</constant>.
406 <title>Examples</title>
408 (def-enum abc (:a :b :c))
409 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
410 ;; the foreign type "abc" to be :int
412 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
413 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
414 ;; the foreign type efoo to be :int
418 <title>Side Effects</title>
419 <para>Creates a :int foreign type, defines constants.</para>
422 <title>Affected by</title>
426 <title>Exceptional Situations</title>
432 <refentry id="def-struct">
434 <refname>def-struct</refname>
435 <refpurpose>Defines a &c; structure.
437 <refclass>Macro</refclass>
440 <title>Syntax</title>
442 <function>def-struct</function> <replaceable>name &rest fields</replaceable>
446 <title>Arguments and Values</title>
449 <term><parameter>name</parameter></term>
451 <para>A symbol that names the structure.
456 <term><parameter>fields</parameter></term>
458 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
465 <title>Description</title>
467 Declares a structure. A special type is available as a slot
468 in the field. It is a pointer that points to an instance of the parent
469 structure. It's type is <constant>:pointer-self</constant>.
474 <title>Examples</title>
476 (def-struct foo (a :unsigned-int)
479 (next :pointer-self))
483 <title>Side Effects</title>
484 <para>Creates a foreign type.</para>
487 <title>Affected by</title>
491 <title>Exceptional Situations</title>
497 <refentry id="get-slot-value">
499 <refname>get-slot-value</refname>
500 <refpurpose>Retrieves a value from a slot of a structure.
502 <refclass>Macro</refclass>
505 <title>Syntax</title>
507 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
511 <title>Arguments and Values</title>
514 <term><parameter>obj</parameter></term>
516 <para>A pointer to foreign structure.
521 <term><parameter>type</parameter></term>
523 <para>A name of the foreign structure.
528 <term><parameter>field</parameter></term>
530 <para>A name of the desired field in foreign structure.
535 <term><returnvalue>value</returnvalue></term>
537 <para>The value of the field in the structure.
544 <title>Description</title>
546 Accesses a slot value from a structure.
550 <title>Examples</title>
552 (get-slot-value foo-ptr 'foo-structure 'field-name)
556 <title>Side Effects</title>
560 <title>Affected by</title>
564 <title>Exceptional Situations</title>
569 <refentry id="get-slot-pointer">
571 <refname>get-slot-pointer</refname>
572 <refpurpose>Retrieves a pointer from a slot of a structure.
574 <refclass>Macro</refclass>
577 <title>Syntax</title>
579 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
583 <title>Arguments and Values</title>
586 <term><parameter>obj</parameter></term>
588 <para>A pointer to foreign structure.
593 <term><parameter>type</parameter></term>
595 <para>A name of the foreign structure.
600 <term><parameter>field</parameter></term>
602 <para>A name of the desired field in foreign structure.
607 <term><returnvalue>pointer</returnvalue></term>
609 <para>The value of the field in the structure.
616 <title>Description</title>
618 This is similar to <function>get-slot-value</function>. It
619 is used when the value of a slot is a pointer type.
623 <title>Examples</title>
625 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
629 <title>Side Effects</title>
633 <title>Affected by</title>
637 <title>Exceptional Situations</title>
643 <refentry id="def-array">
645 <refname>def-array</refname>
646 <refpurpose>Defines a foreign array type.
648 <refclass>Macro</refclass>
651 <title>Syntax</title>
653 <function>def-array</function> <replaceable>name type</replaceable>
657 <title>Arguments and Values</title>
660 <term><parameter>name</parameter></term>
662 <para>A name of the new foreign type.
667 <term><parameter>type</parameter></term>
669 <para>The foreign type of the array elements.
676 <title>Description</title>
678 Defines a foreign array type.
682 <title>Examples</title>
684 (def-array byte-array :unsigned-char)
688 <title>Side Effects</title>
689 <para>Defines a new foreign type.</para>
692 <title>Affected by</title>
696 <title>Exceptional Situations</title>
702 <refentry id="deref-array">
704 <refname>deref-array</refname>
705 <refpurpose>Deference an array.
707 <refclass>Macro</refclass>
710 <title>Syntax</title>
712 <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
716 <title>Arguments and Values</title>
719 <term><parameter>array</parameter></term>
721 <para>A foreign array.
726 <term><parameter>type</parameter></term>
728 <para>The foreign type of the array.
733 <term><parameter>position</parameter></term>
735 <para>An integer specifying the position to retrieve from
741 <term><returnvalue>value</returnvalue></term>
743 <para>The value stored in the position of the array.
750 <title>Description</title>
752 Dereferences (retrieves) the value of an array element.
756 <title>Examples</title>
759 (let ((fs (convert-to-foreign-string "ab")))
760 (values (null-char-p (deref-array fs 'ca 0))
761 (null-char-p (deref-array fs 'ca 2))))
767 <title>Side Effects</title>
771 <title>Affected by</title>
775 <title>Exceptional Situations</title>
780 <refentry id="def-union">
782 <refname>def-union</refname>
783 <refpurpose>Defines a foreign union type.
785 <refclass>Macro</refclass>
788 <title>Syntax</title>
790 <function>def-union</function> <replaceable>name &rest fields</replaceable>
794 <title>Arguments and Values</title>
797 <term><parameter>name</parameter></term>
799 <para>A name of the new union type.
804 <term><parameter>fields</parameter></term>
806 <para>A list of fields of the union.
813 <title>Description</title>
815 Defines a foreign union type.
819 <title>Examples</title>
821 (def-union test-union
825 (let ((u (allocate-foreign-object 'test-union))
826 (setf (get-slot-value u 'test-union 'an-int) (+ 65 (* 66 256)))
828 (ensure-char-character (get-slot-value u 'test-union 'a-char))
829 (free-foreign-object u)))
834 <title>Side Effects</title>
835 <para>Defines a new foreign type.</para>
838 <title>Affected by</title>
842 <title>Exceptional Situations</title>
851 <title>Objects</title>
853 <title>Overview</title>
855 Objects are entities that can allocated, referred to by pointers, and
861 <refentry id="allocate-foreign-object">
863 <refname>allocate-foreign-object</refname>
864 <refpurpose>Allocates an instance of a foreign object.
866 <refclass>Macro</refclass>
869 <title>Syntax</title>
871 <function>allocate-foreign-object</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
875 <title>Arguments and Values</title>
878 <term><parameter>type</parameter></term>
880 <para>A type of foreign object to allocate.
885 <term><returnvalue>ptr</returnvalue></term>
887 <para>A pointer to the foreign object.
894 <title>Description</title>
896 Allocates an instance of a foreign object. It returns a pointer to the object.
900 <title>Examples</title>
902 (def-struct ab (a :int) (b :double))
903 (allocate-foreign-object ab)
908 <title>Side Effects</title>
912 <title>Affected by</title>
916 <title>Exceptional Situations</title>
922 <refentry id="free-foreign-object">
924 <refname>free-foreign-object</refname>
925 <refpurpose>Frees memory that was allocated for a foreign boject.
927 <refclass>Macro</refclass>
930 <title>Syntax</title>
932 <function>free-foreign-object</function> <replaceable>ptr</replaceable>
936 <title>Arguments and Values</title>
939 <term><parameter>ptr</parameter></term>
941 <para>A pointer to the allocated foreign object to free.
948 <title>Description</title>
950 Frees the memory used by the allocation of a foreign object.
954 <title>Side Effects</title>
958 <title>Affected by</title>
962 <title>Exceptional Situations</title>
968 <refentry id="pointer-address">
970 <refname>pointer-address</refname>
971 <refpurpose>Returns the address of a pointer.
973 <refclass>Macro</refclass>
976 <title>Syntax</title>
978 <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
982 <title>Arguments and Values</title>
985 <term><parameter>ptr</parameter></term>
987 <para>A pointer to a foreign object.
992 <term><parameter>address</parameter></term>
994 <para>An integer representing the pointer's address.
1001 <title>Description</title>
1003 Returns the address as an integer of a pointer.
1007 <title>Side Effects</title>
1011 <title>Affected by</title>
1015 <title>Exceptional Situations</title>
1021 <refentry id="deref-pointer">
1023 <refname>deref-pointer</refname>
1024 <refpurpose>Deferences a pointer.
1026 <refclass>Macro</refclass>
1029 <title>Syntax</title>
1031 <function>deref-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
1035 <title>Arguments and Values</title>
1038 <term><parameter>ptr</parameter></term>
1040 <para>A pointer to a foreign object.
1045 <term><parameter>type</parameter></term>
1047 <para>A foreign type of the object being pointed to.
1052 <term><returnvalue>value</returnvalue></term>
1054 <para>The value of the object where the pointer points.
1061 <title>Description</title>
1063 Returns the object to which a pointer points.
1067 <title>Examples</title>
1070 (let ((intp (allocate-foreign-object :int)))
1071 (setf (deref-pointer intp :int) 10)
1073 (deref-pointer intp :int)
1074 (free-foreign-object intp)))
1080 <title>Side Effects</title>
1084 <title>Affected by</title>
1088 <title>Exceptional Situations</title>
1093 <refentry id="ensure-char-character">
1095 <refname>ensure-char-character</refname>
1096 <refpurpose>Ensures that a dereferenced :char pointer is
1099 <refclass>Macro</refclass>
1102 <title>Syntax</title>
1104 <function>ensure-char-character</function> <replaceable>object</replaceable> => <returnvalue>char</returnvalue>
1108 <title>Arguments and Values</title>
1111 <term><parameter>object</parameter></term>
1113 <para>Either a character or a integer specifying a character code.
1118 <term><returnvalue>char</returnvalue></term>
1127 <title>Description</title>
1129 Ensures that an object obtained by dereferencing a
1130 <constant>:char</constant> pointer is a character.
1134 <title>Examples</title>
1137 (let ((fs (convert-to-foreign-string "a")))
1139 (ensure-char-character (deref-pointer fs :char))
1140 (free-foreign-object fs)))
1146 <title>Side Effects</title>
1150 <title>Affected by</title>
1154 <title>Exceptional Situations</title>
1155 <para>Depending upon the implementation and what &uffi; expects, this
1156 macro may signal an error if the object is not a character or
1161 <refentry id="ensure-char-integer">
1163 <refname>ensure-char-integer</refname>
1164 <refpurpose>Ensures that a dereferenced :char pointer is
1167 <refclass>Macro</refclass>
1170 <title>Syntax</title>
1172 <function>ensure-char-integer</function> <replaceable>object</replaceable> => <returnvalue>int</returnvalue>
1176 <title>Arguments and Values</title>
1179 <term><parameter>object</parameter></term>
1181 <para>Either a character or a integer specifying a character code.
1186 <term><returnvalue>int</returnvalue></term>
1195 <title>Description</title>
1197 Ensures that an object obtained by dereferencing a
1198 <constant>:char</constant> pointer is an integer.
1202 <title>Examples</title>
1205 (let ((fs (convert-to-foreign-string "a")))
1207 (ensure-char-integer (deref-pointer fs :char))
1208 (free-foreign-object fs)))
1214 <title>Side Effects</title>
1218 <title>Affected by</title>
1222 <title>Exceptional Situations</title>
1223 <para>Depending upon the implementation and what &uffi; expects, this
1224 macro may signal an error if the object is not a character or
1229 <refentry id="make-null-pointer">
1231 <refname>make-null-pointer</refname>
1232 <refpurpose>Create a &null; pointer.
1234 <refclass>Macro</refclass>
1237 <title>Syntax</title>
1239 <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
1243 <title>Arguments and Values</title>
1246 <term><parameter>type</parameter></term>
1248 <para>A type of object to which the pointer refers.
1253 <term><parameter>ptr</parameter></term>
1255 <para>The &null; pointer of type <parameter>type</parameter>.
1262 <title>Description</title>
1264 Creates a &null; pointer of a specified type.
1268 <title>Side Effects</title>
1272 <title>Affected by</title>
1276 <title>Exceptional Situations</title>
1282 <refentry id="null-pointer-p">
1284 <refname>null-pointer-p</refname>
1285 <refpurpose>Tests a pointer for &null; value.
1287 <refclass>Macro</refclass>
1290 <title>Syntax</title>
1292 <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
1296 <title>Arguments and Values</title>
1299 <term><parameter>ptr</parameter></term>
1301 <para>A foreign object pointer.
1306 <term><returnvalue>is-null</returnvalue></term>
1308 <para>The boolean flag.
1315 <title>Description</title>
1317 A predicate testing if a pointer is has a &null; value.
1321 <title>Side Effects</title>
1325 <title>Affected by</title>
1329 <title>Exceptional Situations</title>
1335 <refentry id="null-cstring-pointer">
1337 <refname>+null-cstring-pointer+</refname>
1338 <refpurpose>A constant &null; cstring pointer.
1340 <refclass>Constant</refclass>
1343 <title>Description</title>
1345 A &null; cstring pointer. This can be used for testing
1346 if a cstring returned by a function is &null;.
1354 <title>Strings</title>
1356 <title>Overview</title>
1358 &uffi; has functions to two types of <varname>C</varname>-compatible
1359 strings, <emphasis>cstring</emphasis> and <emphasis>foreign</emphasis> strings.
1360 cstrings are used as parameters to and from functions. An implementation, such as CMUCL,
1361 may not convert these to a foreign type for efficiency sake. Thus, it is not
1362 possible to "allocate" a cstring. In contrast, foreign strings
1363 always need to have memory for them.
1367 <refentry id="convert-from-cstring">
1369 <refname>convert-from-cstring</refname>
1370 <refpurpose>Converts a cstring to a Lisp string.
1372 <refclass>Macro</refclass>
1375 <title>Syntax</title>
1377 <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
1381 <title>Arguments and Values</title>
1384 <term><parameter>cstring</parameter></term>
1391 <term><returnvalue>string</returnvalue></term>
1393 <para>A Lisp string.
1400 <title>Description</title>
1402 Converts a Lisp string to a <constant>cstring</constant>. This is
1403 most often used when processing the results of a foreign function
1404 that returns a cstring.
1408 <title>Side Effects</title>
1412 <title>Affected by</title>
1416 <title>Exceptional Situations</title>
1422 <refentry id="convert-to-cstring">
1424 <refname>convert-to-cstring</refname>
1425 <refpurpose>Converts a Lisp string to a cstring.
1427 <refclass>Macro</refclass>
1430 <title>Syntax</title>
1432 <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
1436 <title>Arguments and Values</title>
1439 <term><parameter>string</parameter></term>
1441 <para>A Lisp string.
1446 <term><returnvalue>cstring</returnvalue></term>
1455 <title>Description</title>
1457 Converts a Lisp string to a
1458 <varname>cstring</varname>. The
1459 <varname>cstring</varname> should be freed with
1460 <function>free-cstring</function>.
1464 <title>Side Effects</title>
1468 <title>Affected by</title>
1472 <title>Exceptional Situations</title>
1478 <refentry id="free-cstring">
1480 <refname>free-cstring</refname>
1481 <refpurpose>Free memory used by cstring.
1483 <refclass>Macro</refclass>
1486 <title>Syntax</title>
1488 <function>free-cstring</function> <replaceable>cstring</replaceable>
1492 <title>Arguments and Values</title>
1495 <term><parameter>cstring</parameter></term>
1504 <title>Description</title>
1506 Frees any memory possibly allocated by
1507 <function>convert-to-cstring</function>.
1511 <title>Side Effects</title>
1515 <title>Affected by</title>
1519 <title>Exceptional Situations</title>
1525 <refentry id="with-cstring">
1527 <refname>with-cstring</refname>
1528 <refpurpose>Binds a newly created cstring.
1530 <refclass>Macro</refclass>
1533 <title>Syntax</title>
1535 <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
1539 <title>Arguments and Values</title>
1542 <term><parameter>cstring</parameter></term>
1544 <para>A symbol naming the cstring to be created.
1549 <term><parameter>string</parameter></term>
1551 <para>A Lisp string that will be translated to a cstring.
1556 <term><parameter>body</parameter></term>
1558 <para>The body of where the cstring will be bound.
1565 <title>Description</title>
1567 Binds a lexical variable to a newly allocated <varname>cstring</varname>. Automatically frees <varname>cstring</varname>.
1571 <title>Examples</title>
1574 (def-function ("getenv" c-getenv)
1576 :returning :cstring)
1579 "Returns an environment variable, or NIL if it does not exist"
1580 (check-type key string)
1581 (with-cstring (key-cstring key)
1582 (convert-from-cstring (c-getenv key-cstring))))
1587 <title>Side Effects</title>
1591 <title>Affected by</title>
1595 <title>Exceptional Situations</title>
1601 <refentry id="convert-from-foreign-string">
1603 <refname>convert-from-foreign-string</refname>
1604 <refpurpose>Converts a foreign string into a Lisp string.
1606 <refclass>Macro</refclass>
1609 <title>Syntax</title>
1611 <function>convert-from-foreign-string</function> <replaceable>foreign-string &key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
1615 <title>Arguments and Values</title>
1618 <term><parameter>foreign-string</parameter></term>
1620 <para>A foreign string.
1625 <term><parameter>length</parameter></term>
1627 <para>The length of the foreign string to
1628 convert. The default is the length of the string until a &null;
1629 character is reached.
1634 <term><parameter>null-terminated-p</parameter></term>
1636 <para>A boolean flag with a default value of &t; When true,
1637 the string is converted until the first &null; character is reached.
1642 <term><returnvalue>string</returnvalue></term>
1644 <para>A Lisp string.
1651 <title>Description</title>
1653 Returns a Lisp string from a foreign string.
1654 Can translated ASCII and binary strings.
1658 <title>Side Effects</title>
1662 <title>Affected by</title>
1666 <title>Exceptional Situations</title>
1672 <refentry id="convert-to-foreign-string">
1674 <refname>convert-to-foreign-string</refname>
1675 <refpurpose>Converts a Lisp string to a foreign string.
1677 <refclass>Macro</refclass>
1680 <title>Syntax</title>
1682 <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
1686 <title>Arguments and Values</title>
1689 <term><parameter>string</parameter></term>
1691 <para>A Lisp string.
1696 <term><returnvalue>foreign-string</returnvalue></term>
1698 <para>A foreign string.
1705 <title>Description</title>
1707 Converts a Lisp string to a foreign string. Memory should be
1708 freed with <function>free-foreign-object</function>.
1712 <title>Side Effects</title>
1716 <title>Affected by</title>
1720 <title>Exceptional Situations</title>
1727 <refentry id="allocate-foreign-string">
1729 <refname>allocate-foreign-string</refname>
1730 <refpurpose>Allocates space for a foreign string.
1732 <refclass>Macro</refclass>
1735 <title>Syntax</title>
1737 <function>allocate-foreign-string</function> <replaceable>size &key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
1741 <title>Arguments and Values</title>
1744 <term><parameter>size</parameter></term>
1746 <para>The size of the space to be allocated in bytes.
1751 <term><parameter>unsigned</parameter></term>
1753 <para>A boolean flag with a default value of &t;. When true,
1754 marks the pointer as an <constant>:unsigned-char</constant>.
1759 <term><returnvalue>foreign-string</returnvalue></term>
1761 <para>A foreign string which has undefined contents.
1768 <title>Description</title>
1770 Allocates space for a foreign string. Memory should
1771 be freed with <function>free-foreign-object</function>.
1775 <title>Side Effects</title>
1779 <title>Affected by</title>
1783 <title>Exceptional Situations</title>
1791 <title>Functions & Libraries</title>
1793 <refentry id="def-function">
1795 <refname>def-function</refname>
1796 <refpurpose>Declares a function.
1798 <refclass>Macro</refclass>
1801 <title>Syntax</title>
1803 <function>def-function</function> <replaceable>name args &key module returning</replaceable>
1807 <title>Arguments and Values</title>
1810 <term><parameter>name</parameter></term>
1812 <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.
1817 <term><parameter>args</parameter></term>
1819 <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
1824 <term><parameter>module</parameter></term>
1826 <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
1830 <term><returnvalue>returning</returnvalue></term>
1832 <para>A declaration specifying the result type of the
1833 foreign function. If <constant>:void</constant> indicates module does not return any value.
1840 <title>Description</title>
1841 <para>Declares a foreign function.
1845 <title>Examples</title>
1847 (def-function "gethostname"
1848 ((name (* :unsigned-char))
1854 <title>Side Effects</title>
1858 <title>Affected by</title>
1862 <title>Exceptional Situations</title>
1867 <refentry id="load-foreign-library">
1869 <refname>load-foreign-library</refname>
1870 <refpurpose>Loads a foreign library.
1872 <refclass>Function</refclass>
1875 <title>Syntax</title>
1877 <function>load-foreign-library</function> <replaceable>filename &key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
1881 <title>Arguments and Values</title>
1884 <term><parameter>filename</parameter></term>
1886 <para>A string or pathname specifying the library location
1887 in the filesystem. At least one implementation (&lw;) can not
1888 accept a logical pathname.
1893 <term><parameter>module</parameter></term>
1895 <para>A string designating the name of the module to apply
1896 to functions in this library. (Required for Lispworks)
1901 <term><parameter>supporting-libraries</parameter></term>
1903 <para>A list of strings naming the libraries required to
1904 link the foreign library. (Required by CMUCL)
1909 <term><returnvalue>success</returnvalue></term>
1911 <para>A boolean flag, &t; if the library was able to be
1912 loaded successfully or if the library has been previously loaded,
1920 <title>Description</title>
1921 <para>Loads a foreign library. Applies a module name to functions
1922 within the library. Ensures that a library is only loaded once during
1927 <title>Examples</title>
1929 (load-foreign-library #p"/usr/lib/libmysqlclient.so"
1931 :supporting-libraries '("c"))
1936 <title>Side Effects</title>
1937 <para>Loads the foreign code into the Lisp system.
1941 <title>Affected by</title>
1942 <para>Ability to load the file.</para>
1945 <title>Exceptional Situations</title>