[Top][All Lists]

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

Custom allocation of cells

From: Ludovic Courtès
Subject: Custom allocation of cells
Date: Tue, 03 May 2005 17:09:42 +0200
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)


I'd like to know whether one can reliably allocate a cell on its own,
without using `scm_cell ()'.  Basically, I read appendix A of the manual
and I'm now naively trying to do my own cell allocation.  Here is a
(stupid and ugly) example:

  SCM_DEFINE (scm_do_pair, "do-pair", 2, 0, 0,
              (SCM car, SCM cdr),
    static SCM room[512];
    static SCM *where = &room[0];
    SCM the_pair;
    size_t incr;

    if ((scm_t_bits)where & 6)
        /* Align the cell pointer so that Guile considers it as a
           non-immediate object (see tags.h).  */
        incr = (scm_t_bits)where & 6;
        incr = (~incr) & 7;
        where += incr;

    where[0] = car;
    where[1] = cdr;

    the_pair = PTR2SCM (where);

    return (the_pair);

This does return a pair, but the next time the GC runs, Guile
segfaults.  This is because `SCM_SET_GC_MARK ()' assumes that WHERE is
located within a cell segment, which is not the case here.

So my question is: Is there a way to allocate cells, cheaper than
`scm_cell ()', that could be used?  This would be particularly useful
for Guile-VM.  When calling a procedure (i.e. with the interpreter, via
`scm_apply ()'), the VM as to build a list out of the arguments which
are already available on the stack, and this turns out to be pretty


reply via email to

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