godump.c (go_output_typedef): Dump size of structs.

* godump.c (go_output_typedef): Dump size of structs.

mksysinfo, syscall: Change Sizeof names from var to const.

From-SVN: r186678
This commit is contained in:
Ian Lance Taylor 2012-04-22 18:51:44 +00:00 committed by Ian Lance Taylor
parent 970aa0b9a9
commit f12e8bd5c3
4 changed files with 57 additions and 46 deletions

View File

@ -1,3 +1,7 @@
2012-04-22 Ian Lance Taylor <iant@google.com>
* godump.c (go_output_typedef): Dump size of structs.
2012-04-22 Razya Ladelsky <razya@il.ibm.com>
Correcting transform_to_exit_first_loop + fix to PR46886

View File

@ -1024,12 +1024,25 @@ go_output_typedef (struct godump_container *container, tree decl)
fprintf (go_dump_file, "type _%s ",
IDENTIFIER_POINTER (DECL_NAME (decl)));
go_output_type (container);
if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
{
HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
if (size > 0)
fprintf (go_dump_file,
"\nconst _sizeof_%s = " HOST_WIDE_INT_PRINT_DEC,
IDENTIFIER_POINTER (DECL_NAME (decl)),
size);
}
pointer_set_insert (container->decls_seen, decl);
}
else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
{
void **slot;
const char *type;
HOST_WIDE_INT size;
type = IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE ((decl))));
/* If type defined already, skip. */
@ -1047,6 +1060,13 @@ go_output_typedef (struct godump_container *container, tree decl)
fprintf (go_dump_file, "type _%s ",
IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))));
go_output_type (container);
size = int_size_in_bytes (TREE_TYPE (decl));
if (size > 0)
fprintf (go_dump_file,
"\nconst _sizeof_%s = " HOST_WIDE_INT_PRINT_DEC,
IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))),
size);
}
else
return;

View File

@ -39,7 +39,7 @@ func CmsgSpace(datalen int) int {
}
func cmsgData(cmsg *Cmsghdr) unsafe.Pointer {
return unsafe.Pointer(uintptr(unsafe.Pointer(cmsg)) + uintptr(SizeofCmsghdr))
return unsafe.Pointer(uintptr(unsafe.Pointer(cmsg)) + SizeofCmsghdr)
}
type SocketControlMessage struct {
@ -72,7 +72,7 @@ func ParseSocketControlMessage(buf []byte) ([]SocketControlMessage, error) {
func socketControlMessageHeaderAndData(buf []byte) (*Cmsghdr, []byte, error) {
h := (*Cmsghdr)(unsafe.Pointer(&buf[0]))
if int(h.Len) < SizeofCmsghdr || int(h.Len) > len(buf) {
if h.Len < SizeofCmsghdr || int(h.Len) > len(buf) {
return nil, nil, EINVAL
}
return h, buf[cmsgAlignOf(SizeofCmsghdr):], nil

View File

@ -586,9 +586,6 @@ if test -n "$cmsghdr"; then
-e 's/cmsg_type/Type/' \
-e 's/\[\]/[0]/' \
>> ${OUT}
# The size of the cmsghdr struct.
echo 'var SizeofCmsghdr = int(unsafe.Sizeof(Cmsghdr{}))' >> ${OUT}
fi
# The SCM_ flags for Cmsghdr.
@ -603,11 +600,6 @@ grep '^type _ucred ' gen-sysinfo.go | \
-e 's/gid/Gid/' \
>> ${OUT}
# The size of the ucred struct.
if grep 'type Ucred ' ${OUT} >/dev/null 2>&1; then
echo 'var SizeofUcred = int(unsafe.Sizeof(Ucred{}))' >> ${OUT}
fi
# The ip_mreq struct.
grep '^type _ip_mreq ' gen-sysinfo.go | \
sed -e 's/_ip_mreq/IPMreq/' \
@ -621,9 +613,6 @@ if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
fi
# The size of the ip_mreq struct.
echo 'var SizeofIPMreq = int(unsafe.Sizeof(IPMreq{}))' >> ${OUT}
# The ipv6_mreq struct.
grep '^type _ipv6_mreq ' gen-sysinfo.go | \
sed -e 's/_ipv6_mreq/IPv6Mreq/' \
@ -637,9 +626,6 @@ if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
fi
# The size of the ipv6_mreq struct.
echo 'var SizeofIPv6Mreq = int(unsafe.Sizeof(IPv6Mreq{}))' >> ${OUT}
# The ip_mreqn struct.
grep '^type _ip_mreqn ' gen-sysinfo.go | \
sed -e 's/_ip_mreqn/IPMreqn/' \
@ -654,9 +640,6 @@ if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
fi
# The size of the ip_mreqn struct.
echo 'var SizeofIPMreqn = int(unsafe.Sizeof(IPMreqn{}))' >> ${OUT}
# Try to guess the type to use for fd_set.
fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
fds_bits_type="_C_long"
@ -722,8 +705,8 @@ grep '^const _NLM' gen-sysinfo.go | \
# NLMSG_HDRLEN is defined as an expression using sizeof.
if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
if grep '^type NlMsghdr ' ${OUT} > /dev/null 2>&1; then
echo 'var NLMSG_HDRLEN = int((unsafe.Sizeof(NlMsghdr{}) + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1))' >> ${OUT}
if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
fi
fi
@ -741,11 +724,6 @@ grep '^type _rtmsg ' gen-sysinfo.go | \
-e 's/rtm_flags/Flags/' \
>> ${OUT}
# The size of the rtmsg struct.
if grep 'type RtMsg ' ${OUT} > /dev/null 2>&1; then
echo 'var SizeofRtMsg = int(unsafe.Sizeof(RtMsg{}))' >> ${OUT}
fi
# The rtgenmsg struct.
grep '^type _rtgenmsg ' gen-sysinfo.go | \
sed -e 's/_rtgenmsg/RtGenmsg/' \
@ -768,11 +746,6 @@ grep '^const _RTN' gen-sysinfo.go | \
grep '^const _RTPROT' gen-sysinfo.go | \
sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# The size of the rtgenmsg struct.
if grep 'type RtGenmsg ' ${OUT} > /dev/null 2>&1; then
echo 'var SizeofRtGenmsg = int(unsafe.Sizeof(RtGenmsg{}))' >> ${OUT}
fi
# The ifinfomsg struct.
grep '^type _ifinfomsg ' gen-sysinfo.go | \
sed -e 's/_ifinfomsg/IfInfomsg/' \
@ -795,11 +768,6 @@ grep '^const _IFNAMSIZ' gen-sysinfo.go | \
grep '^const _SIOC' gen-sysinfo.go |
sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# The size of the ifinfomsg struct.
if grep 'type IfInfomsg ' ${OUT} > /dev/null 2>&1; then
echo 'var SizeofIfInfomsg = int(unsafe.Sizeof(IfInfomsg{}))' >> ${OUT}
fi
# The ifaddrmsg struct.
grep '^type _ifaddrmsg ' gen-sysinfo.go | \
sed -e 's/_ifaddrmsg/IfAddrmsg/' \
@ -810,11 +778,6 @@ grep '^type _ifaddrmsg ' gen-sysinfo.go | \
-e 's/ifa_index/Index/' \
>> ${OUT}
# The size of the ifaddrmsg struct.
if grep 'type IfAddrmsg ' ${OUT} > /dev/null 2>&1; then
echo 'var SizeofIfAddrmsg = int(unsafe.Sizeof(IfAddrmsg{}))' >> ${OUT}
fi
# The rtattr struct.
grep '^type _rtattr ' gen-sysinfo.go | \
sed -e 's/_rtattr/RtAttr/' \
@ -822,11 +785,6 @@ grep '^type _rtattr ' gen-sysinfo.go | \
-e 's/rta_type/Type/' \
>> ${OUT}
# The size of the rtattr struct.
if grep 'type RtAttr ' ${OUT} > /dev/null 2>&1; then
echo 'var SizeofRtAttr = int(unsafe.Sizeof(RtAttr{}))' >> ${OUT}
fi
# The termios struct.
grep '^type _termios ' gen-sysinfo.go | \
sed -e 's/_termios/Termios/' \
@ -1017,4 +975,33 @@ grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
sed -e 's/_in6_addr/[16]byte/' \
>> ${OUT}
# Struct sizes.
set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
in6_pktinfo Inet6PktInfo inotify_event InotifyEvent linger Linger \
msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
sock_filter SockFilter sock_fprog SockFprog ucred Ucred
while test $# != 0; do
nc=$1
ngo=$2
shift
shift
if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
fi
done
# In order to compile the net package, we need some sizes to exist
# even if the types do not.
if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
echo 'const SizeofIPMreq = 8' >> ${OUT}
fi
if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
fi
if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
echo 'const SizeofIPMreqn = 12' >> ${OUT}
fi
exit $?