[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
#<<c-lambda-end
    ___SCMOBJ s,list,tmp;
    int i;
    char *p = "hello";
    ___EXT(___UTF_8STRING_to_SCMOBJ)(p,&s,___STILL);

    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;

c-lambda-end
))


Many thanks,

Phil

[1] http://libcsv.sourceforge.net/
[2] 
https://webmail.iro.umontreal.ca/pipermail/gambit-list/2005-December/000510.html



More information about the Gambit-list mailing list