The purpose of wrapping a pointer in struct in C
up vote
9
down vote
favorite
In Linux kernel code (up to 3.1.*) I saw such structure definition:
struct skb_frag_struct {
struct page *page;
/* ... */
In newer kernel versions this has evolved into:
struct skb_frag_struct {
struct
struct page *p;
page;
/* ... */
For what purpose could this wrapping be done in this particular case? And why it may be needed in general case?
c pointers struct linux-kernel
add a comment |
up vote
9
down vote
favorite
In Linux kernel code (up to 3.1.*) I saw such structure definition:
struct skb_frag_struct {
struct page *page;
/* ... */
In newer kernel versions this has evolved into:
struct skb_frag_struct {
struct
struct page *p;
page;
/* ... */
For what purpose could this wrapping be done in this particular case? And why it may be needed in general case?
c pointers struct linux-kernel
add a comment |
up vote
9
down vote
favorite
up vote
9
down vote
favorite
In Linux kernel code (up to 3.1.*) I saw such structure definition:
struct skb_frag_struct {
struct page *page;
/* ... */
In newer kernel versions this has evolved into:
struct skb_frag_struct {
struct
struct page *p;
page;
/* ... */
For what purpose could this wrapping be done in this particular case? And why it may be needed in general case?
c pointers struct linux-kernel
In Linux kernel code (up to 3.1.*) I saw such structure definition:
struct skb_frag_struct {
struct page *page;
/* ... */
In newer kernel versions this has evolved into:
struct skb_frag_struct {
struct
struct page *p;
page;
/* ... */
For what purpose could this wrapping be done in this particular case? And why it may be needed in general case?
c pointers struct linux-kernel
c pointers struct linux-kernel
asked Nov 9 at 16:33
z0lupka
30819
30819
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
7
down vote
accepted
It can be helpful in understanding a code change to use the Git Blame View:
https://github.com/torvalds/linux/blame/a978a5b8d83f795e107a2ff759b28643739be70e/include/linux/skbuff.h
You can see what it says in the description of the commit where the change was made:
net: add opaque struct around skb frag page
I've split this bit out of the skb frag destructor patch since it helps enforce
the use of the fragment API.
So it seems this was done just to catch dangling references in the code which were making raw access to a pointer, and force usage of a higher level API. It shouldn't add any runtime cost.
As an aside: the last time I did this myself I had a kind of silly idea which is to split the name of the struct out to something like struct struct page *ge; pa;
...this way the privileged code can read as fragstruct.pa.ge instead of fragstruct.page.p. But outside of that being silly, an advantage of using the same name for the outer struct is helping guide old usages with clear errors.
Though as your confusion points out, a comment // don't access directly, use fragment API
on the p
member would probably have been appropriate in this case.
Beat me to it! :-)
– Groo
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
It can be helpful in understanding a code change to use the Git Blame View:
https://github.com/torvalds/linux/blame/a978a5b8d83f795e107a2ff759b28643739be70e/include/linux/skbuff.h
You can see what it says in the description of the commit where the change was made:
net: add opaque struct around skb frag page
I've split this bit out of the skb frag destructor patch since it helps enforce
the use of the fragment API.
So it seems this was done just to catch dangling references in the code which were making raw access to a pointer, and force usage of a higher level API. It shouldn't add any runtime cost.
As an aside: the last time I did this myself I had a kind of silly idea which is to split the name of the struct out to something like struct struct page *ge; pa;
...this way the privileged code can read as fragstruct.pa.ge instead of fragstruct.page.p. But outside of that being silly, an advantage of using the same name for the outer struct is helping guide old usages with clear errors.
Though as your confusion points out, a comment // don't access directly, use fragment API
on the p
member would probably have been appropriate in this case.
Beat me to it! :-)
– Groo
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
add a comment |
up vote
7
down vote
accepted
It can be helpful in understanding a code change to use the Git Blame View:
https://github.com/torvalds/linux/blame/a978a5b8d83f795e107a2ff759b28643739be70e/include/linux/skbuff.h
You can see what it says in the description of the commit where the change was made:
net: add opaque struct around skb frag page
I've split this bit out of the skb frag destructor patch since it helps enforce
the use of the fragment API.
So it seems this was done just to catch dangling references in the code which were making raw access to a pointer, and force usage of a higher level API. It shouldn't add any runtime cost.
As an aside: the last time I did this myself I had a kind of silly idea which is to split the name of the struct out to something like struct struct page *ge; pa;
...this way the privileged code can read as fragstruct.pa.ge instead of fragstruct.page.p. But outside of that being silly, an advantage of using the same name for the outer struct is helping guide old usages with clear errors.
Though as your confusion points out, a comment // don't access directly, use fragment API
on the p
member would probably have been appropriate in this case.
Beat me to it! :-)
– Groo
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
It can be helpful in understanding a code change to use the Git Blame View:
https://github.com/torvalds/linux/blame/a978a5b8d83f795e107a2ff759b28643739be70e/include/linux/skbuff.h
You can see what it says in the description of the commit where the change was made:
net: add opaque struct around skb frag page
I've split this bit out of the skb frag destructor patch since it helps enforce
the use of the fragment API.
So it seems this was done just to catch dangling references in the code which were making raw access to a pointer, and force usage of a higher level API. It shouldn't add any runtime cost.
As an aside: the last time I did this myself I had a kind of silly idea which is to split the name of the struct out to something like struct struct page *ge; pa;
...this way the privileged code can read as fragstruct.pa.ge instead of fragstruct.page.p. But outside of that being silly, an advantage of using the same name for the outer struct is helping guide old usages with clear errors.
Though as your confusion points out, a comment // don't access directly, use fragment API
on the p
member would probably have been appropriate in this case.
It can be helpful in understanding a code change to use the Git Blame View:
https://github.com/torvalds/linux/blame/a978a5b8d83f795e107a2ff759b28643739be70e/include/linux/skbuff.h
You can see what it says in the description of the commit where the change was made:
net: add opaque struct around skb frag page
I've split this bit out of the skb frag destructor patch since it helps enforce
the use of the fragment API.
So it seems this was done just to catch dangling references in the code which were making raw access to a pointer, and force usage of a higher level API. It shouldn't add any runtime cost.
As an aside: the last time I did this myself I had a kind of silly idea which is to split the name of the struct out to something like struct struct page *ge; pa;
...this way the privileged code can read as fragstruct.pa.ge instead of fragstruct.page.p. But outside of that being silly, an advantage of using the same name for the outer struct is helping guide old usages with clear errors.
Though as your confusion points out, a comment // don't access directly, use fragment API
on the p
member would probably have been appropriate in this case.
edited Nov 9 at 17:10
answered Nov 9 at 16:48
HostileFork
24.7k775131
24.7k775131
Beat me to it! :-)
– Groo
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
add a comment |
Beat me to it! :-)
– Groo
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
Beat me to it! :-)
– Groo
Nov 9 at 16:50
Beat me to it! :-)
– Groo
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
@Groo Great minds think alike. :-)
– HostileFork
Nov 9 at 16:50
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229726%2fthe-purpose-of-wrapping-a-pointer-in-struct-in-c%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown