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....
Afficher les réponses par date
Oh - oops. The final argument to ___UTF_8STRING_to_SCMOBJ is arg_num, not the allocation policy. What should this be?
Thanks,
Phil
Phil Dawes wrote:
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.... _______________________________________________ Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 1-Feb-07, at 5:57 AM, Phil Dawes wrote:
Oh - oops. The final argument to ___UTF_8STRING_to_SCMOBJ is arg_num, not the allocation policy. What should this be?
Thanks,
Phil
You can pass any integer. This information is included in the error code when there is an error. By the way, you should check for errors (such as heap overflow) if you want your code to be robust.
Marc