1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-07-03 16:20:39 +02:00

Manage pre-goops port type list using pairs

Avoids sloppy allocations.

* libguile/ports-internal.h (scm_is_port_type):
(scm_to_port_type, scm_from_port_type): New helpers.
* libguile/goops.c (scm_make_port_classes):
(create_port_classes): Use a list and be thread-safe.
This commit is contained in:
Andy Wingo 2025-06-25 12:41:34 +02:00
parent 9e9567b22a
commit 7d1eda149e
2 changed files with 38 additions and 21 deletions

View file

@ -743,13 +743,6 @@ create_smob_classes (void)
scm_smobs[i].apply != 0); scm_smobs[i].apply != 0);
} }
struct pre_goops_port_type
{
scm_t_port_type *ptob;
struct pre_goops_port_type *prev;
};
struct pre_goops_port_type *pre_goops_port_types;
static void static void
make_port_classes (scm_t_port_type *ptob) make_port_classes (scm_t_port_type *ptob)
{ {
@ -775,6 +768,8 @@ make_port_classes (scm_t_port_type *ptob)
scm_make_standard_class (meta, name, supers, SCM_EOL); scm_make_standard_class (meta, name, supers, SCM_EOL);
} }
static SCM pre_goops_port_types = SCM_EOL;
void void
scm_make_port_classes (scm_t_port_type *ptob) scm_make_port_classes (scm_t_port_type *ptob)
{ {
@ -782,28 +777,30 @@ scm_make_port_classes (scm_t_port_type *ptob)
ptob->output_class = SCM_BOOL_F; ptob->output_class = SCM_BOOL_F;
ptob->input_output_class = SCM_BOOL_F; ptob->input_output_class = SCM_BOOL_F;
scm_i_pthread_mutex_lock (&scm_i_misc_mutex);
if (!goops_loaded_p) if (!goops_loaded_p)
{ {
/* Not really a pair. */ pre_goops_port_types = scm_cons (scm_from_port_type (ptob),
struct pre_goops_port_type *link; pre_goops_port_types);
link = scm_gc_typed_calloc (struct pre_goops_port_type); scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
link->ptob = ptob; }
link->prev = pre_goops_port_types; else
pre_goops_port_types = link; {
return; scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
make_port_classes (ptob);
} }
make_port_classes (ptob);
} }
static void static void
create_port_classes (void) create_port_classes (void)
{ {
while (pre_goops_port_types) scm_i_pthread_mutex_lock (&scm_i_misc_mutex);
{ SCM ptobs = pre_goops_port_types;
make_port_classes (pre_goops_port_types->ptob); pre_goops_port_types = SCM_EOL;
pre_goops_port_types = pre_goops_port_types->prev; scm_i_pthread_mutex_unlock (&scm_i_misc_mutex);
}
for (; scm_is_pair (ptobs); ptobs = scm_cdr (ptobs))
make_port_classes (scm_to_port_type (scm_car (ptobs)));
} }
SCM SCM

View file

@ -72,6 +72,26 @@ struct scm_t_port_type
SCM input_class, output_class, input_output_class; SCM input_class, output_class, input_output_class;
}; };
static inline int
scm_is_port_type (SCM x)
{
return SCM_HAS_TYP7 (x, scm_tc7_port_type);
}
static inline struct scm_t_port_type *
scm_to_port_type (SCM x)
{
if (!scm_is_port_type (x))
abort ();
return (struct scm_t_port_type *) SCM_UNPACK_POINTER (x);
}
static inline SCM
scm_from_port_type (struct scm_t_port_type *x)
{
return SCM_PACK_POINTER (x);
}
/* Port buffers. /* Port buffers.
It's important to avoid calling into the kernel too many times. For It's important to avoid calling into the kernel too many times. For