49 |
"inline.c". |
"inline.c". |
50 |
*/ |
*/ |
51 |
|
|
52 |
|
|
53 |
|
#if (SCM_DEBUG_CELL_ACCESSES == 1) |
54 |
|
#include <stdio.h> |
55 |
|
#endif |
56 |
|
|
57 |
#include "libguile/pairs.h" |
#include "libguile/pairs.h" |
58 |
#include "libguile/gc.h" |
#include "libguile/gc.h" |
59 |
|
|
60 |
|
|
61 |
|
SCM_API SCM scm_cell (scm_t_bits car, scm_t_bits cdr); |
62 |
|
SCM_API SCM scm_double_cell (scm_t_bits car, scm_t_bits cbr, |
63 |
|
scm_t_bits ccr, scm_t_bits cdr); |
64 |
|
|
65 |
#ifdef HAVE_INLINE |
#ifdef HAVE_INLINE |
66 |
|
|
67 |
static inline SCM |
|
68 |
|
|
69 |
|
#ifndef EXTERN_INLINE |
70 |
|
#define EXTERN_INLINE extern inline |
71 |
|
#endif |
72 |
|
|
73 |
|
extern unsigned scm_newcell2_count; |
74 |
|
extern unsigned scm_newcell_count; |
75 |
|
|
76 |
|
|
77 |
|
EXTERN_INLINE |
78 |
|
SCM |
79 |
scm_cell (scm_t_bits car, scm_t_bits cdr) |
scm_cell (scm_t_bits car, scm_t_bits cdr) |
80 |
{ |
{ |
81 |
SCM z; |
SCM z; |
82 |
|
|
83 |
#ifdef GUILE_DEBUG_FREELIST |
if (SCM_NULLP (scm_i_freelist)) |
|
scm_newcell_count++; |
|
|
if (scm_debug_check_freelist) |
|
84 |
{ |
{ |
85 |
scm_check_freelist (scm_freelist); |
z = scm_gc_for_newcell (&scm_i_master_freelist, &scm_i_freelist); |
|
scm_gc(); |
|
|
} |
|
|
#endif |
|
|
|
|
|
if (SCM_NULLP (scm_freelist)) |
|
|
{ |
|
|
z = scm_gc_for_newcell (&scm_master_freelist, &scm_freelist); |
|
86 |
} |
} |
87 |
else |
else |
88 |
{ |
{ |
89 |
z = scm_freelist; |
z = scm_i_freelist; |
90 |
scm_freelist = SCM_FREE_CELL_CDR (scm_freelist); |
scm_i_freelist = SCM_FREE_CELL_CDR (scm_i_freelist); |
91 |
|
} |
92 |
|
|
93 |
|
/* |
94 |
|
We update scm_cells_allocated from this function. If we don't |
95 |
|
update this explicitly, we will have to walk a freelist somewhere |
96 |
|
later on, which seems a lot more expensive. |
97 |
|
*/ |
98 |
|
scm_cells_allocated += 1; |
99 |
|
|
100 |
|
#if (SCM_DEBUG_CELL_ACCESSES == 1) |
101 |
|
if (scm_debug_cell_accesses_p) |
102 |
|
{ |
103 |
|
if (SCM_GC_MARK_P (z)) |
104 |
|
{ |
105 |
|
fprintf(stderr, "scm_cell tried to allocate a marked cell.\n"); |
106 |
|
abort(); |
107 |
|
} |
108 |
|
else if (SCM_GC_CELL_TYPE(z) != scm_tc_free_cell) |
109 |
|
{ |
110 |
|
fprintf(stderr, "cell from freelist is not a free cell.\n"); |
111 |
|
abort(); |
112 |
|
} |
113 |
|
|
114 |
|
SCM_SET_GC_MARK (z); |
115 |
} |
} |
116 |
|
#endif |
117 |
|
|
118 |
|
|
119 |
/* Initialize the type slot last so that the cell is ignored by the |
/* Initialize the type slot last so that the cell is ignored by the |
120 |
GC until it is completely initialized. This is only relevant |
GC until it is completely initialized. This is only relevant |
121 |
when the GC can actually run during this code, which it can't for |
when the GC can actually run during this code, which it can't for |
136 |
#endif |
#endif |
137 |
#endif |
#endif |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
return z; |
return z; |
142 |
} |
} |
143 |
|
|
144 |
static inline SCM |
EXTERN_INLINE |
145 |
|
SCM |
146 |
scm_double_cell (scm_t_bits car, scm_t_bits cbr, |
scm_double_cell (scm_t_bits car, scm_t_bits cbr, |
147 |
scm_t_bits ccr, scm_t_bits cdr) |
scm_t_bits ccr, scm_t_bits cdr) |
148 |
{ |
{ |
149 |
SCM z; |
SCM z; |
150 |
|
|
|
#ifdef GUILE_DEBUG_FREELIST |
|
|
scm_newcell2_count++; |
|
|
if (scm_debug_check_freelist) |
|
|
{ |
|
|
scm_check_freelist (scm_freelist2); |
|
|
scm_gc(); |
|
|
} |
|
|
#endif |
|
151 |
|
|
152 |
if (SCM_NULLP (scm_freelist2)) |
if (SCM_NULLP (scm_i_freelist2)) |
153 |
{ |
{ |
154 |
z = scm_gc_for_newcell (&scm_master_freelist2, &scm_freelist2); |
z = scm_gc_for_newcell (&scm_i_master_freelist2, &scm_i_freelist2); |
155 |
} |
} |
156 |
else |
else |
157 |
{ |
{ |
158 |
z = scm_freelist2; |
z = scm_i_freelist2; |
159 |
scm_freelist2 = SCM_FREE_CELL_CDR (scm_freelist2); |
scm_i_freelist2 = SCM_FREE_CELL_CDR (scm_i_freelist2); |
160 |
} |
} |
161 |
|
|
162 |
|
scm_cells_allocated += 2; |
163 |
|
|
164 |
/* Initialize the type slot last so that the cell is ignored by the |
/* Initialize the type slot last so that the cell is ignored by the |
165 |
GC until it is completely initialized. This is only relevant |
GC until it is completely initialized. This is only relevant |
166 |
when the GC can actually run during this code, which it can't for |
when the GC can actually run during this code, which it can't for |
183 |
#endif |
#endif |
184 |
#endif |
#endif |
185 |
|
|
|
return z; |
|
|
} |
|
|
|
|
|
#else /* !HAVE_INLINE */ |
|
186 |
|
|
187 |
SCM_API SCM scm_cell (scm_t_bits car, scm_t_bits cdr); |
#if (SCM_DEBUG_CELL_ACCESSES == 1) |
188 |
SCM_API SCM scm_double_cell (scm_t_bits car, scm_t_bits cbr, |
if (scm_debug_cell_accesses_p) |
189 |
scm_t_bits ccr, scm_t_bits cdr); |
{ |
190 |
|
if (SCM_GC_MARK_P (z)) |
191 |
|
{ |
192 |
|
fprintf(stderr, |
193 |
|
"scm_double_cell tried to allocate a marked cell.\n"); |
194 |
|
abort(); |
195 |
|
} |
196 |
|
|
197 |
|
SCM_SET_GC_MARK (z); |
198 |
|
} |
199 |
#endif |
#endif |
200 |
|
|
201 |
|
return z; |
202 |
|
} |
203 |
|
|
204 |
|
#endif |
205 |
#endif |
#endif |