[Spice-devel] [PATCH v2] server: Fix conversions between QXLPHYSICAL and pointers
Francois Gouget
fgouget at codeweavers.com
Mon Jan 11 09:44:02 PST 2016
On Mon, 11 Jan 2016, Christophe Fergeau wrote:
> On Mon, Jan 11, 2016 at 06:07:37PM +0100, Francois Gouget wrote:
> > On Mon, 11 Jan 2016, Christophe Fergeau wrote:
> > [...]
> > > > +#define QXLPHYSICAL_FROM_PTR(ptr) ((QXLPHYSICAL)(intptr_t)(ptr))
> > > > +#define QXLPHYSICAL_TO_PTR(ptrtype, phy) ((ptrtype)(intptr_t)(phy))
> > >
> > > 'ptrtype' still does not seem to bring much compared to:
> > >
> > > #define QXLPHYSICAL_TO_PTR(phy) ((void*)(intptr_t)(phy))
> >
> > Without it you cannot write:
> >
> > info = QXLPHYSICAL_TO_PTR(QXLReleaseInfo*, cmd->cmd.data);
> >
> > You have to write the following instead:
> >
> > info = (QXLReleaseInfo*)QXLPHYSICAL_TO_PTR(cmd->cmd.data);
>
> I think in C, void * will be implicitly cast to any other pointer type,
> ie info = QXLPHYSICAL_TO_PTR(cmd->cmd.data); should work.
You're right, it does not generate warnings or errors. I got tripped by
the first use of the macro which is a special case.
QXLPHYSICAL_TO_PTR(QXLDataChunk*, cur->next_chunk)->prev_chunk = QXLPHYSICAL_FROM_PTR(cur);
I will resubmit.
--
Francois Gouget <fgouget at codeweavers.com>
More information about the Spice-devel
mailing list