unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* GC ??
@ 2003-12-02 11:59 dv.praveen
  2003-12-02 14:32 ` Andreas Rottmann
  0 siblings, 1 reply; 10+ messages in thread
From: dv.praveen @ 2003-12-02 11:59 UTC (permalink / raw)


hi,
I am using guile 1.6.0. and programming in C.

I am using scm_boot_guile and scm_shell in the function
I pass to scm_boot_guile.  All the SCM objects that are
created, say using 'scm_make_string', 'scm_make_vector'
etc, and assigned to globals don't seem to exist after
call to scm_shell is made.  My code looks something like
this..

#include <libguile.h>
static SCM vector;
static SCM
retVec()
{
    return vector;
}
static void
CreateVector()
{
    vector = scm_make_vector(SCM_MAKINUM(2), SCM_EOL);
}
static void innerMain(void *closure,
        int argc,
        char **argv)
{
    CreateVector();
    scm_c_define_gsubr("retVec", 0, 0, 0, retVec);
    scm_shell(argc, argv);
}
main(int argc, char **argv)
{
    scm_boot_guile(argc,argv,innerMain,0);
}

After I built the program, and call (retVec) on the
'guile>' promt, it doesn't return vector
'#(() ())'  Then I tried to create guardian and protect
'vector' but it doesn't work.  As far as I understood
GC, it should not free any global variables.  Am I missing
something in my understanding?  Any suggestion on how to
make this work would be helpful.
BTW, after I create guardian I used gh_call1 to call the
guardian procedure.(depreciated, but I could not figure out
how to call using SCM interface)

regards,
Praveen


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
  2003-12-02 11:59 GC ?? dv.praveen
@ 2003-12-02 14:32 ` Andreas Rottmann
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Rottmann @ 2003-12-02 14:32 UTC (permalink / raw)
  Cc: guile-user

dv.praveen@skyworksinc.com writes:

> hi,
> I am using guile 1.6.0. and programming in C.
> 
> I am using scm_boot_guile and scm_shell in the function
> I pass to scm_boot_guile.  All the SCM objects that are
> created, say using 'scm_make_string', 'scm_make_vector'
> etc, and assigned to globals don't seem to exist after
> call to scm_shell is made.  My code looks something like
> this..
> 
> #include <libguile.h>
> static SCM vector;
> static SCM
> retVec()
> {
>     return vector;
> }
> static void
> CreateVector()
> {
>     vector = scm_make_vector(SCM_MAKINUM(2), SCM_EOL);
> }

use 'vector = scm_permanent_object (scm_make_vector(...'

Regards, Andy
-- 
Andreas Rottmann


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
@ 2003-12-03  7:20 dv.praveen
  2003-12-03 10:44 ` Matthias Koeppe
  0 siblings, 1 reply; 10+ messages in thread
From: dv.praveen @ 2003-12-03  7:20 UTC (permalink / raw)


hi Andreas Rottmann,
Thank you very much for the reply.  It works. :)
This function was not covered in the documentation
and I missed it.
My question is still unasnwered.  Shouldn't the
garbage collector attend all the globals and the
recurse on the internal scm objects during the
trace operation?
regards,
Praveen





Andreas Rottmann <e9926584@student.tuwien.ac.at>
02/12/2003 08:02 PM

 
        To:     D.V. Praveen/Intl/Skyworks@Skymail
        cc:     guile-user@gnu.org@SMTP@Exchange
        Subject:        Re: GC ??

dv.praveen@skyworksinc.com writes:

> hi,
> I am using guile 1.6.0. and programming in C.
> 
> I am using scm_boot_guile and scm_shell in the function
> I pass to scm_boot_guile.  All the SCM objects that are
> created, say using 'scm_make_string', 'scm_make_vector'
> etc, and assigned to globals don't seem to exist after
> call to scm_shell is made.  My code looks something like
> this..
> 
> #include <libguile.h>
> static SCM vector;
> static SCM
> retVec()
> {
>     return vector;
> }
> static void
> CreateVector()
> {
>     vector = scm_make_vector(SCM_MAKINUM(2), SCM_EOL);
> }

use 'vector = scm_permanent_object (scm_make_vector(...'

Regards, Andy
-- 
Andreas Rottmann




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
  2003-12-03  7:20 dv.praveen
@ 2003-12-03 10:44 ` Matthias Koeppe
  2003-12-03 12:45   ` Stephen Compall
  0 siblings, 1 reply; 10+ messages in thread
From: Matthias Koeppe @ 2003-12-03 10:44 UTC (permalink / raw)
  Cc: guile-user

dv.praveen@skyworksinc.com writes:

> My question is still unasnwered.  Shouldn't the
> garbage collector attend all the globals and the
> recurse on the internal scm objects during the
> trace operation?

The garbage collector only scans the Scheme heap and the C/Scheme
stack, but neither the global C data nor the C heap.  I think the
rationale is that it would be very expensive to scan these memory
regions because they may be very large and contain only very few
Scheme objects.  Moreover, they may contain many "false pointers" that
look like Scheme objects, which would make garbage collection
ineffective. 

Therefore one needs to manually protect Scheme objects that are stored
in these memory regions from being garbage collected.

-- 
Matthias Koeppe -- http://www.math.uni-magdeburg.de/~mkoeppe


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
       [not found] <200312030720.hB37Khv7022012@smtp1.urprovider.com>
@ 2003-12-03 11:25 ` Andreas Rottmann
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Rottmann @ 2003-12-03 11:25 UTC (permalink / raw)
  Cc: guile-user

"D.V. Praveen" <dv.praveen@skyworksinc.com> writes:

> hi Andreas Rottmann,
> Thank you very much for the reply.  It works. :)
> This function was not covered in the documentation
> and I missed it.
> My question is still unasnwered.  Shouldn't the
> garbage collector attend all the globals and the
> recurse on the internal scm objects during the
> trace operation?
>
Not really, since it can't really know which part of the (global) data
space it should check for SCM values, so you have to register them
explicitly.

Andy
-- 
Andreas Rottmann         | Rotty@ICQ      | 118634484@ICQ | a.rottmann@gmx.at
http://www.8ung.at/rotty | GnuPG Key: http://www.8ung.at/rotty/gpg.asc
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

This reality is really just a fucked-up dream -- Papa Roach


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
  2003-12-03 10:44 ` Matthias Koeppe
@ 2003-12-03 12:45   ` Stephen Compall
  2003-12-03 15:55     ` Ludovic Courtès
  2003-12-03 17:04     ` Matthias Koeppe
  0 siblings, 2 replies; 10+ messages in thread
From: Stephen Compall @ 2003-12-03 12:45 UTC (permalink / raw)


Matthias Koeppe <mkoeppe@merkur.math.uni-magdeburg.de> writes:

> The garbage collector only scans the Scheme heap and the C/Scheme
> stack, but neither the global C data nor the C heap.

Given this, do C functions that use SCM objects and presumably might
call GC at some point need to declare their SCM variables volatile?

--
Stephen Compall or s11 or sirian

brain-damaged, generalization of "Honeywell Brain Damage" (HBD), a
theoretical disease invented to explain certain utter cretinisms in
Multics, adj:
	Obviously wrong; cretinous; demented.  There is an implication
	that the person responsible must have suffered brain damage,
	because he/she should have known better.  Calling something
	brain-damaged is bad; it also implies it is unusable.

SAFE Adriatic Etacs Panama Baranyi quarter Kosovo SDI hackers
investigation national information infrastructure Comirex bomb
Chobetsu warfare


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
@ 2003-12-03 12:58 dv.praveen
  2003-12-03 17:08 ` Matthias Koeppe
  0 siblings, 1 reply; 10+ messages in thread
From: dv.praveen @ 2003-12-03 12:58 UTC (permalink / raw)


hi Matthias,
I am trying to understand Andreas and your mail.
I still have few questions.

+ There would be 3 heaps for program that we write
  a. C heap
  b. C/Scheme heap
  c. Scheme heap.
+ The C heap would not be traced by GC.
+ It is in the Scheme heap GC is going to trace.

What is C/S heap for?
Is it in the Scheme heap guile creates 'heap segments'
for storing Scheme objects?

Andreas told about the function 'scm_permanent_object'.
Given an SCM object to this function where would it
get stored? Would the given value never be reached by
GC or it would be skipped by GC?

What is the difference b/w storing a SCM value using
scm_permanent_object and protecting using guardian proc
returned by scm_make_guardian? Why doesn't guardian proc
work for the program I wrote?

Can you please explain?

regards,
Praveen
 




Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
03/12/2003 04:14 PM

 
        To:     D.V. Praveen/Intl/Skyworks@Skymail
        cc:     guile-user@gnu.org@SMTP@Exchange
        Subject:        Re: GC ??

dv.praveen@skyworksinc.com writes:

> My question is still unasnwered.  Shouldn't the
> garbage collector attend all the globals and the
> recurse on the internal scm objects during the
> trace operation?

The garbage collector only scans the Scheme heap and the C/Scheme
stack, but neither the global C data nor the C heap.  I think the
rationale is that it would be very expensive to scan these memory
regions because they may be very large and contain only very few
Scheme objects.  Moreover, they may contain many "false pointers" that
look like Scheme objects, which would make garbage collection
ineffective. 

Therefore one needs to manually protect Scheme objects that are stored
in these memory regions from being garbage collected.

-- 
Matthias Koeppe -- http://www.math.uni-magdeburg.de/~mkoeppe




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
  2003-12-03 12:45   ` Stephen Compall
@ 2003-12-03 15:55     ` Ludovic Courtès
  2003-12-03 17:04     ` Matthias Koeppe
  1 sibling, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2003-12-03 15:55 UTC (permalink / raw)
  Cc: guile-user

Hi,

Today, 3 hours, 5 minutes, 19 seconds ago, Stephen Compall wrote:
> Given this, do C functions that use SCM objects and presumably might
> call GC at some point need to declare their SCM variables volatile?

No.  If a C function is passed (by Guile) an SCM object, Guile *knows*
the underlying Scheme object is still referenced so it may not be
garbage collected.

Also, note that GC may only happen on scm_must_malloc () calls I think.

Cheers,
Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
  2003-12-03 12:45   ` Stephen Compall
  2003-12-03 15:55     ` Ludovic Courtès
@ 2003-12-03 17:04     ` Matthias Koeppe
  1 sibling, 0 replies; 10+ messages in thread
From: Matthias Koeppe @ 2003-12-03 17:04 UTC (permalink / raw)
  Cc: guile-user

Stephen Compall <s11@member.fsf.org> writes:

> Matthias Koeppe <mkoeppe@merkur.math.uni-magdeburg.de> writes:
>
>> The garbage collector only scans the Scheme heap and the C/Scheme
>> stack, but neither the global C data nor the C heap.
>
> Given this, do C functions that use SCM objects and presumably might
> call GC at some point need to declare their SCM variables volatile?

"Scanning" means finding pointers to live Scheme objects.  Guile's
conservative GC never changes the pointer values of live objects, as a
copying GC would do.  Therefore, there is no reason to declare SCM
variables volatile.

-- 
Matthias Koeppe -- http://www.math.uni-magdeburg.de/~mkoeppe
SWIG makes Guile wrappers for C/C++ libs -- http://www.swig.org
ILISP does module-aware Emacs/Guile interaction -- http://sf.net/projects/ilisp


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GC ??
  2003-12-03 12:58 dv.praveen
@ 2003-12-03 17:08 ` Matthias Koeppe
  0 siblings, 0 replies; 10+ messages in thread
From: Matthias Koeppe @ 2003-12-03 17:08 UTC (permalink / raw)
  Cc: guile-user

dv.praveen@skyworksinc.com writes:

> + There would be 3 heaps for program that we write
>   a. C heap
>   b. C/Scheme heap
>   c. Scheme heap.
> + The C heap would not be traced by GC.
> + It is in the Scheme heap GC is going to trace.
>
> What is C/S heap for?

I wrote "C/Scheme _stack_".  The C and the Scheme side use the same
stack.  This is where nested function calls etc. are recorded.

The Scheme objects are all stored in the Scheme heap.  But pointers to
Scheme objects can live in all three memory regions.

When we say that the GC scans a memory region, it means that it scans
it for pointers to live Scheme objects.  This is also referred to as
the "marking phase" of GC.  After marking all live objects, the GC can
collect (delete) all unmarked objects.

> Andreas told about the function 'scm_permanent_object'.
> Given an SCM object to this function where would it
> get stored? Would the given value never be reached by
> GC or it would be skipped by GC?

As far as I know, scm_permanent_object simply registers its argument
as another root from which the recursive marking procedure is started.

> [about guardians]

I have never used guardians, so I can't help here.

-- 
Matthias Koeppe -- http://www.math.uni-magdeburg.de/~mkoeppe
SWIG makes Guile wrappers for C/C++ libs -- http://www.swig.org
ILISP does module-aware Emacs/Guile interaction -- http://sf.net/projects/ilisp


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-12-03 17:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-02 11:59 GC ?? dv.praveen
2003-12-02 14:32 ` Andreas Rottmann
  -- strict thread matches above, loose matches on Subject: below --
2003-12-03  7:20 dv.praveen
2003-12-03 10:44 ` Matthias Koeppe
2003-12-03 12:45   ` Stephen Compall
2003-12-03 15:55     ` Ludovic Courtès
2003-12-03 17:04     ` Matthias Koeppe
     [not found] <200312030720.hB37Khv7022012@smtp1.urprovider.com>
2003-12-03 11:25 ` Andreas Rottmann
2003-12-03 12:58 dv.praveen
2003-12-03 17:08 ` Matthias Koeppe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).