This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2 2/3] nptl: Change tst-typesizes to _Static_assert
- From: Florian Weimer <fweimer at redhat dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 2 Nov 2017 13:44:00 +0100
- Subject: Re: [PATCH v2 2/3] nptl: Change tst-typesizes to _Static_assert
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3D97A356D6
- References: <1509038067-18532-1-git-send-email-adhemerval.zanella@linaro.org> <1509038067-18532-2-git-send-email-adhemerval.zanella@linaro.org>
On 10/26/2017 07:14 PM, Adhemerval Zanella wrote:
+#define ASSERT_TYPE_SIZE(__type, __size) \
+ _Static_assert (sizeof (__type) == __size, \
+ "sizeof (" #__type ") != " #__size)
+
+#define ASSERT_PTHREAD_INTERNAL_SIZE(__type, __internal) \
+ _Static_assert (sizeof ((__type *) 0)->__size >= sizeof (__internal), \
+ "sizeof (" #__type ".__size) > sizeof (" #__internal ")")
No __ prefixes are need for macro arguments because there cannot be a
name clash. For the second macro, there is an operator discrepancy >= vs >.
I think ((__type) { 0 }).__size is vaguely more portable than the null
pointer dereference.
Regarding the structure of this patch, I wonder if it would be better to
have all the checks in a central place, so that it is easier to see if
any are missing. But if you prefer the current approach, this is fine
as well.
I still have to double-check if the current coverage is adequate.
Thanks,
Florian