Hi Pietro.

That check comes from the similar code in libpoke:

  void
  pvm_alloc_initialize ()
  {
    /* Initialize the Boehm Garbage Collector, but only if it hasn't
       been already initialized.  The later may happen if some other
       library or program uses the boehm GC.  */
    if (!GC_is_init_called ())
      {
        GC_INIT ();
        GC_allow_register_threads ();
      }
  }

Which, as the comment explain, is an attempt to _try_ to coexist with
other applications/libs using the Boehm GC.  I looked at the GC_INIT
macro definition in my gc/gc.h:

  #define GC_INIT() { GC_INIT_CONF_DONT_EXPAND; /* pre-init */ \
                      GC_INIT_CONF_FORCE_UNMAP_ON_GCOLLECT; \
                      GC_INIT_CONF_MAX_RETRIES; \
                      GC_INIT_CONF_FREE_SPACE_DIVISOR; \
                      GC_INIT_CONF_FULL_FREQ; \
                      GC_INIT_CONF_TIME_LIMIT; \
                      GC_INIT_CONF_SUSPEND_SIGNAL; \
                      GC_INIT_CONF_THR_RESTART_SIGNAL; \
                      GC_INIT_CONF_MAXIMUM_HEAP_SIZE; \
                      GC_init(); /* real GC initialization */ \
                      GC_INIT_CONF_ROOTS; /* post-init */ \
                      GC_INIT_CONF_IGNORE_WARN; \
                      GC_INIT_CONF_INITIAL_HEAP_SIZE; }

Doesn't look like a nop when GC_is_init_called returns true..  The
macros before and after GC_init call functions to alter the global state
of the allocator, unless these are guarded internally.

> GC_INIT() checks if the GC is has already been initialized.
> Don't check it a second time.
>
> libga68/ChangeLog:
>
>       PR algol68/123733
>       * ga68-alloc.c (_libga68_init_heap):
>
> Signed-off-by: Pietro Monteiro <[email protected]>
> ---
>  libga68/ga68-alloc.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/libga68/ga68-alloc.c b/libga68/ga68-alloc.c
> index df8a8956c52..0a749cd5984 100644
> --- a/libga68/ga68-alloc.c
> +++ b/libga68/ga68-alloc.c
> @@ -48,11 +48,8 @@ _libga68_malloc_internal (size_t size)
>  void
>  _libga68_init_heap (void)
>  {
> -  if (!GC_is_init_called ())
> -    {
> -      GC_INIT ();
> -      /*      GC_allow_register_threads (); */
> -    }
> +  GC_INIT ();
> +  /* GC_allow_register_threads (); */
>  }
>  
>  void *
>
> base-commit: 2d626c4eb68a33a13a3d497364c493f3b71fb9e7

Reply via email to