guile/libguile/smob.c

673 lines
16 KiB
C
Raw Normal View History

/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
2005-05-23 19:57:22 +00:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <errno.h>
#include "libguile/_scm.h"
C files should #include only the header files they need, not libguile.h (which #includes all the header files); the pointless recompilation was wasting my time. * Makefile.in (all .o dependency lists): Regenerated. * libguile.h: Don't try to get a definition for size_t here... * __scm.h: Do it here. * _scm.h: Since this is the internal libguile header, put things here that all (or a majority) of the libguile files will want. Don't #include <libguile.h> here; that generates dependencies on way too much. Instead, get "__scm.h", "error.h", "pairs.h", "list.h", "gc.h", "gsubr.h", "procs.h", "numbers.h", "symbols.h", "boolean.h", "strings.h", "vectors.h", "root.h", "ports.h", and "async.h". * alist.c: Get "eq.h", "list.h", "alist.h". * append.c: Get "append.h", "list.h". * arbiters.c: Get "arbiters.h", "smob.h". * async.c: Get "async.h", "smob.h", "throw.h", "eval.h". * boolean.c: Get "boolean.h". * chars.c: Get "chars.h". * continuations.c: Get "continuations.h", "dynwind.h", "debug.h", "stackchk.h". * debug.c: Get "debug.h", "feature.h", "read.h", "strports.h", "continuations.h", "alist.h", "srcprop.h", "procprop.h", "smob.h", "genio.h", "throw.h", "eval.h". * dynwind.c: Get "dynwind.h", "alist.h", "eval.h". * eq.c: Get "eq.h", "unif.h", "smob.h", "strorder.h", "stackchk.h". * error.c: Get "error.h", "throw.h", "genio.h", "pairs.h". * eval.c: Get "eval.h", "stackchk.h", "srcprop.h", "debug.h", "hashtab.h", "procprop.h", "markers.h", "smob.h", "throw.h", "continuations.h", "eq.h", "sequences.h", "alist.h", "append.h", "debug.h". * fdsocket.c: Get "fdsocket.h", "unif.h", "filesys.h". * feature.c: Get "feature.h". * files.c: Get "files.h". * filesys.c: Get "filesys.h", "smob.h", "genio.h". * fports.c: Get "fports.h", "markers.h". * gc.c: Get "async.h", "unif.h", "smob.h", "weaks.h", "genio.h", "struct.h", "stackchk.h", "stime.h". * gdbint.c: Get "gdbint.h", "chars.h", "eval.h", "print.h", "read.h", "strports.h", "tag.h". * genio.c: Get "genio.h", "chars.h". * gsubr.c: Get "gsubr.h", "genio.h". * hash.c: Get "hash.h", "chars.h". * hashtab.c: Get "hashtab.h", "eval.h", "hash.h", "alist.h". * init.c: Get everyone who has an scm_init_mumble function: "weaks.h", "vports.h", "version.h", "vectors.h", "variable.h", "unif.h", "throw.h", "tag.h", "symbols.h", "struct.h", "strports.h", "strorder.h", "strop.h", "strings.h", "stime.h", "stackchk.h", "srcprop.h", "socket.h", "simpos.h", "sequences.h", "scmsigs.h", "read.h", "ramap.h", "procs.h", "procprop.h", "print.h", "posix.h", "ports.h", "pairs.h", "options.h", "objprop.h", "numbers.h", "mbstrings.h", "mallocs.h", "load.h", "list.h", "kw.h", "ioext.h", "hashtab.h", "hash.h", "gsubr.h", "gdbint.h", "gc.h", "fports.h", "filesys.h", "files.h", "feature.h", "fdsocket.h", "eval.h", "error.h", "eq.h", "dynwind.h", "debug.h", "continuations.h", "chars.h", "boolean.h", "async.h", "arbiters.h", "append.h", "alist.h". * ioext.c: Get "ioext.h", "fports.h". * kw.c: Get "kw.h", "smob.h", "mbstrings.h", "genio.h". * list.c: Get "list.h", "eq.h". * load.c: Get "load.h", "eval.h", "read.h", "fports.h". * mallocs.c: Get "smob.h", "genio.h". * markers.c: Get "markers.h". * mbstrings.c: Get "mbstrings.h", "read.h", "genio.h", "unif.h", "chars.h". * numbers.c: Get "unif.h", "genio.h". * objprop.c: Get "objprop.h", "weaks.h", "alist.h", "hashtab.h". * options.c: Get "options.h". * ports.c: Get "ports.h", "vports.h", "strports.h", "fports.h", "markers.h", "chars.h", "genio.h". * posix.c: Get "posix.h", "sequences.h", "feature.h", "unif.h", "read.h", "scmsigs.h", "genio.h", "fports.h". * print.c: Get "print.h", "unif.h", "weaks.h", "read.h", "procprop.h", "eval.h", "smob.h", "mbstrings.h", "genio.h", "chars.h". * procprop.c: Get "procprop.h", "eval.h", "alist.h". * procs.c: Get "procs.h". * ramap.c: Get "ramap.h", "feature.h", "eval.h", "eq.h", "chars.h", "smob.h", "unif.h". * read.c: Get "alist.h", "kw.h", "mbstrings.h", "unif.h", "eval.h", "genio.h", "chars.h". * root.c: Get "root.h", "stackchk.h". * scmsigs.c: Get "scmsigs.h". * sequences.c: Get "sequences.h". * simpos.c: Get "simpos.h", "scmsigs.h". * smob.c: Get "smob.h". * socket.c: Get "socket.h", "feature.h". * srcprop.c: Get "srcprop.h", "weaks.h", "hashtab.h", "debug.h", "alist.h", "smob.h". * stackchk.c: Get "stackchk.h", "genio.h". * stime.c: Get "stime.h"."libguile/continuations.h". * strings.c: Get "strings.h", "chars.h". * strop.c: Get "strop.h", "chars.h". * strorder.c: Get "strorder.h", "chars.h". * strports.c: Get "strports.h", "print.h", "eval.h", "unif.h". * struct.c: Get "struct.h", "chars.h". * symbols.c: Get "symbols.h", "mbstrings.h", "alist.h", "variable.h", "eval.h", "chars.h". * tag.c: Get "tag.h", "struct.h", "chars.h". * throw.c: Get "throw.h", "continuations.h", "debug.h", "dynwind.h", "eval.h", "alist.h", "smob.h", "genio.h". * unif.c: Get "unif.h", "feature.h", "strop.h", "sequences.h", "smob.h", "genio.h", "eval.h", "chars.h". * variable.c: Get "variable.h", "smob.h", "genio.h". * vectors.c: Get "vectors.h", "eq.h". * version.c: Get "version.h". * vports.c: Get "vports.h", "fports.h", "chars.h", "eval.h". * weaks.c: Get "weaks.h".
1996-09-10 02:26:07 +00:00
#include "libguile/async.h"
#include "libguile/objects.h"
2005-01-18 13:59:04 +00:00
#include "libguile/goops.h"
#include "libguile/ports.h"
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include "libguile/smob.h"
#include "libguile/boehm-gc.h"
#include <gc/gc_mark.h>
/* scm_smobs scm_numsmob
* implement a fixed sized array of smob records.
* Indexes into this table are used when generating type
* tags for smobjects (if you know a tag you can get an index and conversely).
*/
#define MAX_SMOB_COUNT SCM_I_MAX_SMOB_TYPE_COUNT
long scm_numsmob;
scm_smob_descriptor scm_smobs[MAX_SMOB_COUNT];
/* Lower 16 bit of data must be zero.
*/
void
scm_i_set_smob_flags (SCM x, scm_t_bits data)
{
SCM_SET_CELL_WORD_0 (x, (SCM_CELL_WORD_0 (x) & 0xFFFF) | data);
}
2004-09-24 01:46:09 +00:00
void
scm_assert_smob_type (scm_t_bits tag, SCM val)
{
if (!SCM_SMOB_PREDICATE (tag, val))
scm_wrong_type_arg_msg (NULL, 0, val, scm_smobs[SCM_TC2SMOBNUM(tag)].name);
}
/* {Mark}
*/
/* This function is vestigial. It used to be the mark function's
responsibility to set the mark bit on the smob or port, but now the
generic marking routine in gc.c takes care of that, and a zero
pointer for a mark function means "don't bother". So you never
need scm_mark0.
However, we leave it here because it's harmless to call it, and
people out there have smob code that uses it, and there's no reason
to make their links fail. */
SCM
scm_mark0 (SCM ptr SCM_UNUSED)
{
return SCM_BOOL_F;
}
SCM
/* Dirk::FIXME: The name markcdr is misleading, since the term cdr should only
be used for real pairs. */
scm_markcdr (SCM ptr)
{
return SCM_CELL_OBJECT_1 (ptr);
}
/* {Free}
*/
* validate.h (SCM_NUM2{SIZE,PTRDIFF,SHORT,USHORT,BITS,UBITS,INT,UINT}[_DEF]): new macros. * unif.h: type renaming: scm_array -> scm_array_t scm_array_dim -> scm_array_dim_t the old names are deprecated, all in-Guile uses changed. * tags.h (scm_ubits_t): new typedef, representing unsigned scm_bits_t. * stacks.h: type renaming: scm_info_frame -> scm_info_frame_t scm_stack -> scm_stack_t the old names are deprecated, all in-Guile uses changed. * srcprop.h: type renaming: scm_srcprops -> scm_srcprops_t scm_srcprops_chunk -> scm_srcprops_chunk_t the old names are deprecated, all in-Guile uses changed. * gsubr.c, procs.c, print.c, ports.c, read.c, rdelim.c, ramap.c, rw.c, smob.c, sort.c, srcprop.c, stacks.c, strings.c, strop.c, strorder.c, strports.c, struct.c, symbols.c, unif.c, values.c, vectors.c, vports.c, weaks.c: various int/size_t -> size_t/scm_bits_t changes. * random.h: type renaming: scm_rstate -> scm_rstate_t scm_rng -> scm_rng_t scm_i_rstate -> scm_i_rstate_t the old names are deprecated, all in-Guile uses changed. * procs.h: type renaming: scm_subr_entry -> scm_subr_entry_t the old name is deprecated, all in-Guile uses changed. * options.h (scm_option_t.val): unsigned long -> scm_bits_t. type renaming: scm_option -> scm_option_t the old name is deprecated, all in-Guile uses changed. * objects.c: various long -> scm_bits_t changes. (scm_i_make_class_object): flags: unsigned long -> scm_ubits_t * numbers.h (SCM_FIXNUM_BIT): deprecated, renamed to SCM_I_FIXNUM_BIT. * num2integral.i.c: new file, multiply included by numbers.c, used to "templatize" the various integral <-> num conversion routines. * numbers.c (scm_mkbig, scm_big2num, scm_adjbig, scm_normbig, scm_copybig, scm_2ulong2big, scm_dbl2big, scm_big2dbl): deprecated. (scm_i_mkbig, scm_i_big2inum, scm_i_adjbig, scm_i_normbig, scm_i_copybig, scm_i_short2big, scm_i_ushort2big, scm_i_int2big, scm_i_uint2big, scm_i_long2big, scm_i_ulong2big, scm_i_bits2big, scm_i_ubits2big, scm_i_size2big, scm_i_ptrdiff2big, scm_i_long_long2big, scm_i_ulong_long2big, scm_i_dbl2big, scm_i_big2dbl, scm_short2num, scm_ushort2num, scm_int2num, scm_uint2num, scm_bits2num, scm_ubits2num, scm_size2num, scm_ptrdiff2num, scm_num2short, scm_num2ushort, scm_num2int, scm_num2uint, scm_num2bits, scm_num2ubits, scm_num2ptrdiff, scm_num2size): new functions. * modules.c (scm_module_reverse_lookup): i, n: int -> scm_bits_t.x * load.c: change int -> size_t in various places (where the variable is used to store a string length). (search-path): call scm_done_free, not scm_done_malloc. * list.c (scm_ilength): return a scm_bits_t, not long. some other {int,long} -> scm_bits_t changes. * hashtab.c: various [u]int -> scm_bits_t changes. scm_ihashx_closure -> scm_ihashx_closure_t (and made a typedef). (scm_ihashx): n: uint -> scm_bits_t use scm_bits2num instead of scm_ulong2num. * gsubr.c: various int -> scm_bits_t changes. * gh_data.c (gh_scm2double): no loss of precision any more. * gh.h (gh_str2scm): len: int -> size_t (gh_{get,set}_substr): start: int -> scm_bits_t, len: int -> size_t (gh_<num>2scm): n: int -> scm_bits_t (gh_*vector_length): return scm_[u]size_t, not unsigned long. (gh_length): return scm_bits_t, not unsigned long. * fports.h: type renaming: scm_fport -> scm_fport_t the old name is deprecated, all in-Guile uses changed. * fports.c (fport_fill_input): count: int -> scm_bits_t (fport_flush): init_size, remaining, count: int -> scm_bits_t * debug.h (scm_lookup_cstr, scm_lookup_soft, scm_evstr): removed those prototypes, as the functions they prototype don't exist. * fports.c (default_buffer_size): int -> size_t (scm_fport_buffer_add): read_size, write_size: int -> scm_bits_t default_size: int -> size_t (scm_setvbuf): csize: int -> scm_bits_t * fluids.c (n_fluids): int -> scm_bits_t (grow_fluids): old_length, i: int -> scm_bits_t (next_fluid_num, scm_fluid_ref, scm_fluid_set_x): n: int -> scm_bits_t (scm_c_with_fluids): flen, vlen: int -> scm_bits_t * filesys.c (s_scm_open_fdes): changed calls to SCM_NUM2LONG to the new and shiny SCM_NUM2INT. * extensions.c: extension -> extension_t (and made a typedef). * eval.h (SCM_IFRAME): cast to scm_bits_t, not int. just so there are no nasty surprises if/when the various deeply magic tag bits move somewhere else. * eval.c: changed the locals used to store results of SCM_IFRAME, scm_ilength and such to be of type scm_bits_t (and not int/long). (iqq): depth, edepth: int -> scm_bits_t (scm_eval_stack): int -> scm_bits_t (SCM_CEVAL): various vars are not scm_bits_t instead of int. (check_map_args, scm_map, scm_for_each): len: long -> scm_bits_t i: int -> scm_bits_t * environments.c: changed the many calls to scm_ulong2num to scm_ubits2num. (import_environment_fold): proc_as_ul: ulong -> scm_ubits_t * dynwind.c (scm_dowinds): delta: long -> scm_bits_t * debug.h: type renaming: scm_debug_info -> scm_debug_info_t scm_debug_frame -> scm_debug_frame_t the old names are deprecated, all in-Guile uses changed. (scm_debug_eframe_size): int -> scm_bits_t * debug.c (scm_init_debug): use scm_c_define instead of the deprecated scm_define. * continuations.h: type renaming: scm_contregs -> scm_contregs_t the old name is deprecated, all in-Guile uses changed. (scm_contregs_t.num_stack_items): size_t -> scm_bits_t (scm_contregs_t.num_stack_items): ulong -> scm_ubits_t * continuations.c (scm_make_continuation): change the type of stack_size form long to scm_bits_t. * ports.h: type renaming: scm_port_rw_active -> scm_port_rw_active_t (and made a typedef) scm_port -> scm_port_t scm_ptob_descriptor -> scm_ptob_descriptor_t the old names are deprecated, all in-Guile uses changed. (scm_port_t.entry): int -> scm_bits_t. (scm_port_t.line_number): int -> long. (scm_port_t.putback_buf_size): int -> size_t. * __scm.h (long_long, ulong_long): deprecated (they pollute the global namespace and have little value besides that). (SCM_BITS_LENGTH): new, is the bit size of scm_bits_t (i.e. of an SCM handle). (ifdef spaghetti): include sys/types.h and sys/stdtypes.h, if they exist (for size_t & ptrdiff_t) (scm_sizet): deprecated. * Makefile.am (noinst_HEADERS): add num2integral.i.c
2001-05-24 00:50:51 +00:00
size_t
scm_free0 (SCM ptr SCM_UNUSED)
{
return 0;
}
* validate.h (SCM_NUM2{SIZE,PTRDIFF,SHORT,USHORT,BITS,UBITS,INT,UINT}[_DEF]): new macros. * unif.h: type renaming: scm_array -> scm_array_t scm_array_dim -> scm_array_dim_t the old names are deprecated, all in-Guile uses changed. * tags.h (scm_ubits_t): new typedef, representing unsigned scm_bits_t. * stacks.h: type renaming: scm_info_frame -> scm_info_frame_t scm_stack -> scm_stack_t the old names are deprecated, all in-Guile uses changed. * srcprop.h: type renaming: scm_srcprops -> scm_srcprops_t scm_srcprops_chunk -> scm_srcprops_chunk_t the old names are deprecated, all in-Guile uses changed. * gsubr.c, procs.c, print.c, ports.c, read.c, rdelim.c, ramap.c, rw.c, smob.c, sort.c, srcprop.c, stacks.c, strings.c, strop.c, strorder.c, strports.c, struct.c, symbols.c, unif.c, values.c, vectors.c, vports.c, weaks.c: various int/size_t -> size_t/scm_bits_t changes. * random.h: type renaming: scm_rstate -> scm_rstate_t scm_rng -> scm_rng_t scm_i_rstate -> scm_i_rstate_t the old names are deprecated, all in-Guile uses changed. * procs.h: type renaming: scm_subr_entry -> scm_subr_entry_t the old name is deprecated, all in-Guile uses changed. * options.h (scm_option_t.val): unsigned long -> scm_bits_t. type renaming: scm_option -> scm_option_t the old name is deprecated, all in-Guile uses changed. * objects.c: various long -> scm_bits_t changes. (scm_i_make_class_object): flags: unsigned long -> scm_ubits_t * numbers.h (SCM_FIXNUM_BIT): deprecated, renamed to SCM_I_FIXNUM_BIT. * num2integral.i.c: new file, multiply included by numbers.c, used to "templatize" the various integral <-> num conversion routines. * numbers.c (scm_mkbig, scm_big2num, scm_adjbig, scm_normbig, scm_copybig, scm_2ulong2big, scm_dbl2big, scm_big2dbl): deprecated. (scm_i_mkbig, scm_i_big2inum, scm_i_adjbig, scm_i_normbig, scm_i_copybig, scm_i_short2big, scm_i_ushort2big, scm_i_int2big, scm_i_uint2big, scm_i_long2big, scm_i_ulong2big, scm_i_bits2big, scm_i_ubits2big, scm_i_size2big, scm_i_ptrdiff2big, scm_i_long_long2big, scm_i_ulong_long2big, scm_i_dbl2big, scm_i_big2dbl, scm_short2num, scm_ushort2num, scm_int2num, scm_uint2num, scm_bits2num, scm_ubits2num, scm_size2num, scm_ptrdiff2num, scm_num2short, scm_num2ushort, scm_num2int, scm_num2uint, scm_num2bits, scm_num2ubits, scm_num2ptrdiff, scm_num2size): new functions. * modules.c (scm_module_reverse_lookup): i, n: int -> scm_bits_t.x * load.c: change int -> size_t in various places (where the variable is used to store a string length). (search-path): call scm_done_free, not scm_done_malloc. * list.c (scm_ilength): return a scm_bits_t, not long. some other {int,long} -> scm_bits_t changes. * hashtab.c: various [u]int -> scm_bits_t changes. scm_ihashx_closure -> scm_ihashx_closure_t (and made a typedef). (scm_ihashx): n: uint -> scm_bits_t use scm_bits2num instead of scm_ulong2num. * gsubr.c: various int -> scm_bits_t changes. * gh_data.c (gh_scm2double): no loss of precision any more. * gh.h (gh_str2scm): len: int -> size_t (gh_{get,set}_substr): start: int -> scm_bits_t, len: int -> size_t (gh_<num>2scm): n: int -> scm_bits_t (gh_*vector_length): return scm_[u]size_t, not unsigned long. (gh_length): return scm_bits_t, not unsigned long. * fports.h: type renaming: scm_fport -> scm_fport_t the old name is deprecated, all in-Guile uses changed. * fports.c (fport_fill_input): count: int -> scm_bits_t (fport_flush): init_size, remaining, count: int -> scm_bits_t * debug.h (scm_lookup_cstr, scm_lookup_soft, scm_evstr): removed those prototypes, as the functions they prototype don't exist. * fports.c (default_buffer_size): int -> size_t (scm_fport_buffer_add): read_size, write_size: int -> scm_bits_t default_size: int -> size_t (scm_setvbuf): csize: int -> scm_bits_t * fluids.c (n_fluids): int -> scm_bits_t (grow_fluids): old_length, i: int -> scm_bits_t (next_fluid_num, scm_fluid_ref, scm_fluid_set_x): n: int -> scm_bits_t (scm_c_with_fluids): flen, vlen: int -> scm_bits_t * filesys.c (s_scm_open_fdes): changed calls to SCM_NUM2LONG to the new and shiny SCM_NUM2INT. * extensions.c: extension -> extension_t (and made a typedef). * eval.h (SCM_IFRAME): cast to scm_bits_t, not int. just so there are no nasty surprises if/when the various deeply magic tag bits move somewhere else. * eval.c: changed the locals used to store results of SCM_IFRAME, scm_ilength and such to be of type scm_bits_t (and not int/long). (iqq): depth, edepth: int -> scm_bits_t (scm_eval_stack): int -> scm_bits_t (SCM_CEVAL): various vars are not scm_bits_t instead of int. (check_map_args, scm_map, scm_for_each): len: long -> scm_bits_t i: int -> scm_bits_t * environments.c: changed the many calls to scm_ulong2num to scm_ubits2num. (import_environment_fold): proc_as_ul: ulong -> scm_ubits_t * dynwind.c (scm_dowinds): delta: long -> scm_bits_t * debug.h: type renaming: scm_debug_info -> scm_debug_info_t scm_debug_frame -> scm_debug_frame_t the old names are deprecated, all in-Guile uses changed. (scm_debug_eframe_size): int -> scm_bits_t * debug.c (scm_init_debug): use scm_c_define instead of the deprecated scm_define. * continuations.h: type renaming: scm_contregs -> scm_contregs_t the old name is deprecated, all in-Guile uses changed. (scm_contregs_t.num_stack_items): size_t -> scm_bits_t (scm_contregs_t.num_stack_items): ulong -> scm_ubits_t * continuations.c (scm_make_continuation): change the type of stack_size form long to scm_bits_t. * ports.h: type renaming: scm_port_rw_active -> scm_port_rw_active_t (and made a typedef) scm_port -> scm_port_t scm_ptob_descriptor -> scm_ptob_descriptor_t the old names are deprecated, all in-Guile uses changed. (scm_port_t.entry): int -> scm_bits_t. (scm_port_t.line_number): int -> long. (scm_port_t.putback_buf_size): int -> size_t. * __scm.h (long_long, ulong_long): deprecated (they pollute the global namespace and have little value besides that). (SCM_BITS_LENGTH): new, is the bit size of scm_bits_t (i.e. of an SCM handle). (ifdef spaghetti): include sys/types.h and sys/stdtypes.h, if they exist (for size_t & ptrdiff_t) (scm_sizet): deprecated. * Makefile.am (noinst_HEADERS): add num2integral.i.c
2001-05-24 00:50:51 +00:00
size_t
scm_smob_free (SCM obj)
{
long n = SCM_SMOBNUM (obj);
if (scm_smobs[n].size > 0)
scm_gc_free ((void *) SCM_CELL_WORD_1 (obj),
scm_smobs[n].size, SCM_SMOBNAME (n));
return 0;
}
/* {Print}
*/
int
scm_smob_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
{
long n = SCM_SMOBNUM (exp);
scm_puts ("#<", port);
scm_puts (SCM_SMOBNAME (n) ? SCM_SMOBNAME (n) : "smob", port);
scm_putc (' ', port);
if (scm_smobs[n].size)
scm_uintprint (SCM_CELL_WORD_1 (exp), 16, port);
else
scm_uintprint (SCM_UNPACK (exp), 16, port);
scm_putc ('>', port);
return 1;
}
/* {Apply}
*/
2000-12-07 00:55:12 +00:00
#define SCM_SMOB_APPLY0(SMOB) \
SCM_SMOB_DESCRIPTOR (SMOB).apply (SMOB)
#define SCM_SMOB_APPLY1(SMOB, A1) \
2000-12-07 00:55:12 +00:00
SCM_SMOB_DESCRIPTOR (SMOB).apply (SMOB, A1)
#define SCM_SMOB_APPLY2(SMOB, A1, A2) \
2000-12-07 00:55:12 +00:00
SCM_SMOB_DESCRIPTOR (SMOB).apply (SMOB, A1, A2)
#define SCM_SMOB_APPLY3(SMOB, A1, A2, A3) \
2000-12-07 00:55:12 +00:00
SCM_SMOB_DESCRIPTOR (SMOB).apply (SMOB, A1, A2, A3)
static SCM
scm_smob_apply_0_010 (SCM smob)
{
2000-12-07 00:55:12 +00:00
return SCM_SMOB_APPLY1 (smob, SCM_UNDEFINED);
}
2000-12-07 00:55:12 +00:00
static SCM
scm_smob_apply_0_020 (SCM smob)
{
2000-12-07 00:55:12 +00:00
return SCM_SMOB_APPLY2 (smob, SCM_UNDEFINED, SCM_UNDEFINED);
}
2000-12-07 00:55:12 +00:00
static SCM
scm_smob_apply_0_030 (SCM smob)
{
2000-12-07 00:55:12 +00:00
return SCM_SMOB_APPLY3 (smob, SCM_UNDEFINED, SCM_UNDEFINED, SCM_UNDEFINED);
}
2000-12-07 00:55:12 +00:00
static SCM
scm_smob_apply_0_001 (SCM smob)
{
2000-12-07 00:55:12 +00:00
return SCM_SMOB_APPLY1 (smob, SCM_EOL);
}
static SCM
scm_smob_apply_0_011 (SCM smob)
{
return SCM_SMOB_APPLY2 (smob, SCM_UNDEFINED, SCM_EOL);
}
static SCM
scm_smob_apply_0_021 (SCM smob)
{
return SCM_SMOB_APPLY3 (smob, SCM_UNDEFINED, SCM_UNDEFINED, SCM_EOL);
}
static SCM
scm_smob_apply_0_error (SCM smob)
{
scm_wrong_num_args (smob);
}
static SCM
scm_smob_apply_1_020 (SCM smob, SCM a1)
{
return SCM_SMOB_APPLY2 (smob, a1, SCM_UNDEFINED);
}
static SCM
scm_smob_apply_1_030 (SCM smob, SCM a1)
{
return SCM_SMOB_APPLY3 (smob, a1, SCM_UNDEFINED, SCM_UNDEFINED);
}
static SCM
scm_smob_apply_1_001 (SCM smob, SCM a1)
{
return SCM_SMOB_APPLY1 (smob, scm_list_1 (a1));
2000-12-07 00:55:12 +00:00
}
static SCM
scm_smob_apply_1_011 (SCM smob, SCM a1)
{
return SCM_SMOB_APPLY2 (smob, a1, SCM_EOL);
}
static SCM
scm_smob_apply_1_021 (SCM smob, SCM a1)
{
return SCM_SMOB_APPLY3 (smob, a1, SCM_UNDEFINED, SCM_EOL);
}
static SCM
scm_smob_apply_1_error (SCM smob, SCM a1 SCM_UNUSED)
2000-12-07 00:55:12 +00:00
{
scm_wrong_num_args (smob);
}
static SCM
scm_smob_apply_2_030 (SCM smob, SCM a1, SCM a2)
{
return SCM_SMOB_APPLY3 (smob, a1, a2, SCM_UNDEFINED);
}
static SCM
scm_smob_apply_2_001 (SCM smob, SCM a1, SCM a2)
{
return SCM_SMOB_APPLY1 (smob, scm_list_2 (a1, a2));
}
2000-12-07 00:55:12 +00:00
static SCM
scm_smob_apply_2_011 (SCM smob, SCM a1, SCM a2)
{
return SCM_SMOB_APPLY2 (smob, a1, scm_list_1 (a2));
2000-12-07 00:55:12 +00:00
}
static SCM
scm_smob_apply_2_021 (SCM smob, SCM a1, SCM a2)
{
return SCM_SMOB_APPLY3 (smob, a1, a2, SCM_EOL);
}
static SCM
scm_smob_apply_2_error (SCM smob, SCM a1 SCM_UNUSED, SCM a2 SCM_UNUSED)
2000-12-07 00:55:12 +00:00
{
scm_wrong_num_args (smob);
}
static SCM
scm_smob_apply_3_030 (SCM smob, SCM a1, SCM a2, SCM rst)
{
2004-09-22 17:41:37 +00:00
if (!scm_is_null (SCM_CDR (rst)))
2000-12-07 00:55:12 +00:00
scm_wrong_num_args (smob);
return SCM_SMOB_APPLY3 (smob, a1, a2, SCM_CAR (rst));
}
static SCM
scm_smob_apply_3_001 (SCM smob, SCM a1, SCM a2, SCM rst)
{
return SCM_SMOB_APPLY1 (smob, scm_cons2 (a1, a2, rst));
}
2000-12-07 00:55:12 +00:00
static SCM
scm_smob_apply_3_011 (SCM smob, SCM a1, SCM a2, SCM rst)
{
return SCM_SMOB_APPLY2 (smob, a1, scm_cons (a2, rst));
}
static SCM
scm_smob_apply_3_021 (SCM smob, SCM a1, SCM a2, SCM rst)
{
return SCM_SMOB_APPLY3 (smob, a1, a2, rst);
}
static SCM
scm_smob_apply_3_error (SCM smob,
SCM a1 SCM_UNUSED,
SCM a2 SCM_UNUSED,
SCM rst SCM_UNUSED)
2000-12-07 00:55:12 +00:00
{
scm_wrong_num_args (smob);
}
2001-06-14 19:50:43 +00:00
scm_t_bits
scm_make_smob_type (char const *name, size_t size)
#define FUNC_NAME "scm_make_smob_type"
{
long new_smob;
2005-03-02 20:42:01 +00:00
SCM_CRITICAL_SECTION_START;
new_smob = scm_numsmob;
if (scm_numsmob != MAX_SMOB_COUNT)
++scm_numsmob;
2005-03-02 20:42:01 +00:00
SCM_CRITICAL_SECTION_END;
if (new_smob == MAX_SMOB_COUNT)
scm_misc_error (FUNC_NAME, "maximum number of smobs exceeded", SCM_EOL);
scm_smobs[new_smob].name = name;
if (size != 0)
2000-06-29 15:54:58 +00:00
{
scm_smobs[new_smob].size = size;
scm_smobs[new_smob].free = scm_smob_free;
2000-06-29 15:54:58 +00:00
}
/* Make a class object if Goops is present. */
if (scm_smob_class)
scm_smob_class[new_smob] = scm_make_extended_class (name, 0);
return scm_tc7_smob + new_smob * 256;
}
#undef FUNC_NAME
void
2001-06-14 19:50:43 +00:00
scm_set_smob_mark (scm_t_bits tc, SCM (*mark) (SCM))
{
scm_smobs[SCM_TC2SMOBNUM (tc)].mark = mark;
}
void
2001-06-14 19:50:43 +00:00
scm_set_smob_free (scm_t_bits tc, size_t (*free) (SCM))
{
scm_smobs[SCM_TC2SMOBNUM (tc)].free = free;
}
void
2001-06-14 19:50:43 +00:00
scm_set_smob_print (scm_t_bits tc, int (*print) (SCM, SCM, scm_print_state*))
{
scm_smobs[SCM_TC2SMOBNUM (tc)].print = print;
}
void
2001-06-14 19:50:43 +00:00
scm_set_smob_equalp (scm_t_bits tc, SCM (*equalp) (SCM, SCM))
{
scm_smobs[SCM_TC2SMOBNUM (tc)].equalp = equalp;
}
void
2001-06-14 19:50:43 +00:00
scm_set_smob_apply (scm_t_bits tc, SCM (*apply) (),
unsigned int req, unsigned int opt, unsigned int rst)
{
2000-12-07 00:55:12 +00:00
SCM (*apply_0) (SCM);
SCM (*apply_1) (SCM, SCM);
SCM (*apply_2) (SCM, SCM, SCM);
SCM (*apply_3) (SCM, SCM, SCM, SCM);
int type = SCM_GSUBR_MAKTYPE (req, opt, rst);
if (rst > 1 || req + opt + rst > 3)
2000-12-07 00:55:12 +00:00
{
puts ("Unsupported smob application type");
abort ();
}
switch (type)
{
case SCM_GSUBR_MAKTYPE (0, 0, 0):
apply_0 = apply; break;
2000-12-07 00:55:12 +00:00
case SCM_GSUBR_MAKTYPE (0, 1, 0):
apply_0 = scm_smob_apply_0_010; break;
case SCM_GSUBR_MAKTYPE (0, 2, 0):
apply_0 = scm_smob_apply_0_020; break;
case SCM_GSUBR_MAKTYPE (0, 3, 0):
apply_0 = scm_smob_apply_0_030; break;
case SCM_GSUBR_MAKTYPE (0, 0, 1):
apply_0 = scm_smob_apply_0_001; break;
case SCM_GSUBR_MAKTYPE (0, 1, 1):
apply_0 = scm_smob_apply_0_011; break;
case SCM_GSUBR_MAKTYPE (0, 2, 1):
apply_0 = scm_smob_apply_0_021; break;
default:
apply_0 = scm_smob_apply_0_error; break;
}
switch (type)
{
case SCM_GSUBR_MAKTYPE (1, 0, 0):
case SCM_GSUBR_MAKTYPE (0, 1, 0):
apply_1 = apply; break;
2000-12-07 00:55:12 +00:00
case SCM_GSUBR_MAKTYPE (1, 1, 0):
case SCM_GSUBR_MAKTYPE (0, 2, 0):
apply_1 = scm_smob_apply_1_020; break;
case SCM_GSUBR_MAKTYPE (1, 2, 0):
case SCM_GSUBR_MAKTYPE (0, 3, 0):
apply_1 = scm_smob_apply_1_030; break;
case SCM_GSUBR_MAKTYPE (0, 0, 1):
apply_1 = scm_smob_apply_1_001; break;
case SCM_GSUBR_MAKTYPE (1, 0, 1):
case SCM_GSUBR_MAKTYPE (0, 1, 1):
apply_1 = scm_smob_apply_1_011; break;
case SCM_GSUBR_MAKTYPE (1, 1, 1):
case SCM_GSUBR_MAKTYPE (0, 2, 1):
apply_1 = scm_smob_apply_1_021; break;
default:
apply_1 = scm_smob_apply_1_error; break;
}
switch (type)
{
case SCM_GSUBR_MAKTYPE (2, 0, 0):
case SCM_GSUBR_MAKTYPE (1, 1, 0):
case SCM_GSUBR_MAKTYPE (0, 2, 0):
apply_2 = apply; break;
2000-12-07 00:55:12 +00:00
case SCM_GSUBR_MAKTYPE (2, 1, 0):
case SCM_GSUBR_MAKTYPE (1, 2, 0):
case SCM_GSUBR_MAKTYPE (0, 3, 0):
apply_2 = scm_smob_apply_2_030; break;
case SCM_GSUBR_MAKTYPE (0, 0, 1):
apply_2 = scm_smob_apply_2_001; break;
case SCM_GSUBR_MAKTYPE (1, 0, 1):
case SCM_GSUBR_MAKTYPE (0, 1, 1):
apply_2 = scm_smob_apply_2_011; break;
case SCM_GSUBR_MAKTYPE (2, 0, 1):
case SCM_GSUBR_MAKTYPE (1, 1, 1):
case SCM_GSUBR_MAKTYPE (0, 2, 1):
apply_2 = scm_smob_apply_2_021; break;
default:
apply_2 = scm_smob_apply_2_error; break;
}
switch (type)
{
case SCM_GSUBR_MAKTYPE (3, 0, 0):
case SCM_GSUBR_MAKTYPE (2, 1, 0):
case SCM_GSUBR_MAKTYPE (1, 2, 0):
case SCM_GSUBR_MAKTYPE (0, 3, 0):
apply_3 = scm_smob_apply_3_030; break;
case SCM_GSUBR_MAKTYPE (0, 0, 1):
apply_3 = scm_smob_apply_3_001; break;
case SCM_GSUBR_MAKTYPE (1, 0, 1):
case SCM_GSUBR_MAKTYPE (0, 1, 1):
apply_3 = scm_smob_apply_3_011; break;
case SCM_GSUBR_MAKTYPE (2, 0, 1):
case SCM_GSUBR_MAKTYPE (1, 1, 1):
case SCM_GSUBR_MAKTYPE (0, 2, 1):
apply_3 = scm_smob_apply_3_021; break;
default:
apply_3 = scm_smob_apply_3_error; break;
}
2001-02-03 04:59:16 +00:00
scm_smobs[SCM_TC2SMOBNUM (tc)].apply = apply;
2000-12-07 00:55:12 +00:00
scm_smobs[SCM_TC2SMOBNUM (tc)].apply_0 = apply_0;
scm_smobs[SCM_TC2SMOBNUM (tc)].apply_1 = apply_1;
scm_smobs[SCM_TC2SMOBNUM (tc)].apply_2 = apply_2;
scm_smobs[SCM_TC2SMOBNUM (tc)].apply_3 = apply_3;
2000-12-07 07:10:26 +00:00
scm_smobs[SCM_TC2SMOBNUM (tc)].gsubr_type = type;
if (scm_smob_class)
scm_i_inherit_applicable (scm_smob_class[SCM_TC2SMOBNUM (tc)]);
}
SCM
2001-06-14 19:50:43 +00:00
scm_make_smob (scm_t_bits tc)
{
scm_t_bits n = SCM_TC2SMOBNUM (tc);
* validate.h (SCM_NUM2{SIZE,PTRDIFF,SHORT,USHORT,BITS,UBITS,INT,UINT}[_DEF]): new macros. * unif.h: type renaming: scm_array -> scm_array_t scm_array_dim -> scm_array_dim_t the old names are deprecated, all in-Guile uses changed. * tags.h (scm_ubits_t): new typedef, representing unsigned scm_bits_t. * stacks.h: type renaming: scm_info_frame -> scm_info_frame_t scm_stack -> scm_stack_t the old names are deprecated, all in-Guile uses changed. * srcprop.h: type renaming: scm_srcprops -> scm_srcprops_t scm_srcprops_chunk -> scm_srcprops_chunk_t the old names are deprecated, all in-Guile uses changed. * gsubr.c, procs.c, print.c, ports.c, read.c, rdelim.c, ramap.c, rw.c, smob.c, sort.c, srcprop.c, stacks.c, strings.c, strop.c, strorder.c, strports.c, struct.c, symbols.c, unif.c, values.c, vectors.c, vports.c, weaks.c: various int/size_t -> size_t/scm_bits_t changes. * random.h: type renaming: scm_rstate -> scm_rstate_t scm_rng -> scm_rng_t scm_i_rstate -> scm_i_rstate_t the old names are deprecated, all in-Guile uses changed. * procs.h: type renaming: scm_subr_entry -> scm_subr_entry_t the old name is deprecated, all in-Guile uses changed. * options.h (scm_option_t.val): unsigned long -> scm_bits_t. type renaming: scm_option -> scm_option_t the old name is deprecated, all in-Guile uses changed. * objects.c: various long -> scm_bits_t changes. (scm_i_make_class_object): flags: unsigned long -> scm_ubits_t * numbers.h (SCM_FIXNUM_BIT): deprecated, renamed to SCM_I_FIXNUM_BIT. * num2integral.i.c: new file, multiply included by numbers.c, used to "templatize" the various integral <-> num conversion routines. * numbers.c (scm_mkbig, scm_big2num, scm_adjbig, scm_normbig, scm_copybig, scm_2ulong2big, scm_dbl2big, scm_big2dbl): deprecated. (scm_i_mkbig, scm_i_big2inum, scm_i_adjbig, scm_i_normbig, scm_i_copybig, scm_i_short2big, scm_i_ushort2big, scm_i_int2big, scm_i_uint2big, scm_i_long2big, scm_i_ulong2big, scm_i_bits2big, scm_i_ubits2big, scm_i_size2big, scm_i_ptrdiff2big, scm_i_long_long2big, scm_i_ulong_long2big, scm_i_dbl2big, scm_i_big2dbl, scm_short2num, scm_ushort2num, scm_int2num, scm_uint2num, scm_bits2num, scm_ubits2num, scm_size2num, scm_ptrdiff2num, scm_num2short, scm_num2ushort, scm_num2int, scm_num2uint, scm_num2bits, scm_num2ubits, scm_num2ptrdiff, scm_num2size): new functions. * modules.c (scm_module_reverse_lookup): i, n: int -> scm_bits_t.x * load.c: change int -> size_t in various places (where the variable is used to store a string length). (search-path): call scm_done_free, not scm_done_malloc. * list.c (scm_ilength): return a scm_bits_t, not long. some other {int,long} -> scm_bits_t changes. * hashtab.c: various [u]int -> scm_bits_t changes. scm_ihashx_closure -> scm_ihashx_closure_t (and made a typedef). (scm_ihashx): n: uint -> scm_bits_t use scm_bits2num instead of scm_ulong2num. * gsubr.c: various int -> scm_bits_t changes. * gh_data.c (gh_scm2double): no loss of precision any more. * gh.h (gh_str2scm): len: int -> size_t (gh_{get,set}_substr): start: int -> scm_bits_t, len: int -> size_t (gh_<num>2scm): n: int -> scm_bits_t (gh_*vector_length): return scm_[u]size_t, not unsigned long. (gh_length): return scm_bits_t, not unsigned long. * fports.h: type renaming: scm_fport -> scm_fport_t the old name is deprecated, all in-Guile uses changed. * fports.c (fport_fill_input): count: int -> scm_bits_t (fport_flush): init_size, remaining, count: int -> scm_bits_t * debug.h (scm_lookup_cstr, scm_lookup_soft, scm_evstr): removed those prototypes, as the functions they prototype don't exist. * fports.c (default_buffer_size): int -> size_t (scm_fport_buffer_add): read_size, write_size: int -> scm_bits_t default_size: int -> size_t (scm_setvbuf): csize: int -> scm_bits_t * fluids.c (n_fluids): int -> scm_bits_t (grow_fluids): old_length, i: int -> scm_bits_t (next_fluid_num, scm_fluid_ref, scm_fluid_set_x): n: int -> scm_bits_t (scm_c_with_fluids): flen, vlen: int -> scm_bits_t * filesys.c (s_scm_open_fdes): changed calls to SCM_NUM2LONG to the new and shiny SCM_NUM2INT. * extensions.c: extension -> extension_t (and made a typedef). * eval.h (SCM_IFRAME): cast to scm_bits_t, not int. just so there are no nasty surprises if/when the various deeply magic tag bits move somewhere else. * eval.c: changed the locals used to store results of SCM_IFRAME, scm_ilength and such to be of type scm_bits_t (and not int/long). (iqq): depth, edepth: int -> scm_bits_t (scm_eval_stack): int -> scm_bits_t (SCM_CEVAL): various vars are not scm_bits_t instead of int. (check_map_args, scm_map, scm_for_each): len: long -> scm_bits_t i: int -> scm_bits_t * environments.c: changed the many calls to scm_ulong2num to scm_ubits2num. (import_environment_fold): proc_as_ul: ulong -> scm_ubits_t * dynwind.c (scm_dowinds): delta: long -> scm_bits_t * debug.h: type renaming: scm_debug_info -> scm_debug_info_t scm_debug_frame -> scm_debug_frame_t the old names are deprecated, all in-Guile uses changed. (scm_debug_eframe_size): int -> scm_bits_t * debug.c (scm_init_debug): use scm_c_define instead of the deprecated scm_define. * continuations.h: type renaming: scm_contregs -> scm_contregs_t the old name is deprecated, all in-Guile uses changed. (scm_contregs_t.num_stack_items): size_t -> scm_bits_t (scm_contregs_t.num_stack_items): ulong -> scm_ubits_t * continuations.c (scm_make_continuation): change the type of stack_size form long to scm_bits_t. * ports.h: type renaming: scm_port_rw_active -> scm_port_rw_active_t (and made a typedef) scm_port -> scm_port_t scm_ptob_descriptor -> scm_ptob_descriptor_t the old names are deprecated, all in-Guile uses changed. (scm_port_t.entry): int -> scm_bits_t. (scm_port_t.line_number): int -> long. (scm_port_t.putback_buf_size): int -> size_t. * __scm.h (long_long, ulong_long): deprecated (they pollute the global namespace and have little value besides that). (SCM_BITS_LENGTH): new, is the bit size of scm_bits_t (i.e. of an SCM handle). (ifdef spaghetti): include sys/types.h and sys/stdtypes.h, if they exist (for size_t & ptrdiff_t) (scm_sizet): deprecated. * Makefile.am (noinst_HEADERS): add num2integral.i.c
2001-05-24 00:50:51 +00:00
size_t size = scm_smobs[n].size;
scm_t_bits data = (size > 0
? (scm_t_bits) scm_gc_malloc (size, SCM_SMOBNAME (n))
: 0);
SCM_RETURN_NEWSMOB (tc, data);
}
/* {Initialization for the type of free cells}
*/
static int
free_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
{
char buf[100];
2000-12-08 17:32:56 +00:00
sprintf (buf, "#<freed cell %p; GC missed a reference>",
(void *) SCM_UNPACK (exp));
scm_puts (buf, port);
#if (SCM_DEBUG_CELL_ACCESSES == 1)
if (scm_debug_cell_accesses_p)
abort();
#endif
return 1;
}
/* Marking SMOBs using user-supplied mark procedures. */
/* The freelist and GC kind used for SMOB types that provide a custom mark
procedure. */
static void **smob_freelist = NULL;
static int smob_gc_kind = 0;
/* The generic SMOB mark procedure that gets called for SMOBs allocated with
`scm_i_new_smob_with_mark_proc ()'. */
static struct GC_ms_entry *
smob_mark (GC_word *addr, struct GC_ms_entry *mark_stack_ptr,
struct GC_ms_entry *mark_stack_limit, GC_word env)
{
register SCM cell;
register scm_t_bits tc, smobnum;
cell = PTR2SCM (addr);
if (SCM_TYP7 (cell) != scm_tc7_smob)
/* It is likely that the GC passed us a pointer to a free-list element
which we must ignore (see warning in `gc/gc_mark.h'). */
return mark_stack_ptr;
tc = SCM_CELL_WORD_0 (cell);
smobnum = SCM_TC2SMOBNUM (tc);
if (smobnum >= scm_numsmob)
/* The first word looks corrupt. */
abort ();
mark_stack_ptr = GC_MARK_AND_PUSH (SCM2PTR (SCM_CELL_OBJECT_1 (cell)),
mark_stack_ptr,
mark_stack_limit, NULL);
mark_stack_ptr = GC_MARK_AND_PUSH (SCM2PTR (SCM_CELL_OBJECT_2 (cell)),
mark_stack_ptr,
mark_stack_limit, NULL);
mark_stack_ptr = GC_MARK_AND_PUSH (SCM2PTR (SCM_CELL_OBJECT_3 (cell)),
mark_stack_ptr,
mark_stack_limit, NULL);
if (scm_smobs[smobnum].mark)
{
SCM obj;
SCM_I_CURRENT_THREAD->current_mark_stack_ptr = mark_stack_ptr;
SCM_I_CURRENT_THREAD->current_mark_stack_limit = mark_stack_limit;
/* Invoke the SMOB's mark procedure, which will in turn invoke
`scm_gc_mark ()', which may modify `current_mark_stack_ptr'. */
obj = scm_smobs[smobnum].mark (cell);
mark_stack_ptr = SCM_I_CURRENT_THREAD->current_mark_stack_ptr;
if (SCM_NIMP (obj))
/* Mark the returned object. */
mark_stack_ptr = GC_MARK_AND_PUSH (SCM2PTR (obj),
mark_stack_ptr,
mark_stack_limit, NULL);
SCM_I_CURRENT_THREAD->current_mark_stack_limit = NULL;
SCM_I_CURRENT_THREAD->current_mark_stack_ptr = NULL;
}
return mark_stack_ptr;
}
/* Mark object O. We assume that this function is only called during the
mark phase, i.e., from within `smob_mark ()' or one of its
descendents. */
void
scm_gc_mark (SCM o)
{
#define CURRENT_MARK_PTR \
((struct GC_ms_entry *)(SCM_I_CURRENT_THREAD->current_mark_stack_ptr))
#define CURRENT_MARK_LIMIT \
((struct GC_ms_entry *)(SCM_I_CURRENT_THREAD->current_mark_stack_limit))
if (SCM_NIMP (o))
{
/* At this point, the `current_mark_*' fields of the current thread
must be defined (they are set in `smob_mark ()'). */
register struct GC_ms_entry *mark_stack_ptr;
if (!CURRENT_MARK_PTR)
/* The function was not called from a mark procedure. */
abort ();
mark_stack_ptr = GC_MARK_AND_PUSH (SCM2PTR (o),
CURRENT_MARK_PTR, CURRENT_MARK_LIMIT,
NULL);
SCM_I_CURRENT_THREAD->current_mark_stack_ptr = mark_stack_ptr;
}
#undef CURRENT_MARK_PTR
#undef CURRENT_MARK_LIMIT
}
/* Return a SMOB with typecode TC. The SMOB type corresponding to TC may
provide a custom mark procedure and it will be honored. */
SCM
scm_i_new_smob_with_mark_proc (scm_t_bits tc, scm_t_bits data1,
scm_t_bits data2, scm_t_bits data3)
{
/* Return a double cell. */
SCM cell = SCM_PACK (GC_generic_malloc (2 * sizeof (scm_t_cell),
smob_gc_kind));
SCM_SET_CELL_WORD_3 (cell, data3);
SCM_SET_CELL_WORD_2 (cell, data2);
SCM_SET_CELL_WORD_1 (cell, data1);
SCM_SET_CELL_WORD_0 (cell, tc);
return cell;
}
/* Finalize SMOB by calling its SMOB type's free function, if any. */
void
scm_i_finalize_smob (GC_PTR ptr, GC_PTR data)
{
SCM smob;
size_t (* free_smob) (SCM);
smob = PTR2SCM (ptr);
#if 0
printf ("finalizing SMOB %p (smobnum: %u)\n",
ptr, SCM_SMOBNUM (smob));
#endif
free_smob = scm_smobs[SCM_SMOBNUM (smob)].free;
if (free_smob)
free_smob (smob);
}
void
scm_smob_prehistory ()
{
long i;
2001-06-14 19:50:43 +00:00
scm_t_bits tc;
2000-12-08 17:32:56 +00:00
smob_freelist = GC_new_free_list ();
smob_gc_kind = GC_new_kind ((void **)smob_freelist,
GC_MAKE_PROC (GC_new_proc (smob_mark), 0),
0,
/* Clear new objects. As of version 7.1, libgc
doesn't seem to support passing 0 here. */
1);
scm_numsmob = 0;
for (i = 0; i < MAX_SMOB_COUNT; ++i)
{
scm_smobs[i].name = 0;
scm_smobs[i].size = 0;
scm_smobs[i].mark = 0;
scm_smobs[i].free = 0;
scm_smobs[i].print = scm_smob_print;
scm_smobs[i].equalp = 0;
scm_smobs[i].apply = 0;
scm_smobs[i].apply_0 = 0;
scm_smobs[i].apply_1 = 0;
scm_smobs[i].apply_2 = 0;
scm_smobs[i].apply_3 = 0;
scm_smobs[i].gsubr_type = 0;
}
/* WARNING: This scm_make_smob_type call must be done first. */
2000-12-08 17:32:56 +00:00
tc = scm_make_smob_type ("free", 0);
scm_set_smob_print (tc, free_print);
}
/*
Local Variables:
c-file-style: "gnu"
End:
*/