[Spice-devel] [PATCH v2] server: Fix conversions between QXLPHYSICAL and pointers

Francois Gouget fgouget at codeweavers.com
Mon Jan 11 09:07:37 PST 2016


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);

That can work too. Would you prefer that form?


> > @@ -1155,8 +1158,8 @@ SPICE_GNUC_VISIBLE QXLCommandExt* spice_replay_next_cmd(SpiceReplay *replay,
> >      case QXL_CMD_DRAW:
> >      case QXL_CMD_UPDATE:
> >      case QXL_CMD_SURFACE:
> > -        info = (QXLReleaseInfo *)cmd->cmd.data;
> > -        info->id = (uint64_t)cmd;
> > +        info = QXLPHYSICAL_TO_PTR(QXLReleaseInfo*, cmd->cmd.data);
> > +        info->id = (uint64_t)(uintptr_t)cmd;
> 
> Is the addition of that (uintptr_t) cast mandatory here? (not really
> important, just curious).

It is. Without it one gets the following error because cmd is a 32 bit 
QXLCommandExt* pointer:

red-replay-qxl.c: In function 'spice_replay_next_cmd':
red-replay-qxl.c:1162: error: cast from pointer to integer of different size [-Wpointer-to-int-cast]

Maybe it should go in separately though.

-- 
Francois Gouget <fgouget at codeweavers.com>



More information about the Spice-devel mailing list