chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] memory monitoring and leak debugging? (should the ad


From: Daniel Ortmann
Subject: Re: [Chicken-users] memory monitoring and leak debugging? (should the advice be in a web page?)
Date: Wed, 7 Aug 2019 16:10:04 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

I have Scheme calling the C yylex() and can easily get all of the token ints.

I am trying to return '(tok,lineno) '(tok,lineno,intval) or '(tok,lineno,strval)
    C_word *ptr, *sptr;
    C_word lst;
...
        case TOK_G_R_SECT:

            printf("gettoken:(TOK_G_R_SECT,line,text) = (%2d,%3d,'%s')\n", tok, lineno, yylval.sptr);
            ptr = C_alloc(C_SIZEOF_LIST(3));
            lst = C_list(&ptr, 3, C_fix(tok), C_fix(lineno), C_fix(0)); /*C_string2(&sptr, yylval.sptr));*/
            return callin(lst);

Question 1:
Does this stumbling attempt fall under that warning about not calling from C to Scheme?  Or is that warning for something else?

Question 2:
Do I need a bit better magic words to get that 'lst =' line working?  Or am I missing something more major?

Thank you!


On 8/7/19 3:00 PM, Kristian Lein-Mathisen wrote:

Hi Daniel and welcome to the Chicken mailing list.

Another thing to keep in mind is that the Chicken garbage-collector will move objects around during gc. That can cause a lot of hard-to-find bugs, and is probably one of the reasons for Joerg advice on not calling back into Scheme from your foreign-lambdas.

Another cause of problems with the relocations is that you cannot reference Chicken objects in C long-term, because the gc won't be able to update those pointers.

Having said that, the ffi in Chicken is really nice to use, so much that I often use it to explore new C api's.

And also, I sometimes use valgrind to check for memory leaks.

Best of luck!
K.

On Tue, Aug 6, 2019, 22:18 Jörg F. Wittenberger <address@hidden> wrote:
Hello Daniel,

welcome here.

Since CHICKEN compiles into C, all the tools you are used with C to use
are still there.

Personally I'm not a fan of fancy debuggers, since most of the things I
write tend to depend on external (network) events.  I'd welcome tips
how to automate those jobs using better tools than printing log
messages.

Memory use in code mixing C and CHICKEN Scheme can be hairy.  I tend to
recommend to abstain from calling back from C into Scheme until you
know what you are doing.
http://wiki.call-cc.org/man/5/C%20interface#notes

Otherwise I used to run my code under valgrind, which helped me a lot
to catch some errors.

Best Regards

/Jörg

Am Tue, 6 Aug 2019 10:37:06 -0500
schrieb Daniel Ortmann <address@hidden>:

> Hello all,
> I am new to Chicken Scheme and experimenting with binding scheme to a
> C scanner built with Flex.  The results are fast but I feel the need
> to monitor memory use and watch for leaks.
>
> The only relevant thing I find on call-cc.org is this url:
> http://wiki.call-cc.org/chicken-for-emacs-lisp-programmers#tooling
>
> What are your experiences, tools, and practices with debugging mixed
> Scheme + C code?



_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users

_______________________________________________
Chicken-users mailing list
address@hidden
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.nongnu.org_mailman_listinfo_chicken-2Dusers&d=DwIGaQ&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=Dkq-B4wf3U4UeyggH34kSw8HWPy7CqI3u3RwPXz2f5o&m=uGR1RxlutvwNyGUJ8DkkNMO13p4pIcq2C8qZP_SlF2Q&s=zCUp8Z1mO63DzrUtaQUUKKKpB3z_x70a3OgFBS5Unn4&e= 


reply via email to

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