unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* seg fault with repeated function calls from C?
@ 2008-12-16  6:22 Anand Dixit
  2008-12-16 17:17 ` Anand Dixit
  0 siblings, 1 reply; 8+ messages in thread
From: Anand Dixit @ 2008-12-16  6:22 UTC (permalink / raw)
  To: guile-user

Hi all,
   I am calling a guile function from my C code. Its a fairly straight
forward implementation. However, as I keep calling this function a
number of times, it breaks at some point with a segmentation fault. Here
is the relevant portion :

int tmp,count=10000;
for (tmp=1;tmp<count;tmp++) {
		func_symbol = scm_c_lookup("EsourceFn");	
  func = scm_variable_ref(func_symbol);
ret=scm_call_4(func,scm_int2num(i),scm_int2num(j),scm_int2num(k),scm_double2num(currentTime));
		retValue = scm_num2double(ret,0,"fdtd");
		printf("Value from guile is tmp=%d %g\n",tmp,retValue);
		}

The break point in one case was after 4000+ calls. I was able to
localize the point of failure to the "scm_call_4" line. Any clue would
be greatly appreciated.
   
  Thanks,
  - Anand





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

* Re: seg fault with repeated function calls from C?
  2008-12-16  6:22 seg fault with repeated function calls from C? Anand Dixit
@ 2008-12-16 17:17 ` Anand Dixit
  2008-12-16 20:08   ` Ludovic Courtès
  2008-12-16 22:23   ` Andy Wingo
  0 siblings, 2 replies; 8+ messages in thread
From: Anand Dixit @ 2008-12-16 17:17 UTC (permalink / raw)
  To: guile-user

Resending to the group.My apologies if you receive it twice but I didn't
see the post in the archives.

 - Anand


On Mon, 2008-12-15 at 22:22 -0800, Anand Dixit wrote:
> Hi all,
>    I am calling a guile function from my C code. Its a fairly straight
> forward implementation. However, as I keep calling this function a
> number of times, it breaks at some point with a segmentation fault. Here
> is the relevant portion :
> 
> int tmp,count=10000;
> for (tmp=1;tmp<count;tmp++) {
> 		func_symbol = scm_c_lookup("EsourceFn");	
>   func = scm_variable_ref(func_symbol);
> ret=scm_call_4(func,scm_int2num(i),scm_int2num(j),scm_int2num(k),scm_double2num(currentTime));
> 		retValue = scm_num2double(ret,0,"fdtd");
> 		printf("Value from guile is tmp=%d %g\n",tmp,retValue);
> 		}
> 
> The break point in one case was after 4000+ calls. I was able to
> localize the point of failure to the "scm_call_4" line. Any clue would
> be greatly appreciated.
>    
>   Thanks,
>   - Anand
> 





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

* Re: seg fault with repeated function calls from C?
  2008-12-16 17:17 ` Anand Dixit
@ 2008-12-16 20:08   ` Ludovic Courtès
  2008-12-17  0:23     ` Anand Dixit
  2008-12-16 22:23   ` Andy Wingo
  1 sibling, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2008-12-16 20:08 UTC (permalink / raw)
  To: guile-user; +Cc: Anand Dixit

Hello,

Anand Dixit <Anand.Dixit@Sun.COM> writes:

> Resending to the group.My apologies if you receive it twice but I didn't
> see the post in the archives.

Apparently I did not receive it the first time.

>>    I am calling a guile function from my C code. Its a fairly straight
>> forward implementation. However, as I keep calling this function a
>> number of times, it breaks at some point with a segmentation fault. Here
>> is the relevant portion :
>> 
>> int tmp,count=10000;
>> for (tmp=1;tmp<count;tmp++) {
>> 		func_symbol = scm_c_lookup("EsourceFn");	
>>   func = scm_variable_ref(func_symbol);
>> ret=scm_call_4(func,scm_int2num(i),scm_int2num(j),scm_int2num(k),scm_double2num(currentTime));
>> 		retValue = scm_num2double(ret,0,"fdtd");
>> 		printf("Value from guile is tmp=%d %g\n",tmp,retValue);
>> 		}
>> 
>> The break point in one case was after 4000+ calls. I was able to
>> localize the point of failure to the "scm_call_4" line. Any clue would
>> be greatly appreciated.

Could you provide a complete backtrace with GDB?  To do that, run GDB as
follows on the `core' file yielded by the segfault:

  $ gdb `which guile` core
  (gdb) bt full

(If there's no `core' file, type "ulimit -c unlimited".)

Could it be that the `EsourceFn' symbol becomes unbound at some point,
or that it becomes bound to something that's not a procedure?  Both
errors should normally be caught gracefully, but it's worth
investigating.

Also, which version of Guile are you using?

Thanks,
Ludo'.





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

* Re: seg fault with repeated function calls from C?
  2008-12-16 17:17 ` Anand Dixit
  2008-12-16 20:08   ` Ludovic Courtès
@ 2008-12-16 22:23   ` Andy Wingo
  2008-12-17  0:46     ` Anand Dixit
  1 sibling, 1 reply; 8+ messages in thread
From: Andy Wingo @ 2008-12-16 22:23 UTC (permalink / raw)
  To: Anand Dixit; +Cc: guile-user

On Tue 16 Dec 2008 18:17, Anand Dixit <Anand.Dixit@Sun.COM> writes:

>>    I am calling a guile function from my C code. Its a fairly straight
>> forward implementation. However, as I keep calling this function a
>> number of times, it breaks at some point with a segmentation fault. Here
>> is the relevant portion :

Can we see a C-level backtrace? Things look OK to me on first glance.

Andy
-- 
http://wingolog.org/




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

* Re: seg fault with repeated function calls from C?
  2008-12-16 20:08   ` Ludovic Courtès
@ 2008-12-17  0:23     ` Anand Dixit
  2008-12-17 10:28       ` Neil Jerram
  0 siblings, 1 reply; 8+ messages in thread
From: Anand Dixit @ 2008-12-17  0:23 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-user

Hi Ludo,
  Looks like it accepts a post to guile-user only when you are
registered. That would explain why the first post didn't show up. 

  Guile version is 1.8.3 running on Ubuntu 8.04. I tried the gdb
commands you mentioned and here is a portion of the output :

This GDB was configured as "x86_64-linux-gnu"...
(no debugging symbols found)

warning: core file may not match specified executable file.

(no debugging symbols found)
(no debugging symbols found)
Core was generated by `fdtd poisson.ctl'.
Program terminated with signal 11, Segmentation fault.
[New process 12395]
#0  0x00007f18eff3b49b in ?? ()
(gdb) bt full
#0  0x00007f18eff3b49b in ?? ()
No symbol table info available.
#1  0x00007f18eff3b3c7 in ?? ()
No symbol table info available.
#2  0x00007ffff83f19dc in ?? ()

  This continues to #132 lines. My C++ code is compiled with -g option.
I am not sure if this is what you expected from gdb.
 
  Thanks,
  Anand

On Tue, 2008-12-16 at 21:08 +0100, Ludovic Courtès wrote:
> Hello,
> 
> Anand Dixit <Anand.Dixit@Sun.COM> writes:
> 
> > Resending to the group.My apologies if you receive it twice but I didn't
> > see the post in the archives.
> 
> Apparently I did not receive it the first time.
> 
> >>    I am calling a guile function from my C code. Its a fairly straight
> >> forward implementation. However, as I keep calling this function a
> >> number of times, it breaks at some point with a segmentation fault. Here
> >> is the relevant portion :
> >> 
> >> int tmp,count=10000;
> >> for (tmp=1;tmp<count;tmp++) {
> >> 		func_symbol = scm_c_lookup("EsourceFn");	
> >>   func = scm_variable_ref(func_symbol);
> >> ret=scm_call_4(func,scm_int2num(i),scm_int2num(j),scm_int2num(k),scm_double2num(currentTime));
> >> 		retValue = scm_num2double(ret,0,"fdtd");
> >> 		printf("Value from guile is tmp=%d %g\n",tmp,retValue);
> >> 		}
> >> 
> >> The break point in one case was after 4000+ calls. I was able to
> >> localize the point of failure to the "scm_call_4" line. Any clue would
> >> be greatly appreciated.
> 
> Could you provide a complete backtrace with GDB?  To do that, run GDB as
> follows on the `core' file yielded by the segfault:
> 
>   $ gdb `which guile` core
>   (gdb) bt full
> 
> (If there's no `core' file, type "ulimit -c unlimited".)
> 
> Could it be that the `EsourceFn' symbol becomes unbound at some point,
> or that it becomes bound to something that's not a procedure?  Both
> errors should normally be caught gracefully, but it's worth
> investigating.
> 
> Also, which version of Guile are you using?
> 
> Thanks,
> Ludo'.
> 
> 
> 





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

* Re: seg fault with repeated function calls from C?
  2008-12-16 22:23   ` Andy Wingo
@ 2008-12-17  0:46     ` Anand Dixit
  2008-12-17  2:46       ` Anand Dixit
  0 siblings, 1 reply; 8+ messages in thread
From: Anand Dixit @ 2008-12-17  0:46 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-user

Hi Andy,
 
  Here is the output from 'gdb fdtd core' (fdtd is the excutable name).
Another point to note: I had similar problems with the scm_c_eval_string
command - it would also give me segmentation fault after some
iterations. scm_call allows for more evaluations before failing. Let me
know if you want me to try some other command.

--------------------
This GDB was configured as "x86_64-linux-gnu"...

warning: Can't read pathname for load map: Input/output error.
Reading symbols from /usr/lib/libguile.so.17...done.
Loaded symbols for /usr/lib/libguile.so.17
Reading symbols from /usr/lib/libltdl.so.3...done.
Loaded symbols for /usr/lib/libltdl.so.3
Reading symbols from /usr/lib/libgmp.so.3...done.
Loaded symbols for /usr/lib/libgmp.so.3
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /lib/libnsl.so.1...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /lib/libpthread.so.0...done.
Loaded symbols for /lib/libpthread.so.0
Reading symbols from /lib/libm.so.6...done.
Loaded symbols for /lib/libm.so.6
Reading symbols from /usr/lib/libstdc++.so.6...done.
Loaded symbols for /usr/lib/libstdc++.so.6
Reading symbols from /lib/libgcc_s.so.1...done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux-x86-64.so.2...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /usr/lib/libguilereadline-v-17.so.17...done.
Loaded symbols for /usr/lib/libguilereadline-v-17.so.17
Reading symbols from /lib/libreadline.so.5...done.
Loaded symbols for /lib/libreadline.so.5
Reading symbols from /lib/libncurses.so.5...done.
Loaded symbols for /lib/libncurses.so.5
Core was generated by `fdtd poisson.ctl'.
Program terminated with signal 11, Segmentation fault.
[New process 12395]
#0  0x00007f18eff3b49b in scm_gc_mark () from /usr/lib/libguile.so.17
(gdb) bt
#0  0x00007f18eff3b49b in scm_gc_mark () from /usr/lib/libguile.so.17
#1  0x00007f18eff3b3c7 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#2  0x00007f18eff3b3c7 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#3  0x00007f18eff3b241 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#4  0x00007f18eff3b2d6 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#5  0x00007f18eff3b241 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#6  0x00007f18eff3b2d6 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#7  0x00007f18eff3b241 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#8  0x00007f18eff3b2d6 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#9  0x00007f18eff3b3c7 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#10 0x00007f18eff3b241 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#11 0x00007f18eff3b2d6 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#12 0x00007f18eff3b3c7 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#13 0x00007f18eff3b241 in scm_gc_mark_dependencies ()
from /usr/lib/libguile.so.17
#14 0x00007f18eff814a3 in scm_threads_mark_stacks ()
from /usr/lib/libguile.so.17
#15 0x00007f18eff3b598 in scm_mark_all () from /usr/lib/libguile.so.17
#16 0x00007f18eff3a64a in scm_i_gc () from /usr/lib/libguile.so.17
#17 0x00007f18eff3a84e in scm_gc_for_newcell ()
from /usr/lib/libguile.so.17
#18 0x00007f18eff5a3e5 in scm_cons () from /usr/lib/libguile.so.17
#19 0x00007f18eff5a3ff in scm_cons2 () from /usr/lib/libguile.so.17
#20 0x00007f18eff2fee5 in scm_call_4 () from /usr/lib/libguile.so.17
#21 0x00000000004288ab in Esource::fixE (this=0xe04b80) at
esource.hpp:61
#22 0x0000000000423b4a in inner_main (argc=<value optimized out>,
argv=0x7ffff83f3dd8)
---Type <return> to continue, or q <return> to quit---
    at fdtd.cpp:722
#23 0x00007f18eff3e99e in ?? () from /usr/lib/libguile.so.17
#24 0x00007f18eff48caf in ?? () from /usr/lib/libguile.so.17
#25 0x00007f18eff2119a in ?? () from /usr/lib/libguile.so.17
#26 0x00007f18eff82865 in scm_c_catch () from /usr/lib/libguile.so.17
#27 0x00007f18eff215b6 in scm_i_with_continuation_barrier ()
from /usr/lib/libguile.so.17
#28 0x00007f18eff21650 in scm_c_with_continuation_barrier ()
from /usr/lib/libguile.so.17
#29 0x00007f18eff81ce3 in scm_i_with_guile_and_parent ()
from /usr/lib/libguile.so.17
#30 0x00007f18eff48c75 in scm_boot_guile () from /usr/lib/libguile.so.17
#31 0x0000000000417dee in main (argc=0, argv=0x10000000000) at
fdtd.cpp:1005

--------------------------
 Thanks,
   - Anand

On Tue, 2008-12-16 at 23:23 +0100, Andy Wingo wrote:
> On Tue 16 Dec 2008 18:17, Anand Dixit <Anand.Dixit@Sun.COM> writes:
> 
> >>    I am calling a guile function from my C code. Its a fairly straight
> >> forward implementation. However, as I keep calling this function a
> >> number of times, it breaks at some point with a segmentation fault. Here
> >> is the relevant portion :
> 
> Can we see a C-level backtrace? Things look OK to me on first glance.
> 
> Andy





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

* Re: seg fault with repeated function calls from C?
  2008-12-17  0:46     ` Anand Dixit
@ 2008-12-17  2:46       ` Anand Dixit
  0 siblings, 0 replies; 8+ messages in thread
From: Anand Dixit @ 2008-12-17  2:46 UTC (permalink / raw)
  To: guile-user

Hi all,
 
  I was using a few deprecated commands from the 'gh_' interface
(specifically gh_enter and gh_scm2newstr). On a hunch, I converted those
to scm calls, removed the include for guile/gh.h and now I don't have
any trouble even with 5million calls to scm_call_4. The question now is
if the problem was related to the gh_ functions interacting in some way
or have I just postponed when I see the problem again. After all, the
segment that was giving segmentation fault was not making any explicit
gh_ calls.

  Thanks,
  - Anand






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

* Re: seg fault with repeated function calls from C?
  2008-12-17  0:23     ` Anand Dixit
@ 2008-12-17 10:28       ` Neil Jerram
  0 siblings, 0 replies; 8+ messages in thread
From: Neil Jerram @ 2008-12-17 10:28 UTC (permalink / raw)
  To: Anand Dixit; +Cc: Ludovic Courtès, guile-user

2008/12/17 Anand Dixit <Anand.Dixit@sun.com>:
> Hi Ludo,
>  Looks like it accepts a post to guile-user only when you are
> registered. That would explain why the first post didn't show up.

Posts to guile-user from non-subscribers are moderated by a group of
GNU project volunteers.  So if they all happen to be busy at the same
time, there can be a delay before emails are seen and allowed through.
 (Your email has come through now.)

The same applies to all the Guile lists.

Regards,
          Neil




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

end of thread, other threads:[~2008-12-17 10:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-16  6:22 seg fault with repeated function calls from C? Anand Dixit
2008-12-16 17:17 ` Anand Dixit
2008-12-16 20:08   ` Ludovic Courtès
2008-12-17  0:23     ` Anand Dixit
2008-12-17 10:28       ` Neil Jerram
2008-12-16 22:23   ` Andy Wingo
2008-12-17  0:46     ` Anand Dixit
2008-12-17  2:46       ` Anand Dixit

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).