Update copyright year range in all GDB files.
[binutils-gdb.git] / gdb / guile / scm-type.c
blob52817ea4ede9b5d3597143c1dd5e90da95507cd9
1 /* Scheme interface to types.
3 Copyright (C) 2008-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* See README file in this directory for implementation notes, coding
21 conventions, et.al. */
23 #include "defs.h"
24 #include "arch-utils.h"
25 #include "value.h"
26 #include "gdbtypes.h"
27 #include "objfiles.h"
28 #include "language.h"
29 #include "bcache.h"
30 #include "dwarf2loc.h"
31 #include "typeprint.h"
32 #include "guile-internal.h"
34 /* The <gdb:type> smob.
35 The type is chained with all types associated with its objfile, if any.
36 This lets us copy the underlying struct type when the objfile is
37 deleted.
38 The typedef for this struct is in guile-internal.h. */
40 struct _type_smob
42 /* This always appears first.
43 eqable_gdb_smob is used so that types are eq?-able.
44 Also, a type object can be associated with an objfile. eqable_gdb_smob
45 lets us track the lifetime of all types associated with an objfile.
46 When an objfile is deleted we need to invalidate the type object. */
47 eqable_gdb_smob base;
49 /* The GDB type structure this smob is wrapping. */
50 struct type *type;
53 /* A field smob. */
55 typedef struct
57 /* This always appears first. */
58 gdb_smob base;
60 /* Backlink to the containing <gdb:type> object. */
61 SCM type_scm;
63 /* The field number in TYPE_SCM. */
64 int field_num;
65 } field_smob;
67 static const char type_smob_name[] = "gdb:type";
68 static const char field_smob_name[] = "gdb:field";
70 static const char not_composite_error[] =
71 N_("type is not a structure, union, or enum type");
73 /* The tag Guile knows the type smob by. */
74 static scm_t_bits type_smob_tag;
76 /* The tag Guile knows the field smob by. */
77 static scm_t_bits field_smob_tag;
79 /* The "next" procedure for field iterators. */
80 static SCM tyscm_next_field_x_proc;
82 /* Keywords used in argument passing. */
83 static SCM block_keyword;
85 static const struct objfile_data *tyscm_objfile_data_key;
87 /* Hash table to uniquify global (non-objfile-owned) types. */
88 static htab_t global_types_map;
90 static struct type *tyscm_get_composite (struct type *type);
92 /* Return the type field of T_SMOB.
93 This exists so that we don't have to export the struct's contents. */
95 struct type *
96 tyscm_type_smob_type (type_smob *t_smob)
98 return t_smob->type;
101 /* Return the name of TYPE in expanded form. If there's an error
102 computing the name, throws the gdb exception with scm_throw. */
104 static std::string
105 tyscm_type_name (struct type *type)
107 SCM excp;
110 string_file stb;
112 LA_PRINT_TYPE (type, "", &stb, -1, 0, &type_print_raw_options);
113 return std::move (stb.string ());
115 catch (const gdb_exception &except)
117 excp = gdbscm_scm_from_gdb_exception (unpack (except));
120 gdbscm_throw (excp);
123 /* Administrivia for type smobs. */
125 /* Helper function to hash a type_smob. */
127 static hashval_t
128 tyscm_hash_type_smob (const void *p)
130 const type_smob *t_smob = (const type_smob *) p;
132 return htab_hash_pointer (t_smob->type);
135 /* Helper function to compute equality of type_smobs. */
137 static int
138 tyscm_eq_type_smob (const void *ap, const void *bp)
140 const type_smob *a = (const type_smob *) ap;
141 const type_smob *b = (const type_smob *) bp;
143 return (a->type == b->type
144 && a->type != NULL);
147 /* Return the struct type pointer -> SCM mapping table.
148 If type is owned by an objfile, the mapping table is created if necessary.
149 Otherwise, type is not owned by an objfile, and we use
150 global_types_map. */
152 static htab_t
153 tyscm_type_map (struct type *type)
155 struct objfile *objfile = TYPE_OBJFILE (type);
156 htab_t htab;
158 if (objfile == NULL)
159 return global_types_map;
161 htab = (htab_t) objfile_data (objfile, tyscm_objfile_data_key);
162 if (htab == NULL)
164 htab = gdbscm_create_eqable_gsmob_ptr_map (tyscm_hash_type_smob,
165 tyscm_eq_type_smob);
166 set_objfile_data (objfile, tyscm_objfile_data_key, htab);
169 return htab;
172 /* The smob "free" function for <gdb:type>. */
174 static size_t
175 tyscm_free_type_smob (SCM self)
177 type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (self);
179 if (t_smob->type != NULL)
181 htab_t htab = tyscm_type_map (t_smob->type);
183 gdbscm_clear_eqable_gsmob_ptr_slot (htab, &t_smob->base);
186 /* Not necessary, done to catch bugs. */
187 t_smob->type = NULL;
189 return 0;
192 /* The smob "print" function for <gdb:type>. */
194 static int
195 tyscm_print_type_smob (SCM self, SCM port, scm_print_state *pstate)
197 type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (self);
198 std::string name = tyscm_type_name (t_smob->type);
200 /* pstate->writingp = zero if invoked by display/~A, and nonzero if
201 invoked by write/~S. What to do here may need to evolve.
202 IWBN if we could pass an argument to format that would we could use
203 instead of writingp. */
204 if (pstate->writingp)
205 gdbscm_printf (port, "#<%s ", type_smob_name);
207 scm_puts (name.c_str (), port);
209 if (pstate->writingp)
210 scm_puts (">", port);
212 scm_remember_upto_here_1 (self);
214 /* Non-zero means success. */
215 return 1;
218 /* The smob "equal?" function for <gdb:type>. */
220 static SCM
221 tyscm_equal_p_type_smob (SCM type1_scm, SCM type2_scm)
223 type_smob *type1_smob, *type2_smob;
224 struct type *type1, *type2;
225 bool result = false;
227 SCM_ASSERT_TYPE (tyscm_is_type (type1_scm), type1_scm, SCM_ARG1, FUNC_NAME,
228 type_smob_name);
229 SCM_ASSERT_TYPE (tyscm_is_type (type2_scm), type2_scm, SCM_ARG2, FUNC_NAME,
230 type_smob_name);
231 type1_smob = (type_smob *) SCM_SMOB_DATA (type1_scm);
232 type2_smob = (type_smob *) SCM_SMOB_DATA (type2_scm);
233 type1 = type1_smob->type;
234 type2 = type2_smob->type;
236 gdbscm_gdb_exception exc {};
239 result = types_deeply_equal (type1, type2);
241 catch (const gdb_exception &except)
243 exc = unpack (except);
246 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
247 return scm_from_bool (result);
250 /* Low level routine to create a <gdb:type> object. */
252 static SCM
253 tyscm_make_type_smob (void)
255 type_smob *t_smob = (type_smob *)
256 scm_gc_malloc (sizeof (type_smob), type_smob_name);
257 SCM t_scm;
259 /* This must be filled in by the caller. */
260 t_smob->type = NULL;
262 t_scm = scm_new_smob (type_smob_tag, (scm_t_bits) t_smob);
263 gdbscm_init_eqable_gsmob (&t_smob->base, t_scm);
265 return t_scm;
268 /* Return non-zero if SCM is a <gdb:type> object. */
271 tyscm_is_type (SCM self)
273 return SCM_SMOB_PREDICATE (type_smob_tag, self);
276 /* (type? object) -> boolean */
278 static SCM
279 gdbscm_type_p (SCM self)
281 return scm_from_bool (tyscm_is_type (self));
284 /* Return the existing object that encapsulates TYPE, or create a new
285 <gdb:type> object. */
288 tyscm_scm_from_type (struct type *type)
290 htab_t htab;
291 eqable_gdb_smob **slot;
292 type_smob *t_smob, t_smob_for_lookup;
293 SCM t_scm;
295 /* If we've already created a gsmob for this type, return it.
296 This makes types eq?-able. */
297 htab = tyscm_type_map (type);
298 t_smob_for_lookup.type = type;
299 slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &t_smob_for_lookup.base);
300 if (*slot != NULL)
301 return (*slot)->containing_scm;
303 t_scm = tyscm_make_type_smob ();
304 t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
305 t_smob->type = type;
306 gdbscm_fill_eqable_gsmob_ptr_slot (slot, &t_smob->base);
308 return t_scm;
311 /* Returns the <gdb:type> object in SELF.
312 Throws an exception if SELF is not a <gdb:type> object. */
314 static SCM
315 tyscm_get_type_arg_unsafe (SCM self, int arg_pos, const char *func_name)
317 SCM_ASSERT_TYPE (tyscm_is_type (self), self, arg_pos, func_name,
318 type_smob_name);
320 return self;
323 /* Returns a pointer to the type smob of SELF.
324 Throws an exception if SELF is not a <gdb:type> object. */
326 type_smob *
327 tyscm_get_type_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
329 SCM t_scm = tyscm_get_type_arg_unsafe (self, arg_pos, func_name);
330 type_smob *t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
332 return t_smob;
335 /* Return the type field of T_SCM, an object of type <gdb:type>.
336 This exists so that we don't have to export the struct's contents. */
338 struct type *
339 tyscm_scm_to_type (SCM t_scm)
341 type_smob *t_smob;
343 gdb_assert (tyscm_is_type (t_scm));
344 t_smob = (type_smob *) SCM_SMOB_DATA (t_scm);
345 return t_smob->type;
348 /* Helper function for save_objfile_types to make a deep copy of the type. */
350 static int
351 tyscm_copy_type_recursive (void **slot, void *info)
353 type_smob *t_smob = (type_smob *) *slot;
354 htab_t copied_types = (htab_t) info;
355 struct objfile *objfile = TYPE_OBJFILE (t_smob->type);
356 htab_t htab;
357 eqable_gdb_smob **new_slot;
358 type_smob t_smob_for_lookup;
360 gdb_assert (objfile != NULL);
362 htab_empty (copied_types);
363 t_smob->type = copy_type_recursive (objfile, t_smob->type, copied_types);
365 /* The eq?-hashtab that the type lived in is going away.
366 Add the type to its new eq?-hashtab: Otherwise if/when the type is later
367 garbage collected we'll assert-fail if the type isn't in the hashtab.
368 PR 16612.
370 Types now live in "arch space", and things like "char" that came from
371 the objfile *could* be considered eq? with the arch "char" type.
372 However, they weren't before the objfile got deleted, so making them
373 eq? now is debatable. */
374 htab = tyscm_type_map (t_smob->type);
375 t_smob_for_lookup.type = t_smob->type;
376 new_slot = gdbscm_find_eqable_gsmob_ptr_slot (htab, &t_smob_for_lookup.base);
377 gdb_assert (*new_slot == NULL);
378 gdbscm_fill_eqable_gsmob_ptr_slot (new_slot, &t_smob->base);
380 return 1;
383 /* Called when OBJFILE is about to be deleted.
384 Make a copy of all types associated with OBJFILE. */
386 static void
387 save_objfile_types (struct objfile *objfile, void *datum)
389 htab_t htab = (htab_t) datum;
390 htab_t copied_types;
392 if (!gdb_scheme_initialized)
393 return;
395 copied_types = create_copied_types_hash (objfile);
397 if (htab != NULL)
399 htab_traverse_noresize (htab, tyscm_copy_type_recursive, copied_types);
400 htab_delete (htab);
403 htab_delete (copied_types);
406 /* Administrivia for field smobs. */
408 /* The smob "print" function for <gdb:field>. */
410 static int
411 tyscm_print_field_smob (SCM self, SCM port, scm_print_state *pstate)
413 field_smob *f_smob = (field_smob *) SCM_SMOB_DATA (self);
415 gdbscm_printf (port, "#<%s ", field_smob_name);
416 scm_write (f_smob->type_scm, port);
417 gdbscm_printf (port, " %d", f_smob->field_num);
418 scm_puts (">", port);
420 scm_remember_upto_here_1 (self);
422 /* Non-zero means success. */
423 return 1;
426 /* Low level routine to create a <gdb:field> object for field FIELD_NUM
427 of type TYPE_SCM. */
429 static SCM
430 tyscm_make_field_smob (SCM type_scm, int field_num)
432 field_smob *f_smob = (field_smob *)
433 scm_gc_malloc (sizeof (field_smob), field_smob_name);
434 SCM result;
436 f_smob->type_scm = type_scm;
437 f_smob->field_num = field_num;
438 result = scm_new_smob (field_smob_tag, (scm_t_bits) f_smob);
439 gdbscm_init_gsmob (&f_smob->base);
441 return result;
444 /* Return non-zero if SCM is a <gdb:field> object. */
446 static int
447 tyscm_is_field (SCM self)
449 return SCM_SMOB_PREDICATE (field_smob_tag, self);
452 /* (field? object) -> boolean */
454 static SCM
455 gdbscm_field_p (SCM self)
457 return scm_from_bool (tyscm_is_field (self));
460 /* Create a new <gdb:field> object that encapsulates field FIELD_NUM
461 in type TYPE_SCM. */
464 tyscm_scm_from_field (SCM type_scm, int field_num)
466 return tyscm_make_field_smob (type_scm, field_num);
469 /* Returns the <gdb:field> object in SELF.
470 Throws an exception if SELF is not a <gdb:field> object. */
472 static SCM
473 tyscm_get_field_arg_unsafe (SCM self, int arg_pos, const char *func_name)
475 SCM_ASSERT_TYPE (tyscm_is_field (self), self, arg_pos, func_name,
476 field_smob_name);
478 return self;
481 /* Returns a pointer to the field smob of SELF.
482 Throws an exception if SELF is not a <gdb:field> object. */
484 static field_smob *
485 tyscm_get_field_smob_arg_unsafe (SCM self, int arg_pos, const char *func_name)
487 SCM f_scm = tyscm_get_field_arg_unsafe (self, arg_pos, func_name);
488 field_smob *f_smob = (field_smob *) SCM_SMOB_DATA (f_scm);
490 return f_smob;
493 /* Returns a pointer to the type struct in F_SMOB
494 (the type the field is in). */
496 static struct type *
497 tyscm_field_smob_containing_type (field_smob *f_smob)
499 type_smob *t_smob;
501 gdb_assert (tyscm_is_type (f_smob->type_scm));
502 t_smob = (type_smob *) SCM_SMOB_DATA (f_smob->type_scm);
504 return t_smob->type;
507 /* Returns a pointer to the field struct of F_SMOB. */
509 static struct field *
510 tyscm_field_smob_to_field (field_smob *f_smob)
512 struct type *type = tyscm_field_smob_containing_type (f_smob);
514 /* This should be non-NULL by construction. */
515 gdb_assert (TYPE_FIELDS (type) != NULL);
517 return &TYPE_FIELD (type, f_smob->field_num);
520 /* Type smob accessors. */
522 /* (type-code <gdb:type>) -> integer
523 Return the code for this type. */
525 static SCM
526 gdbscm_type_code (SCM self)
528 type_smob *t_smob
529 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
530 struct type *type = t_smob->type;
532 return scm_from_int (TYPE_CODE (type));
535 /* (type-fields <gdb:type>) -> list
536 Return a list of all fields. Each element is a <gdb:field> object.
537 This also supports arrays, we return a field list of one element,
538 the range type. */
540 static SCM
541 gdbscm_type_fields (SCM self)
543 type_smob *t_smob
544 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
545 struct type *type = t_smob->type;
546 struct type *containing_type;
547 SCM containing_type_scm, result;
548 int i;
550 containing_type = tyscm_get_composite (type);
551 if (containing_type == NULL)
552 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
553 _(not_composite_error));
555 /* If SELF is a typedef or reference, we want the underlying type,
556 which is what tyscm_get_composite returns. */
557 if (containing_type == type)
558 containing_type_scm = self;
559 else
560 containing_type_scm = tyscm_scm_from_type (containing_type);
562 result = SCM_EOL;
563 for (i = 0; i < TYPE_NFIELDS (containing_type); ++i)
564 result = scm_cons (tyscm_make_field_smob (containing_type_scm, i), result);
566 return scm_reverse_x (result, SCM_EOL);
569 /* (type-tag <gdb:type>) -> string
570 Return the type's tag, or #f. */
572 static SCM
573 gdbscm_type_tag (SCM self)
575 type_smob *t_smob
576 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
577 struct type *type = t_smob->type;
578 const char *tagname = nullptr;
580 if (TYPE_CODE (type) == TYPE_CODE_STRUCT
581 || TYPE_CODE (type) == TYPE_CODE_UNION
582 || TYPE_CODE (type) == TYPE_CODE_ENUM)
583 tagname = TYPE_NAME (type);
585 if (tagname == nullptr)
586 return SCM_BOOL_F;
587 return gdbscm_scm_from_c_string (tagname);
590 /* (type-name <gdb:type>) -> string
591 Return the type's name, or #f. */
593 static SCM
594 gdbscm_type_name (SCM self)
596 type_smob *t_smob
597 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
598 struct type *type = t_smob->type;
600 if (!TYPE_NAME (type))
601 return SCM_BOOL_F;
602 return gdbscm_scm_from_c_string (TYPE_NAME (type));
605 /* (type-print-name <gdb:type>) -> string
606 Return the print name of type.
607 TODO: template support elided for now. */
609 static SCM
610 gdbscm_type_print_name (SCM self)
612 type_smob *t_smob
613 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
614 struct type *type = t_smob->type;
615 std::string thetype = tyscm_type_name (type);
616 SCM result = gdbscm_scm_from_c_string (thetype.c_str ());
618 return result;
621 /* (type-sizeof <gdb:type>) -> integer
622 Return the size of the type represented by SELF, in bytes. */
624 static SCM
625 gdbscm_type_sizeof (SCM self)
627 type_smob *t_smob
628 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
629 struct type *type = t_smob->type;
633 check_typedef (type);
635 catch (const gdb_exception &except)
639 /* Ignore exceptions. */
641 return scm_from_long (TYPE_LENGTH (type));
644 /* (type-strip-typedefs <gdb:type>) -> <gdb:type>
645 Return the type, stripped of typedefs. */
647 static SCM
648 gdbscm_type_strip_typedefs (SCM self)
650 type_smob *t_smob
651 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
652 struct type *type = t_smob->type;
654 gdbscm_gdb_exception exc {};
657 type = check_typedef (type);
659 catch (const gdb_exception &except)
661 exc = unpack (except);
664 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
665 return tyscm_scm_from_type (type);
668 /* Strip typedefs and pointers/reference from a type. Then check that
669 it is a struct, union, or enum type. If not, return NULL. */
671 static struct type *
672 tyscm_get_composite (struct type *type)
675 for (;;)
677 gdbscm_gdb_exception exc {};
680 type = check_typedef (type);
682 catch (const gdb_exception &except)
684 exc = unpack (except);
687 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
688 if (TYPE_CODE (type) != TYPE_CODE_PTR
689 && TYPE_CODE (type) != TYPE_CODE_REF)
690 break;
691 type = TYPE_TARGET_TYPE (type);
694 /* If this is not a struct, union, or enum type, raise TypeError
695 exception. */
696 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
697 && TYPE_CODE (type) != TYPE_CODE_UNION
698 && TYPE_CODE (type) != TYPE_CODE_ENUM)
699 return NULL;
701 return type;
704 /* Helper for tyscm_array and tyscm_vector. */
706 static SCM
707 tyscm_array_1 (SCM self, SCM n1_scm, SCM n2_scm, int is_vector,
708 const char *func_name)
710 type_smob *t_smob
711 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, func_name);
712 struct type *type = t_smob->type;
713 long n1, n2 = 0;
714 struct type *array = NULL;
716 gdbscm_parse_function_args (func_name, SCM_ARG2, NULL, "l|l",
717 n1_scm, &n1, n2_scm, &n2);
719 if (SCM_UNBNDP (n2_scm))
721 n2 = n1;
722 n1 = 0;
725 if (n2 < n1 - 1) /* Note: An empty array has n2 == n1 - 1. */
727 gdbscm_out_of_range_error (func_name, SCM_ARG3,
728 scm_cons (scm_from_long (n1),
729 scm_from_long (n2)),
730 _("Array length must not be negative"));
733 gdbscm_gdb_exception exc {};
736 array = lookup_array_range_type (type, n1, n2);
737 if (is_vector)
738 make_vector_type (array);
740 catch (const gdb_exception &except)
742 exc = unpack (except);
745 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
746 return tyscm_scm_from_type (array);
749 /* (type-array <gdb:type> [low-bound] high-bound) -> <gdb:type>
750 The array has indices [low-bound,high-bound].
751 If low-bound is not provided zero is used.
752 Return an array type.
754 IWBN if the one argument version specified a size, not the high bound.
755 It's too easy to pass one argument thinking it is the size of the array.
756 The current semantics are for compatibility with the Python version.
757 Later we can add #:size. */
759 static SCM
760 gdbscm_type_array (SCM self, SCM n1, SCM n2)
762 return tyscm_array_1 (self, n1, n2, 0, FUNC_NAME);
765 /* (type-vector <gdb:type> [low-bound] high-bound) -> <gdb:type>
766 The array has indices [low-bound,high-bound].
767 If low-bound is not provided zero is used.
768 Return a vector type.
770 IWBN if the one argument version specified a size, not the high bound.
771 It's too easy to pass one argument thinking it is the size of the array.
772 The current semantics are for compatibility with the Python version.
773 Later we can add #:size. */
775 static SCM
776 gdbscm_type_vector (SCM self, SCM n1, SCM n2)
778 return tyscm_array_1 (self, n1, n2, 1, FUNC_NAME);
781 /* (type-pointer <gdb:type>) -> <gdb:type>
782 Return a <gdb:type> object which represents a pointer to SELF. */
784 static SCM
785 gdbscm_type_pointer (SCM self)
787 type_smob *t_smob
788 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
789 struct type *type = t_smob->type;
791 gdbscm_gdb_exception exc {};
794 type = lookup_pointer_type (type);
796 catch (const gdb_exception &except)
798 exc = unpack (except);
801 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
802 return tyscm_scm_from_type (type);
805 /* (type-range <gdb:type>) -> (low high)
806 Return the range of a type represented by SELF. The return type is
807 a list. The first element is the low bound, and the second element
808 is the high bound. */
810 static SCM
811 gdbscm_type_range (SCM self)
813 type_smob *t_smob
814 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
815 struct type *type = t_smob->type;
816 SCM low_scm, high_scm;
817 /* Initialize these to appease GCC warnings. */
818 LONGEST low = 0, high = 0;
820 SCM_ASSERT_TYPE (TYPE_CODE (type) == TYPE_CODE_ARRAY
821 || TYPE_CODE (type) == TYPE_CODE_STRING
822 || TYPE_CODE (type) == TYPE_CODE_RANGE,
823 self, SCM_ARG1, FUNC_NAME, _("ranged type"));
825 switch (TYPE_CODE (type))
827 case TYPE_CODE_ARRAY:
828 case TYPE_CODE_STRING:
829 low = TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
830 high = TYPE_HIGH_BOUND (TYPE_INDEX_TYPE (type));
831 break;
832 case TYPE_CODE_RANGE:
833 low = TYPE_LOW_BOUND (type);
834 high = TYPE_HIGH_BOUND (type);
835 break;
838 low_scm = gdbscm_scm_from_longest (low);
839 high_scm = gdbscm_scm_from_longest (high);
841 return scm_list_2 (low_scm, high_scm);
844 /* (type-reference <gdb:type>) -> <gdb:type>
845 Return a <gdb:type> object which represents a reference to SELF. */
847 static SCM
848 gdbscm_type_reference (SCM self)
850 type_smob *t_smob
851 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
852 struct type *type = t_smob->type;
854 gdbscm_gdb_exception exc {};
857 type = lookup_lvalue_reference_type (type);
859 catch (const gdb_exception &except)
861 exc = unpack (except);
864 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
865 return tyscm_scm_from_type (type);
868 /* (type-target <gdb:type>) -> <gdb:type>
869 Return a <gdb:type> object which represents the target type of SELF. */
871 static SCM
872 gdbscm_type_target (SCM self)
874 type_smob *t_smob
875 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
876 struct type *type = t_smob->type;
878 SCM_ASSERT (TYPE_TARGET_TYPE (type), self, SCM_ARG1, FUNC_NAME);
880 return tyscm_scm_from_type (TYPE_TARGET_TYPE (type));
883 /* (type-const <gdb:type>) -> <gdb:type>
884 Return a const-qualified type variant. */
886 static SCM
887 gdbscm_type_const (SCM self)
889 type_smob *t_smob
890 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
891 struct type *type = t_smob->type;
893 gdbscm_gdb_exception exc {};
896 type = make_cv_type (1, 0, type, NULL);
898 catch (const gdb_exception &except)
900 exc = unpack (except);
903 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
904 return tyscm_scm_from_type (type);
907 /* (type-volatile <gdb:type>) -> <gdb:type>
908 Return a volatile-qualified type variant. */
910 static SCM
911 gdbscm_type_volatile (SCM self)
913 type_smob *t_smob
914 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
915 struct type *type = t_smob->type;
917 gdbscm_gdb_exception exc {};
920 type = make_cv_type (0, 1, type, NULL);
922 catch (const gdb_exception &except)
924 exc = unpack (except);
927 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
928 return tyscm_scm_from_type (type);
931 /* (type-unqualified <gdb:type>) -> <gdb:type>
932 Return an unqualified type variant. */
934 static SCM
935 gdbscm_type_unqualified (SCM self)
937 type_smob *t_smob
938 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
939 struct type *type = t_smob->type;
941 gdbscm_gdb_exception exc {};
944 type = make_cv_type (0, 0, type, NULL);
946 catch (const gdb_exception &except)
948 exc = unpack (except);
951 GDBSCM_HANDLE_GDB_EXCEPTION (exc);
952 return tyscm_scm_from_type (type);
955 /* Field related accessors of types. */
957 /* (type-num-fields <gdb:type>) -> integer
958 Return number of fields. */
960 static SCM
961 gdbscm_type_num_fields (SCM self)
963 type_smob *t_smob
964 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
965 struct type *type = t_smob->type;
967 type = tyscm_get_composite (type);
968 if (type == NULL)
969 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
970 _(not_composite_error));
972 return scm_from_long (TYPE_NFIELDS (type));
975 /* (type-field <gdb:type> string) -> <gdb:field>
976 Return the <gdb:field> object for the field named by the argument. */
978 static SCM
979 gdbscm_type_field (SCM self, SCM field_scm)
981 type_smob *t_smob
982 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
983 struct type *type = t_smob->type;
985 SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
986 _("string"));
988 /* We want just fields of this type, not of base types, so instead of
989 using lookup_struct_elt_type, portions of that function are
990 copied here. */
992 type = tyscm_get_composite (type);
993 if (type == NULL)
994 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
995 _(not_composite_error));
998 gdb::unique_xmalloc_ptr<char> field = gdbscm_scm_to_c_string (field_scm);
1000 for (int i = 0; i < TYPE_NFIELDS (type); i++)
1002 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1004 if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
1006 field.reset (nullptr);
1007 return tyscm_make_field_smob (self, i);
1012 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, field_scm,
1013 _("Unknown field"));
1016 /* (type-has-field? <gdb:type> string) -> boolean
1017 Return boolean indicating if type SELF has FIELD_SCM (a string). */
1019 static SCM
1020 gdbscm_type_has_field_p (SCM self, SCM field_scm)
1022 type_smob *t_smob
1023 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1024 struct type *type = t_smob->type;
1026 SCM_ASSERT_TYPE (scm_is_string (field_scm), field_scm, SCM_ARG2, FUNC_NAME,
1027 _("string"));
1029 /* We want just fields of this type, not of base types, so instead of
1030 using lookup_struct_elt_type, portions of that function are
1031 copied here. */
1033 type = tyscm_get_composite (type);
1034 if (type == NULL)
1035 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
1036 _(not_composite_error));
1039 gdb::unique_xmalloc_ptr<char> field
1040 = gdbscm_scm_to_c_string (field_scm);
1042 for (int i = 0; i < TYPE_NFIELDS (type); i++)
1044 const char *t_field_name = TYPE_FIELD_NAME (type, i);
1046 if (t_field_name && (strcmp_iw (t_field_name, field.get ()) == 0))
1047 return SCM_BOOL_T;
1051 return SCM_BOOL_F;
1054 /* (make-field-iterator <gdb:type>) -> <gdb:iterator>
1055 Make a field iterator object. */
1057 static SCM
1058 gdbscm_make_field_iterator (SCM self)
1060 type_smob *t_smob
1061 = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1062 struct type *type = t_smob->type;
1063 struct type *containing_type;
1064 SCM containing_type_scm;
1066 containing_type = tyscm_get_composite (type);
1067 if (containing_type == NULL)
1068 gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, self,
1069 _(not_composite_error));
1071 /* If SELF is a typedef or reference, we want the underlying type,
1072 which is what tyscm_get_composite returns. */
1073 if (containing_type == type)
1074 containing_type_scm = self;
1075 else
1076 containing_type_scm = tyscm_scm_from_type (containing_type);
1078 return gdbscm_make_iterator (containing_type_scm, scm_from_int (0),
1079 tyscm_next_field_x_proc);
1082 /* (type-next-field! <gdb:iterator>) -> <gdb:field>
1083 Return the next field in the iteration through the list of fields of the
1084 type, or (end-of-iteration).
1085 SELF is a <gdb:iterator> object created by gdbscm_make_field_iterator.
1086 This is the next! <gdb:iterator> function, not exported to the user. */
1088 static SCM
1089 gdbscm_type_next_field_x (SCM self)
1091 iterator_smob *i_smob;
1092 type_smob *t_smob;
1093 struct type *type;
1094 SCM it_scm, result, progress, object;
1095 int field;
1097 it_scm = itscm_get_iterator_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1098 i_smob = (iterator_smob *) SCM_SMOB_DATA (it_scm);
1099 object = itscm_iterator_smob_object (i_smob);
1100 progress = itscm_iterator_smob_progress (i_smob);
1102 SCM_ASSERT_TYPE (tyscm_is_type (object), object,
1103 SCM_ARG1, FUNC_NAME, type_smob_name);
1104 t_smob = (type_smob *) SCM_SMOB_DATA (object);
1105 type = t_smob->type;
1107 SCM_ASSERT_TYPE (scm_is_signed_integer (progress,
1108 0, TYPE_NFIELDS (type)),
1109 progress, SCM_ARG1, FUNC_NAME, _("integer"));
1110 field = scm_to_int (progress);
1112 if (field < TYPE_NFIELDS (type))
1114 result = tyscm_make_field_smob (object, field);
1115 itscm_set_iterator_smob_progress_x (i_smob, scm_from_int (field + 1));
1116 return result;
1119 return gdbscm_end_of_iteration ();
1122 /* Field smob accessors. */
1124 /* (field-name <gdb:field>) -> string
1125 Return the name of this field or #f if there isn't one. */
1127 static SCM
1128 gdbscm_field_name (SCM self)
1130 field_smob *f_smob
1131 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1132 struct field *field = tyscm_field_smob_to_field (f_smob);
1134 if (FIELD_NAME (*field))
1135 return gdbscm_scm_from_c_string (FIELD_NAME (*field));
1136 return SCM_BOOL_F;
1139 /* (field-type <gdb:field>) -> <gdb:type>
1140 Return the <gdb:type> object of the field or #f if there isn't one. */
1142 static SCM
1143 gdbscm_field_type (SCM self)
1145 field_smob *f_smob
1146 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1147 struct field *field = tyscm_field_smob_to_field (f_smob);
1149 /* A field can have a NULL type in some situations. */
1150 if (FIELD_TYPE (*field))
1151 return tyscm_scm_from_type (FIELD_TYPE (*field));
1152 return SCM_BOOL_F;
1155 /* (field-enumval <gdb:field>) -> integer
1156 For enum values, return its value as an integer. */
1158 static SCM
1159 gdbscm_field_enumval (SCM self)
1161 field_smob *f_smob
1162 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1163 struct field *field = tyscm_field_smob_to_field (f_smob);
1164 struct type *type = tyscm_field_smob_containing_type (f_smob);
1166 SCM_ASSERT_TYPE (TYPE_CODE (type) == TYPE_CODE_ENUM,
1167 self, SCM_ARG1, FUNC_NAME, _("enum type"));
1169 return scm_from_long (FIELD_ENUMVAL (*field));
1172 /* (field-bitpos <gdb:field>) -> integer
1173 For bitfields, return its offset in bits. */
1175 static SCM
1176 gdbscm_field_bitpos (SCM self)
1178 field_smob *f_smob
1179 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1180 struct field *field = tyscm_field_smob_to_field (f_smob);
1181 struct type *type = tyscm_field_smob_containing_type (f_smob);
1183 SCM_ASSERT_TYPE (TYPE_CODE (type) != TYPE_CODE_ENUM,
1184 self, SCM_ARG1, FUNC_NAME, _("non-enum type"));
1186 return scm_from_long (FIELD_BITPOS (*field));
1189 /* (field-bitsize <gdb:field>) -> integer
1190 Return the size of the field in bits. */
1192 static SCM
1193 gdbscm_field_bitsize (SCM self)
1195 field_smob *f_smob
1196 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1197 struct field *field = tyscm_field_smob_to_field (f_smob);
1199 return scm_from_long (FIELD_BITPOS (*field));
1202 /* (field-artificial? <gdb:field>) -> boolean
1203 Return #t if field is artificial. */
1205 static SCM
1206 gdbscm_field_artificial_p (SCM self)
1208 field_smob *f_smob
1209 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1210 struct field *field = tyscm_field_smob_to_field (f_smob);
1212 return scm_from_bool (FIELD_ARTIFICIAL (*field));
1215 /* (field-baseclass? <gdb:field>) -> boolean
1216 Return #t if field is a baseclass. */
1218 static SCM
1219 gdbscm_field_baseclass_p (SCM self)
1221 field_smob *f_smob
1222 = tyscm_get_field_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
1223 struct type *type = tyscm_field_smob_containing_type (f_smob);
1225 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1226 return scm_from_bool (f_smob->field_num < TYPE_N_BASECLASSES (type));
1227 return SCM_BOOL_F;
1230 /* Return the type named TYPE_NAME in BLOCK.
1231 Returns NULL if not found.
1232 This routine does not throw an error. */
1234 static struct type *
1235 tyscm_lookup_typename (const char *type_name, const struct block *block)
1237 struct type *type = NULL;
1241 if (startswith (type_name, "struct "))
1242 type = lookup_struct (type_name + 7, NULL);
1243 else if (startswith (type_name, "union "))
1244 type = lookup_union (type_name + 6, NULL);
1245 else if (startswith (type_name, "enum "))
1246 type = lookup_enum (type_name + 5, NULL);
1247 else
1248 type = lookup_typename (current_language,
1249 type_name, block, 0);
1251 catch (const gdb_exception &except)
1253 return NULL;
1256 return type;
1259 /* (lookup-type name [#:block <gdb:block>]) -> <gdb:type>
1260 TODO: legacy template support left out until needed. */
1262 static SCM
1263 gdbscm_lookup_type (SCM name_scm, SCM rest)
1265 SCM keywords[] = { block_keyword, SCM_BOOL_F };
1266 char *name;
1267 SCM block_scm = SCM_BOOL_F;
1268 int block_arg_pos = -1;
1269 const struct block *block = NULL;
1270 struct type *type;
1272 gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, keywords, "s#O",
1273 name_scm, &name,
1274 rest, &block_arg_pos, &block_scm);
1276 if (block_arg_pos != -1)
1278 SCM exception;
1280 block = bkscm_scm_to_block (block_scm, block_arg_pos, FUNC_NAME,
1281 &exception);
1282 if (block == NULL)
1284 xfree (name);
1285 gdbscm_throw (exception);
1288 type = tyscm_lookup_typename (name, block);
1289 xfree (name);
1291 if (type != NULL)
1292 return tyscm_scm_from_type (type);
1293 return SCM_BOOL_F;
1296 /* Initialize the Scheme type code. */
1299 static const scheme_integer_constant type_integer_constants[] =
1301 #define X(SYM) { #SYM, SYM }
1302 X (TYPE_CODE_BITSTRING),
1303 X (TYPE_CODE_PTR),
1304 X (TYPE_CODE_ARRAY),
1305 X (TYPE_CODE_STRUCT),
1306 X (TYPE_CODE_UNION),
1307 X (TYPE_CODE_ENUM),
1308 X (TYPE_CODE_FLAGS),
1309 X (TYPE_CODE_FUNC),
1310 X (TYPE_CODE_INT),
1311 X (TYPE_CODE_FLT),
1312 X (TYPE_CODE_VOID),
1313 X (TYPE_CODE_SET),
1314 X (TYPE_CODE_RANGE),
1315 X (TYPE_CODE_STRING),
1316 X (TYPE_CODE_ERROR),
1317 X (TYPE_CODE_METHOD),
1318 X (TYPE_CODE_METHODPTR),
1319 X (TYPE_CODE_MEMBERPTR),
1320 X (TYPE_CODE_REF),
1321 X (TYPE_CODE_CHAR),
1322 X (TYPE_CODE_BOOL),
1323 X (TYPE_CODE_COMPLEX),
1324 X (TYPE_CODE_TYPEDEF),
1325 X (TYPE_CODE_NAMESPACE),
1326 X (TYPE_CODE_DECFLOAT),
1327 X (TYPE_CODE_INTERNAL_FUNCTION),
1328 #undef X
1330 END_INTEGER_CONSTANTS
1333 static const scheme_function type_functions[] =
1335 { "type?", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_p),
1337 Return #t if the object is a <gdb:type> object." },
1339 { "lookup-type", 1, 0, 1, as_a_scm_t_subr (gdbscm_lookup_type),
1341 Return the <gdb:type> object representing string or #f if not found.\n\
1342 If block is given then the type is looked for in that block.\n\
1344 Arguments: string [#:block <gdb:block>]" },
1346 { "type-code", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_code),
1348 Return the code of the type" },
1350 { "type-tag", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_tag),
1352 Return the tag name of the type, or #f if there isn't one." },
1354 { "type-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_name),
1356 Return the name of the type as a string, or #f if there isn't one." },
1358 { "type-print-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_print_name),
1360 Return the print name of the type as a string." },
1362 { "type-sizeof", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_sizeof),
1364 Return the size of the type, in bytes." },
1366 { "type-strip-typedefs", 1, 0, 0,
1367 as_a_scm_t_subr (gdbscm_type_strip_typedefs),
1369 Return a type formed by stripping the type of all typedefs." },
1371 { "type-array", 2, 1, 0, as_a_scm_t_subr (gdbscm_type_array),
1373 Return a type representing an array of objects of the type.\n\
1375 Arguments: <gdb:type> [low-bound] high-bound\n\
1376 If low-bound is not provided zero is used.\n\
1377 N.B. If only the high-bound parameter is specified, it is not\n\
1378 the array size.\n\
1379 Valid bounds for array indices are [low-bound,high-bound]." },
1381 { "type-vector", 2, 1, 0, as_a_scm_t_subr (gdbscm_type_vector),
1383 Return a type representing a vector of objects of the type.\n\
1384 Vectors differ from arrays in that if the current language has C-style\n\
1385 arrays, vectors don't decay to a pointer to the first element.\n\
1386 They are first class values.\n\
1388 Arguments: <gdb:type> [low-bound] high-bound\n\
1389 If low-bound is not provided zero is used.\n\
1390 N.B. If only the high-bound parameter is specified, it is not\n\
1391 the array size.\n\
1392 Valid bounds for array indices are [low-bound,high-bound]." },
1394 { "type-pointer", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_pointer),
1396 Return a type of pointer to the type." },
1398 { "type-range", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_range),
1400 Return (low high) representing the range for the type." },
1402 { "type-reference", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_reference),
1404 Return a type of reference to the type." },
1406 { "type-target", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_target),
1408 Return the target type of the type." },
1410 { "type-const", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_const),
1412 Return a const variant of the type." },
1414 { "type-volatile", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_volatile),
1416 Return a volatile variant of the type." },
1418 { "type-unqualified", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_unqualified),
1420 Return a variant of the type without const or volatile attributes." },
1422 { "type-num-fields", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_num_fields),
1424 Return the number of fields of the type." },
1426 { "type-fields", 1, 0, 0, as_a_scm_t_subr (gdbscm_type_fields),
1428 Return the list of <gdb:field> objects of fields of the type." },
1430 { "make-field-iterator", 1, 0, 0,
1431 as_a_scm_t_subr (gdbscm_make_field_iterator),
1433 Return a <gdb:iterator> object for iterating over the fields of the type." },
1435 { "type-field", 2, 0, 0, as_a_scm_t_subr (gdbscm_type_field),
1437 Return the field named by string of the type.\n\
1439 Arguments: <gdb:type> string" },
1441 { "type-has-field?", 2, 0, 0, as_a_scm_t_subr (gdbscm_type_has_field_p),
1443 Return #t if the type has field named string.\n\
1445 Arguments: <gdb:type> string" },
1447 { "field?", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_p),
1449 Return #t if the object is a <gdb:field> object." },
1451 { "field-name", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_name),
1453 Return the name of the field." },
1455 { "field-type", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_type),
1457 Return the type of the field." },
1459 { "field-enumval", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_enumval),
1461 Return the enum value represented by the field." },
1463 { "field-bitpos", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_bitpos),
1465 Return the offset in bits of the field in its containing type." },
1467 { "field-bitsize", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_bitsize),
1469 Return the size of the field in bits." },
1471 { "field-artificial?", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_artificial_p),
1473 Return #t if the field is artificial." },
1475 { "field-baseclass?", 1, 0, 0, as_a_scm_t_subr (gdbscm_field_baseclass_p),
1477 Return #t if the field is a baseclass." },
1479 END_FUNCTIONS
1482 void
1483 gdbscm_initialize_types (void)
1485 type_smob_tag = gdbscm_make_smob_type (type_smob_name, sizeof (type_smob));
1486 scm_set_smob_free (type_smob_tag, tyscm_free_type_smob);
1487 scm_set_smob_print (type_smob_tag, tyscm_print_type_smob);
1488 scm_set_smob_equalp (type_smob_tag, tyscm_equal_p_type_smob);
1490 field_smob_tag = gdbscm_make_smob_type (field_smob_name,
1491 sizeof (field_smob));
1492 scm_set_smob_print (field_smob_tag, tyscm_print_field_smob);
1494 gdbscm_define_integer_constants (type_integer_constants, 1);
1495 gdbscm_define_functions (type_functions, 1);
1497 /* This function is "private". */
1498 tyscm_next_field_x_proc
1499 = scm_c_define_gsubr ("%type-next-field!", 1, 0, 0,
1500 as_a_scm_t_subr (gdbscm_type_next_field_x));
1501 scm_set_procedure_property_x (tyscm_next_field_x_proc,
1502 gdbscm_documentation_symbol,
1503 gdbscm_scm_from_c_string ("\
1504 Internal function to assist the type fields iterator."));
1506 block_keyword = scm_from_latin1_keyword ("block");
1508 /* Register an objfile "free" callback so we can properly copy types
1509 associated with the objfile when it's about to be deleted. */
1510 tyscm_objfile_data_key
1511 = register_objfile_data_with_cleanup (save_objfile_types, NULL);
1513 global_types_map = gdbscm_create_eqable_gsmob_ptr_map (tyscm_hash_type_smob,
1514 tyscm_eq_type_smob);