[eclipse-users] ec_cleanup() segmentation fault

From: Giuseppe Di Guglielmo <giuseppe.diguglielmo_at_...95...>
Date: Tue, 05 Feb 2008 14:19:17 +0100
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().

Consider this simple code, please, the real code is bigger but this example
has the same issue (at the end of the main() function):
----
// test.cc
#include <iostream>
#include <eclipseclass.h>
#include <map>
#include <vector>
#include <math.h>
using namespace std;


EC_word set_bounds(EC_word, long, long);

EC_word eq(EC_word, EC_word);
EC_word add_e(EC_word, EC_word);
EC_word mul_e(EC_word, EC_word);
EC_word div_e(EC_word, EC_word);
EC_word geq(EC_word, EC_word);
EC_word leq(EC_word, EC_word);
EC_word g(EC_word, EC_word);
EC_word l(EC_word, EC_word);
EC_word and_e(EC_word, EC_word);
EC_word or_e(EC_word, EC_word);
EC_word not_e(EC_word);


int main(int argc, char* argv[]) {


	char* ECLIPSE_HOME = getenv("ECLIPSE_HOME");

	if (ECLIPSE_HOME == NULL) {
		cout << "You have to define ECLIPSE_HOME enviroment
variable";
		return 1;
	}

	cout << "ECLiPSe home: " << ECLIPSE_HOME << endl;

	ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, (void *)ECLIPSE_HOME);
	ec_set_option_int(EC_OPTION_LOCALSIZE, 128*1024*1024);
	ec_set_option_int(EC_OPTION_GLOBALSIZE, 128*1024*1024);
	ec_init();

	EC_atom fail = EC_atom("fail");
	EC_atom random = EC_atom("random");
	post_goal("lib(ic)");
	EC_ref Search;

	EC_ref in1_e;
	long in1;



	int bit_num=27;

	int upper_bound = 125;
	int half_interval = upper_bound/2;
	int lower_bound = -126;


	cout << "Interval: X in [ " << lower_bound << " , " << upper_bound
<< " ]" << endl;


	post_goal(set_bounds(in1_e, lower_bound, upper_bound));
	
	// (!(((x*4)+x)>=10)) <==> x < 2
	cout << "X < 2" << endl;
	post_goal(not_e(geq(add_e(mul_e(in1_e, 4),in1_e),10)));
	post_goal(term(EC_functor("indomain",2), in1_e, random));

	while (EC_succeed == EC_resume(Search)) {
		if ((EC_word(in1_e).is_long(&in1) == EC_succeed)) {
			cout << "IN1 : " << in1 << endl;
		} else {
			cout << "ERROR" << endl;
			return 1;
		}
		Search.cut_to();
		post_goal(fail);
	}

	ec_cleanup(); // <---- this is the segmentation fault point...


	return 0;
}

// support
EC_word set_bounds(EC_word vars, long lb, long ub) { //
	return (term(EC_functor("::",2), vars, term(EC_functor("..",2), lb,
					ub)));
}

EC_word eq(EC_word lhs, EC_word rhs) {
	// =
	return (term(EC_functor("#=",2), lhs, rhs));
}

EC_word add_e(EC_word lhs, EC_word rhs) {
	// +
	return (term(EC_functor("+",2), lhs, rhs));
}

EC_word mul_e(EC_word lhs, EC_word rhs) {
	// *
	return (term(EC_functor("*",2), lhs, rhs));
}

EC_word div_e(EC_word lhs, EC_word rhs) {
	// /
	return (term(EC_functor("/",2), lhs, rhs));
}

EC_word geq(EC_word lhs, EC_word rhs) {
	// >=
	return (term(EC_functor("#>=",2), lhs, rhs));
}

EC_word leq(EC_word lhs, EC_word rhs) {
	// <=
	return (term(EC_functor("#=<",2), lhs, rhs));
}

EC_word g(EC_word lhs, EC_word rhs) {
	// >
	return (term(EC_functor("#>",2), lhs, rhs));
}

EC_word l(EC_word lhs, EC_word rhs) {
	// <
	return (term(EC_functor("#<",2), lhs, rhs));
}

EC_word and_e(EC_word lhs, EC_word rhs) {
	// and
	return (term(EC_functor("and",2), lhs, rhs));
}

EC_word or_e(EC_word lhs, EC_word rhs) {
	// or
	return (term(EC_functor("or",2), lhs, rhs));
}

EC_word not_e(EC_word hs) {
	// not
	return (term(EC_functor("neg",1), hs));
}
// END test.cc

----

 




----------------------------------------------------------------------------
Giuseppe Di Guglielmo       Dept. of Computer Science - University of
Verona 
                               Strada le Grazie, 15 - 37134 Verona - Italy

Phone Office:   +39 045 8027049         Fax:    +39 045 8027068
Phone Home:     +39 045 6152251         Mobile: +39 347 0493371

WWW: http://profs.sci.univr.it/~diguglielmo

email: giuseppe.diguglielmo_at_...95... 
email: diguglielmo_at_...96...          Skype: giuseppe.diguglielmo  

----------------------------------------------------------------------------


This e-mail message is intended for the addressee(s) only and may contain 
confidential and or privileged information.  If you are not the intended 
recipient of this e-mail message, you should not read, copy, forward or 
otherwise distribute or further disclose the information in it. If you have 
received this e-mail message in error, please contact the originator of this
e-mail message via e-mail and delete all copies of this message from your 
computer or network, thank you.
Received on Tue Feb 05 2008 - 13:19:25 CET

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST