~ubuntu-branches/ubuntu/trusty/mit-scheme/trusty

« back to all changes in this revision

Viewing changes to doc/ffi/ffi.texinfo

  • Committer: Package Import Robot
  • Author(s): Chris Hanson
  • Date: 2011-10-15 03:08:33 UTC
  • mfrom: (1.1.8) (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20111015030833-x7qc6yxuulvxbafv
Tags: 9.1-1
* New upstream.
* debian/control, debian/copyright, debian/mit-scheme-doc.*,
  debian/mit-scheme.install, debian/rules, Upstream has removed cover
  texts from documentation licenses, so merge packages mit-scheme and
  mit-scheme-doc back together.
* debian/compat: Bump to current version.
* debian/control: Bump standards-version to current and make
  necessary changes.
* debian/rules: Fix lintian warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\input texinfo @c -*-Texinfo-*-
 
2
@comment %**start of header
 
3
@setfilename mit-scheme-ffi
 
4
@set VERSION 0.1
 
5
@settitle FFI @value{VERSION}
 
6
@comment %**end of header
 
7
 
 
8
@macro myresult{}
 
9
@ifhtml
 
10
 =>
 
11
@end ifhtml
 
12
@ifnothtml
 
13
 @result{}
 
14
@end ifnothtml
 
15
@end macro
 
16
 
 
17
@copying
 
18
This manual documents @acronym{FFI} @value{VERSION}.
 
19
 
 
20
Copyright @copyright{} 2006, 2007, 2008, 2009, 2010 Matthew Birkholz
 
21
 
 
22
@quotation
 
23
Permission is granted to copy, distribute and/or modify this document
 
24
under the terms of the GNU Free Documentation License, Version 1.2 or
 
25
any later version published by the Free Software Foundation; with no
 
26
Invariant Sections, with no Front-Cover Texts and no Back-Cover Texts.
 
27
A copy of the license is included in the section entitled ``GNU Free
 
28
Documentation License.''
 
29
@end quotation
 
30
@end copying
 
31
 
 
32
@dircategory Programming Languages
 
33
@direntry
 
34
* FFI: (mit-scheme-ffi).                MIT/GNU Scheme Foreign Functions
 
35
@end direntry
 
36
 
 
37
@titlepage
 
38
@title The FFI Reference Manual
 
39
@subtitle a Foreign Function Interface (@value{VERSION})
 
40
@subtitle for MIT/GNU Scheme version 7.7.90+
 
41
@author by Matt Birkholz
 
42
@page
 
43
@vskip 0pt plus 1filll
 
44
@insertcopying
 
45
@end titlepage
 
46
 
 
47
@ifnottex
 
48
@node Top, Introduction, (dir), (dir)
 
49
@top FFI
 
50
 
 
51
@insertcopying
 
52
@end ifnottex
 
53
 
 
54
@menu
 
55
* Introduction:: A synopsis and quick summary.
 
56
* C Declarations:: Declare C types and functions.
 
57
* Alien Data:: Manipulate C data.
 
58
* Alien Functions:: Generate callout trampolines and call them.
 
59
* Callbacks:: Generate callback trampolines and get interrupted by them.
 
60
* Compiling and Linking:: Build and install the shim.
 
61
* Hello World:: A short example.
 
62
* GNU Free Documentation License::
 
63
@end menu
 
64
 
 
65
 
 
66
@node Introduction, C Declarations, Top, Top
 
67
@chapter Introduction
 
68
 
 
69
This FFI provides Scheme syntax for calling C functions and accessing
 
70
C data.  The functions and data structures are declared in a case
 
71
sensitive @file{.cdecl} file, which is used by a shim generator to
 
72
produce callout and callback trampoline functions.  The trampolines
 
73
are compiled and linked to the C toolkit, producing a shared object
 
74
that Scheme can dynamically load.
 
75
 
 
76
@heading Synopsis
 
77
 
 
78
Examples of the new syntax:
 
79
 
 
80
@example
 
81
(C-include "prhello")
 
82
 
 
83
@group
 
84
(malloc (C-sizeof "GdkEvent"))
 
85
@myresult{} #[alien 42 0x081afc60]
 
86
@end group
 
87
 
 
88
@group
 
89
(C-> @verb{"#@42"} "GdkEvent any type")
 
90
@myresult{} 14
 
91
@end group
 
92
 
 
93
(C->= @verb{"#@42"} "GdkEvent any type" 13)
 
94
 
 
95
@group
 
96
(C-enum "GDK_MAP")
 
97
@myresult{} 14
 
98
@end group
 
99
 
 
100
@group
 
101
(C-enum "GdkEventType" 14)
 
102
@myresult{} |GDK_MAP|
 
103
@end group
 
104
 
 
105
@group
 
106
(C-sizeof "GdkColor")
 
107
@myresult{} 12
 
108
@end group
 
109
 
 
110
@group
 
111
(C-offset "GdkColor blue")
 
112
@myresult{} 8
 
113
@end group
 
114
 
 
115
@group
 
116
(C-array-loc @verb{"#@43"} "GdkColor" (C-enum "GTK_STATE_NORMAL"))
 
117
@myresult{} #[alien 44 0x081afc60] @r{; New alien.}
 
118
@end group
 
119
 
 
120
@group
 
121
(C-array-loc! @verb{"#@43"} "GdkColor" (C-enum "GTK_STATE_PRELIGHT"))
 
122
@myresult{} #[alien 43 0x081afc78] @r{; Modified alien.}
 
123
@end group
 
124
 
 
125
@group
 
126
(C-call "gtk_window_new" retval args @dots{})
 
127
@myresult{} #!unspecific
 
128
@end group
 
129
 
 
130
@group
 
131
(C-callback "delete_event")
 
132
@myresult{} #[alien-function 44 Scm_delete_event]
 
133
@end group
 
134
 
 
135
@group
 
136
(C-callback (lambda (window event) @dots{}))
 
137
@myresult{} 13                     @r{; A fixnum registration ID.}
 
138
@end group
 
139
 
 
140
@end example
 
141
@comment The C-array-loc! example assumes 2 GdkColors are 6 words, #x18bytes.
 
142
@comment 0x081afc78 - 0x081afc60 = 0x18
 
143
 
 
144
@heading Summary
 
145
 
 
146
A Scheme-like declaration of a toolkit's C functions, constants, and
 
147
data types is given in a case sensitive @file{.cdecl} file.  The C
 
148
declarations look like this:
 
149
 
 
150
@smallexample
 
151
(extern (* GtkWidget)              @r{; gtk+-2.4.0/gtk/gtkwindow.h}
 
152
        gtk_window_new
 
153
        (type GtkWindowType))
 
154
 
 
155
(typedef GtkWindowType             @r{; gtk+-2.4.0/gtk/gtkenums.h}
 
156
         (enum
 
157
          (GTK_WINDOW_TOPLEVEL)
 
158
          (GTK_WINDOW_POPUP)))
 
159
@end smallexample
 
160
 
 
161
The @strong{@code{c-generate}} procedure reads these declarations and
 
162
writes three files: @file{@i{library}-types.bin} (a fasdump of the
 
163
parsed declarations), @file{@i{library}-const.c} (a C program that
 
164
prints C constants and struct offsets), and @file{@i{library}-shim.c}
 
165
(trampoline functions adapting Scheme procedure application to C
 
166
function call).  The @file{-const.c} program generates a
 
167
@file{-const.scm} file, which can be syntaxed to produce a
 
168
@file{-const.bin} file.
 
169
 
 
170
@smallexample
 
171
(load-option 'FFI)
 
172
(c-generate "prhello" "#include <gtk/gtk.h>")
 
173
@end smallexample
 
174
 
 
175
The @file{-types.bin} and @file{-const.bin} files together provide
 
176
the information needed to expand @code{C-...} syntax, and are only
 
177
needed at syntax time.  The compiled @file{-shim.so} file is used at
 
178
run time, dynamically loaded into the Scheme machine.  @ref{Compiling
 
179
and Linking}, which describes these files in more detail, and shows
 
180
how they might be built and installed.
 
181
 
 
182
@smallexample
 
183
(C-include "prhello")
 
184
@end smallexample
 
185
 
 
186
The @strong{@code{C-include}} syntax loads the @file{-types.bin} and
 
187
@file{-const.bin} files @emph{at syntax time}.  It should appear
 
188
at the top level of any file containing @code{C-...} syntax, or be
 
189
evaluated in the syntax environment of such code.
 
190
 
 
191
The @strong{@code{C-call}} syntax arranges to invoke a callout
 
192
trampoline.  Arguments to the trampoline can be integers, floats,
 
193
strings or aliens (non-heap pointers, to C data structures,
 
194
@pxref{Alien Data}).
 
195
 
 
196
@smallexample
 
197
(let ((alien (make-alien '|GtkWidget|)))
 
198
  (C-call "gtk_window_new" alien type)
 
199
  (if (alien-null? alien) (error "could not open new window"))
 
200
  alien)
 
201
@end smallexample
 
202
 
 
203
The @strong{@code{C-callback}} syntax is used when registering a
 
204
Scheme callback trampoline.  The two forms of the syntax provide two
 
205
arguments for the registration function: the callback trampoline's
 
206
address, and a ``user data'' argument.  When the toolkit calls the
 
207
trampoline, it must provide the fixnum-sized user data as an argument.
 
208
 
 
209
@smallexample
 
210
(C-call "g_signal_connect" window "delete_event"
 
211
        (C-callback "delete_event")     ; @r{@i{e.g. &Scm_delete_event}}
 
212
        (C-callback                     ; @r{@i{e.g. 314}}
 
213
          (lambda (window event)
 
214
            (C-call "gtk_widget_destroy" window)
 
215
            0)))
 
216
@end smallexample
 
217
 
 
218
The first use of @code{C-callback} (above) expands into a callback
 
219
trampoline address --- an alien function.  The second use evaluates to
 
220
a fixnum, which is associated with the given Scheme procedure.
 
221
 
 
222
The @strong{@code{C->}} and @strong{@code{C->=}} syntaxes peek and
 
223
poke values into alien data structures.  They take an alien and a
 
224
constant string specifying the alien data type and the member to be
 
225
accessed (if any).
 
226
 
 
227
@smallexample
 
228
@group
 
229
(C-> alien "GdkRectangle y")
 
230
@expansion{}
 
231
(#[primitive c-peek-int] alien 4)
 
232
@end group
 
233
 
 
234
@group
 
235
(C->= alien "GdkRectangle width" 0)
 
236
@expansion{}
 
237
(#[primitive c-poke-int] alien 8 0)
 
238
@end group
 
239
@end smallexample
 
240
 
 
241
@smallexample
 
242
@group
 
243
(C-> alien "GdkEvent any type")
 
244
@expansion{}
 
245
(#[primitive c-peek-int] alien 0)
 
246
@end group
 
247
@end smallexample
 
248
 
 
249
@smallexample
 
250
@group
 
251
(C-> alien "gfloat")
 
252
@expansion{}
 
253
(#[primitive c-peek-float] alien 0)
 
254
@end group
 
255
@end smallexample
 
256
 
 
257
A three argument form of the syntax provides an alien to receive a
 
258
peeked pointer.  This avoids consing a new alien.
 
259
 
 
260
@smallexample
 
261
(C-> alien "GtkWidget style" alien)
 
262
@end smallexample
 
263
 
 
264
The above syntax is understood to say ``The data at this @code{alien}
 
265
address is a GtkWidget.  Load its @code{style} member (an alien
 
266
address), into @code{alien} (clobbering @code{alien}'s old address).''
 
267
 
 
268
The @strong{@code{C-enum}}, @strong{@code{C-sizeof}} and
 
269
@strong{@code{C-offset}} syntaxes all
 
270
transform into integer constants.  The last two transform into a padded
 
271
byte size and a byte offset respectively.
 
272
 
 
273
@smallexample
 
274
@group
 
275
(C-enum "GTK_WINDOW_POPUP")
 
276
@expansion{}
 
277
1
 
278
@end group
 
279
 
 
280
@group
 
281
(C-sizeof "GdkColor")
 
282
@expansion{}
 
283
12
 
284
@end group
 
285
 
 
286
@group
 
287
(C-offset "GdkColor blue")
 
288
@expansion{}
 
289
8
 
290
@end group
 
291
 
 
292
@end smallexample
 
293
 
 
294
The two element form of the @code{C-enum} syntax can be used to find
 
295
the name of a constant given its runtime value.  It expects the name
 
296
of an enum type in a constant string.  If the runtime (second)
 
297
argument is not one of the constants declared by that type, the
 
298
returned value is @code{#f}.
 
299
 
 
300
@smallexample
 
301
@group
 
302
(C-enum "GdkEventType" (C-> @verb{"#@42"} "GdkEvent any type"))
 
303
@myresult{}
 
304
|GDK_MAP|
 
305
@end group
 
306
@end smallexample
 
307
 
 
308
The @strong{@code{c-array-loc}} and @strong{@code{c-array-loc!}}
 
309
syntaxes compute the locations of C array elements.  They can be used
 
310
to advance a scan pointer or locate an element by its index.  The
 
311
examples in the synopsis might expand as shown here.
 
312
 
 
313
@smallexample
 
314
(C-array-loc @verb{"#@43"} "GdkColor" (C-enum "GTK_STATE_NORMAL"))
 
315
@expansion{}
 
316
(alien-byte-increment @verb{"#@43"} (* (C-sizeof "GdkColor")
 
317
                              (C-enum "GTK_STATE_NORMAL")))
 
318
@expansion{}
 
319
(alien-byte-increment @verb{"#@43"} 0)
 
320
@myresult{}
 
321
@verb{"#@44"}
 
322
 
 
323
(C-array-loc! @verb{"#@43"} "GdkColor" (C-enum "GTK_STATE_PRELIGHT"))
 
324
@expansion{}
 
325
(alien-byte-increment! @verb{"#@43"} (* (C-sizeof "GdkColor")
 
326
                               (C-enum "GTK_STATE_PRELIGHT")))
 
327
@expansion{}
 
328
(alien-byte-increment! @verb{"#@43"} 24)
 
329
@myresult{}
 
330
@verb{"#@43"}
 
331
@end smallexample
 
332
 
 
333
A simple scan of characters in the wide string @code{alien} might
 
334
look like this.
 
335
 
 
336
@smallexample
 
337
(let ((len (C-> alien "toolkit_string_type int_member"))
 
338
      (scan (C-> alien "toolkit_string_type array_member")))
 
339
  (let loop ((n 0))
 
340
    (if (< n len)
 
341
        (let ((wchar (C-> scan "wchar")))
 
342
          (process wchar)
 
343
          (C-array-loc! scan "wchar" 1)
 
344
          (loop (1+ n))))))
 
345
@end smallexample
 
346
 
 
347
That is a quick look at the facilities.  The next section describes
 
348
the C declaration language, and the following sections examine the FFI's
 
349
syntax and runtime facilities in detail.  Final sections provide an
 
350
example program and show how its dynamically loaded shim is built.
 
351
 
 
352
 
 
353
@node C Declarations, Alien Data, Introduction, Top
 
354
@chapter C Declarations
 
355
 
 
356
A shim between Scheme and a C toolkit is specified by a case sensitive
 
357
@file{.cdecl} file containing Scheme-like declarations of all relevant
 
358
toolkit types, constants, and functions.  Callback functions to be
 
359
passed to the toolkit are also specified here.
 
360
 
 
361
There are some limitations on the C types that can be declared.
 
362
Basic, struct, union, enum and pointer types are allowed, but
 
363
bit-field members are not supported.  C function parameters can be
 
364
basic, enum or pointer types.  The return type of a C function is the
 
365
same plus @code{void}.  Basically, no struct or union argument or
 
366
return types, at the moment.
 
367
 
 
368
Each top-level form in the C declaration file must look like one of
 
369
these:
 
370
 
 
371
@smallexample
 
372
(include "filename")
 
373
(typedef Name @var{any})
 
374
(struct Name (Member @var{type}) @dots{})
 
375
(union Name (Member @var{type}) @dots{})
 
376
(enum @i{Name} (Member) @dots{})
 
377
(extern @var{return-type} Name (param1 @var{arg-type}) @dots{})
 
378
(callback @var{return-type} Name (param1 @var{arg-type}) @dots{})
 
379
@end smallexample
 
380
 
 
381
An enum's @i{@var{Name}} is optional.
 
382
 
 
383
@var{arg-type} is currently restricted to the following forms.  It is
 
384
assumed that a lone @var{Name} is defined as a type on this list:
 
385
 
 
386
@smallexample
 
387
Name
 
388
@var{basics}
 
389
(* @var{any})
 
390
(enum Name)
 
391
(enum @i{Name} (Member) @dots{})
 
392
@end smallexample
 
393
 
 
394
@var{return-type} can be either @var{arg-type} or the word @code{void}.
 
395
 
 
396
@var{basics} can be any of the words: @code{char}, @code{uchar},
 
397
@code{short}, @code{ushort}, @code{int}, @code{uint}, @code{long},
 
398
@code{ulong}, @code{float}, or @code{double} (all lowercase).
 
399
 
 
400
@var{type} includes structs and unions:
 
401
 
 
402
@smallexample
 
403
@var{arg-type}
 
404
(struct Name)
 
405
(struct @i{Name} (Member @var{type}) @dots{})
 
406
(union Name)
 
407
(union @i{Name} (Member @var{type}) @dots{})
 
408
@end smallexample
 
409
 
 
410
@var{any} is any @var{type} @emph{or} @code{void}.
 
411
 
 
412
The @code{include} expression includes another @file{.cdecl} file in
 
413
the current @file{.cdecl} file.  The string argument is interpreted
 
414
relative to the current file's directory.
 
415
 
 
416
While the informal grammar above allows anonymous structs to be
 
417
specified for argument or member types, they are of little use outside
 
418
top-level, @i{named} struct or union declarations.  The peek and poke
 
419
(@code{C->} and @code{C->=}) syntax expects a type name (e.g.
 
420
@code{"GdkEventAny"} or @code{"struct _GdkEventAny"}) before any
 
421
member names.
 
422
 
 
423
@smallexample
 
424
(C-include "prhello")
 
425
@end smallexample
 
426
 
 
427
The @strong{@code{C-include}} syntax takes a library name and loads
 
428
the corresponding @file{-types} and @file{-const} files at syntax
 
429
time.  This makes the C types and constants available to the other
 
430
@code{C-...} syntax expanders.  The form binds @code{c-includes} in
 
431
the syntax environment @i{unless} it is already defined there.  Thus a
 
432
@code{(C-includes "library")} form can be placed at the top of every
 
433
file with @code{C-...} syntax, @emph{or} loaded into the syntax-time
 
434
environment of those files.
 
435
 
 
436
 
 
437
@node Alien Data, Alien Functions, C Declarations, Top
 
438
@chapter Alien Data
 
439
 
 
440
A C data structure is represented by an alien containing the data
 
441
structure's memory address.  ``Peek'' primitives are available to read
 
442
pointers and the basic C types (e.g. ints, floats) at small (fixnum)
 
443
offsets from an alien's address.  They return to Scheme an alien
 
444
address, integer or flonum as appropriate.  ``Poke'' primitives
 
445
do the reverse, storing pointers, integers or floats at fixnum offsets
 
446
from alien addresses.
 
447
Other procedures on aliens are @code{alien?},
 
448
@code{alien-null?}, @code{alien-null!}, @code{copy-alien}, @code{alien=?},
 
449
@code{alien-byte-increment}, and @code{c-peek-cstring}.  Refer to
 
450
@file{ffi.pkg} in The Source for a complete list.
 
451
 
 
452
The @code{C->} and @code{C->=} syntaxes apply the peek and poke
 
453
primitives to constant offsets.  They expect their first argument
 
454
subform to be a constant string --- space-separated words naming a C
 
455
type and any member to be accessed.  A member within a struct or union
 
456
member is specified by appending its name.  For example @code{"struct
 
457
_GdkEvent any window"} would specify a peek at the @code{window}
 
458
member of the @code{any} member of the @code{struct _GdkEvent} data at
 
459
some alien address.  Note that the final member's type must be a basic
 
460
C type, pointer type, or enum type.  Otherwise, an error is signaled
 
461
at syntax time.
 
462
 
 
463
@smallexample
 
464
@group
 
465
(C-> alien "struct _GdkEvent any window" window-alien)
 
466
@expansion{}
 
467
(#[primitive c-peek-pointer] alien 0 window-alien)
 
468
@myresult{}
 
469
#[alien 44 (* GdkWindow) 0x081afc60]
 
470
@end group
 
471
@end smallexample
 
472
 
 
473
Note that in the example above, the final member has a pointer type.
 
474
In this case an extra alien argument can be provided to receive the
 
475
peeked pointer.  Otherwise a new alien is created and returned.
 
476
 
 
477
@heading Malloc
 
478
 
 
479
The @code{malloc} procedure returns an alien that will automatically
 
480
free the malloced memory when it is garbage collected.
 
481
It can also be explicitly freed with the @code{free} procedure.  The alien
 
482
address can be incremented to scan the malloced memory, then freed
 
483
(without returning it to the original, malloced address).  A band
 
484
restore marks all malloced aliens as though they have been freed.
 
485
 
 
486
@smallexample
 
487
(free (malloc '|GdkRectangle|))
 
488
@end smallexample
 
489
 
 
490
 
 
491
@node Alien Functions, Callbacks, Alien Data, Top
 
492
@chapter Alien Functions
 
493
 
 
494
The @code{C-call} syntax produces code that applies @code{call-alien}
 
495
to an alien function structure --- a cache for the callout
 
496
trampoline's entry address.
 
497
 
 
498
@smallexample
 
499
@group
 
500
(C-call "gtk_button_new" (make-alien '(* |GtkWidget|)))
 
501
@expansion{}
 
502
(call-alien '#[alien-function gtk_button_new] (make-alien @dots{}))
 
503
@end group
 
504
@end smallexample
 
505
 
 
506
The alien function contains all the information needed to load the
 
507
callout trampoline on demand (i.e. its name and library).  Once the
 
508
alien function has cached the entry address, @code{call-alien} can
 
509
invoke the trampoline (via @code{#[primitive c-call]}).  The
 
510
trampoline gets its arguments off the Scheme stack, converts them to C
 
511
values, calls the C function, conses a result, and returns it to
 
512
Scheme.  As a special case a function returning a pointer type
 
513
expects an extra first argument.  If this argument is @code{#f}, the
 
514
return value is discarded.  If the argument is an alien, the
 
515
function's return value clobbers the alien's address.  This makes it
 
516
easy to grab pointers to toolkit resources without dropping them, or
 
517
avoid unnecessary consing of aliens.
 
518
 
 
519
The @code{alien-function} structures are fasdumpable.  The caching
 
520
mechanism invalidates the cache when a band is restored, or a
 
521
fasdumped object is fasloaded.  The alien function will lookup the
 
522
trampoline entry point again on demand.
 
523
 
 
524
 
 
525
@node Callbacks, Compiling and Linking, Alien Functions, Top
 
526
@chapter Callbacks
 
527
 
 
528
A callback declaration must include a parameter named ``ID''.  The ID
 
529
argument will be used to find the Scheme callback procedure.  It must
 
530
be the same ``user data'' value provided to the toolkit when the
 
531
callback was registered.  For example, a callback trampoline named
 
532
@code{Scm_delete_event} might be declared like this:
 
533
 
 
534
@smallexample
 
535
(callback gint
 
536
          delete_event
 
537
          (window (* GtkWidget))
 
538
          (event (* GdkEventAny))
 
539
          (ID gpointer))
 
540
@end smallexample
 
541
 
 
542
The callback might be registered with the toolkit like this:
 
543
 
 
544
@smallexample
 
545
(C-call "g_signal_connect" window "delete_event"
 
546
        (C-callback "delete_event")     ; @r{@i{e.g. &Scm_delete_event}}
 
547
        (C-callback                     ; @r{@i{e.g. 314}}
 
548
          (lambda (window event)
 
549
            (C-call "gtk_widget_destroy" window)
 
550
            0)))
 
551
@end smallexample
 
552
 
 
553
The toolkit's registration function, @code{g_signal_connect}, would be
 
554
declared like this:
 
555
 
 
556
@smallexample
 
557
(extern void
 
558
        g_signal_connect
 
559
        (object (* GtkObject))
 
560
        (name (* gchar))
 
561
        (CALLBACK GtkSignalFunc)
 
562
        (ID gpointer))
 
563
@end smallexample
 
564
 
 
565
This function should have parameters named @code{CALLBACK} and
 
566
@code{ID}.  The callout trampoline will convert the callback argument
 
567
from a Scheme alien function to an entry address.  The @code{ID} argument
 
568
will be converted to a C integer and then cast to its declared type
 
569
(in this example, @code{gpointer}).
 
570
 
 
571
Note that the registered callback procedures are effectively pinned.
 
572
They cannot be garbage collected.  They are ``on call'' to handle
 
573
callbacks from the toolkit until they are explicitly de-registered.  A
 
574
band restore automatically de-registers all callbacks.
 
575
 
 
576
The callback procedures are executed like an interrupt handler.  They
 
577
actually interrupt the thread executing the most recent callout,
 
578
e.g. to @code{gtk_main}.  The thread runs with thread switching
 
579
disabled for the duration of the callback, and can callout to the
 
580
toolkit, which can callback again.  The (nested) callbacks and nested
 
581
callouts all run in the same thread, and so will return in LIFO order
 
582
as expected by the toolkit.  Note that the runtime system will not
 
583
balk at a callback procedure that calls @code{yield-thread}, waits for
 
584
I/O, sleeps, or otherwise causes a thread switch.  Presumably such a
 
585
procedure has some other way of enforcing the LIFO ordering.
 
586
 
 
587
The @code{outf-console} procedure is provided for debugging purposes.
 
588
It writes one or more argument strings (and @code{write}s any
 
589
non-strings) to the console and flushes, atomically, via a machine
 
590
primitive, bypassing the runtime's I/O buffering and thread switching.
 
591
Thus multiple debugging trace messages arrive on the console intact
 
592
and uninterrupted.
 
593
 
 
594
 
 
595
@node Compiling and Linking, Hello World, Callbacks, Top
 
596
@chapter Compiling and Linking
 
597
 
 
598
The @strong{@code{c-generate}} procedure takes a library name and an
 
599
optional preamble.  It reads the @file{@i{library}.cdecl} file and
 
600
writes two @file{.c} files.  The preamble is included at the top of
 
601
both.  It typically contains @code{#include} C pre-processor
 
602
directives required by the C library, but could include additional
 
603
shim code.  Here is a short script that generates a shim for the
 
604
example ``Hello, World!'' program.
 
605
 
 
606
@smallexample
 
607
(load-option 'FFI)
 
608
(c-generate "prhello" "#include <gtk/gtk.h>")
 
609
@end smallexample
 
610
 
 
611
This script will produce three files:
 
612
 
 
613
@table @file
 
614
 
 
615
@item prhello-shim.c
 
616
This file contains the trampoline functions --- one for each declared
 
617
C extern or callback.  It includes the @file{mit-scheme.h} header
 
618
file, found in the @code{AUXDIR} directory ---
 
619
e.g. @file{/usr/local/lib/mit-scheme/}.
 
620
 
 
621
@item prhello-const.c
 
622
This file contains a C program that creates
 
623
@file{prhello-const.scm}.  It is compiled and linked
 
624
as normal for programs using the toolkit, and does not depend on the
 
625
Scheme machine.  It does not actually call any
 
626
toolkit functions.  It just collects information from the compiler
 
627
about the declared C types and constants.
 
628
 
 
629
@item prhello-types.bin
 
630
This file is a fasdumped @code{c-includes} structure containing all of
 
631
the types, constants and functions declared in the @file{.cdecl} file.
 
632
 
 
633
@end table
 
634
 
 
635
The following Makefile rules describe the process of building and
 
636
installing a shim for the example ``Hello, World!'' program.
 
637
 
 
638
@example
 
639
@verbatim
 
640
install-example: build-example
 
641
        $(INSTALL_DATA) prhello-types.bin ../lib/.
 
642
        $(INSTALL_DATA) prhello-const.bin ../lib/.
 
643
        $(INSTALL_DATA) prhello-shim.so ../lib/.
 
644
 
 
645
build-example: prhello-shim.so prhello-types.bin prhello-const.bin
 
646
 
 
647
prhello-shim.so: prhello-shim.o
 
648
        $(CC) -shared -fPIC -o $@ $^ `pkg-config --libs gtk+-2.0`
 
649
 
 
650
prhello-shim.o: prhello-shim.c
 
651
        $(CC) -I../lib -Wall -fPIC `pkg-config --cflags gtk+-2.0` -o $@ -c $<
 
652
 
 
653
prhello-shim.c prhello-const.c prhello-types.bin: prhello.cdecl
 
654
        (echo "(load-option 'FFI)"; \
 
655
         echo '(C-generate "prhello" "#include <gtk/gtk.h>")') \
 
656
        | ../microcode/scheme --library ../lib --batch-mode
 
657
 
 
658
prhello-const.bin: prhello-const.scm
 
659
        echo '(sf "prhello-const")' | mit-scheme --compiler --batch-mode
 
660
 
 
661
prhello-const.scm: prhello-const
 
662
        ./prhello-const
 
663
 
 
664
prhello-const: prhello-const.o
 
665
        @rm -f $@
 
666
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ `pkg-config --libs gtk+-2.0`
 
667
 
 
668
prhello-const.o: prhello-const.c
 
669
        $(CC) `pkg-config --cflags gtk+-2.0` $(CFLAGS) -o $@ -c $<
 
670
@end verbatim
 
671
@end example
 
672
 
 
673
 
 
674
@node Hello World, GNU Free Documentation License, Compiling and Linking, Top
 
675
@chapter Hello World
 
676
 
 
677
This
 
678
@iftex
 
679
chapter
 
680
@end iftex
 
681
@ifnottex
 
682
node
 
683
@end ifnottex
 
684
includes the C declarations and Scheme code required to implement
 
685
Havoc Pennington's Hello World example from
 
686
@uref{http://developer.gnome.org/doc/GGAD/, GGAD}.  For an extra,
 
687
Schemely treat, its @code{delete_event} callback is a Scheme procedure
 
688
closed over a binding of @code{counter} that is used to implement some
 
689
impertinent behavior.
 
690
@example
 
691
@verbatiminclude prhello.scm
 
692
@end example
 
693
 
 
694
Here are the C declarations.
 
695
@example
 
696
@verbatiminclude prhello.cdecl
 
697
@end example
 
698
 
 
699
 
 
700
@node GNU Free Documentation License, , Hello World, Top
 
701
@appendix GNU Free Documentation License
 
702
 
 
703
@center Version 1.2, November 2002
 
704
 
 
705
@display
 
706
Copyright @copyright{} 2000,2001,2002 Free Software Foundation, Inc.
 
707
51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 
708
 
 
709
Everyone is permitted to copy and distribute verbatim copies
 
710
of this license document, but changing it is not allowed.
 
711
@end display
 
712
 
 
713
@enumerate 0
 
714
@item
 
715
PREAMBLE
 
716
 
 
717
The purpose of this License is to make a manual, textbook, or other
 
718
functional and useful document @dfn{free} in the sense of freedom: to
 
719
assure everyone the effective freedom to copy and redistribute it,
 
720
with or without modifying it, either commercially or noncommercially.
 
721
Secondarily, this License preserves for the author and publisher a way
 
722
to get credit for their work, while not being considered responsible
 
723
for modifications made by others.
 
724
 
 
725
This License is a kind of ``copyleft'', which means that derivative
 
726
works of the document must themselves be free in the same sense.  It
 
727
complements the GNU General Public License, which is a copyleft
 
728
license designed for free software.
 
729
 
 
730
We have designed this License in order to use it for manuals for free
 
731
software, because free software needs free documentation: a free
 
732
program should come with manuals providing the same freedoms that the
 
733
software does.  But this License is not limited to software manuals;
 
734
it can be used for any textual work, regardless of subject matter or
 
735
whether it is published as a printed book.  We recommend this License
 
736
principally for works whose purpose is instruction or reference.
 
737
 
 
738
@item
 
739
APPLICABILITY AND DEFINITIONS
 
740
 
 
741
This License applies to any manual or other work, in any medium, that
 
742
contains a notice placed by the copyright holder saying it can be
 
743
distributed under the terms of this License.  Such a notice grants a
 
744
world-wide, royalty-free license, unlimited in duration, to use that
 
745
work under the conditions stated herein.  The ``Document'', below,
 
746
refers to any such manual or work.  Any member of the public is a
 
747
licensee, and is addressed as ``you''.  You accept the license if you
 
748
copy, modify or distribute the work in a way requiring permission
 
749
under copyright law.
 
750
 
 
751
A ``Modified Version'' of the Document means any work containing the
 
752
Document or a portion of it, either copied verbatim, or with
 
753
modifications and/or translated into another language.
 
754
 
 
755
A ``Secondary Section'' is a named appendix or a front-matter section
 
756
of the Document that deals exclusively with the relationship of the
 
757
publishers or authors of the Document to the Document's overall
 
758
subject (or to related matters) and contains nothing that could fall
 
759
directly within that overall subject.  (Thus, if the Document is in
 
760
part a textbook of mathematics, a Secondary Section may not explain
 
761
any mathematics.)  The relationship could be a matter of historical
 
762
connection with the subject or with related matters, or of legal,
 
763
commercial, philosophical, ethical or political position regarding
 
764
them.
 
765
 
 
766
The ``Invariant Sections'' are certain Secondary Sections whose titles
 
767
are designated, as being those of Invariant Sections, in the notice
 
768
that says that the Document is released under this License.  If a
 
769
section does not fit the above definition of Secondary then it is not
 
770
allowed to be designated as Invariant.  The Document may contain zero
 
771
Invariant Sections.  If the Document does not identify any Invariant
 
772
Sections then there are none.
 
773
 
 
774
The ``Cover Texts'' are certain short passages of text that are listed,
 
775
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
 
776
the Document is released under this License.  A Front-Cover Text may
 
777
be at most 5 words, and a Back-Cover Text may be at most 25 words.
 
778
 
 
779
A ``Transparent'' copy of the Document means a machine-readable copy,
 
780
represented in a format whose specification is available to the
 
781
general public, that is suitable for revising the document
 
782
straightforwardly with generic text editors or (for images composed of
 
783
pixels) generic paint programs or (for drawings) some widely available
 
784
drawing editor, and that is suitable for input to text formatters or
 
785
for automatic translation to a variety of formats suitable for input
 
786
to text formatters.  A copy made in an otherwise Transparent file
 
787
format whose markup, or absence of markup, has been arranged to thwart
 
788
or discourage subsequent modification by readers is not Transparent.
 
789
An image format is not Transparent if used for any substantial amount
 
790
of text.  A copy that is not ``Transparent'' is called ``Opaque''.
 
791
 
 
792
Examples of suitable formats for Transparent copies include plain
 
793
@sc{ascii} without markup, Texinfo input format, La@TeX{} input
 
794
format, @acronym{SGML} or @acronym{XML} using a publicly available
 
795
@acronym{DTD}, and standard-conforming simple @acronym{HTML},
 
796
PostScript or @acronym{PDF} designed for human modification.  Examples
 
797
of transparent image formats include @acronym{PNG}, @acronym{XCF} and
 
798
@acronym{JPG}.  Opaque formats include proprietary formats that can be
 
799
read and edited only by proprietary word processors, @acronym{SGML} or
 
800
@acronym{XML} for which the @acronym{DTD} and/or processing tools are
 
801
not generally available, and the machine-generated @acronym{HTML},
 
802
PostScript or @acronym{PDF} produced by some word processors for
 
803
output purposes only.
 
804
 
 
805
The ``Title Page'' means, for a printed book, the title page itself,
 
806
plus such following pages as are needed to hold, legibly, the material
 
807
this License requires to appear in the title page.  For works in
 
808
formats which do not have any title page as such, ``Title Page'' means
 
809
the text near the most prominent appearance of the work's title,
 
810
preceding the beginning of the body of the text.
 
811
 
 
812
A section ``Entitled XYZ'' means a named subunit of the Document whose
 
813
title either is precisely XYZ or contains XYZ in parentheses following
 
814
text that translates XYZ in another language.  (Here XYZ stands for a
 
815
specific section name mentioned below, such as ``Acknowledgements'',
 
816
``Dedications'', ``Endorsements'', or ``History''.)  To ``Preserve the Title''
 
817
of such a section when you modify the Document means that it remains a
 
818
section ``Entitled XYZ'' according to this definition.
 
819
 
 
820
The Document may include Warranty Disclaimers next to the notice which
 
821
states that this License applies to the Document.  These Warranty
 
822
Disclaimers are considered to be included by reference in this
 
823
License, but only as regards disclaiming warranties: any other
 
824
implication that these Warranty Disclaimers may have is void and has
 
825
no effect on the meaning of this License.
 
826
 
 
827
@item
 
828
VERBATIM COPYING
 
829
 
 
830
You may copy and distribute the Document in any medium, either
 
831
commercially or noncommercially, provided that this License, the
 
832
copyright notices, and the license notice saying this License applies
 
833
to the Document are reproduced in all copies, and that you add no other
 
834
conditions whatsoever to those of this License.  You may not use
 
835
technical measures to obstruct or control the reading or further
 
836
copying of the copies you make or distribute.  However, you may accept
 
837
compensation in exchange for copies.  If you distribute a large enough
 
838
number of copies you must also follow the conditions in section 3.
 
839
 
 
840
You may also lend copies, under the same conditions stated above, and
 
841
you may publicly display copies.
 
842
 
 
843
@item
 
844
COPYING IN QUANTITY
 
845
 
 
846
If you publish printed copies (or copies in media that commonly have
 
847
printed covers) of the Document, numbering more than 100, and the
 
848
Document's license notice requires Cover Texts, you must enclose the
 
849
copies in covers that carry, clearly and legibly, all these Cover
 
850
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
 
851
the back cover.  Both covers must also clearly and legibly identify
 
852
you as the publisher of these copies.  The front cover must present
 
853
the full title with all words of the title equally prominent and
 
854
visible.  You may add other material on the covers in addition.
 
855
Copying with changes limited to the covers, as long as they preserve
 
856
the title of the Document and satisfy these conditions, can be treated
 
857
as verbatim copying in other respects.
 
858
 
 
859
If the required texts for either cover are too voluminous to fit
 
860
legibly, you should put the first ones listed (as many as fit
 
861
reasonably) on the actual cover, and continue the rest onto adjacent
 
862
pages.
 
863
 
 
864
If you publish or distribute Opaque copies of the Document numbering
 
865
more than 100, you must either include a machine-readable Transparent
 
866
copy along with each Opaque copy, or state in or with each Opaque copy
 
867
a computer-network location from which the general network-using
 
868
public has access to download using public-standard network protocols
 
869
a complete Transparent copy of the Document, free of added material.
 
870
If you use the latter option, you must take reasonably prudent steps,
 
871
when you begin distribution of Opaque copies in quantity, to ensure
 
872
that this Transparent copy will remain thus accessible at the stated
 
873
location until at least one year after the last time you distribute an
 
874
Opaque copy (directly or through your agents or retailers) of that
 
875
edition to the public.
 
876
 
 
877
It is requested, but not required, that you contact the authors of the
 
878
Document well before redistributing any large number of copies, to give
 
879
them a chance to provide you with an updated version of the Document.
 
880
 
 
881
@item
 
882
MODIFICATIONS
 
883
 
 
884
You may copy and distribute a Modified Version of the Document under
 
885
the conditions of sections 2 and 3 above, provided that you release
 
886
the Modified Version under precisely this License, with the Modified
 
887
Version filling the role of the Document, thus licensing distribution
 
888
and modification of the Modified Version to whoever possesses a copy
 
889
of it.  In addition, you must do these things in the Modified Version:
 
890
 
 
891
@enumerate A
 
892
@item
 
893
Use in the Title Page (and on the covers, if any) a title distinct
 
894
from that of the Document, and from those of previous versions
 
895
(which should, if there were any, be listed in the History section
 
896
of the Document).  You may use the same title as a previous version
 
897
if the original publisher of that version gives permission.
 
898
 
 
899
@item
 
900
List on the Title Page, as authors, one or more persons or entities
 
901
responsible for authorship of the modifications in the Modified
 
902
Version, together with at least five of the principal authors of the
 
903
Document (all of its principal authors, if it has fewer than five),
 
904
unless they release you from this requirement.
 
905
 
 
906
@item
 
907
State on the Title page the name of the publisher of the
 
908
Modified Version, as the publisher.
 
909
 
 
910
@item
 
911
Preserve all the copyright notices of the Document.
 
912
 
 
913
@item
 
914
Add an appropriate copyright notice for your modifications
 
915
adjacent to the other copyright notices.
 
916
 
 
917
@item
 
918
Include, immediately after the copyright notices, a license notice
 
919
giving the public permission to use the Modified Version under the
 
920
terms of this License, in the form shown in the Addendum below.
 
921
 
 
922
@item
 
923
Preserve in that license notice the full lists of Invariant Sections
 
924
and required Cover Texts given in the Document's license notice.
 
925
 
 
926
@item
 
927
Include an unaltered copy of this License.
 
928
 
 
929
@item
 
930
Preserve the section Entitled ``History'', Preserve its Title, and add
 
931
to it an item stating at least the title, year, new authors, and
 
932
publisher of the Modified Version as given on the Title Page.  If
 
933
there is no section Entitled ``History'' in the Document, create one
 
934
stating the title, year, authors, and publisher of the Document as
 
935
given on its Title Page, then add an item describing the Modified
 
936
Version as stated in the previous sentence.
 
937
 
 
938
@item
 
939
Preserve the network location, if any, given in the Document for
 
940
public access to a Transparent copy of the Document, and likewise
 
941
the network locations given in the Document for previous versions
 
942
it was based on.  These may be placed in the ``History'' section.
 
943
You may omit a network location for a work that was published at
 
944
least four years before the Document itself, or if the original
 
945
publisher of the version it refers to gives permission.
 
946
 
 
947
@item
 
948
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
 
949
the Title of the section, and preserve in the section all the
 
950
substance and tone of each of the contributor acknowledgements and/or
 
951
dedications given therein.
 
952
 
 
953
@item
 
954
Preserve all the Invariant Sections of the Document,
 
955
unaltered in their text and in their titles.  Section numbers
 
956
or the equivalent are not considered part of the section titles.
 
957
 
 
958
@item
 
959
Delete any section Entitled ``Endorsements''.  Such a section
 
960
may not be included in the Modified Version.
 
961
 
 
962
@item
 
963
Do not retitle any existing section to be Entitled ``Endorsements'' or
 
964
to conflict in title with any Invariant Section.
 
965
 
 
966
@item
 
967
Preserve any Warranty Disclaimers.
 
968
@end enumerate
 
969
 
 
970
If the Modified Version includes new front-matter sections or
 
971
appendices that qualify as Secondary Sections and contain no material
 
972
copied from the Document, you may at your option designate some or all
 
973
of these sections as invariant.  To do this, add their titles to the
 
974
list of Invariant Sections in the Modified Version's license notice.
 
975
These titles must be distinct from any other section titles.
 
976
 
 
977
You may add a section Entitled ``Endorsements'', provided it contains
 
978
nothing but endorsements of your Modified Version by various
 
979
parties---for example, statements of peer review or that the text has
 
980
been approved by an organization as the authoritative definition of a
 
981
standard.
 
982
 
 
983
You may add a passage of up to five words as a Front-Cover Text, and a
 
984
passage of up to 25 words as a Back-Cover Text, to the end of the list
 
985
of Cover Texts in the Modified Version.  Only one passage of
 
986
Front-Cover Text and one of Back-Cover Text may be added by (or
 
987
through arrangements made by) any one entity.  If the Document already
 
988
includes a cover text for the same cover, previously added by you or
 
989
by arrangement made by the same entity you are acting on behalf of,
 
990
you may not add another; but you may replace the old one, on explicit
 
991
permission from the previous publisher that added the old one.
 
992
 
 
993
The author(s) and publisher(s) of the Document do not by this License
 
994
give permission to use their names for publicity for or to assert or
 
995
imply endorsement of any Modified Version.
 
996
 
 
997
@item
 
998
COMBINING DOCUMENTS
 
999
 
 
1000
You may combine the Document with other documents released under this
 
1001
License, under the terms defined in section 4 above for modified
 
1002
versions, provided that you include in the combination all of the
 
1003
Invariant Sections of all of the original documents, unmodified, and
 
1004
list them all as Invariant Sections of your combined work in its
 
1005
license notice, and that you preserve all their Warranty Disclaimers.
 
1006
 
 
1007
The combined work need only contain one copy of this License, and
 
1008
multiple identical Invariant Sections may be replaced with a single
 
1009
copy.  If there are multiple Invariant Sections with the same name but
 
1010
different contents, make the title of each such section unique by
 
1011
adding at the end of it, in parentheses, the name of the original
 
1012
author or publisher of that section if known, or else a unique number.
 
1013
Make the same adjustment to the section titles in the list of
 
1014
Invariant Sections in the license notice of the combined work.
 
1015
 
 
1016
In the combination, you must combine any sections Entitled ``History''
 
1017
in the various original documents, forming one section Entitled
 
1018
``History''; likewise combine any sections Entitled ``Acknowledgements'',
 
1019
and any sections Entitled ``Dedications''.  You must delete all
 
1020
sections Entitled ``Endorsements.''
 
1021
 
 
1022
@item
 
1023
COLLECTIONS OF DOCUMENTS
 
1024
 
 
1025
You may make a collection consisting of the Document and other documents
 
1026
released under this License, and replace the individual copies of this
 
1027
License in the various documents with a single copy that is included in
 
1028
the collection, provided that you follow the rules of this License for
 
1029
verbatim copying of each of the documents in all other respects.
 
1030
 
 
1031
You may extract a single document from such a collection, and distribute
 
1032
it individually under this License, provided you insert a copy of this
 
1033
License into the extracted document, and follow this License in all
 
1034
other respects regarding verbatim copying of that document.
 
1035
 
 
1036
@item
 
1037
AGGREGATION WITH INDEPENDENT WORKS
 
1038
 
 
1039
A compilation of the Document or its derivatives with other separate
 
1040
and independent documents or works, in or on a volume of a storage or
 
1041
distribution medium, is called an ``aggregate'' if the copyright
 
1042
resulting from the compilation is not used to limit the legal rights
 
1043
of the compilation's users beyond what the individual works permit.
 
1044
When the Document is included an aggregate, this License does not
 
1045
apply to the other works in the aggregate which are not themselves
 
1046
derivative works of the Document.
 
1047
 
 
1048
If the Cover Text requirement of section 3 is applicable to these
 
1049
copies of the Document, then if the Document is less than one half of
 
1050
the entire aggregate, the Document's Cover Texts may be placed on
 
1051
covers that bracket the Document within the aggregate, or the
 
1052
electronic equivalent of covers if the Document is in electronic form.
 
1053
Otherwise they must appear on printed covers that bracket the whole
 
1054
aggregate.
 
1055
 
 
1056
@item
 
1057
TRANSLATION
 
1058
 
 
1059
Translation is considered a kind of modification, so you may
 
1060
distribute translations of the Document under the terms of section 4.
 
1061
Replacing Invariant Sections with translations requires special
 
1062
permission from their copyright holders, but you may include
 
1063
translations of some or all Invariant Sections in addition to the
 
1064
original versions of these Invariant Sections.  You may include a
 
1065
translation of this License, and all the license notices in the
 
1066
Document, and any Warrany Disclaimers, provided that you also include
 
1067
the original English version of this License and the original versions
 
1068
of those notices and disclaimers.  In case of a disagreement between
 
1069
the translation and the original version of this License or a notice
 
1070
or disclaimer, the original version will prevail.
 
1071
 
 
1072
If a section in the Document is Entitled ``Acknowledgements'',
 
1073
``Dedications'', or ``History'', the requirement (section 4) to Preserve
 
1074
its Title (section 1) will typically require changing the actual
 
1075
title.
 
1076
 
 
1077
@item
 
1078
TERMINATION
 
1079
 
 
1080
You may not copy, modify, sublicense, or distribute the Document except
 
1081
as expressly provided for under this License.  Any other attempt to
 
1082
copy, modify, sublicense or distribute the Document is void, and will
 
1083
automatically terminate your rights under this License.  However,
 
1084
parties who have received copies, or rights, from you under this
 
1085
License will not have their licenses terminated so long as such
 
1086
parties remain in full compliance.
 
1087
 
 
1088
@item
 
1089
FUTURE REVISIONS OF THIS LICENSE
 
1090
 
 
1091
The Free Software Foundation may publish new, revised versions
 
1092
of the GNU Free Documentation License from time to time.  Such new
 
1093
versions will be similar in spirit to the present version, but may
 
1094
differ in detail to address new problems or concerns.  See
 
1095
@uref{http://www.gnu.org/copyleft/}.
 
1096
 
 
1097
Each version of the License is given a distinguishing version number.
 
1098
If the Document specifies that a particular numbered version of this
 
1099
License ``or any later version'' applies to it, you have the option of
 
1100
following the terms and conditions either of that specified version or
 
1101
of any later version that has been published (not as a draft) by the
 
1102
Free Software Foundation.  If the Document does not specify a version
 
1103
number of this License, you may choose any version ever published (not
 
1104
as a draft) by the Free Software Foundation.
 
1105
@end enumerate
 
1106
 
 
1107
@page
 
1108
@appendixsec ADDENDUM: How to use this License for your documents
 
1109
 
 
1110
To use this License in a document you have written, include a copy of
 
1111
the License in the document and put the following copyright and
 
1112
license notices just after the title page:
 
1113
 
 
1114
@smallexample
 
1115
@group
 
1116
  Copyright (C)  @var{year}  @var{your name}.
 
1117
  Permission is granted to copy, distribute and/or modify this document
 
1118
  under the terms of the GNU Free Documentation License, Version 1.2
 
1119
  or any later version published by the Free Software Foundation;
 
1120
  with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 
1121
  A copy of the license is included in the section entitled ``GNU
 
1122
  Free Documentation License''.
 
1123
@end group
 
1124
@end smallexample
 
1125
 
 
1126
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
 
1127
replace the ``with...Texts.'' line with this:
 
1128
 
 
1129
@smallexample
 
1130
@group
 
1131
    with the Invariant Sections being @var{list their titles}, with
 
1132
    the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
 
1133
    being @var{list}.
 
1134
@end group
 
1135
@end smallexample
 
1136
 
 
1137
If you have Invariant Sections without Cover Texts, or some other
 
1138
combination of the three, merge those two alternatives to suit the
 
1139
situation.
 
1140
 
 
1141
If your document contains nontrivial examples of program code, we
 
1142
recommend releasing these examples in parallel under your choice of
 
1143
free software license, such as the GNU General Public License,
 
1144
to permit their use in free software.
 
1145
 
 
1146
@bye