Re: [gtkmm] Possible bug in SigC::Connection::disconnect()



On Tue, 2003-11-25 at 11:23, Ole André Vadla Ravnås wrote:
> I'll try to change my test-case to only use libsigc++ and no glibmm
> (gtkmm).

Here I go again. I managed to reproduce the problems with a "pure"
libstdc++ test-case, no glibmm/gtkmm involved. Hope this helps (oh and
just for the record, I'm using libsigc++ 1.2.5, gcc 3.3.2 and glibc
2.3.2).

Regards
Ole André


/*
 * Test-case to trigger a possible SigC::Connection::disconnect() bug.
 *
 * Compile with:
 *   g++ $(pkg-config --cflags --libs sigc++-1.2) -Wall
disconnect_bug.cpp
 *
 * Run through valgrind to see the errors reported (which,
unfortunately,
 * doesn't make this simple app crash).
 *
 * Compile with NO_WEIRD_BEHAVIOUR defined, run through valgrind once
 * again and just watch the errors disappear.
 */

#include <iostream>
#include <string>
#include <sigc++/sigc++.h>

using std::cout;
using std::endl;
using std::string;

class client : public SigC::Object {
public:
	client() { done_ = false; }
	~client() {}
	
	void connect();
	bool done() { return done_; };

	SigC::Signal1<void, string> recv_message;
private:
	bool done_;
	
	SigC::Connection handler_conn_;

	void send_cmd(string c, SigC::Slot1<void, string> handler);
	
	void handle_reply_a(string r);
	void handle_reply_b(string r);
	void handle_reply_c(string r);
};

void client::connect()
{
	cout << "connected" << endl;

	send_cmd("hello", SigC::slot(*this, &client::handle_reply_a));
}

void client::send_cmd(string c, SigC::Slot1<void, string> handler)
{
	cout << "send_cmd: sending '" << c << "'" << endl;

#ifndef NO_WEIRD_BEHAVIOUR
	if (handler_conn_.connected())
		handler_conn_.disconnect();
#endif

	handler_conn_ = recv_message.connect(handler);
}

void client::handle_reply_a(string r)
{
	cout << "handle_reply_a: " << r << endl;

	send_cmd("user", SigC::slot(*this, &client::handle_reply_b));
}

void client::handle_reply_b(string r)
{
	cout << "handle_reply_b: " << r << endl;
	
	send_cmd("pass", SigC::slot(*this, &client::handle_reply_c));
}

void client::handle_reply_c(string r)
{
	cout << "handle_reply_c: " << r << endl;
	done_ = true;
}

void recv_line(string s)
{
	cout << "recv_line: " << s << endl;
}

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

	c.recv_message.connect(SigC::slot(recv_line));

	c.connect();

	while (!c.done()) {
		cout << "mainloop: about to emit recv_message signal" << endl;
		c.recv_message.emit("arbitrary reply");
		cout << "mainloop: done emitting recv_message signal" << endl;
		sleep(1);
	}

	return 0;
}





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