From: ghawkins@unix1.tcd.ie (George C. Hawkins)
Subject: problem with g++ compiled code at run time.
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 20 Jul 1992 20:31:23 GMT

Hi there,

I'm using g++ to write a motif/X package on a Sun IPC. I've switched to
g++ (gcc-2.2.2) from CC version 2.0, an AT&T cfront based C++ compiler
supplied by Sun. But I seem to be having some problems running a
program, that compiles and runs fine with CC. With g++ it compiles
without warnings (even with the -Wall switch set) but when it runs it
ends up calling abort (more explanation next paragraph). I've included
a typescript file of a gdb session along with the very simple .gdbinit
file I use (in a unix shar file along with all the files necessary to
compile and run my problem).

The only files you need to look at are graph.c which contains main(),
which new()s up an instance of the class OOXmBackedDrawingArea, next
thing it does is call the fatal function createDefaultGC() of the
OOXmBackedDrawingArea instance, which is redefined from it's parent
class. The child class is OOXmBackedDrawingArea and is defined in
OOXmBackedDrawingArea.h, it redefines the function createDefaultGC()
which is a virtual function of it's parent class OOXmDrawingArea, which
is defined in OOXmDrawingArea.h. The problem occurs when the
createDefaultGC() of OOXmBackedDrawingArea tries to call the
createDefaultGC() function of it's parent class using
OOXmDrawingArea::createDefaultGC(). All I can say is the call blitzes.

I find that if I remove the virtual function in the parent class. And
do the work that that function did in place of the function call to it
in the child class, everything works okay.

I know I didn't get any warranty with g++ but I would be amazingly
greatful for any quick responce as I have a review meeting on Monday
next! Being underfunded (aren't we all) greatful is all I can be :-)

Thanks for your time, even if you can't respond by Monday - I'm sure
you guys are very busy and perhaps you don't have motif too hand,
yours,


George!


ps I presume you have some kind of Hippocratic oath as far as the
privacy of source code sent to you goes, as I'm not sure of the legal
rights on my code (I'm sure I don't have any rights to it :-)


# This is a shell archive.  Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
#
# Wrapped by orange!root on Mon Jul 20 16:39:45 BST 1992
# Contents:  .gdbinit Draw Makefile OOGC.h OOXDrawable.h OOXPixmap.h
#	OOXSurface.h OOXmBackedDrawingArea.h OOXmDrawingArea.c
#	OOXmDrawingArea.h OOXtBase.c OOXtBase.h args.c args.h dispatcher.c draw
#	draw.c recalc.c recalc.h typescript
 
echo x - .gdbinit
sed 's/^@//' > ".gdbinit" <<'@//E*O*F .gdbinit//'
file draw.exe
set env XAPPLRESDIR=.
@//E*O*F .gdbinit//
chmod u=rw,g=r,o=r .gdbinit
 
echo x - Draw
sed 's/^@//' > "Draw" <<'@//E*O*F Draw//'
Draw*title: test pad
Draw*geometry: 256x256+320+194
Draw*highlightThickness: 0
Draw*foreground: black

Draw*mainWindow.mappedWhenManaged: False
Draw*drawingArea.background: lightsteelblue
@//E*O*F Draw//
chmod u=rw,g=r,o=r Draw
 
echo x - Makefile
sed 's/^@//' > "Makefile" <<'@//E*O*F Makefile//'
PROGRAM = draw.exe
SRCS = draw.c args.c recalc.c OOXtBase.c OOXmDrawingArea.c
#

# Compiler flags.
CFLAGS = -g -Wall
CPPFLAGS = -I/usr/local/X11/include -DMAIN -DXTFUNCPROTO

# Derived parameters.
OBJS = $(SRCS:%.c=%.o)

# Rules for C++.
CC=g++
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c
LINK.c = $(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH)

$(PROGRAM): $(OBJS)
	$(CC) -g -L/XTech/lib $(TARGET_ARCH) -o $(PROGRAM) \
        $(OBJS) \
        -lXm -lXt -lX11 -lXmu -lm

recalc.o:
	gcc $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c recalc.c

clean:
	$(RM) $(PROGRAM) $(OBJS) core

depend:
	makedepend -- $(CFLAGS) -- \
	$(CPPFLAGS) -I/usr/local/lib/g++-include -I/usr/local/lib/gcc-include \
	-- $(SRCS)
@//E*O*F Makefile//
chmod u=rw,g=,o= Makefile
 
echo x - OOGC.h
sed 's/^@//' > "OOGC.h" <<'@//E*O*F OOGC.h//'
class OOGC {
	private:
		Display* display;
		XGCValues save_values;
		unsigned long save_valuemask;

	public:
		GC gc;
		GContext gid;

		OOGC(Display* parent_display,Drawable drawable,unsigned long valuemask,XGCValues* values,GC init_gc = NULL)
		{
			display = parent_display;

			if (init_gc != NULL) gc = init_gc;
			else gc = XCreateGC(display,drawable,valuemask,values);

			gid = XGContextFromGC(gc);
		}

		void getGCValues(unsigned long valuemask,XGCValues* values)
		{
			XGetGCValues(display,gc,valuemask,values);
		}

		void changeGC(unsigned long valuemask,XGCValues* values)
		{
			XChangeGC(display,gc,valuemask,values);
		}

		void saveGC(unsigned long valuemask,XGCValues* values = NULL)
		{
			save_valuemask = valuemask;
			getGCValues(save_valuemask,&save_values);
			if (values != NULL) *values = save_values;
		}

		void restoreGC()
		{
			changeGC(save_valuemask,&save_values);
		}

		void setLineWidth(unsigned line_width)
		{
			XGCValues values;

			values.line_width = line_width;
			changeGC(GCLineWidth,&values);
		}

		void setLineStyle(int line_style)
		{
			XGCValues values;

			values.line_style = line_style;
			changeGC(GCLineStyle,&values);
		}

		void setForeground(unsigned long foreground)
		{
			XSetForeground(display,gc,foreground);
		}
};
@//E*O*F OOGC.h//
chmod u=rw,g=r,o=r OOGC.h
 
echo x - OOXDrawable.h
sed 's/^@//' > "OOXDrawable.h" <<'@//E*O*F OOXDrawable.h//'
class OOXDrawable : public OOXSurface {
	protected:
		Display* display;

	public:
		Drawable drawable; // unfortunately things get too difficult if this is private

		void drawArc(int x,int y,unsigned width,unsigned height,int angle1,int angle2)
		{
			XDrawArc(display,drawable,oogc->gc,x,y,width,height,angle1,angle2);
		}

		void drawLine(int x1,int y1,int x2,int y2)
		{
			XDrawLine(display,drawable,oogc->gc,x1,y1,x2,y2);
		}

		void drawLines(XPoint* points,int npoints, int mode)
		{
			XDrawLines(display,drawable,oogc->gc,points,npoints,mode);
		}

		void drawRectangle(int x,int y,unsigned width,unsigned height)
		{
			XDrawRectangle(display,drawable,oogc->gc,x,y,width,height);
		}

		void drawString(int x,int y,char* string)
		{
			XDrawString(display,drawable,oogc->gc,x,y,string,strlen(string));
		}

		void drawImageString(int x,int y,char* string)
		{
			XDrawImageString(display,drawable,oogc->gc,x,y,string,strlen(string));
		}

		void fillArc(int x,int y,unsigned width,unsigned height,int angle1,int angle2)
		{
			XFillArc(display,drawable,oogc->gc,x,y,width,height,angle1,angle2);
		}

		void fillPolygon(XPoint* points,int npoints,int shape,int mode)
		{
			XFillPolygon(display,drawable,oogc->gc,points,npoints,shape,mode);
		}

		void fillRectangle(int x,int y,unsigned width,unsigned height)
		{
			XFillRectangle(display,drawable,oogc->gc,x,y,width,height);
		}

		void copyArea(OOXDrawable* dest,int src_x,int src_y,unsigned width,unsigned height,int dest_x,int dest_y)
		{
			XCopyArea(display,drawable,dest->drawable,oogc->gc,src_x,src_y,width,height,dest_x,dest_y);
		}

		virtual void createDefaultGC() = 0;
};
@//E*O*F OOXDrawable.h//
chmod u=rw,g=r,o=r OOXDrawable.h
 
echo x - OOXPixmap.h
sed 's/^@//' > "OOXPixmap.h" <<'@//E*O*F OOXPixmap.h//'
class OOXPixmap : public OOXDrawable {
	public:
		OOXPixmap(Display* parent_display,Drawable parent_drawable,Dimension init_width,Dimension init_height,unsigned depth)
		{
			display = parent_display;
			width = init_width;
			height = init_height;
			drawable = XCreatePixmap(display,parent_drawable,width,height,depth);
		}

		void clear()
		{
			XGCValues values;
			unsigned long tmp;

			oogc->saveGC(GCForeground | GCBackground,&values);

			tmp = values.foreground;
			values.foreground = values.background;
			values.background = tmp;
			oogc->changeGC(GCForeground | GCBackground,&values);
			fillRectangle(0,0,width,height);

			oogc->restoreGC();
		}

		void createDefaultGC() { /* write some other time */ }
};
@//E*O*F OOXPixmap.h//
chmod u=rw,g=r,o=r OOXPixmap.h
 
echo x - OOXSurface.h
sed 's/^@//' > "OOXSurface.h" <<'@//E*O*F OOXSurface.h//'
typedef struct {
	int x;
	int y;
} Point; // because X's dam stupid XPoint consists of two shorts


class OOXSurface {
	protected:
		Dimension width,height;

	public:
		OOGC* oogc;  // unfortunately things get too difficult if this is private

		virtual void drawArc(int x,int y,unsigned width,unsigned height,int angle1,int angle2) = 0;
		virtual void drawLine(int x1,int y1,int x2,int y2) = 0;
		virtual void drawLines(XPoint* points,int npoints, int mode) = 0;
		virtual void drawRectangle(int x,int y,unsigned width,unsigned height) = 0;
		virtual void drawString(int x,int y,char* string) = 0;
		virtual void drawImageString(int x,int y,char* string) = 0;
		virtual void fillArc(int x,int y,unsigned width,unsigned height,int angle1,int angle2) = 0;
		virtual void fillPolygon(XPoint* points,int npoints,int shape,int mode) = 0;
		virtual void fillRectangle(int x,int y,unsigned width,unsigned height) = 0;
};
@//E*O*F OOXSurface.h//
chmod u=rw,g=r,o=r OOXSurface.h
 
echo x - OOXmBackedDrawingArea.h
sed 's/^@//' > "OOXmBackedDrawingArea.h" <<'@//E*O*F OOXmBackedDrawingArea.h//'
class OOXmBackedDrawingArea : public OOXmDrawingArea {
	protected:
		OOXPixmap* back;
		Boolean instant;

	public:
		void createDefaultGC()
		{
			OOXmDrawingArea::createDefaultGC();
			back->oogc = oogc;
		}

		OOXmBackedDrawingArea(Widget parent,char* name,Dimension init_width,Dimension init_height) : (parent,name,init_width,init_height)
		{
			Arg_stack arg;

			back = new OOXPixmap(display,DefaultRootWindow(display),width,height,DefaultDepthOfScreen(XtScreen(parent)));
			arg.push(XmNbackgroundPixmap,(XtArgVal)back->drawable);
			arg.set_values(widget);
		}

		void drawArc(int x,int y,unsigned width,unsigned height,int angle1,int angle2)
		{
			if (instant) OOXmDrawingArea::drawArc(x,y,width,height,angle1,angle2);
			back->drawArc(x,y,width,height,angle1,angle2);
		}

		void drawLine(int x1,int y1,int x2,int y2)
		{
			if (instant) OOXmDrawingArea::drawLine(x1,y1,x2,y2);
			back->drawLine(x1,y1,x2,y2);
		}

		void drawLines(XPoint* points,int npoints, int mode)
		{
			if (instant) OOXmDrawingArea::drawLines(points,npoints,mode);
			back->drawLines(points,npoints,mode);
		}

		void drawRectangle(int x,int y,unsigned width,unsigned height)
		{
			if (instant) OOXmDrawingArea::drawRectangle(x,y,width,height);
			back->drawRectangle(x,y,width,height);
		}

		void drawString(int x,int y,char* string)
		{
			if (instant) OOXmDrawingArea::drawString(x,y,string);
			back->drawString(x,y,string);
		}

		void drawImageString(int x,int y,char* string)
		{
			if (instant) OOXmDrawingArea::drawImageString(x,y,string);
			back->drawImageString(x,y,string);
		}

		void fillArc(int x,int y,unsigned width,unsigned height,int angle1,int angle2)
		{
			if (instant) OOXmDrawingArea::fillArc(x,y,width,height,angle1,angle2);
			back->fillArc(x,y,width,height,angle1,angle2);
		}

		void fillPolygon(XPoint* points,int npoints,int shape,int mode)
		{
			if (instant) OOXmDrawingArea::fillPolygon(points,npoints,shape,mode);
			back->fillPolygon(points,npoints,shape,mode);
		}

		void fillRectangle(int x,int y,unsigned width,unsigned height)
		{
			if (instant) OOXmDrawingArea::fillRectangle(x,y,width,height);
			back->fillRectangle(x,y,width,height);
		}

		void startRedraw()
		{
			back->clear();
			instant = False;
		}

		void endRedraw()
		{
			back->copyArea(this,0,0,width,height,0,0);
			instant = True;
		}
};
@//E*O*F OOXmBackedDrawingArea.h//
chmod u=rw,g=r,o=r OOXmBackedDrawingArea.h
 
echo x - OOXmDrawingArea.c
sed 's/^@//' > "OOXmDrawingArea.c" <<'@//E*O*F OOXmDrawingArea.c//'
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <Xm/DrawingA.h>
#include "OOXtBase.h"
#include "args.h"
#include "OOGC.h"
#include "OOXSurface.h"
#include "OOXDrawable.h"
#include "OOXmDrawingArea.h"


void OOXmDrawingArea::dispatcher(Widget,XtPointer client_dispatcher,XEvent* new_event,Boolean*)
{
	XEvent motion_event = *new_event;
	Window win_d;
	int int_d;
	unsigned u_int_d;
	// the _d indicates a dummy variable just used to keep an X call happy
	Point cursor_pos;
	int event_type;
	int mouse_button;

	event_type = new_event->type;

	switch (event_type) {
		case ButtonPress:
		case ButtonRelease:
			cursor_pos.x = ((XButtonEvent*)new_event)->x;
			cursor_pos.y = ((XButtonEvent*)new_event)->y;
			mouse_button = ((XButtonEvent*)new_event)->button;
			break;
		case MotionNotify:
			while (XCheckMaskEvent(display,ButtonMotionMask,&motion_event)); // eat motion events
			XQueryPointer(display,motion_event.xmotion.window,&win_d,&win_d,&int_d,&int_d,&cursor_pos.x,&cursor_pos.y,&u_int_d);
			mouse_button = (int)AnyButton;
	}
	
	((OOXmDispatcherProc)client_dispatcher)(event_type,mouse_button,cursor_pos);
}


void OOXmDrawingArea::createDefaultGC()
{
	Arg_stack arg;
	Pixel foreground,background;
	XGCValues values;

	// get the current fg and bg colors for the gc
	arg.push(XmNforeground,(XtArgVal)&foreground);
	arg.push(XmNbackground,(XtArgVal)&background);
	arg.get_values(widget);

	values.function = GXcopy;
	values.foreground = foreground;
	values.background = background;
	values.fill_style = FillSolid;
	oogc = new OOGC(display,drawable,GCForeground | GCBackground | GCFunction | GCFillStyle,&values);
}
@//E*O*F OOXmDrawingArea.c//
chmod u=rw,g=r,o=r OOXmDrawingArea.c
 
echo x - OOXmDrawingArea.h
sed 's/^@//' > "OOXmDrawingArea.h" <<'@//E*O*F OOXmDrawingArea.h//'
typedef void (*OOXmDispatcherProc)(int,int,Point);

class OOXmDrawingArea : public OOXtBase,public OOXDrawable {
	private:
		void dispatcher(Widget,XtPointer,XEvent*,Boolean*);

	public:
		Widget widget;

		OOXmDrawingArea(Widget parent,char* name,Dimension init_width,Dimension init_height)
		{
			Arg_stack arg;

			display = XtDisplay(parent);
			width = init_width;
			height = init_height;

			arg.push(XmNwidth,width);
			arg.push(XmNheight,height);
			widget = XtCreateManagedWidget(name,xmDrawingAreaWidgetClass,parent,arg.stack(),arg.count);
			drawable = XtWindow(widget);
		}

		void addDispatcher(OOXmDispatcherProc client_dispatcher)
		{
			OOXtAddMemberFunctionEventHandler(widget,ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | PointerMotionHintMask,
			    False,(OOXtEventHandler)&OOXmDrawingArea::dispatcher,(XtPointer)client_dispatcher);
		}

		virtual void createDefaultGC();
		//^^^^^ I'm not sure if this is necessary - once a virtual always a virtual?
};
@//E*O*F OOXmDrawingArea.h//
chmod u=rw,g=r,o=r OOXmDrawingArea.h
 
echo x - OOXtBase.c
sed 's/^@//' > "OOXtBase.c" <<'@//E*O*F OOXtBase.c//'
#include <X11/Intrinsic.h>
#include "OOXtBase.h"
#include <stdio.h>


void OOXtBase::call_callback(Widget caller, XtPointer record_ptr, XtPointer call_data)
{
	Record record = *((Record*)record_ptr);

	(record.object_r->*record.callback_r)(caller, record.client_data_r, call_data);
}


Ticket OOXtBase::OOXtAddMemberFunctionCallback(Widget widget, String callback_name, 
					     OOXtCallbackProc callback, XtPointer client_data)
{
	Record* new_record = new Record; // memory leak

	new_record->object_r = this;
	new_record->callback_r = callback;
	new_record->client_data_r = client_data;

	XtAddCallback(widget, callback_name, (XtCallbackProc)&OOXtBase::call_callback, (XtPointer)new_record);

	return new_record;
}


void OOXtBase::call_event_handler(Widget caller, XtPointer record_ptr, XEvent* event, Boolean* continue_to_dispatch)
{
	Record record = *((Record*)record_ptr);

	(record.object_r->*record.event_proc_r)(caller, record.client_data_r, event, continue_to_dispatch);
}


Ticket OOXtBase::OOXtAddMemberFunctionEventHandler(Widget widget, EventMask event_mask, Boolean nonmaskable, 
						 OOXtEventHandler proc, XtPointer client_data)
{
	Record* new_record = new Record; // memory leak

	new_record->object_r = this;
	new_record->event_proc_r = proc;
	new_record->client_data_r = client_data;

	XtAddEventHandler(widget, event_mask, nonmaskable, (XtEventHandler)&OOXtBase::call_event_handler, 
	    (XtPointer)new_record);

	return new_record;
}


Boolean OOXtBase::call_work_proc(XtPointer record_ptr)
{
	Record record = *((Record*)record_ptr);

	if ((record.object_r->*record.work_proc_r)(record.client_data_r)) {
		delete (Record*)record_ptr;
		return True;
	} else return False;
}


XtWorkProcId OOXtBase::OOXtAppAddMemberFunctionWorkProc(XtAppContext app_context, OOXtWorkProc proc, XtPointer client_data)
{
	Record* new_record = new Record;

	new_record->object_r = this;
	new_record->work_proc_r = proc;
	new_record->client_data_r = client_data;

	return XtAppAddWorkProc(app_context, (XtWorkProc)&OOXtBase::call_work_proc, (XtPointer)new_record);
}
@//E*O*F OOXtBase.c//
chmod u=rw,g=r,o=r OOXtBase.c
 
echo x - OOXtBase.h
sed 's/^@//' > "OOXtBase.h" <<'@//E*O*F OOXtBase.h//'
class OOXtBase;

typedef void (OOXtBase::*OOXtCallbackProc)(Widget, XtPointer, XtPointer);
typedef void (OOXtBase::*OOXtEventHandler)(Widget, XtPointer, XEvent*, Boolean*);
typedef Boolean (OOXtBase::*OOXtWorkProc)(XtPointer);

typedef struct {
	OOXtBase* object_r;
	union {
		OOXtCallbackProc callback_r;
		OOXtEventHandler event_proc_r;
		OOXtWorkProc work_proc_r;
	};
	XtPointer client_data_r;
} Record;

typedef Record* Ticket;

class OOXtBase {

	protected:

		static void call_callback(Widget, XtPointer, XtPointer);
		void OOXtRemoveMemberFunctionCallback(Widget widget, 
		    String callback_name, Ticket client_data)
		{
			XtRemoveCallback(widget, callback_name, 
			    (XtCallbackProc)&OOXtBase::call_callback, 
			    (XtPointer)client_data);
			delete client_data;
		}
		Ticket OOXtAddMemberFunctionCallback(Widget, String, OOXtCallbackProc, XtPointer);

		static void call_event_handler(Widget, XtPointer, XEvent*, Boolean*);
		void OOXtRemoveMemberFunctionEventHandler(Widget widget, EventMask event_mask, 
		    Boolean nonmaskable, Ticket client_data)
		{
			XtRemoveEventHandler(widget, event_mask, nonmaskable, 
			    (XtEventHandler)&OOXtBase::call_event_handler, 
			    (XtPointer)client_data);
			delete client_data;
		}
		Ticket OOXtAddMemberFunctionEventHandler(Widget, EventMask, Boolean, OOXtEventHandler, XtPointer);

		static Boolean call_work_proc(XtPointer);
		XtWorkProcId OOXtAppAddMemberFunctionWorkProc(XtAppContext, OOXtWorkProc, XtPointer);
};
@//E*O*F OOXtBase.h//
chmod u=rw,g=r,o=r OOXtBase.h
 
echo x - args.c
sed 's/^@//' > "args.c" <<'@//E*O*F args.c//'
#include <X11/Intrinsic.h>
#include "args.h"


void Arg_stack::push(String resource_name, XtArgVal value)
{
	if (clear_stack) {
		count = 0;
		clear_stack = False;
	}
	XtSetArg(simple_stack[count], resource_name, value); count++;
}
@//E*O*F args.c//
chmod u=rw,g=r,o=r args.c
 
echo x - args.h
sed 's/^@//' > "args.h" <<'@//E*O*F args.h//'
#define HOLD	False
// use to hang onto stack values


class Arg_stack {
	private:
		Boolean clear_stack;
		Arg simple_stack[32]; // if you push on more than 32 you're in trouble!

	public:
		int count;

	Arg_stack()
	{
		count = 0;
		clear_stack = False;
	}

	void push(String resource_name, XtArgVal value);

	Arg* stack(Boolean clear_cmd = True)
	{
		clear_stack = clear_cmd;
		return(simple_stack);
	}

	void get_values(Widget object, Boolean clear_cmd = True)
	{
		clear_stack = clear_cmd;
		XtGetValues(object, simple_stack, count);
	}

	void set_values(Widget object, Boolean clear_cmd = True)
	{
		clear_stack = clear_cmd;
		XtSetValues(object, simple_stack, count);
	}
};
@//E*O*F args.h//
chmod u=rw,g=r,o=r args.h
 
echo x - dispatcher.c
sed 's/^@//' > "dispatcher.c" <<'@//E*O*F dispatcher.c//'
void dispatcher(Widget,XtPointer,XEvent* new_event,Boolean*)
{
	XEvent motion_event = *new_event;
	Window win_d;
	int int_d;
	unsigned u_int_d;
	// the _d indicates a dummy variable just used to keep an X call happy
	Coords cursor_pos;
	int mouse_event;
	int mouse_button;

	mouse_event = new_event->type;

	switch (mouse_event) {
		case ButtonPress:
		case ButtonRelease:
			cursor_pos.x = ((XButtonEvent*)new_event)->x;
			cursor_pos.y = ((XButtonEvent*)new_event)->y;
			mouse_button = ((XButtonEvent*)new_event)->button;
			break;
		case MotionNotify:
			while (XCheckMaskEvent(map_display,ButtonMotionMask,&motion_event)); // eat motion events
			XQueryPointer(map_display,motion_event.xmotion.window,&win_d,&win_d,&int_d,&int_d,&cursor_pos.x,&cursor_pos.y,&u_int_d);
			mouse_button = (int)AnyButton;
	}

	selector(mouse_event,mouse_button,cursor_pos);
}
@//E*O*F dispatcher.c//
chmod u=rw,g=r,o=r dispatcher.c
 
echo x - draw
sed 's/^@//' > "draw" <<'@//E*O*F draw//'
XAPPLRESDIR=.
export XAPPLRESDIR
@./draw.exe
@//E*O*F draw//
chmod u=rwx,g=rx,o=rx draw
 
echo x - draw.c
sed 's/^@//' > "draw.c" <<'@//E*O*F draw.c//'
#include <X11/Intrinsic.h>
#include <Xm/MainW.h>
#include <Xm/RowColumn.h>
#include <Xm/CascadeBG.h>
#include <Xm/PushBG.h>
#include <Xm/SeparatoG.h>
#include <Xm/DrawingA.h>
#include <iostream.h>
#include <unistd.h>
#include <libc.h>
#include <stdio.h>
extern "C" {
#include "recalc.h"
}
#include "args.h"
#include "OOXtBase.h"
#include "OOGC.h"
#include "OOXSurface.h"
#include "OOXDrawable.h"
#include "OOXPixmap.h"
#include "OOXmDrawingArea.h"
#include "OOXmBackedDrawingArea.h"

#define SIDE 256


void testDispatcher(int type,int button,Point position)
{
	cout << "event type: ";
	switch (type) {
		case ButtonPress:
			cout << "ButtonPress, ";
			break;
		case ButtonRelease:
			cout << "ButtonRelease, ";
			break;
		case MotionNotify:
			cout << "MotionNotify, ";
			break;
	}
	cout << "mouse button: " << button << ", point x: " << position.x << ", point y: " << position.y << ".\n";
}

	
int main(int argc,char* argv[])
{
	XtAppContext app_context;
	Widget shell;
	OOXmBackedDrawingArea* drawing_area;

	// initialize the toolkit
	XtRealizeWidget(shell = XtAppInitialize(&app_context,"Draw",NULL,0,(Cardinal*)&argc,argv,NULL,NULL,0));

	// create the drawingArea widget for visuals and draw some lines
	drawing_area = new OOXmBackedDrawingArea(shell,"drawingArea",SIDE,SIDE);
	drawing_area->createDefaultGC();
	drawing_area->startRedraw();
	for(int loop = 0;loop < 1024;loop++) {
		static int x1,y1,x2,y2,tmp;

		x1 = rand() % SIDE;
		y1 = rand() % SIDE;
		x2 = rand() % SIDE;
		y2 = rand() % SIDE;
		if (x2 < x1) {
			tmp = x1;
			x1 = x2;
			x2 = tmp;
		}
		if (y2 < y1) {
			tmp = y1;
			y1 = y2;
			y2 = tmp;
		}
		drawing_area->drawRectangle(x1,y1,x2,y2);
	}
	drawing_area->endRedraw();
	drawing_area->addDispatcher(testDispatcher);

	// start going
	XtAppMainLoop(app_context);
}
@//E*O*F draw.c//
chmod u=rw,g=r,o=r draw.c
 
echo x - recalc.c
sed 's/^@//' > "recalc.c" <<'@//E*O*F recalc.c//'
#include <X11/IntrinsicP.h>

#include <X11/ShellP.h>
/* this file may not be compiled with C++ as this will result in a
 * reserved word conflict on including the above file <X11/ShellP.h>
 */

#include "recalc.h"

void RecalculateGeometry(Widget widget)
{
	(*(XtClass(widget)->core_class.resize))(widget);
}
@//E*O*F recalc.c//
chmod u=rw,g=r,o=r recalc.c
 
echo x - recalc.h
sed 's/^@//' > "recalc.h" <<'@//E*O*F recalc.h//'
extern void RecalculateGeometry(Widget);
@//E*O*F recalc.h//
chmod u=rw,g=r,o=r recalc.h
 
echo x - typescript
sed 's/^@//' > "typescript" <<'@//E*O*F typescript//'
Script started on Mon Jul 20 15:10:57 1992
sun(send)[101]: gdb
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.5, Copyright 1992 Free Software Foundation, Inc.
(gdb) list 56
51		// initialize the toolkit
52		XtRealizeWidget(shell = XtAppInitialize(&app_context,"Draw",NULL,0,(Cardinal*)&argc,argv,NULL,NULL,0));
53	
54		// create the drawingArea widget for visuals and draw some lines
55		drawing_area = new OOXmBackedDrawingArea(shell,"drawingArea",SIDE,SIDE);
56		drawing_area->createDefaultGC();
57		drawing_area->startRedraw();
58		for(int loop = 0;loop < 1024;loop++) {
59			static int x1,y1,x2,y2,tmp;
60	
(gdb) break 56
Breakpoint 1 at 0x361c: file draw.c, line 56.
(gdb) run -synchronous
Starting program: /home/ghawkins/likely/wp5/new/send/draw.exe -synchronous

Breakpoint 1, main (argc=1, argv=0xf7fff874) at draw.c:56
56		drawing_area->createDefaultGC();
(gdb) stepi
0x3620	56		drawing_area->createDefaultGC();
(gdb) 
0x3624	56		drawing_area->createDefaultGC();
(gdb) 
0x3628	56		drawing_area->createDefaultGC();
(gdb) 
0x362c	56		drawing_area->createDefaultGC();
(gdb) 
0x3630	56		drawing_area->createDefaultGC();
(gdb) 
0x3634	56		drawing_area->createDefaultGC();
(gdb) 
0x3638	56		drawing_area->createDefaultGC();
(gdb) 
0x363c	56		drawing_area->createDefaultGC();
(gdb) 
0x3640	56		drawing_area->createDefaultGC();
(gdb) 
0x3644	56		drawing_area->createDefaultGC();
(gdb) 
0x3648	56		drawing_area->createDefaultGC();
(gdb) 
0x364c	56		drawing_area->createDefaultGC();
(gdb) 
0x3650	56		drawing_area->createDefaultGC();
(gdb) 
0x3654	56		drawing_area->createDefaultGC();
(gdb) 
0x3658	56		drawing_area->createDefaultGC();
(gdb) 
0x365c	56		drawing_area->createDefaultGC();
(gdb) 
OOXmBackedDrawingArea::createDefaultGC (this=0x2d6d8) at OOXmBackedDrawingArea.h:8
8			{
(gdb) 
0x2c44 in OOXmBackedDrawingArea::createDefaultGC (this=0x401083) at OOXmBackedDrawingArea.h:8
8			{
(gdb) 
9				OOXmDrawingArea::createDefaultGC();
(gdb) 
0x2c4c	9				OOXmDrawingArea::createDefaultGC();
(gdb) 
0x2c50	9				OOXmDrawingArea::createDefaultGC();
(gdb) 
0x2c54	9				OOXmDrawingArea::createDefaultGC();
(gdb) 
0x1a1bc in _DYNAMIC ()
(gdb) 
0x1a1c0 in _DYNAMIC ()
(gdb) 
0x1a1c4 in _DYNAMIC ()
(gdb) 
0x1a060 in _DYNAMIC ()
(gdb) 
0x1a064 in _DYNAMIC ()
(gdb) 
0x1a068 in _DYNAMIC ()
(gdb) 
0xf77e0070 in end ()
(gdb) step
Current function has no line number information.
Single stepping until function exit.

Program received signal 6, Abort
0xf756c008 in kill ()
(gdb) quit
The program is running.  Quit anyway? (y or n) y
sun(send)[102]: exit
script done on Mon Jul 20 15:12:17 1992
@//E*O*F typescript//
chmod u=rw,g=r,o=r typescript
 
echo Inspecting for damage in transit...
temp=/tmp/shar$$; dtemp=/tmp/.shar$$
trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
cat > $temp <<\!!!
       2       5      36 .gdbinit
       7      13     188 Draw
      31      87     709 Makefile
      63     115    1283 OOGC.h
      59     123    1646 OOXDrawable.h
      28      64     723 OOXPixmap.h
      23     122     915 OOXSurface.h
      87     164    2334 OOXmBackedDrawingArea.h
      58     135    1630 OOXmDrawingArea.c
      32      74     987 OOXmDrawingArea.h
      73     159    2072 OOXtBase.c
      47     104    1484 OOXtBase.h
      12      25     232 args.c
      38      88     680 args.h
      28      70     861 dispatcher.c
       3       4      44 draw
      82     211    1797 draw.c
      13      38     309 recalc.c
       1       3      41 recalc.h
      94     303    2757 typescript
     781    1907   20728 total
!!!
wc  .gdbinit Draw Makefile OOGC.h OOXDrawable.h OOXPixmap.h OOXSurface.h OOXmBackedDrawingArea.h OOXmDrawingArea.c OOXmDrawingArea.h OOXtBase.c OOXtBase.h args.c args.h dispatcher.c draw draw.c recalc.c recalc.h typescript | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
if [ -s $dtemp ]
then echo "Ouch [diff of wc output]:" ; cat $dtemp
else echo "No problems found."
fi
exit 0

Newsgroups: gnu.gcc.bug