Date: Mon, 16 Apr 2012 14:28:50 +0200 From: Sebastian Huber <sebastian.huber@embedded-brains.de> To: freebsd-hackers@freebsd.org, freebsd-arm@freebsd.org Subject: XDR Library and Short Enums Message-ID: <4F8C1082.3020801@embedded-brains.de>
next in thread | raw e-mail | index | archive | help
Hi, the XDR library implementation of xdr_enum() is currently: /* * XDR enumerations */ bool_t xdr_enum(XDR *xdrs, enum_t *ep) { enum sizecheck { SIZEVAL }; /* used to find the size of an enum */ /* * enums are treated as ints */ /* LINTED */ if (sizeof (enum sizecheck) == sizeof (long)) { return (xdr_long(xdrs, (long *)(void *)ep)); } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (int)) { return (xdr_int(xdrs, (int *)(void *)ep)); } else /* LINTED */ if (sizeof (enum sizecheck) == sizeof (short)) { return (xdr_short(xdrs, (short *)(void *)ep)); } else { return (FALSE); } } The enum_t is defined as: typedef int32_t enum_t; This is problematic with short enums (variable sized enums). I case of short enums sizeof (enum sizecheck) would be 1. The ARM EABI lets you a choice between two alternatives described in the document issued by ARM. See also section 7.1.3 "Enumerated Types" http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf How would you implement and use the XDR library with short enums? The xdr_enum() can be easily changed to: /* * XDR enumerations */ bool_t xdr_enum(XDR *xdrs, enum_t *ep) { /* * enums are treated as ints */ /* LINTED */ if (sizeof (enum_t) == sizeof (long)) { return (xdr_long(xdrs, (long *)(void *)ep)); } else /* LINTED */ if (sizeof (enum_t) == sizeof (int)) { return (xdr_int(xdrs, (int *)(void *)ep)); } else /* LINTED */ if (sizeof (enum_t) == sizeof (short)) { return (xdr_short(xdrs, (short *)(void *)ep)); } else { return (FALSE); } } The problem is in the XDR library usage. An example is this (rpc_msg.h): enum msg_type { CALL=0, REPLY=1 }; How would you fix this? What about enum msg_type { CALL=0, REPLY=1, _MSG_TYPE_INVALID = 0xffffffff }; ? -- Sebastian Huber, embedded brains GmbH Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany Phone : +49 89 18 90 80 79-6 Fax : +49 89 18 90 80 79-9 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4F8C1082.3020801>