Re: [eclipse-users] ec_cleanup() segmentation fault

From: Kish Shen <kish_at_...2...>
Date: Tue, 05 Feb 2008 15:55:41 +0000
Hi Giuseppe,

I think the seg fault is caused by an incorrect use of cut_to() method:

 >    while (EC_succeed == EC_resume(Search)) {
 >      ......
 >        Search.cut_to();

You should not be calling cut_to() with Search, which is not 
initialised, and will thus cause the cut to be applied to some undefined 
value (i.e. essentially a random value), which leads to the seg fault..

As mentioned in the ECLiPSe embedding manual

cut_to() should be applied to a ToC cut return value of an EC_resume, in 
this case EC_resume with two arguments, not the one with one argument 
that you called, so you need something like:

    EC_ref  ToC;
    while (EC_succeed == EC_resume(Search, ToC)) {

I tested the change to your code as shown above, and the program runs 
without crashing.

We are looking to see if it is possible for the C++ interface to catch 
these sort of errors and abort the execution when these errors are 
detected, instead of crashing like this.

However, a more general point about interfacing to ECLiPSe from an 
external language: it is best to try and keep the interface between the 
two languages as simple as possible -- in particular, try to avoid 
constructing complex data structures for the other language (e.g. 
ECLiPSe data structures/goals in C++, as in your case), and in using 
such dangerous features as applying a cut from C++ (which is what 
cut_to() does, except that unlike ECLiPSe, the programmer need to supply 
the correct for the cut to apply to). In general, it is

1) easy to get these wrong, but difficult for ECLiPSe to catch every 
possible error,

2) it is much more difficult to read the code and see what the actual 
data structures etc. are,

If there is a problem that is not caught by the interface, the resulting 
problem might cause a seg fault immediately if you are lucky, or it can 
mess up the ECLiPSe execution state in subtle ways that may cause 
problems some time later that would be very difficult to debug..

So for your example, instead of constructing the expressions in C++ and 
then calling a goal and then applying a cut to it from C++, it is better 
to write an ECLiPSe program with the goal and cut:

mygoal(...) :-
    <do set up>
    indomain(....), !.

then in your C++ code, you can call ECLiPSe to load the file with 
mygoal(...) in it, and then call mygoal, which does the set up of the 
various terms you need (you can supply the data via the arguments for 
mygoal), and then does the indomain(...) followed by the cut, all in 



Giuseppe Di Guglielmo wrote:
> Dear all,
> I am using last release of ECLiPSe and its C++ interface.
> The produced executable fails with a segmentation fault on ec_cleanup()
> function. The debugger says that the problem is related to EC_ref destructor
> invoked in ec_cleanup().
Received on Tue Feb 05 2008 - 15:56:23 CET

This archive was generated by hypermail 2.3.0 : Wed Aug 21 2019 - 09:13:31 CEST