On 8/8/07, Joshua Hoblitt <[EMAIL PROTECTED]> wrote:
> On Wed, Aug 08, 2007 at 12:17:17AM -0700, chromatic wrote:
> > The string_from_cstring() function has a slight flaw, in that it has to
> > allocate a piece of memory and create a C-style string from a nice happy
> > STRING. It's the responsibility of the caller to discard the C string
> > appropriately.
> >
> > This is tricky if that string immediately gets passed to real_exception() or
> > some other C function which does not return control; there's no chance to
> > free the string with string_cstring_free().
>
> I hate to sound like the nag here but why don't we just not write code
> in form 'real_exception(string_from_cstring(foo))'. Part of living with
> dynamic memory allocating is dealing with the line bloat of shoving that
> free() call in there.
>
i'm not a great c programmer, so could you explain to me what code
should look like instead of what it shouldn't? here's the code at
src/pmc/delegate.pmc, line 51 as an example (copied here):
_class = string_to_cstring(interp, pmc->vtable->whoami);
real_exception(interp, NULL, E_LookupError,
"Can't find vtable method '%s' in class '%s'", meth, _class);
/* sorry, can't do this here. will it leak?
string_cstring_free(_class);
*/
~jerry