emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hash-table-{to, from}-alist


From: Andreas Schwab
Subject: Re: hash-table-{to, from}-alist
Date: Tue, 02 Dec 2008 22:27:37 +0100
User-agent: Gnus/5.110009 (No Gnus v0.9) Emacs/22.3 (gnu/linux)

Ted Zlatanov <address@hidden> writes:

> I ended up with this code to put a list into Fmake_hash_table format
> ('params' is a Lisp_Object that holds a bunch of conses).
>
>             int param_count = 0;
>             Lisp_Object *pa = (Lisp_Object*) 
> xmalloc(XFASTINT(Flength(params)) * sizeof(Lisp_Object));
>
>             while (!NILP(params))
>               {
>                 pa[param_count++] = CAR_SAFE(params);
>                 params = CDR_SAFE(params);
>               }
>
>             Lisp_Object ht = Fmake_hash_table(param_count, pa);

This is of course a memory leak, since pa is never freed.

> I would prefer it if I could avoid all that work, but it seems (from
> reading lisp.h and hunting for similar code) that it must be done as
> above.  I don't see a macro to convert a Lisp_Object that holds a list
> into the Lisp_Object* that a lot of functions need.

Since you know the max size of the array, just declare it as such.

(One more reason to implement it in Lisp.)

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]