[Nouveau] nouveau_object_new beginner question

Ilia Mirkin imirkin at alum.mit.edu
Thu May 22 08:14:09 PDT 2014


On Thu, May 22, 2014 at 10:37 AM, Daniel Melo Jorge da Cunha
<dmjcunha at gmail.com> wrote:
> I'm sorry for this beginner question but I can't understand.
> File ../nouveau/nouveau.c, function nouveau_object_new.
> Assuming data has content. First, obj->data = obj + 1. This is perfect
> after the memcpy call.
> But when: *(struct nouveau_object **)obj->data = obj;
> I can't understand because now obj and obj->data has the same address,
> while previously obj->data pointed exactly to the contents of data.
> What am I missing?

You're a little off in your analysis. That line does

*obj->data = obj

not

obj->data = obj.

Basically it makes the assumption that the first field of the data is
a pointer, and then sets it to the newly-created obj structure. It's a
little fragile, but all the objects assigned to data do indeed start
with a nouveau_object pointer (nouveau_fifo and its derivatives,
nv04_notify).

Hope this helps,

  -ilia


More information about the Nouveau mailing list