Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* C++ gurus; AbiWord pointer casting on Alpha
@ 1998-11-16 10:44 Shaw Terwilliger
  1998-11-17  0:56 ` Bibek Sahu
  0 siblings, 1 reply; 5+ messages in thread
From: Shaw Terwilliger @ 1998-11-16 10:44 UTC (permalink / raw)
  To: axp-list

On Sun, Nov 15, 1998 at 10:50:20PM -0500, Michael J. Donahue wrote:
> >>                _wd * wd = (_wd *)m_menuFactoryItems[k].callback_action;
> Ulrich's question is the first thing to check.  Anyone with experience
> porting 32-bit apps to the Alpha knows that pointer casts are red flags.

Without even trying the compiler test, I can assure you it's our
casting problem.  :)  Unfortunately, it's deeper than our code, it's
GTK+.  The callback_action member is a "guint", which should be defined
to be sizeof(unsigned int) on your platform.  This works on Intels, breaks on
Alphas (and any other platform where sizeof(unsigned int) !=               
sizeof(unsigned int *)).                                                 

So, now it's time to find out why the GTK+ guys are using guints as
pointer substitutes.  I really feel bad for not digging into the code
as soon as Brian put out this message, but I'll soon get to deal with
the Alpha issues every day, thanks to him.  :)                          
        
--           
Shaw Terwilliger (twig@advancenet.net sterwill@abisource.com)


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

* Re: C++ gurus; AbiWord pointer casting on Alpha
  1998-11-16 10:44 C++ gurus; AbiWord pointer casting on Alpha Shaw Terwilliger
@ 1998-11-17  0:56 ` Bibek Sahu
  1998-11-17  1:12   ` Paul Tomblin
  0 siblings, 1 reply; 5+ messages in thread
From: Bibek Sahu @ 1998-11-17  0:56 UTC (permalink / raw)
  To: axp-list; +Cc: sterwill


	On a whim, I decided to test this.  I compiled and ran the
'testgtk' program that came with gtk+, testing specifically those parts of
it that used 'callback_action'.  It worked flawlessly.

	Although I don't know the code well enough to be positive, it
appears that 'callback_action' is supposed to be data rather than a
function pointer.  The 'callback_data' member, defined to be of type
gpointer, which is in all the structures that include callback_action
might be more appropriate if you need a pointer.

- Bob

On Mon, 16 Nov 1998, Shaw Terwilliger wrote:

> On Sun, Nov 15, 1998 at 10:50:20PM -0500, Michael J. Donahue wrote:
> > >>                _wd * wd = (_wd *)m_menuFactoryItems[k].callback_action;
> > Ulrich's question is the first thing to check.  Anyone with experience
> > porting 32-bit apps to the Alpha knows that pointer casts are red flags.
> 
> Without even trying the compiler test, I can assure you it's our
> casting problem.  :)  Unfortunately, it's deeper than our code, it's
> GTK+.  The callback_action member is a "guint", which should be defined
> to be sizeof(unsigned int) on your platform.  This works on Intels, breaks on
> Alphas (and any other platform where sizeof(unsigned int) !=               
> sizeof(unsigned int *)).                                                 
> 
> So, now it's time to find out why the GTK+ guys are using guints as
> pointer substitutes.  I really feel bad for not digging into the code
> as soon as Brian put out this message, but I'll soon get to deal with
> the Alpha issues every day, thanks to him.  :)                          
>         
> --           
> Shaw Terwilliger (twig@advancenet.net sterwill@abisource.com)
> 
> -- 
> To unsubscribe: send e-mail to axp-list-request@redhat.com with
> 'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com
> 


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

* Re: C++ gurus; AbiWord pointer casting on Alpha
  1998-11-17  0:56 ` Bibek Sahu
@ 1998-11-17  1:12   ` Paul Tomblin
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Tomblin @ 1998-11-17  1:12 UTC (permalink / raw)
  To: axp-list

Quoting Bibek Sahu (scorpio@dodds.net):
> 	On a whim, I decided to test this.  I compiled and ran the
> 'testgtk' program that came with gtk+, testing specifically those parts of
> it that used 'callback_action'.  It worked flawlessly.
> 
> 	Although I don't know the code well enough to be positive, it
> appears that 'callback_action' is supposed to be data rather than a
> function pointer.  The 'callback_data' member, defined to be of type
> gpointer, which is in all the structures that include callback_action
> might be more appropriate if you need a pointer.

I've never done any gtk programming, but one of the weirdnesses you get used
to in Xt and Motif programming is the XtCallback structure.  Callbacks are
called with three arguments, the last two are of type XtPointer, which is
usually typedefed as void*.  But they are often used, both in the Xt libraries
itself and in user code, to pass integers instead of pointers.


-- 
"Linux's homebase is currently commodity network and server infrastructure. By
folding extended functionality ... into today's commodity services, we raise
the bar & change the rules of the game."
- Microsoft leaks their strategy for monopolizing the Internet and the desktop.


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

* Re: C++ gurus; AbiWord pointer casting on Alpha
       [not found] <3650D107.CDA25BE0@postman.abisource.com>
@ 1998-11-19 22:26 ` Bibek Sahu
  1998-11-19 23:02   ` Bibek Sahu
  0 siblings, 1 reply; 5+ messages in thread
From: Bibek Sahu @ 1998-11-19 22:26 UTC (permalink / raw)
  To: Shaw Terwilliger, axp-list

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1675 bytes --]


	Ok, scratch that, I was wrong: there is no 'callback_data' member.

	I looked at the Gimp source to see how it was done there (since it
does work fine on my machine), and discovered that AbiWord was being done
in a fundamentally incorrect manner.

	Gotta love that GTK documentation, huh?  I had to dig through the
gtk headers and another program's source code to figure this out... THAT I
consider to be fundamentally Wrong. ;-)

	At any rate, since the menuing code was already using the
UT_Vectors, the fix was trivial.  A patch is attached.  Menus work for me
now; hurray! :-)

	However, it still does segfault on exit.  I'll look into that
later.

- Bibek

On Mon, 16 Nov 1998, Shaw Terwilliger wrote:

> Bibek Sahu wrote:
> >         Although I don't know the code well enough to be positive, it
> > appears that 'callback_action' is supposed to be data rather than a
> > function pointer.  The 'callback_data' member, defined to be of type
> > gpointer, which is in all the structures that include callback_action
> > might be more appropriate if you need a pointer.
> 
> Hm... I'm still wondering if it's a compiler thing (testgtk is C,
> we're using C++; odd chance that the C++ compiler is doing much
> different
> casting here).  If we're abusing that member (storing pointers instead
> of, say, an index to a list of functions), the GTK guys sure haven't
> told me so.  I asked on the list early this morning, and on the IRC
> channel.  None of them seem to really know; the total lack of
> documentation
> on GTK+ doesn't help much.  :)  
> 
> I'll take a look at this some more and try to get back to the Alpha
> list about it.
> 
> -- 
> Shaw Terwilliger
> 

[-- Attachment #2: Type: TEXT/PLAIN, Size: 1665 bytes --]

--- ev_UnixMenu.cpp.orig	Thu Nov 19 14:55:12 1998
+++ ev_UnixMenu.cpp	Thu Nov 19 16:04:09 1998
@@ -369,7 +369,7 @@
 	UT_ASSERT(wd);
 	m_vecMenuWidgets.addItem(wd);
 
-	p->callback_action = (guint)wd;
+	p->callback_action = m_vecMenuWidgets.findItem(wd);
 	p->item_type = NULL;
 	if (bCheckable)
 		p->item_type = "<CheckItem>";
@@ -402,7 +402,7 @@
 	UT_ASSERT(wd);
 	m_vecMenuWidgets.addItem(wd);
 
-	p->callback_action = (guint)wd;
+	p->callback_action = m_vecMenuWidgets.findItem(wd);
 	p->item_type = "<Branch>";
 
 	// append this name to the prefix, omitting the "&".
@@ -445,7 +445,7 @@
 	UT_ASSERT(wd);
 	m_vecMenuWidgets.addItem(wd);
 
-	p->callback_action = (guint)wd;
+	p->callback_action = m_vecMenuWidgets.findItem(wd);
 	p->item_type = "<Separator>";
 }
 
@@ -607,7 +607,7 @@
 					_wd * wd = new _wd(this,id);
 					UT_ASSERT(wd);
 
-					p->callback_action = (guint)wd;
+					p->callback_action = m_vecMenuWidgets.findItem(wd);
 					p->item_type = NULL;
 
 					// Currently no checkable dynamic items
@@ -642,7 +642,7 @@
 {
 	for (UT_uint32 k=0; (k < m_nrActualFactoryItems); k++)
 	{
-		_wd * wd = (_wd *)m_menuFactoryItems[k].callback_action;
+		_wd * wd = (_wd *)m_vecMenuWidgets.getNthItem(m_menuFactoryItems[k].callback_action);
 		if (wd && (wd->m_id==id))
 			return m_menuFactoryItems[k].path;
 	}
@@ -654,7 +654,7 @@
 {
 	for (UT_uint32 k=0; (k < m_nrActualFactoryItems); k++)
 	{
-		_wd * wd = (_wd *)m_menuFactoryItems[k].callback_action;
+		_wd * wd = (_wd *)m_vecMenuWidgets.getNthItem(m_menuFactoryItems[k].callback_action);
 		if (wd && (wd->m_id==id))
 			return UT_TRUE;
 	}

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

* Re: C++ gurus; AbiWord pointer casting on Alpha
  1998-11-19 22:26 ` Bibek Sahu
@ 1998-11-19 23:02   ` Bibek Sahu
  0 siblings, 0 replies; 5+ messages in thread
From: Bibek Sahu @ 1998-11-19 23:02 UTC (permalink / raw)
  To: axp-list; +Cc: Shaw Terwilliger


	I spoke too soon.  It allows menus to be displayed, but activating
a menu item still causes a segfault.  However, that is a different (though
related) problem.

- Bibek

On Thu, 19 Nov 1998, Bibek Sahu wrote:

> 
> 	Ok, scratch that, I was wrong: there is no 'callback_data' member.
> 
> 	I looked at the Gimp source to see how it was done there (since it
> does work fine on my machine), and discovered that AbiWord was being done
> in a fundamentally incorrect manner.
> 
> 	Gotta love that GTK documentation, huh?  I had to dig through the
> gtk headers and another program's source code to figure this out... THAT I
> consider to be fundamentally Wrong. ;-)
> 
> 	At any rate, since the menuing code was already using the
> UT_Vectors, the fix was trivial.  A patch is attached.  Menus work for me
> now; hurray! :-)
> 
> 	However, it still does segfault on exit.  I'll look into that
> later.
> 
> - Bibek
> 
> On Mon, 16 Nov 1998, Shaw Terwilliger wrote:
> 
> > Bibek Sahu wrote:
> > >         Although I don't know the code well enough to be positive, it
> > > appears that 'callback_action' is supposed to be data rather than a
> > > function pointer.  The 'callback_data' member, defined to be of type
> > > gpointer, which is in all the structures that include callback_action
> > > might be more appropriate if you need a pointer.
> > 
> > Hm... I'm still wondering if it's a compiler thing (testgtk is C,
> > we're using C++; odd chance that the C++ compiler is doing much
> > different
> > casting here).  If we're abusing that member (storing pointers instead
> > of, say, an index to a list of functions), the GTK guys sure haven't
> > told me so.  I asked on the list early this morning, and on the IRC
> > channel.  None of them seem to really know; the total lack of
> > documentation
> > on GTK+ doesn't help much.  :)  
> > 
> > I'll take a look at this some more and try to get back to the Alpha
> > list about it.
> > 
> > -- 
> > Shaw Terwilliger
> > 
> 


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

end of thread, other threads:[~1998-11-19 23:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-11-16 10:44 C++ gurus; AbiWord pointer casting on Alpha Shaw Terwilliger
1998-11-17  0:56 ` Bibek Sahu
1998-11-17  1:12   ` Paul Tomblin
     [not found] <3650D107.CDA25BE0@postman.abisource.com>
1998-11-19 22:26 ` Bibek Sahu
1998-11-19 23:02   ` Bibek Sahu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox