2018-06-17 13:03:39 +02:00
|
|
|
|
/* Copyright (C) 1995-2004,2006,2008-2014,2018
|
|
|
|
|
|
* Free Software Foundation, Inc.
|
2002-08-04 00:18:33 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
|
|
* as published by the Free Software Foundation; either version 3 of
|
|
|
|
|
|
* the License, or (at your option) any later version.
|
2002-08-04 00:18:33 +00:00
|
|
|
|
*
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* This library is distributed in the hope that it will be useful, but
|
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
* Lesser General Public License for more details.
|
2002-08-04 00:18:33 +00:00
|
|
|
|
*
|
2003-04-05 19:15:35 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-06-17 00:22:09 +01:00
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
|
|
* 02110-1301 USA
|
2003-04-05 19:15:35 +00:00
|
|
|
|
*/
|
2002-08-04 00:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-13 15:35:27 +02:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2003-03-25 23:55:20 +00:00
|
|
|
|
# include <config.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
#include <string.h>
|
2011-12-22 09:54:24 -05:00
|
|
|
|
#include <stdlib.h>
|
2002-08-04 00:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
#include "libguile/eval.h"
|
|
|
|
|
|
#include "libguile/stime.h"
|
|
|
|
|
|
#include "libguile/stackchk.h"
|
|
|
|
|
|
#include "libguile/struct.h"
|
|
|
|
|
|
#include "libguile/smob.h"
|
2009-07-17 01:08:35 +02:00
|
|
|
|
#include "libguile/arrays.h"
|
2002-08-04 00:18:33 +00:00
|
|
|
|
#include "libguile/async.h"
|
|
|
|
|
|
#include "libguile/ports.h"
|
|
|
|
|
|
#include "libguile/strings.h"
|
|
|
|
|
|
#include "libguile/vectors.h"
|
|
|
|
|
|
#include "libguile/hashtab.h"
|
|
|
|
|
|
#include "libguile/tags.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "libguile/deprecation.h"
|
|
|
|
|
|
#include "libguile/gc.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GUILE_DEBUG_MALLOC
|
|
|
|
|
|
#include "libguile/debug-malloc.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
INIT_MALLOC_LIMIT is the initial amount of malloc usage which will
|
|
|
|
|
|
trigger a GC.
|
|
|
|
|
|
|
|
|
|
|
|
After startup (at the guile> prompt), we have approximately 100k of
|
|
|
|
|
|
alloced memory, which won't go away on GC. Let's set the init such
|
|
|
|
|
|
that we get a nice yield on the next allocation:
|
|
|
|
|
|
*/
|
2002-08-04 14:09:14 +00:00
|
|
|
|
#define SCM_DEFAULT_INIT_MALLOC_LIMIT 200*1024
|
2002-08-04 00:18:33 +00:00
|
|
|
|
#define SCM_DEFAULT_MALLOC_MINYIELD 40
|
|
|
|
|
|
|
2002-09-05 20:43:43 +00:00
|
|
|
|
/* #define DEBUGINFO */
|
2002-08-04 00:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
|
do_realloc (void *from, size_t new_size)
|
|
|
|
|
|
{
|
|
|
|
|
|
scm_gc_register_allocation (new_size);
|
|
|
|
|
|
return realloc (from, new_size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
|
do_calloc (size_t n, size_t size)
|
|
|
|
|
|
{
|
|
|
|
|
|
scm_gc_register_allocation (size);
|
|
|
|
|
|
return calloc (n, size);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
|
do_gc_malloc (size_t size, const char *what)
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Ensure nonzero size to be compatible with always-nonzero return of
|
|
|
|
|
|
glibc malloc. */
|
|
|
|
|
|
return GC_MALLOC (size ? size : sizeof (void *));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
|
do_gc_malloc_atomic (size_t size, const char *what)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GC_MALLOC_ATOMIC (size ? size : sizeof (void *));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void*
|
|
|
|
|
|
do_gc_realloc (void *from, size_t size, const char *what)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GC_REALLOC (from, size ? size : sizeof (void *));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
do_gc_free (void *ptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
GC_FREE (ptr);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
|
|
|
|
|
|
/* Function for non-cell memory management.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
|
|
scm_realloc (void *mem, size_t size)
|
|
|
|
|
|
{
|
|
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
ptr = do_realloc (mem, size);
|
2011-11-29 21:36:31 +01:00
|
|
|
|
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
if (ptr || size == 0)
|
2002-08-04 00:18:33 +00:00
|
|
|
|
return ptr;
|
|
|
|
|
|
|
2006-03-21 22:16:33 +00:00
|
|
|
|
/* Time is hard: trigger a full, ``stop-the-world'' GC, and try again. */
|
2011-11-29 21:36:31 +01:00
|
|
|
|
GC_gcollect_and_unmap ();
|
2005-03-10 18:39:53 +00:00
|
|
|
|
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
ptr = do_realloc (mem, size);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
if (ptr)
|
|
|
|
|
|
return ptr;
|
|
|
|
|
|
|
2014-03-22 15:49:31 +01:00
|
|
|
|
scm_report_out_of_memory ();
|
|
|
|
|
|
|
|
|
|
|
|
/* Not reached. */
|
|
|
|
|
|
return NULL;
|
2002-08-04 00:18:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-04 23:33:28 +00:00
|
|
|
|
void *
|
|
|
|
|
|
scm_malloc (size_t sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_realloc (NULL, sz);
|
|
|
|
|
|
}
|
2002-08-05 23:04:44 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
Hmm. Should we use the C convention for arguments (i.e. N_ELTS,
|
|
|
|
|
|
SIZEOF_ELT)? --hwn
|
|
|
|
|
|
*/
|
|
|
|
|
|
void *
|
|
|
|
|
|
scm_calloc (size_t sz)
|
|
|
|
|
|
{
|
2002-08-28 23:13:30 +00:00
|
|
|
|
void * ptr;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
By default, try to use calloc, as it is likely more efficient than
|
|
|
|
|
|
calling memset by hand.
|
|
|
|
|
|
*/
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
ptr = do_calloc (sz, 1);
|
|
|
|
|
|
if (ptr || sz == 0)
|
2002-08-28 23:13:30 +00:00
|
|
|
|
return ptr;
|
2006-03-21 22:16:33 +00:00
|
|
|
|
|
2002-08-28 23:13:30 +00:00
|
|
|
|
ptr = scm_realloc (NULL, sz);
|
2002-08-05 23:04:44 +00:00
|
|
|
|
memset (ptr, 0x0, sz);
|
|
|
|
|
|
return ptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-04 23:33:28 +00:00
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
char *
|
|
|
|
|
|
scm_strndup (const char *str, size_t n)
|
|
|
|
|
|
{
|
2002-12-21 18:59:47 +00:00
|
|
|
|
char *dst = scm_malloc (n + 1);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
memcpy (dst, str, n);
|
|
|
|
|
|
dst[n] = 0;
|
|
|
|
|
|
return dst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
|
scm_strdup (const char *str)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_strndup (str, strlen (str));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-03-10 18:39:53 +00:00
|
|
|
|
|
2003-07-06 14:54:07 +00:00
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
scm_gc_register_collectable_memory (void *mem, size_t size, const char *what)
|
|
|
|
|
|
{
|
2011-12-02 19:07:21 +01:00
|
|
|
|
scm_gc_register_allocation (size);
|
|
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
#ifdef GUILE_DEBUG_MALLOC
|
|
|
|
|
|
if (mem)
|
2011-10-22 13:28:53 +02:00
|
|
|
|
scm_malloc_register (mem, what);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-07-06 14:54:07 +00:00
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
void
|
|
|
|
|
|
scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what)
|
|
|
|
|
|
{
|
2006-04-04 21:27:23 +00:00
|
|
|
|
/* Nothing to do. */
|
2002-08-04 00:18:33 +00:00
|
|
|
|
#ifdef GUILE_DEBUG_MALLOC
|
|
|
|
|
|
if (mem)
|
|
|
|
|
|
scm_malloc_unregister (mem);
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-12-04 19:31:20 +01:00
|
|
|
|
/* Allocate SIZE bytes of memory whose contents should not be scanned
|
|
|
|
|
|
for pointers (useful, e.g., for strings). Note though that this
|
|
|
|
|
|
memory is *not* cleared; be sure to initialize it to prevent
|
|
|
|
|
|
information leaks. */
|
2006-04-04 21:27:23 +00:00
|
|
|
|
void *
|
|
|
|
|
|
scm_gc_malloc_pointerless (size_t size, const char *what)
|
|
|
|
|
|
{
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
return do_gc_malloc_atomic (size, what);
|
2006-04-04 21:27:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
void *
|
|
|
|
|
|
scm_gc_malloc (size_t size, const char *what)
|
|
|
|
|
|
{
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
return do_gc_malloc (size, what);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-04 23:33:28 +00:00
|
|
|
|
void *
|
|
|
|
|
|
scm_gc_calloc (size_t size, const char *what)
|
|
|
|
|
|
{
|
2009-10-26 10:25:38 +01:00
|
|
|
|
/* `GC_MALLOC ()' always returns a zeroed buffer. */
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
return do_gc_malloc (size, what);
|
2002-08-04 23:33:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-08-04 00:18:33 +00:00
|
|
|
|
void *
|
|
|
|
|
|
scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what)
|
|
|
|
|
|
{
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
return do_gc_realloc (mem, new_size, what);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
scm_gc_free (void *mem, size_t size, const char *what)
|
|
|
|
|
|
{
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
do_gc_free (mem);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
|
scm_gc_strndup (const char *str, size_t n, const char *what)
|
|
|
|
|
|
{
|
Fix --enable-debug-malloc
* libguile/gc-malloc.c (do_realloc, do_calloc, do_gc_malloc)
(do_gc_malloc_atomic, do_gc_realloc, do_gc_free): Wrap the allocators
in helper methods. The non-GC allocators call
scm_gc_register_allocation, and the GC allocators ensure that
gc_malloc returns a nonzero value.
(scm_realloc, scm_calloc): Allow NULL return for malloc(0). It is
permitted by POSIX. Don't wrap in a SCM_SYSCALL; the only possible
errno is ENOMEM.
(scm_gc_malloc_pointerless, scm_gc_malloc, scm_gc_calloc):
(scm_gc_realloc, scm_gc_free, scm_gc_strndump): Use the wrappers.
Don't call the debug-malloc registrations and deregistrations, as it
is neither mandatory nor advised to call scm_gc_free. Fixes
compilation with debug-malloc.
(scm_must_free): Don't scm_malloc_unregister.
2012-02-05 15:55:09 +01:00
|
|
|
|
char *dst = do_gc_malloc_atomic (n + 1, what);
|
2002-08-04 00:18:33 +00:00
|
|
|
|
memcpy (dst, str, n);
|
|
|
|
|
|
dst[n] = 0;
|
|
|
|
|
|
return dst;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
|
scm_gc_strdup (const char *str, const char *what)
|
|
|
|
|
|
{
|
|
|
|
|
|
return scm_gc_strndup (str, strlen (str), what);
|
|
|
|
|
|
}
|