Avoid signed overflow and use size_t in bytevectors.c.
[bpt/guile.git] / libguile / struct.c
CommitLineData
1b787ef9 1/* Copyright (C) 1996,1997,1998,1999,2000,2001, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
0f2d19dd 2 *
73be1d9e 3 * This library is free software; you can redistribute it and/or
53befeb7
NJ
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
0f2d19dd 7 *
53befeb7
NJ
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
73be1d9e
MV
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
0f2d19dd 12 *
73be1d9e
MV
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
53befeb7
NJ
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 * 02110-1301 USA
73be1d9e 17 */
1bbd0b84 18
0f2d19dd 19\f
dbb605f5 20#ifdef HAVE_CONFIG_H
a6f7f57d
RB
21# include <config.h>
22#endif
0f2d19dd 23
66e78727 24#include <alloca.h>
aa42c036 25#include <assert.h>
66e78727 26
6d46f1e4
AW
27#define SCM_BUILDING_DEPRECATED_CODE
28
a0599745 29#include "libguile/_scm.h"
4e047c3e 30#include "libguile/async.h"
a0599745
MD
31#include "libguile/chars.h"
32#include "libguile/eval.h"
33#include "libguile/alist.h"
34#include "libguile/weaks.h"
35#include "libguile/hashtab.h"
36#include "libguile/ports.h"
37#include "libguile/strings.h"
27646f41 38#include "libguile/srfi-13.h"
a0599745
MD
39
40#include "libguile/validate.h"
41#include "libguile/struct.h"
0f2d19dd 42
d15ad007
LC
43#include "libguile/eq.h"
44
95b88819
GH
45#ifdef HAVE_STRING_H
46#include <string.h>
47#endif
48
1c44468d 49#include "libguile/bdw-gc.h"
5e67dc27 50
0f2d19dd
JB
51\f
52
b6cf4d02
AW
53/* A needlessly obscure test. */
54#define SCM_LAYOUT_TAILP(X) (((X) & 32) == 0) /* R, W or O */
55
0f2d19dd 56static SCM required_vtable_fields = SCM_BOOL_F;
b6cf4d02
AW
57static SCM required_applicable_fields = SCM_BOOL_F;
58static SCM required_applicable_with_setter_fields = SCM_BOOL_F;
db5ed685
AW
59SCM scm_applicable_struct_vtable_vtable;
60SCM scm_applicable_struct_with_setter_vtable_vtable;
61SCM scm_standard_vtable_vtable;
62
0f2d19dd
JB
63
64\f
a1ec6916 65SCM_DEFINE (scm_make_struct_layout, "make-struct-layout", 1, 0, 0,
1bbd0b84 66 (SCM fields),
b380b885 67 "Return a new structure layout object.\n\n"
7c31152f 68 "@var{fields} must be a string made up of pairs of characters\n"
b380b885
MD
69 "strung together. The first character of each pair describes a field\n"
70 "type, the second a field protection. Allowed types are 'p' for\n"
71 "GC-protected Scheme data, 'u' for unprotected binary data, and 's' for\n"
04323af4 72 "a field that points to the structure itself. Allowed protections\n"
b6cf4d02
AW
73 "are 'w' for mutable fields, 'h' for hidden fields, 'r' for read-only\n"
74 "fields, and 'o' for opaque fields.\n\n"
75 "Hidden fields are writable, but they will not consume an initializer arg\n"
76 "passed to @code{make-struct}. They are useful to add slots to a struct\n"
77 "in a way that preserves backward-compatibility with existing calls to\n"
78 "@code{make-struct}, especially for derived vtables.\n\n"
79 "The last field protection specification may be capitalized to indicate\n"
80 "that the field is a tail-array.")
1bbd0b84 81#define FUNC_NAME s_scm_make_struct_layout
0f2d19dd
JB
82{
83 SCM new_sym;
27646f41 84 scm_t_wchar c;
2ade72d7 85
7f991c7d
LC
86 SCM_VALIDATE_STRING (1, fields);
87
1bbd0b84 88 { /* scope */
1be6b49c 89 size_t len;
0f2d19dd
JB
90 int x;
91
cc95e00a 92 len = scm_i_string_length (fields);
2ade72d7
DH
93 if (len % 2 == 1)
94 SCM_MISC_ERROR ("odd length field specification: ~S",
1afff620 95 scm_list_1 (fields));
2ade72d7 96
0f2d19dd
JB
97 for (x = 0; x < len; x += 2)
98 {
27646f41 99 switch (c = scm_i_string_ref (fields, x))
0f2d19dd
JB
100 {
101 case 'u':
102 case 'p':
103#if 0
104 case 'i':
105 case 'd':
106#endif
107 case 's':
108 break;
109 default:
2ade72d7 110 SCM_MISC_ERROR ("unrecognized field type: ~S",
27646f41 111 scm_list_1 (SCM_MAKE_CHAR (c)));
0f2d19dd
JB
112 }
113
27646f41 114 switch (c = scm_i_string_ref (fields, x + 1))
0f2d19dd
JB
115 {
116 case 'w':
b6cf4d02 117 case 'h':
27646f41 118 if (scm_i_string_ref (fields, x) == 's')
2ade72d7 119 SCM_MISC_ERROR ("self fields not writable", SCM_EOL);
0f2d19dd
JB
120 case 'r':
121 case 'o':
122 break;
2c36c351
MD
123 case 'R':
124 case 'W':
125 case 'O':
27646f41 126 if (scm_i_string_ref (fields, x) == 's')
2ade72d7
DH
127 SCM_MISC_ERROR ("self fields not allowed in tail array",
128 SCM_EOL);
129 if (x != len - 2)
130 SCM_MISC_ERROR ("tail array field must be last field in layout",
131 SCM_EOL);
2c36c351 132 break;
0f2d19dd 133 default:
2ade72d7 134 SCM_MISC_ERROR ("unrecognized ref specification: ~S",
27646f41 135 scm_list_1 (SCM_MAKE_CHAR (c)));
0f2d19dd
JB
136 }
137#if 0
27646f41 138 if (scm_i_string_ref (fields, x, 'd'))
0f2d19dd 139 {
27646f41 140 if (!scm_i_string_ref (fields, x+2, '-'))
2ade72d7 141 SCM_MISC_ERROR ("missing dash field at position ~A",
e11e83f3 142 scm_list_1 (scm_from_int (x / 2)));
0f2d19dd
JB
143 x += 2;
144 goto recheck_ref;
145 }
146#endif
147 }
cc95e00a 148 new_sym = scm_string_to_symbol (fields);
0f2d19dd 149 }
8824ac88
MV
150 scm_remember_upto_here_1 (fields);
151 return new_sym;
0f2d19dd 152}
1bbd0b84 153#undef FUNC_NAME
0f2d19dd
JB
154
155\f
1b787ef9
AW
156/* Check whether VTABLE instances have a simple layout (i.e., either
157 only "pr" or only "pw" fields and no tail array) and update its flags
158 accordingly. */
aa42c036
LC
159static void
160set_vtable_layout_flags (SCM vtable)
161{
162 size_t len, field;
163 SCM layout;
164 const char *c_layout;
165 scm_t_bits flags = SCM_VTABLE_FLAG_SIMPLE;
166
167 layout = SCM_VTABLE_LAYOUT (vtable);
168 c_layout = scm_i_symbol_chars (layout);
169 len = scm_i_symbol_length (layout);
170
171 assert (len % 2 == 0);
172
173 /* Update FLAGS according to LAYOUT. */
174 for (field = 0;
175 field < len && flags & SCM_VTABLE_FLAG_SIMPLE;
176 field += 2)
177 {
178 if (c_layout[field] != 'p')
179 flags = 0;
180 else
181 switch (c_layout[field + 1])
182 {
183 case 'w':
e03b7f73 184 if (field == 0)
aa42c036
LC
185 flags |= SCM_VTABLE_FLAG_SIMPLE_RW;
186 break;
187
188 case 'r':
e03b7f73 189 flags &= ~SCM_VTABLE_FLAG_SIMPLE_RW;
aa42c036
LC
190 break;
191
192 default:
193 flags = 0;
194 }
195 }
196
197 if (flags & SCM_VTABLE_FLAG_SIMPLE)
198 {
199 /* VTABLE is simple so update its flags and record the size of its
200 instances. */
201 SCM_SET_VTABLE_FLAGS (vtable, flags);
202 SCM_STRUCT_DATA_SET (vtable, scm_vtable_index_size, len / 2);
203 }
204}
0f2d19dd 205
631237b4
AW
206static int
207scm_is_valid_vtable_layout (SCM layout)
208{
209 size_t len, n;
210 const char *c_layout;
211
212 c_layout = scm_i_symbol_chars (layout);
213 len = scm_i_symbol_length (layout);
214
215 if (len % 2)
216 return 0;
217
218 for (n = 0; n < len; n += 2)
219 switch (c_layout[n])
220 {
221 case 'u':
222 case 'p':
223 case 's':
224 switch (c_layout[n+1])
225 {
226 case 'W':
227 case 'R':
228 case 'O':
229 if (n + 2 != len)
230 return 0;
231 case 'w':
232 case 'h':
233 case 'r':
234 case 'o':
235 break;
236 default:
237 return 0;
238 }
239 break;
240 default:
241 return 0;
242 }
243 return 1;
244}
245
696ac4df
LC
246/* Have OBJ, a newly created vtable, inherit flags from VTABLE. VTABLE is a
247 vtable-vtable and OBJ is an instance of VTABLE. */
51f66c91
AW
248void
249scm_i_struct_inherit_vtable_magic (SCM vtable, SCM obj)
250#define FUNC_NAME "%inherit-vtable-magic"
251{
252 /* Verily, what is the deal here, you ask? Basically, we need to know a couple
253 of properties of structures at runtime. For example, "is this structure a
254 vtable of vtables (a metaclass)?"; also, "is this structure applicable?".
255 Both of these questions also imply a certain layout of the structure. So
256 instead of checking the layout at runtime, what we do is pre-verify the
257 layout -- so that at runtime we can just check the applicable flag and
696ac4df 258 dispatch directly to the Scheme procedure in slot 0. */
51f66c91
AW
259 SCM olayout;
260
696ac4df 261 /* Verify that OBJ is a valid vtable. */
631237b4 262 if (! scm_is_valid_vtable_layout (SCM_VTABLE_LAYOUT (obj)))
a2220d7e 263 SCM_MISC_ERROR ("invalid layout for new vtable: ~a",
51f66c91
AW
264 scm_list_1 (SCM_VTABLE_LAYOUT (obj)));
265
aa42c036
LC
266 set_vtable_layout_flags (obj);
267
696ac4df
LC
268 /* If OBJ's vtable is compatible with the required vtable (class) layout, it
269 is a metaclass. */
51f66c91
AW
270 olayout = scm_symbol_to_string (SCM_VTABLE_LAYOUT (obj));
271 if (scm_is_true (scm_leq_p (scm_string_length (required_vtable_fields),
272 scm_string_length (olayout)))
273 && scm_is_true (scm_string_eq (olayout, required_vtable_fields,
274 scm_from_size_t (0),
275 scm_string_length (required_vtable_fields),
276 scm_from_size_t (0),
277 scm_string_length (required_vtable_fields))))
278 SCM_SET_VTABLE_FLAGS (obj, SCM_VTABLE_FLAG_VTABLE);
279
696ac4df
LC
280 /* Finally, if OBJ is an applicable class, verify that its vtable is
281 compatible with the required applicable layout. */
51f66c91
AW
282 if (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_SETTER_VTABLE))
283 {
284 if (scm_is_false (scm_string_eq (olayout, required_applicable_with_setter_fields,
285 scm_from_size_t (0),
286 scm_from_size_t (4),
287 scm_from_size_t (0),
288 scm_from_size_t (4))))
a2220d7e 289 SCM_MISC_ERROR ("invalid applicable-with-setter struct layout",
51f66c91
AW
290 scm_list_1 (olayout));
291 SCM_SET_VTABLE_FLAGS (obj, SCM_VTABLE_FLAG_APPLICABLE | SCM_VTABLE_FLAG_SETTER);
292 }
293 else if (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_APPLICABLE_VTABLE))
294 {
295 if (scm_is_false (scm_string_eq (olayout, required_applicable_fields,
296 scm_from_size_t (0),
297 scm_from_size_t (2),
298 scm_from_size_t (0),
299 scm_from_size_t (2))))
a2220d7e 300 SCM_MISC_ERROR ("invalid applicable struct layout",
51f66c91
AW
301 scm_list_1 (olayout));
302 SCM_SET_VTABLE_FLAGS (obj, SCM_VTABLE_FLAG_APPLICABLE);
303 }
a2220d7e
AW
304
305 SCM_SET_VTABLE_FLAGS (obj, SCM_VTABLE_FLAG_VALIDATED);
51f66c91
AW
306}
307#undef FUNC_NAME
0f2d19dd 308
1cc91f1b 309
f7620510 310static void
66e78727
AW
311scm_struct_init (SCM handle, SCM layout, size_t n_tail,
312 size_t n_inits, scm_t_bits *inits)
0f2d19dd 313{
aa42c036
LC
314 SCM vtable;
315 scm_t_bits *mem;
316
317 vtable = SCM_STRUCT_VTABLE (handle);
318 mem = SCM_STRUCT_DATA (handle);
319
320 if (SCM_UNPACK (vtable) != 0
321 && SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_SIMPLE)
322 && n_tail == 0
323 && n_inits == SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size))
324 /* The fast path: HANDLE has N_INITS "p" fields. */
325 memcpy (mem, inits, n_inits * sizeof (SCM));
326 else
0f2d19dd 327 {
aa42c036
LC
328 scm_t_wchar prot = 0;
329 int n_fields = scm_i_symbol_length (layout) / 2;
330 int tailp = 0;
331 int i;
332 size_t inits_idx = 0;
333
334 i = -2;
335 while (n_fields)
2c36c351 336 {
aa42c036 337 if (!tailp)
2c36c351 338 {
aa42c036
LC
339 i += 2;
340 prot = scm_i_symbol_ref (layout, i+1);
341 if (SCM_LAYOUT_TAILP (prot))
342 {
343 tailp = 1;
344 prot = prot == 'R' ? 'r' : prot == 'W' ? 'w' : 'o';
345 *mem++ = (scm_t_bits)n_tail;
346 n_fields += n_tail - 1;
347 if (n_fields == 0)
348 break;
349 }
2c36c351 350 }
aa42c036 351 switch (scm_i_symbol_ref (layout, i))
0f2d19dd 352 {
aa42c036
LC
353 case 'u':
354 if ((prot != 'r' && prot != 'w') || inits_idx == n_inits)
355 *mem = 0;
356 else
357 {
358 *mem = scm_to_ulong (SCM_PACK (inits[inits_idx]));
359 inits_idx++;
360 }
361 break;
362
363 case 'p':
364 if ((prot != 'r' && prot != 'w') || inits_idx == n_inits)
365 *mem = SCM_UNPACK (SCM_BOOL_F);
366 else
367 {
368 *mem = inits[inits_idx];
369 inits_idx++;
370 }
371
372 break;
373
374 case 's':
375 *mem = SCM_UNPACK (handle);
376 break;
0f2d19dd 377 }
0f2d19dd 378
aa42c036
LC
379 n_fields--;
380 mem++;
0f2d19dd 381 }
0f2d19dd
JB
382 }
383}
384
385
a1ec6916 386SCM_DEFINE (scm_struct_p, "struct?", 1, 0, 0,
1bbd0b84 387 (SCM x),
0233bfc1 388 "Return @code{#t} iff @var{x} is a structure object, else\n"
942e5b91 389 "@code{#f}.")
1bbd0b84 390#define FUNC_NAME s_scm_struct_p
0f2d19dd 391{
7888309b 392 return scm_from_bool(SCM_STRUCTP (x));
0f2d19dd 393}
1bbd0b84 394#undef FUNC_NAME
0f2d19dd 395
a1ec6916 396SCM_DEFINE (scm_struct_vtable_p, "struct-vtable?", 1, 0, 0,
1bbd0b84 397 (SCM x),
0233bfc1 398 "Return @code{#t} iff @var{x} is a vtable structure.")
1bbd0b84 399#define FUNC_NAME s_scm_struct_vtable_p
0f2d19dd 400{
a2220d7e
AW
401 if (!SCM_STRUCTP (x)
402 || !SCM_STRUCT_VTABLE_FLAG_IS_SET (x, SCM_VTABLE_FLAG_VTABLE))
403 return SCM_BOOL_F;
404 if (!SCM_VTABLE_FLAG_IS_SET (x, SCM_VTABLE_FLAG_VALIDATED))
405 SCM_MISC_ERROR ("vtable has invalid layout: ~A",
406 scm_list_1 (SCM_VTABLE_LAYOUT (x)));
407 return SCM_BOOL_T;
0f2d19dd 408}
1bbd0b84 409#undef FUNC_NAME
0f2d19dd 410
14d1400f 411
51f66c91
AW
412/* Finalization: invoke the finalizer of the struct pointed to by PTR. */
413static void
6922d92f 414struct_finalizer_trampoline (void *ptr, void *unused_data)
51f66c91
AW
415{
416 SCM obj = PTR2SCM (ptr);
417 scm_t_struct_finalize finalize = SCM_STRUCT_FINALIZER (obj);
418
419 if (finalize)
420 finalize (obj);
421}
422
14d1400f
JB
423/* All struct data must be allocated at an address whose bottom three
424 bits are zero. This is because the tag for a struct lives in the
425 bottom three bits of the struct's car, and the upper bits point to
426 the data of its vtable, which is a struct itself. Thus, if the
427 address of that data doesn't end in three zeros, tagging it will
428 destroy the pointer.
429
b6cf4d02
AW
430 I suppose we should make it clear here that, the data must be 8-byte aligned,
431 *within* the struct, and the struct itself should be 8-byte aligned. In
432 practice we ensure this because the data starts two words into a struct.
14d1400f 433
b6cf4d02
AW
434 This function allocates an 8-byte aligned block of memory, whose first word
435 points to the given vtable data, then a data pointer, then n_words of data.
436 */
437SCM
96a44c1c 438scm_i_alloc_struct (scm_t_bits *vtable_data, int n_words)
14d1400f 439{
9a974fd3
AW
440 SCM ret;
441
442 ret = scm_words ((scm_t_bits)vtable_data | scm_tc3_struct, n_words + 2);
443 SCM_SET_CELL_WORD_1 (ret, (scm_t_bits)SCM_CELL_OBJECT_LOC (ret, 2));
5e67dc27 444
51f66c91
AW
445 /* vtable_data can be null when making a vtable vtable */
446 if (vtable_data && vtable_data[scm_vtable_index_instance_finalize])
75ba64d6
AW
447 /* Register a finalizer for the newly created instance. */
448 scm_i_set_finalizer (SCM2PTR (ret), struct_finalizer_trampoline, NULL);
5e67dc27 449
9a974fd3 450 return ret;
5e67dc27
LC
451}
452
5e67dc27 453\f
66e78727
AW
454SCM
455scm_c_make_structv (SCM vtable, size_t n_tail, size_t n_init, scm_t_bits *init)
456#define FUNC_NAME "make-struct"
0f2d19dd
JB
457{
458 SCM layout;
a55c2b68 459 size_t basic_size;
b6cf4d02 460 SCM obj;
0f2d19dd 461
34d19ef6 462 SCM_VALIDATE_VTABLE (1, vtable);
0f2d19dd 463
b6cf4d02 464 layout = SCM_VTABLE_LAYOUT (vtable);
cc95e00a 465 basic_size = scm_i_symbol_length (layout) / 2;
651f2cd2 466
66e78727 467 if (n_tail != 0)
651f2cd2
KR
468 {
469 SCM layout_str, last_char;
470
471 if (basic_size == 0)
472 {
473 bad_tail:
474 SCM_MISC_ERROR ("tail array not allowed unless layout ends R, W, or O", SCM_EOL);
475 }
476
477 layout_str = scm_symbol_to_string (layout);
478 last_char = scm_string_ref (layout_str,
479 scm_from_size_t (2 * basic_size - 1));
480 if (! SCM_LAYOUT_TAILP (SCM_CHAR (last_char)))
481 goto bad_tail;
482 }
cb823e63 483
96a44c1c 484 obj = scm_i_alloc_struct (SCM_STRUCT_DATA (vtable), basic_size + n_tail);
5e67dc27 485
66e78727 486 scm_struct_init (obj, layout, n_tail, n_init, init);
b6cf4d02 487
a2220d7e
AW
488 /* If we're making a vtable, validate its layout and inherit
489 flags. However we allow for separation of allocation and
490 initialization, to humor GOOPS, so only validate if the layout was
491 passed as an initarg. */
b6cf4d02 492 if (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_VTABLE)
b6cf4d02 493 && scm_is_true (SCM_VTABLE_LAYOUT (obj)))
51f66c91 494 scm_i_struct_inherit_vtable_magic (vtable, obj);
651f2cd2 495
b6cf4d02 496 return obj;
0f2d19dd 497}
1bbd0b84 498#undef FUNC_NAME
0f2d19dd 499
66e78727
AW
500SCM
501scm_c_make_struct (SCM vtable, size_t n_tail, size_t n_init, scm_t_bits init, ...)
502{
503 va_list foo;
504 scm_t_bits *v;
505 size_t i;
506
507 v = alloca (sizeof (scm_t_bits) * n_init);
508
509 va_start (foo, init);
510 for (i = 0; i < n_init; i++)
511 {
512 v[i] = init;
513 init = va_arg (foo, scm_t_bits);
514 }
515 va_end (foo);
516
517 return scm_c_make_structv (vtable, n_tail, n_init, v);
518}
519
520SCM_DEFINE (scm_make_struct, "make-struct", 2, 0, 1,
521 (SCM vtable, SCM tail_array_size, SCM init),
522 "Create a new structure.\n\n"
b7e64f8b
BT
523 "@var{vtable} must be a vtable structure (@pxref{Vtables}).\n\n"
524 "@var{tail_array_size} must be a non-negative integer. If the layout\n"
525 "specification indicated by @var{vtable} includes a tail-array,\n"
66e78727
AW
526 "this is the number of elements allocated to that array.\n\n"
527 "The @var{init1}, @dots{} are optional arguments describing how\n"
528 "successive fields of the structure should be initialized. Only fields\n"
529 "with protection 'r' or 'w' can be initialized, except for fields of\n"
530 "type 's', which are automatically initialized to point to the new\n"
531 "structure itself. Fields with protection 'o' can not be initialized by\n"
532 "Scheme programs.\n\n"
533 "If fewer optional arguments than initializable fields are supplied,\n"
534 "fields of type 'p' get default value #f while fields of type 'u' are\n"
535 "initialized to 0.\n\n"
536 "For more information, see the documentation for @code{make-vtable-vtable}.")
537#define FUNC_NAME s_scm_make_struct
538{
539 size_t i, n_init;
540 long ilen;
541 scm_t_bits *v;
542
543 SCM_VALIDATE_VTABLE (1, vtable);
544 ilen = scm_ilength (init);
545 if (ilen < 0)
546 SCM_MISC_ERROR ("Rest arguments do not form a proper list.", SCM_EOL);
547
548 n_init = (size_t)ilen;
549
550 /* best to use alloca, but init could be big, so hack to avoid a possible
551 stack overflow */
552 if (n_init < 64)
553 v = alloca (n_init * sizeof(scm_t_bits));
554 else
555 v = scm_gc_malloc (n_init * sizeof(scm_t_bits), "struct");
556
557 for (i = 0; i < n_init; i++, init = SCM_CDR (init))
558 v[i] = SCM_UNPACK (SCM_CAR (init));
559
560 return scm_c_make_structv (vtable, scm_to_size_t (tail_array_size), n_init, v);
561}
562#undef FUNC_NAME
563
0f2d19dd
JB
564
565
6d46f1e4
AW
566#if SCM_ENABLE_DEPRECATED == 1
567SCM
568scm_make_vtable_vtable (SCM user_fields, SCM tail_array_size, SCM init)
569#define FUNC_NAME "make-vtable-vtable"
0f2d19dd 570{
696ac4df
LC
571 SCM fields, layout, obj;
572 size_t basic_size, n_tail, i, n_init;
66e78727
AW
573 long ilen;
574 scm_t_bits *v;
0f2d19dd 575
d1ca2c64 576 SCM_VALIDATE_STRING (1, user_fields);
66e78727
AW
577 ilen = scm_ilength (init);
578 if (ilen < 0)
579 SCM_MISC_ERROR ("Rest arguments do not form a proper list.", SCM_EOL);
580
581 n_init = (size_t)ilen + 1; /* + 1 for the layout */
582
583 /* best to use alloca, but init could be big, so hack to avoid a possible
584 stack overflow */
585 if (n_init < 64)
586 v = alloca (n_init * sizeof(scm_t_bits));
587 else
588 v = scm_gc_malloc (n_init * sizeof(scm_t_bits), "struct");
0f2d19dd 589
1afff620
KN
590 fields = scm_string_append (scm_list_2 (required_vtable_fields,
591 user_fields));
0f2d19dd 592 layout = scm_make_struct_layout (fields);
a2220d7e
AW
593 if (!scm_is_valid_vtable_layout (layout))
594 SCM_MISC_ERROR ("invalid user fields", scm_list_1 (user_fields));
595
cc95e00a 596 basic_size = scm_i_symbol_length (layout) / 2;
66e78727
AW
597 n_tail = scm_to_size_t (tail_array_size);
598
599 i = 0;
600 v[i++] = SCM_UNPACK (layout);
601 for (; i < n_init; i++, init = SCM_CDR (init))
602 v[i] = SCM_UNPACK (SCM_CAR (init));
603
9de87eea 604 SCM_CRITICAL_SECTION_START;
96a44c1c 605 obj = scm_i_alloc_struct (NULL, basic_size + n_tail);
696ac4df
LC
606 /* Make it so that the vtable of OBJ is itself. */
607 SCM_SET_CELL_WORD_0 (obj, (scm_t_bits) SCM_STRUCT_DATA (obj) | scm_tc3_struct);
9de87eea 608 SCM_CRITICAL_SECTION_END;
696ac4df 609
66e78727 610 scm_struct_init (obj, layout, n_tail, n_init, v);
a2220d7e
AW
611 SCM_SET_VTABLE_FLAGS (obj,
612 SCM_VTABLE_FLAG_VTABLE | SCM_VTABLE_FLAG_VALIDATED);
696ac4df 613
b6cf4d02 614 return obj;
0f2d19dd 615}
1bbd0b84 616#undef FUNC_NAME
6d46f1e4
AW
617#endif
618
619SCM
620scm_i_make_vtable_vtable (SCM user_fields)
621#define FUNC_NAME "make-vtable-vtable"
622{
623 SCM fields, layout, obj;
624 size_t basic_size;
625 scm_t_bits v;
626
627 SCM_VALIDATE_STRING (1, user_fields);
628
629 fields = scm_string_append (scm_list_2 (required_vtable_fields,
630 user_fields));
631 layout = scm_make_struct_layout (fields);
632 if (!scm_is_valid_vtable_layout (layout))
633 SCM_MISC_ERROR ("invalid user fields", scm_list_1 (user_fields));
634
635 basic_size = scm_i_symbol_length (layout) / 2;
636
637 obj = scm_i_alloc_struct (NULL, basic_size);
638 /* Make it so that the vtable of OBJ is itself. */
639 SCM_SET_CELL_WORD_0 (obj, (scm_t_bits) SCM_STRUCT_DATA (obj) | scm_tc3_struct);
0f2d19dd 640
6d46f1e4
AW
641 v = SCM_UNPACK (layout);
642 scm_struct_init (obj, layout, 0, 1, &v);
643 SCM_SET_VTABLE_FLAGS (obj,
644 SCM_VTABLE_FLAG_VTABLE | SCM_VTABLE_FLAG_VALIDATED);
645
646 return obj;
647}
648#undef FUNC_NAME
d15ad007 649
651f2cd2
KR
650SCM_DEFINE (scm_make_vtable, "make-vtable", 1, 1, 0,
651 (SCM fields, SCM printer),
652 "Create a vtable, for creating structures with the given\n"
653 "@var{fields}.\n"
654 "\n"
655 "The optional @var{printer} argument is a function to be called\n"
656 "@code{(@var{printer} struct port)} on the structures created.\n"
657 "It should look at @var{struct} and write to @var{port}.")
658#define FUNC_NAME s_scm_make_vtable
659{
660 if (SCM_UNBNDP (printer))
661 printer = SCM_BOOL_F;
662
db5ed685 663 return scm_make_struct (scm_standard_vtable_vtable, SCM_INUM0,
651f2cd2
KR
664 scm_list_2 (scm_make_struct_layout (fields),
665 printer));
666}
667#undef FUNC_NAME
668
669
d15ad007
LC
670/* Return true if S1 and S2 are equal structures, i.e., if their vtable and
671 contents are the same. Field protections are honored. Thus, it is an
672 error to test the equality of structures that contain opaque fields. */
673SCM
674scm_i_struct_equalp (SCM s1, SCM s2)
675#define FUNC_NAME "scm_i_struct_equalp"
676{
677 SCM vtable1, vtable2, layout;
678 size_t struct_size, field_num;
679
680 SCM_VALIDATE_STRUCT (1, s1);
681 SCM_VALIDATE_STRUCT (2, s2);
682
683 vtable1 = SCM_STRUCT_VTABLE (s1);
684 vtable2 = SCM_STRUCT_VTABLE (s2);
685
686 if (!scm_is_eq (vtable1, vtable2))
687 return SCM_BOOL_F;
688
689 layout = SCM_STRUCT_LAYOUT (s1);
690 struct_size = scm_i_symbol_length (layout) / 2;
691
692 for (field_num = 0; field_num < struct_size; field_num++)
693 {
694 SCM s_field_num;
695 SCM field1, field2;
696
697 /* We have to use `scm_struct_ref ()' here so that fields are accessed
698 consistently, notably wrt. field types and access rights. */
699 s_field_num = scm_from_size_t (field_num);
700 field1 = scm_struct_ref (s1, s_field_num);
701 field2 = scm_struct_ref (s2, s_field_num);
702
42ddb3cb
LC
703 /* Self-referencing fields (type `s') must be skipped to avoid infinite
704 recursion. */
705 if (!(scm_is_eq (field1, s1) && (scm_is_eq (field2, s2))))
706 if (scm_is_false (scm_equal_p (field1, field2)))
707 return SCM_BOOL_F;
d15ad007
LC
708 }
709
42ddb3cb
LC
710 /* FIXME: Tail elements should be tested for equality. */
711
d15ad007
LC
712 return SCM_BOOL_T;
713}
714#undef FUNC_NAME
715
716
0f2d19dd
JB
717\f
718
719
a1ec6916 720SCM_DEFINE (scm_struct_ref, "struct-ref", 2, 0, 0,
1bbd0b84 721 (SCM handle, SCM pos),
b7e64f8b
BT
722 "Access the @var{pos}th field of struct associated with\n"
723 "@var{handle}.\n"
724 "\n"
725 "If the field is of type 'p', then it can be set to an arbitrary\n"
726 "value.\n"
727 "\n"
728 "If the field is of type 'u', then it can only be set to a\n"
729 "non-negative integer value small enough to fit in one machine\n"
730 "word.")
1bbd0b84 731#define FUNC_NAME s_scm_struct_ref
0f2d19dd 732{
aa42c036
LC
733 SCM vtable, answer = SCM_UNDEFINED;
734 scm_t_bits *data;
a55c2b68 735 size_t p;
0f2d19dd 736
34d19ef6 737 SCM_VALIDATE_STRUCT (1, handle);
0f2d19dd 738
aa42c036 739 vtable = SCM_STRUCT_VTABLE (handle);
0f2d19dd 740 data = SCM_STRUCT_DATA (handle);
a55c2b68 741 p = scm_to_size_t (pos);
0f2d19dd 742
aa42c036
LC
743 if (SCM_LIKELY (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_SIMPLE)
744 && p < SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size)))
e03b7f73
LC
745 /* The fast path: HANDLE is a struct with only "p" fields. */
746 answer = SCM_PACK (data[p]);
2c36c351 747 else
0f2d19dd 748 {
aa42c036
LC
749 SCM layout;
750 size_t layout_len, n_fields;
751 scm_t_wchar field_type = 0;
752
753 layout = SCM_STRUCT_LAYOUT (handle);
754 layout_len = scm_i_symbol_length (layout);
755 n_fields = layout_len / 2;
756
757 if (SCM_LAYOUT_TAILP (scm_i_symbol_ref (layout, layout_len - 1)))
758 n_fields += data[n_fields - 1];
759
760 SCM_ASSERT_RANGE (1, pos, p < n_fields);
761
762 if (p * 2 < layout_len)
763 {
764 scm_t_wchar ref;
765 field_type = scm_i_symbol_ref (layout, p * 2);
766 ref = scm_i_symbol_ref (layout, p * 2 + 1);
767 if ((ref != 'r') && (ref != 'w') && (ref != 'h'))
768 {
769 if ((ref == 'R') || (ref == 'W'))
770 field_type = 'u';
771 else
772 SCM_MISC_ERROR ("ref denied for field ~A", scm_list_1 (pos));
773 }
774 }
775 else if (scm_i_symbol_ref (layout, layout_len - 1) != 'O')
776 field_type = scm_i_symbol_ref(layout, layout_len - 2);
777 else
778 SCM_MISC_ERROR ("ref denied for field ~A", scm_list_1 (pos));
779
780 switch (field_type)
781 {
782 case 'u':
783 answer = scm_from_ulong (data[p]);
784 break;
0f2d19dd
JB
785
786#if 0
aa42c036
LC
787 case 'i':
788 answer = scm_from_long (data[p]);
789 break;
0f2d19dd 790
aa42c036
LC
791 case 'd':
792 answer = scm_make_real (*((double *)&(data[p])));
793 break;
0f2d19dd
JB
794#endif
795
aa42c036
LC
796 case 's':
797 case 'p':
798 answer = SCM_PACK (data[p]);
799 break;
0f2d19dd
JB
800
801
aa42c036
LC
802 default:
803 SCM_MISC_ERROR ("unrecognized field type: ~S",
804 scm_list_1 (SCM_MAKE_CHAR (field_type)));
805 }
0f2d19dd
JB
806 }
807
808 return answer;
809}
1bbd0b84 810#undef FUNC_NAME
0f2d19dd
JB
811
812
a1ec6916 813SCM_DEFINE (scm_struct_set_x, "struct-set!", 3, 0, 0,
1bbd0b84 814 (SCM handle, SCM pos, SCM val),
e3239868
DH
815 "Set the slot of the structure @var{handle} with index @var{pos}\n"
816 "to @var{val}. Signal an error if the slot can not be written\n"
817 "to.")
1bbd0b84 818#define FUNC_NAME s_scm_struct_set_x
0f2d19dd 819{
aa42c036
LC
820 SCM vtable;
821 scm_t_bits *data;
a55c2b68 822 size_t p;
0f2d19dd 823
34d19ef6 824 SCM_VALIDATE_STRUCT (1, handle);
0f2d19dd 825
aa42c036 826 vtable = SCM_STRUCT_VTABLE (handle);
0f2d19dd 827 data = SCM_STRUCT_DATA (handle);
a55c2b68 828 p = scm_to_size_t (pos);
0f2d19dd 829
aa42c036
LC
830 if (SCM_LIKELY (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_SIMPLE)
831 && SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_SIMPLE_RW)
832 && p < SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size)))
e03b7f73 833 /* The fast path: HANDLE is a struct with only "pw" fields. */
aa42c036
LC
834 data[p] = SCM_UNPACK (val);
835 else
836 {
837 SCM layout;
838 size_t layout_len, n_fields;
839 scm_t_wchar field_type = 0;
0f2d19dd 840
aa42c036
LC
841 layout = SCM_STRUCT_LAYOUT (handle);
842 layout_len = scm_i_symbol_length (layout);
843 n_fields = layout_len / 2;
0f2d19dd 844
aa42c036
LC
845 if (SCM_LAYOUT_TAILP (scm_i_symbol_ref (layout, layout_len - 1)))
846 n_fields += data[n_fields - 1];
847
848 SCM_ASSERT_RANGE (1, pos, p < n_fields);
849
850 if (p * 2 < layout_len)
851 {
852 char set_x;
853 field_type = scm_i_symbol_ref (layout, p * 2);
854 set_x = scm_i_symbol_ref (layout, p * 2 + 1);
855 if (set_x != 'w' && set_x != 'h')
856 SCM_MISC_ERROR ("set! denied for field ~A", scm_list_1 (pos));
857 }
858 else if (scm_i_symbol_ref (layout, layout_len - 1) == 'W')
859 field_type = scm_i_symbol_ref (layout, layout_len - 2);
860 else
1afff620 861 SCM_MISC_ERROR ("set! denied for field ~A", scm_list_1 (pos));
aa42c036
LC
862
863 switch (field_type)
864 {
865 case 'u':
866 data[p] = SCM_NUM2ULONG (3, val);
867 break;
0f2d19dd
JB
868
869#if 0
aa42c036
LC
870 case 'i':
871 data[p] = SCM_NUM2LONG (3, val);
872 break;
0f2d19dd 873
aa42c036
LC
874 case 'd':
875 *((double *)&(data[p])) = scm_num2dbl (val, (char *)SCM_ARG3);
876 break;
0f2d19dd
JB
877#endif
878
aa42c036
LC
879 case 'p':
880 data[p] = SCM_UNPACK (val);
881 break;
0f2d19dd 882
aa42c036
LC
883 case 's':
884 SCM_MISC_ERROR ("self fields immutable", SCM_EOL);
0f2d19dd 885
aa42c036
LC
886 default:
887 SCM_MISC_ERROR ("unrecognized field type: ~S",
888 scm_list_1 (SCM_MAKE_CHAR (field_type)));
889 }
0f2d19dd
JB
890 }
891
892 return val;
893}
1bbd0b84 894#undef FUNC_NAME
0f2d19dd
JB
895
896
a1ec6916 897SCM_DEFINE (scm_struct_vtable, "struct-vtable", 1, 0, 0,
1bbd0b84 898 (SCM handle),
b7e64f8b
BT
899 "Return the vtable structure that describes the type of struct\n"
900 "associated with @var{handle}.")
1bbd0b84 901#define FUNC_NAME s_scm_struct_vtable
0f2d19dd 902{
34d19ef6 903 SCM_VALIDATE_STRUCT (1, handle);
0f2d19dd
JB
904 return SCM_STRUCT_VTABLE (handle);
905}
1bbd0b84 906#undef FUNC_NAME
0f2d19dd
JB
907
908
98d5f601
MD
909/* {Associating names and classes with vtables}
910 *
911 * The name of a vtable should probably be stored as a slot. This is
912 * a backward compatible solution until agreement has been achieved on
913 * how to associate names with vtables.
914 */
915
c014a02e 916unsigned long
d587c9e8 917scm_struct_ihashq (SCM obj, unsigned long n, void *closure)
98d5f601 918{
ad196599
MD
919 /* The length of the hash table should be a relative prime it's not
920 necessary to shift down the address. */
f1267706 921 return SCM_UNPACK (obj) % n;
98d5f601
MD
922}
923
8ac870de
LC
924/* Return the hash of struct OBJ, modulo N. Traverse OBJ's fields to
925 compute the result, unless DEPTH is zero. */
926unsigned long
927scm_i_struct_hash (SCM obj, unsigned long n, size_t depth)
928#define FUNC_NAME "hash"
929{
930 SCM layout;
931 scm_t_bits *data;
932 size_t struct_size, field_num;
933 unsigned long hash;
934
935 SCM_VALIDATE_STRUCT (1, obj);
936
937 layout = SCM_STRUCT_LAYOUT (obj);
938 struct_size = scm_i_symbol_length (layout) / 2;
939 data = SCM_STRUCT_DATA (obj);
940
941 hash = SCM_UNPACK (SCM_STRUCT_VTABLE (obj)) % n;
942 if (depth > 0)
943 for (field_num = 0; field_num < struct_size; field_num++)
944 {
945 int protection;
946
947 protection = scm_i_symbol_ref (layout, field_num * 2 + 1);
948 if (protection != 'h' && protection != 'o')
949 {
950 int type;
951 type = scm_i_symbol_ref (layout, field_num * 2);
952 switch (type)
953 {
954 case 'p':
955 hash ^= scm_hasher (SCM_PACK (data[field_num]), n,
956 depth / 2);
957 break;
958 case 'u':
959 hash ^= data[field_num] % n;
960 break;
961 default:
962 /* Ignore 's' fields. */;
963 }
964 }
965 }
966
967 /* FIXME: Tail elements should be taken into account. */
968
969 return hash % n;
970}
971#undef FUNC_NAME
972
a1ec6916 973SCM_DEFINE (scm_struct_vtable_name, "struct-vtable-name", 1, 0, 0,
1bbd0b84 974 (SCM vtable),
e3239868 975 "Return the name of the vtable @var{vtable}.")
1bbd0b84 976#define FUNC_NAME s_scm_struct_vtable_name
98d5f601 977{
34d19ef6 978 SCM_VALIDATE_VTABLE (1, vtable);
f3c6a02c 979 return SCM_VTABLE_NAME (vtable);
98d5f601 980}
1bbd0b84 981#undef FUNC_NAME
98d5f601 982
a1ec6916 983SCM_DEFINE (scm_set_struct_vtable_name_x, "set-struct-vtable-name!", 2, 0, 0,
1bbd0b84 984 (SCM vtable, SCM name),
e3239868 985 "Set the name of the vtable @var{vtable} to @var{name}.")
1bbd0b84 986#define FUNC_NAME s_scm_set_struct_vtable_name_x
98d5f601 987{
34d19ef6
HWN
988 SCM_VALIDATE_VTABLE (1, vtable);
989 SCM_VALIDATE_SYMBOL (2, name);
f3c6a02c
AW
990 SCM_SET_VTABLE_NAME (vtable, name);
991 /* FIXME: remove this, and implement proper struct classes instead.
992 (Vtables *are* classes.) */
993 scm_i_define_class_for_vtable (vtable);
98d5f601 994 return SCM_UNSPECIFIED;
0f2d19dd 995}
1bbd0b84 996#undef FUNC_NAME
0f2d19dd
JB
997
998
999\f
1000
bafcafb2 1001void
1bbd0b84 1002scm_print_struct (SCM exp, SCM port, scm_print_state *pstate)
bafcafb2 1003{
7888309b 1004 if (scm_is_true (scm_procedure_p (SCM_STRUCT_PRINTER (exp))))
4bfdf158
MD
1005 scm_printer_apply (SCM_STRUCT_PRINTER (exp), exp, port, pstate);
1006 else
bafcafb2 1007 {
a1ae1799
MD
1008 SCM vtable = SCM_STRUCT_VTABLE (exp);
1009 SCM name = scm_struct_vtable_name (vtable);
1010 scm_puts ("#<", port);
7888309b 1011 if (scm_is_true (name))
b6cf4d02
AW
1012 {
1013 scm_display (name, port);
1014 scm_putc (' ', port);
1015 }
a1ae1799 1016 else
b6cf4d02
AW
1017 {
1018 if (SCM_VTABLE_FLAG_IS_SET (vtable, SCM_VTABLE_FLAG_VTABLE))
1019 scm_puts ("vtable:", port);
1020 else
1021 scm_puts ("struct:", port);
1022 scm_uintprint (SCM_UNPACK (vtable), 16, port);
1023 scm_putc (' ', port);
1024 scm_write (SCM_VTABLE_LAYOUT (vtable), port);
1025 scm_putc (' ', port);
1026 }
0345e278 1027 scm_uintprint (SCM_UNPACK (exp), 16, port);
b6cf4d02
AW
1028 /* hackety hack */
1029 if (SCM_STRUCT_APPLICABLE_P (exp))
1030 {
1031 if (scm_is_true (SCM_STRUCT_PROCEDURE (exp)))
1032 {
1033 scm_puts (" proc: ", port);
1034 if (scm_is_true (scm_procedure_p (SCM_STRUCT_PROCEDURE (exp))))
1035 scm_write (SCM_STRUCT_PROCEDURE (exp), port);
1036 else
1037 scm_puts ("(not a procedure?)", port);
1038 }
1039 if (SCM_STRUCT_SETTER_P (exp))
1040 {
1041 scm_puts (" setter: ", port);
1042 scm_write (SCM_STRUCT_SETTER (exp), port);
1043 }
1044 }
b7f3516f 1045 scm_putc ('>', port);
bafcafb2 1046 }
bafcafb2 1047}
1cc91f1b 1048
0f2d19dd
JB
1049void
1050scm_init_struct ()
0f2d19dd 1051{
880e114b
AW
1052 SCM name;
1053
01e74380
LC
1054 /* The first word of a struct is equal to `SCM_STRUCT_DATA (vtable) +
1055 scm_tc3_struct', and `SCM_STRUCT_DATA (vtable)' is 2 words after VTABLE by
1056 default. */
1057 GC_REGISTER_DISPLACEMENT (2 * sizeof (scm_t_bits) + scm_tc3_struct);
b6cf4d02 1058
227eff6a
LC
1059 /* In the general case, `SCM_STRUCT_DATA (obj)' points 2 words after the
1060 beginning of a GC-allocated region; that region is different from that of
1061 OBJ once OBJ has undergone class redefinition. */
1062 GC_REGISTER_DISPLACEMENT (2 * sizeof (scm_t_bits));
1063
b6cf4d02 1064 required_vtable_fields = scm_from_locale_string (SCM_VTABLE_BASE_LAYOUT);
2921f537 1065 scm_c_define ("standard-vtable-fields", required_vtable_fields);
b6cf4d02
AW
1066 required_applicable_fields = scm_from_locale_string (SCM_APPLICABLE_BASE_LAYOUT);
1067 required_applicable_with_setter_fields = scm_from_locale_string (SCM_APPLICABLE_WITH_SETTER_BASE_LAYOUT);
651f2cd2 1068
6d46f1e4 1069 scm_standard_vtable_vtable = scm_i_make_vtable_vtable (scm_nullstr);
880e114b
AW
1070 name = scm_from_utf8_symbol ("<standard-vtable>");
1071 scm_set_struct_vtable_name_x (scm_standard_vtable_vtable, name);
1072 scm_define (name, scm_standard_vtable_vtable);
b6cf4d02
AW
1073
1074 scm_applicable_struct_vtable_vtable =
db5ed685 1075 scm_make_struct (scm_standard_vtable_vtable, SCM_INUM0,
b6cf4d02 1076 scm_list_1 (scm_make_struct_layout (required_vtable_fields)));
880e114b 1077 name = scm_from_utf8_symbol ("<applicable-struct-vtable>");
b6cf4d02
AW
1078 SCM_SET_VTABLE_FLAGS (scm_applicable_struct_vtable_vtable,
1079 SCM_VTABLE_FLAG_APPLICABLE_VTABLE);
880e114b
AW
1080 scm_set_struct_vtable_name_x (scm_applicable_struct_vtable_vtable, name);
1081 scm_define (name, scm_applicable_struct_vtable_vtable);
b6cf4d02
AW
1082
1083 scm_applicable_struct_with_setter_vtable_vtable =
db5ed685 1084 scm_make_struct (scm_standard_vtable_vtable, SCM_INUM0,
b6cf4d02 1085 scm_list_1 (scm_make_struct_layout (required_vtable_fields)));
880e114b
AW
1086 name = scm_from_utf8_symbol ("<applicable-struct-with-setter-vtable>");
1087 scm_set_struct_vtable_name_x (scm_applicable_struct_with_setter_vtable_vtable, name);
b6cf4d02
AW
1088 SCM_SET_VTABLE_FLAGS (scm_applicable_struct_with_setter_vtable_vtable,
1089 SCM_VTABLE_FLAG_APPLICABLE_VTABLE | SCM_VTABLE_FLAG_SETTER_VTABLE);
880e114b 1090 scm_define (name, scm_applicable_struct_with_setter_vtable_vtable);
651f2cd2 1091
e11e83f3 1092 scm_c_define ("vtable-index-layout", scm_from_int (scm_vtable_index_layout));
86d31dfe 1093 scm_c_define ("vtable-index-printer",
b6cf4d02 1094 scm_from_int (scm_vtable_index_instance_printer));
e11e83f3 1095 scm_c_define ("vtable-offset-user", scm_from_int (scm_vtable_offset_user));
a0599745 1096#include "libguile/struct.x"
6d46f1e4
AW
1097#if SCM_ENABLE_DEPRECATED
1098 scm_c_define_gsubr ("make-vtable-vtable", 2, 0, 1, scm_make_vtable_vtable);
1099#endif
0f2d19dd 1100}
89e00824
ML
1101
1102/*
1103 Local Variables:
1104 c-file-style: "gnu"
1105 End:
1106*/