Skip to content

Instantly share code, notes, and snippets.

@jrfondren
Created November 11, 2018 02:51
Show Gist options
  • Save jrfondren/1d98e9dcc056184f1317a1ac47e59673 to your computer and use it in GitHub Desktop.
Save jrfondren/1d98e9dcc056184f1317a1ac47e59673 to your computer and use it in GitHub Desktop.
sys/resource.h 's struct-of-unions completely foils gcc & zig header analysis
-- gcc -c -fdump-ada-spec "getr.h" -C # where getr.h is #include <sys/resource.h>
...
pragma Convention (C_Pass_By_Copy, anon1055_anon1068_union);
pragma Unchecked_Union (anon1055_anon1068_union);type anon1055_anon1069_union (discr : unsigned := 0) is record
case discr is
when 0 =>
ru_nivcsw : aliased long; -- /usr/include/x86_64-linux-gnu/bits/resource.h:281
when others =>
uu_ru_nivcsw_word : aliased x86_64_linux_gnu_bits_types_h.uu_syscall_slong_t; -- /usr/include/x86_64-linux-gnu/bits/resource.h:282
end case;
end record;
pragma Convention (C_Pass_By_Copy, anon1055_anon1069_union);
pragma Unchecked_Union (anon1055_anon1069_union);type rusage is record
ru_utime : aliased x86_64_linux_gnu_bits_time_h.timeval; -- /usr/include/x86_64-linux-gnu/bits/resource.h:190
ru_stime : aliased x86_64_linux_gnu_bits_time_h.timeval; -- /usr/include/x86_64-linux-gnu/bits/resource.h:192
anon1845 : aliased anon1055_anon1056_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:198
anon1849 : aliased anon1055_anon1057_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:206
anon1853 : aliased anon1055_anon1058_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:212
anon1857 : aliased anon1055_anon1059_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:218
anon1861 : aliased anon1055_anon1060_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:225
anon1865 : aliased anon1055_anon1061_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:231
anon1869 : aliased anon1055_anon1062_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:237
anon1873 : aliased anon1055_anon1063_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:244
anon1877 : aliased anon1055_anon1064_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:250
anon1881 : aliased anon1055_anon1065_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:256
anon1885 : aliased anon1055_anon1066_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:262
anon1889 : aliased anon1055_anon1067_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:268
anon1893 : aliased anon1055_anon1068_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:276
anon1897 : aliased anon1055_anon1069_union; -- /usr/include/x86_64-linux-gnu/bits/resource.h:283
end record;
// zig translate-c /usr/include/sys/resource.h|perl -lne 'print if /pub const struct_rusage/ .. /^}/'
pub const struct_rusage = extern struct.{
ru_utime: struct_timeval,
ru_stime: struct_timeval,
@"": extern union.{
ru_maxrss: c_long,
__ru_maxrss_word: __syscall_slong_t,
},
@"": extern union.{
ru_ixrss: c_long,
__ru_ixrss_word: __syscall_slong_t,
},
@"": extern union.{
ru_idrss: c_long,
__ru_idrss_word: __syscall_slong_t,
},
@"": extern union.{
ru_isrss: c_long,
__ru_isrss_word: __syscall_slong_t,
},
@"": extern union.{
ru_minflt: c_long,
__ru_minflt_word: __syscall_slong_t,
},
@"": extern union.{
ru_majflt: c_long,
__ru_majflt_word: __syscall_slong_t,
},
@"": extern union.{
ru_nswap: c_long,
__ru_nswap_word: __syscall_slong_t,
},
@"": extern union.{
ru_inblock: c_long,
__ru_inblock_word: __syscall_slong_t,
},
@"": extern union.{
ru_oublock: c_long,
__ru_oublock_word: __syscall_slong_t,
},
@"": extern union.{
ru_msgsnd: c_long,
__ru_msgsnd_word: __syscall_slong_t,
},
@"": extern union.{
ru_msgrcv: c_long,
__ru_msgrcv_word: __syscall_slong_t,
},
@"": extern union.{
ru_nsignals: c_long,
__ru_nsignals_word: __syscall_slong_t,
},
@"": extern union.{
ru_nvcsw: c_long,
__ru_nvcsw_word: __syscall_slong_t,
},
@"": extern union.{
ru_nivcsw: c_long,
__ru_nivcsw_word: __syscall_slong_t,
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment