~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to doc/UIM-SCM

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
This document describes usage of the uim-scm API and facility for
 
2
developers.
 
3
 
 
4
 
 
5
* Abstract
 
6
 
 
7
  The uim-scm API is responsible for follwing two roles.
 
8
 
 
9
  - Provides Scheme interpreter interfaces to input method plugin
 
10
    developers
 
11
 
 
12
  - Abstracts Scheme interpreter implementation and narrows its
 
13
    interfaces to provide switcheable base of libuim
 
14
 
 
15
  Other developers should not use this API since the API easily causes
 
16
  fatal crash involving GC if you does not pay attention enough. Be
 
17
  careful.
 
18
 
 
19
 
 
20
* Protecting lisp objects from GC
 
21
 
 
22
  uim-scm provides the lisp object type named 'uim_lisp'. Since all of
 
23
  the objects are managed by a conservative mark and sweep GC, you
 
24
  have to protect them from undesirable collection. The word
 
25
  'protection' means that instructing GC "it's in use, don't
 
26
  mark". There are two methods of protection.
 
27
 
 
28
  1. static storage protection
 
29
 
 
30
    You can allocate arbitrary static storage as for uim_lisp by
 
31
    uim_scm_gc_protect(). The function must be invoked before using
 
32
    the variables.
 
33
 
 
34
 
 
35
    static uim_lisp foo;
 
36
    static uim_lisp bar;
 
37
 
 
38
    void
 
39
    uim_plugin_instance_init(void) {
 
40
      uim_scm_gc_protect(&foo);
 
41
      uim_scm_gc_protect(&bar);
 
42
    }
 
43
 
 
44
 
 
45
  2. stack protection
 
46
 
 
47
    You can also protect your lisp objects on stack (i.e. auto
 
48
    storage). See following example.
 
49
 
 
50
 
 
51
    static char *
 
52
    literalize_string(const char *str)
 
53
    {
 
54
      uim_lisp stack_start;
 
55
      uim_lisp form;
 
56
      char *escaped;
 
57
 
 
58
      uim_scm_gc_protect_stack(&stack_start);
 
59
      form = uim_scm_list2(uim_scm_make_symbol("string-escape"),
 
60
                           uim_scm_make_str(str));
 
61
      escaped = uim_scm_c_str(uim_scm_eval(form));
 
62
      uim_scm_gc_unprotect_stack(&stack_start);
 
63
 
 
64
      return escaped;
 
65
    }
 
66
 
 
67
 
 
68
    Combination of uim_scm_gc_protect_stack(),
 
69
    uim_scm_gc_unprotect_stack() and the dummy variable 'stack_start'
 
70
    consists of the stack protection. In this case, the lisp objects
 
71
    'form', anonymous return value of uim_scm_make_symbol(),
 
72
    uim_scm_make_str() and uim_scm_eval() are protected by the method
 
73
    (although some objects may be placed into registers, the registers
 
74
    are also protected implicitly).
 
75
 
 
76
    The 'stack_start' indicates start point of protected region. And
 
77
    uim_scm_gc_protect_stack() instructs the GC protection. After the
 
78
    invocation, the region from stack_start to top of the stack is
 
79
    left untouched at GC marking.
 
80
 
 
81
    Protected stack regions can be nested or duplexed.
 
82
 
 
83
    Be careful to place stack_start. There are some bad examples.
 
84
 
 
85
    - invalid order
 
86
 
 
87
      uim_lisp form;         /* XXX out of protected region */
 
88
      uim_lisp stack_start;
 
89
 
 
90
    - invalid order (2)
 
91
 
 
92
      uim_lisp form, stack_start;   /* XXX may by out of protected region */
 
93
 
 
94
    - uncertain way
 
95
 
 
96
      uim_lisp stack_start, form;   /* ??? may be implementation dependent */
 
97
 
 
98
 
 
99
* Internal
 
100
 
 
101
  This API is not intended to provide all R5RS features. Only 'core'
 
102
  ones to write Scheme-C adapters should be added. Consider how
 
103
  frequently it will be used, and whether it should be written by C,
 
104
  when you want to add an API function.
 
105
 
 
106
  Current implemenation of uim-scm only provides the Siod
 
107
  interpreter. To avoid namespace pollution, all Siod functions are
 
108
  defined as static and wrapped into uim-scm.c by direct inclusion
 
109
  rather than linked via public symbols. After elaboration of uim-scm
 
110
  API, the Scheme interpreter implementation can be switched to
 
111
  another one such as uim-scm-tinyscheme.c or uim-scm-gauche.c. But
 
112
  *.[hc] under uim/ and *.scm are still depending on Siod in several
 
113
  ways. At least full test suite for *.scm files are required to
 
114
  migrate to another Scheme implementation.