summaryrefslogtreecommitdiff
path: root/lily/smobs.cc
blob: 34b5bb36ab697e30da50d1480f01eb0bb6ea49d5 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
  smobs.cc -- implement Smob protection

  source file of the GNU LilyPond music typesetter

  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/

#include "smobs.hh"

/*
  The CDR contains the actual protected list.
 */
static SCM smob_protection_list = SCM_EOL;

void
init_smob_protection ()
{
  smob_protection_list = scm_cons (SCM_BOOL_F, SCM_EOL);
  scm_gc_protect_object (smob_protection_list);
}
ADD_SCM_INIT_FUNC (init_smob_protection, init_smob_protection);

LY_DEFINE(ly_smob_protects, "ly:smob-protects",
	  0, 0, 0, (),
	  "Return lily's internal smob protection list")
{
  return scm_is_pair (smob_protection_list)
    ? scm_cdr (smob_protection_list)
    : SCM_EOL;
}

void
protect_smob (SCM smob, SCM *prot_cons)
{
#if 0
  SCM s = scm_cdr (smob_protection_list);
  while (scm_is_pair (s) && scm_car (s) == SCM_BOOL_F)
    {
      s = scm_cdr (s);
    }
  SCM prot = scm_cons (smob, s);
  scm_set_cdr_x (smob_protection_list,
		 prot);
  *prot_cons = prot;
#else
  (void) prot_cons; 
  scm_gc_protect_object (smob);
#endif
}

void
unprotect_smob (SCM smob, SCM *prot_cons)
{
#if 1
  (void) prot_cons; 
  scm_gc_unprotect_object (smob);
#else
  SCM next = scm_cdr (*prot_cons);

  if (next == SCM_EOL)
    scm_set_car_x (*prot_cons, SCM_BOOL_F);
  else
    {
      scm_set_car_x (*prot_cons, SCM_BOOL_F);
      while (scm_is_pair (next)
	     && scm_car (next) == SCM_BOOL_F)

	next = scm_cdr (next);

      scm_set_cdr_x (*prot_cons, next);
    }

  *prot_cons = SCM_EOL;
#endif
}