* libguile/hashtab.h (SCM_HASHTABLE_VECTOR):
(SCM_SET_HASHTABLE_VECTOR):
(SCM_HASHTABLE):
(SCM_HASHTABLE_N_ITEMS):
(SCM_SET_HASHTABLE_N_ITEMS):
(SCM_HASHTABLE_INCREMENT):
(SCM_HASHTABLE_DECREMENT):
(SCM_HASHTABLE_UPPER):
(SCM_HASHTABLE_LOWER):
(SCM_HASHTABLE_N_BUCKETS):
(SCM_HASHTABLE_BUCKET):
(SCM_SET_HASHTABLE_BUCKET): Remove these internal definitions from the
public interface.
(scm_t_hashtable): Add a tag, and add buckets.
(scm_is_hashtable):
(scm_to_hashtable):
(scm_from_hashtable): New helpers.
* libguile/modules.c (scm_module_reverse_lookup): Adapt to hash table
API change.
* libguile/hashtab.c: Rework to access hash table data through the typed
"struct scm_t_hashtable".
* libguile/foreign.h (SCM_IMMUTABLE_POINTER): Remove. This was part of
the implementation of static subrs, a long long time ago, but hasn't
been used since 2013 (27337b6373).
* libguile/numbers.h (scm_t_double, scm_t_complex): Change type and pad
to scm_t_bits.
(struct scm_fraction): New type.
(scm_is_fraction, scm_to_fraction, scm_from_fraction)
(scm_fraction_numerator, scm_fraction_denominator): New helpers.
(SCM_FRACTIONP, SCM_FRACTION_NUMERATOR, SCM_FRACTION_DENOMINATOR): Use
new helpers.
* libguile/numbers.c (scm_i_make_ratio_already_reduced): Allocate using
scm_allocate_tagged.
* libguile/keywords-internal.h: New file.
* libguile/Makefile.am (noinst_HEADERS): Add new file.
* libguile/hash.c:
* libguile/init.c:
* libguile/keywords.c: Include new file.
(scm_symbol_to_keyword): Allocate via scm_allocate_tagged.
* libguile/gc.h:
* libguile/pairs.h (scm_pair_car_loc, scm_pair_cdr_loc): New helpers.
(SCM_CARLOC, SCM_CDRLOC): Move here from gc.h.
* libguile/list.c (scm_list_1, scm_list_2, scm_list_3): Just use
scm_cons.
* libguile/pairs.h: Remove inline scm_cons, scm_car, scm_cdr defnitions;
this is less important now with the VM. Add a "struct scm_pair", and
make all SCM_CAR / SCM_CDR checks use it. For now it does type checking
as well.
* libguile/pairs.c (scm_cons, scm_car, scm_cdr): Implement here.
* libguile/scm.h (SCM_DEBUG_PAIR_ACCESSES): No more macro!
* libguile/posix.c (free_string_pointers):
(free_string_pointers_on_unwind):
(allocate_string_pointers): Move here from string.c, and use malloc/free
instead of GC facilities. Adapt all users.
* libguile/strings.h:
* libguile/strings.c (scm_i_allocate_string_pointers): Remove.
* libguile/struct.c (scm_struct_init_1_default):
(scm_struct_init_1): New helpers.
(scm_struct_init_array): Use new helpers.
(scm_struct_init_list): New function.
(scm_make_struct_no_tail): Use scm_struct_init_list instead of mallocing.
Gosh this was a slog
* libguile/dynstack.c (dynstack_ensure_space): Use malloc and free.
Threads have off-heap dynstacks, with manual marking.
(scm_trace_dynstack): Implement tracing.
(trace_pinned_trampoline, scm_trace_dynstack_roots): Implement tracing
for active threads.
(scm_dynstack_capture): Tag dynstacks.
* libguile/dynstack.h (scm_t_dynstack): Add a tag.
(scm_t_dynstack_winder_flags): Add SCM_F_DYNSTACK_WINDER_MANAGED.
* libguile/dynwind.h (scm_t_wind_flags): Add SCM_F_WIND_MANAGED.
* libguile/dynwind.c (scm_dynwind_unwind_handler_with_scm)
(scm_dynwind_rewind_handler_with_scm): These values need to be traced by
GC.
* libguile/scm.h (scm_tc16_dynstack_slice): New typecode. No need for
equality etc because it shouldn't escape to Scheme (currently).
* libguile/trace.h: Add trace decls.
* libguile/threads.c (scm_trace_thread_roots): Trace dynstacks
explicitly here, as they are off-heap.
Instead of a 4-word object that has a tag, stream, pt, and ptob, just
add tag, stream, and ptob fields to pt. Also add a "stream mode",
indicating to the GC how the stream should be traced.
* libguile/custom-ports.c (scm_init_custom_ports): Indicate that streams
are managed.
* libguile/fports.c (scm_make_fptob): Streams are managed.
* libguile/ports-internal.h (scm_t_port_type): Add enum to indicate
stream management.
(scm_t_port): Add type-and-flags, stream, and ptob members.
* libguile/ports.c (scm_port_stream, scm_port_type): New helpers.
(scm_make_port_type): Init stream mode to CONSERVATIVE.
(scm_set_port_stream_mode): New API.
(scm_c_make_port_with_encoding): Adapt to new port representation.
(scm_init_ports): Void ports have unmanaged streams.
* libguile/ports.h (scm_is_port, scm_to_port, scm_from_port): New inline
functions.
(SCM_PORT, SCM_STREAM, SCM_PORT_TYPE): Rework in terms of new functions.
(SCM_SETSTREAM): Remove.
(enum scm_port_stream_mode): New.
(scm_set_port_stream_mode): New.
* libguile/smob.h:
* libguile/smob.c (scm_make_managed_smob_type): New API, to declare that
a SMOB has a certain number of fields, all of which will be traced by
the GC. 0 indicates "unknown", and will disable evacuation.
(scm_make_smob_type): Call scm_make_managed_smob_type with 0 nfields.
(scm_set_smob_field_is_unmanaged): New API to indicate that a field is
unmanaged (and should not be traced by GC).
* libguile/print.c (iprin1):
* libguile/eq.c (scm_equal_p): Add case for locales and also regexps
which we missed in the past.
* libguile/finalizers.h:
* libguile/finalizers.c (scm_i_add_locale_finalizer):
(run_finalizer): Add locale finalizers.
* libguile/scm.h (scm_tc16_locale): New tc16.
* module/oop/goops.scm:
* libguile/goops.c: Add locale class.
* libguile/i18n.c: Give locale objects their own tc16.
* libguile/i18n.c: Remove shim for pre-POSIX 2008, given that gnulib
does appear to have newlocale/uselocale implementations.
* libguile/posix.c: No USE_GNU_LOCALE_API define.
* libguile/r6rs-ports.c: Remove stray include.
* module/ice-9/binary-ports.scm (bytevector-concatenate-reverse):
(bytevector-copy*): New helpers.
(open-bytevector-output-port): New implementation.
* libguile/r6rs-ports.c (scm_open_bytevector_output_port):
(init_bytevector_port_vars): Arrange to proxy to Scheme.
* libguile/random.h (scm_t_rstate): Put a tag word in the beginning.
(scm_is_random_state, scm_to_random_state, scm_from_random_state): New
helpers.
(SCM_RSTATEP, SCM_RSTATE): Use the new helpers.
(scm_masktab): Make private.
* libguile/random.c: Adapt random states to not be a smob.
* libguile/eq.c:
* libguile/print.c:
* libguile/scm.h:
* module/oop/goops.scm: Add new random-state cases. Fix a number of
classes for other types that were recently changed to not be smobs.
The goal was that, as part of a print operation, all nested prints of
contained data would be able to use the same parameters (e.g. write or
not), and also detect cycles, highlight objects, etc. The mechanism was
a heap-allocated data structure. However, given that:
1. Nobody accessed print states from Scheme
2. `write` and `display` should move to Scheme anyway, in order to be
suspendable
3. The "fancyp" and "highlight" options were unused
4. A simple stack-allocated data structure with a per-thread key could
do the trick just as well, without needing the weird freelist
structure
5. Ports-with-print-states were a source of bugs
In the end we switch print states to be something completely internal to
print.c. There are no more SCM print-state objects, and no more
ports-with-print-state.
* libguile/print.h: Remove print state from API.
* libguile/print.c (struct scm_print_state): Move definition here.
(scm_print_opts): Remove "highlight-prefix" and "highlight-suffix"
options, as they were not used.
(ENTER_NESTED_DATA): Remove "fancyp" case.
(init_print_state_key, get_print_state, push_print_state)
(maybe_push_print_state, pop_print_state): New facility to manage stack
of active print states.
(scm_iprin1, print_vector): No more fancyp.
(iprin1): Access "writingp" member directly. Don't make ports with
print states.
(scm_prin1): Manage print state stack.
(scm_iprlist): No more fancyp.
(scm_valid_oport_value_p): Remove; valid outports are SCM_OPOUTPORTP.
* libguile/backtrace.c:
* libguile/filesys.c:
* libguile/fports.c:
* libguile/goops.c:
* libguile/ioext.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/promises.c:
* libguile/socket.c:
* libguile/struct.c: Remove cases that dealt with
ports-with-print-states.
* libguile/private-options.h: Remove highlight options.
* module/ice-9/ports.scm (inherit-print-state): Deprecate.
* libguile/deprecated.c:
* libguile/deprecated.h: Add deprecation shims for print states, as far
as that is possible.
* libguile/mallocs.c:
* libguile/mallocs.h: Delete files. These exposed a SMOB interface for
traced mallocs, which is not compatible with precise tracing, and was
unused and undocumented.
* libguile.h:
* libguile/Makefile.am:
* libguile/init.c: Remove mallocs.
* libguile/options.c:
* libguile/ports.c: Remove useless mallocs.h includes
* libguile/scm.h: Allocate a tc16 for syntax transformers.
* libguile/expand.c: Adapt to renamings.
* libguile/eq.c:
* libguile/goops.c:
* libguile/print.c: Add tc16 cases.
* libguile/macros.h:
* libguile/macros.c (scm_i_make_primitive_syntax_transformer):
(scm_i_primitive_syntax_transformer): Rename internal functions from
scm_i_make_primitive_macro, etc. Use new representation.
(scm_make_syntax_transformer): Update for new representation.