[gambit-list] list ref counting with c interface

Phil Dawes pdawes at users.sf.net
Thu Feb 1 05:33:31 EST 2007

Hi Marc, Hi List,

I need a fast csv parser and so I plan to wrap a the C libcsv[1] code. 
My gambit interface will be doing a lot of consing and so I just wanted 
to check that I've correctly interpreted how the C scheme-object 
refcounting works (from previous posts[2]). Here's an example which 
returns a list of a million elements - have I done all the 
de-referencing right?
(I'm assuming that everytime I put a scheme object into another one, I 
can release it - correct?)

(define test-return-list
   (c-lambda () scheme-object
    ___SCMOBJ s,list,tmp;
    int i;
    char *p = "hello";

    list = ___NUL;

    for (i=0; i<1000000; i++){
         tmp  = ___EXT(___make_pair) (s,list, ___STILL);
         ___EXT(___release_scmobj) (list);
         list = tmp;

    /* deref remaining ref counts */
    ___EXT(___release_scmobj) (list);
    ___EXT(___release_scmobj) (s);

    ___result = list;


Many thanks,


[1] http://libcsv.sourceforge.net/

More information about the Gambit-list mailing list