Re: bonobo_x_object



On Wed, 2 May 2001, ERDI Gergo wrote:
> > I would reccommend using 'bonobo_x_object (servant)', since its a
> > pretty fun routine. It detetects the pointer type by magic, so it
> > should be possible to build it into the 'SELF' macro ie.
> > Self *self = SELF (servant);
> 
> This sounds more like something thats existence we should deny :)

	:-) Well, having read the code again - I spotted yet another
stupid thinko in the routine, however I think the concept is good. In
libbonobo it's a lot cleaner and easier to understand, but here is the new
version - it should be safe I think, but scrutiny welcome:

/**
 * bonobo_x_object:
 * @p: a pointer to something
 * 
 * This function can be passed a BonoboXObject * or a
 * PortableServer_Servant, and it will return a BonoboXObject *.
 * 
 * Return value: a BonoboXObject or NULL.
 **/
BonoboXObject *
bonobo_x_object (gpointer p)
{
	BonoboXObject *xobj;

	if (!p)
		return NULL;

	xobj = p;

	if (xobj->base.corba_objref ==
	    BONOBO_X_OBJECT_GET_CORBA (xobj) &&
	    xobj->base.servant ==
	    BONOBO_X_OBJECT_GET_SERVANT (xobj))
		return xobj;

	else {
		BonoboObjectServant *s = p;

		if ((xobj = s->bonobo_object) ==
		    BONOBO_X_SERVANT_GET_OBJECT (s) &&
		    &xobj->servant == p)
			return xobj;
		else
			g_warning ("Serious error, unidentifiable "
				   "pointer type");
	}

	return NULL;
}

	Clearly, it is not designed to safely characterize random
pointers, just a BonoboXObject or a BonoboObjectServant.

	Regards,

		Michael.

-- 
 mmeeks gnu org  <><, Pseudo Engineer, itinerant idiot





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