[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: scm_must_malloc() vs. malloc()
From: |
Martin Grabmueller |
Subject: |
Re: scm_must_malloc() vs. malloc() |
Date: |
Wed, 14 Mar 2001 10:54:05 +0100 |
> From: Dirk Herrmann <address@hidden>
> Date: Tue, 13 Mar 2001 17:48:39 +0100 (MET)
>
> On Tue, 13 Mar 2001, Martin Grabmueller wrote:
>
> > Additionally, gh_data.c contains a lot of code like this:
> >
> > if (m == 0)
> > m = (short *) malloc (n * sizeof (short));
> > for (i = 0; i < n; ++i)
> > m[i] = SCM_INUM (SCM_VELTS (obj)[i]);
> >
> > I think these should get replaced by calls to scm_must_malloc too.
> > We don't want segfaults, do we?
>
> These should, IMO, _not_ be replaced by scm_must_malloc. Let me try
> to give an explanation about when scm_must_malloc should be used:
[snip explanation]
So the rule of thumb is: If we return something which the caller must
free() herself, we use malloc, otherwise scm_must_malloc()?
> Now, looking at the code in gh_data.c: Some functions convert scheme
> vectors into a corresponding C level array. The C level array is
> created with malloc. But, these arrays are not under control of the
> garbage collector. It completely depends on the calling function
> what it will do with them. Thus, in these cases you should not use
> scm_must_malloc.
Then I suppose it's correct to change `gh_scm2newstr', `symbol2newstr'
to use malloc(), because it returns malloc()ed memory which the caller
must free. I'll fix that.
Regards,
'martin