[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH] include/essentials.h: introduce compile-time assert



Hi Yuri,

very nice! I like that. Quite straightforward and elegant, too, well, except for the error message. ;)

I can think of immediate application areas. The first thing that comes to my mind is the memory regions code where we've been hit by errors before because array numbers went out of sync. Although we'd probably have to fiddle with the implementation a bit there, but it might work...

Reviewed-by: Florian Schmidt <florian.schmidt@xxxxxxxxx>

On 5/10/19 12:43 PM, Yuri Volchkov wrote:
Macro UK_CTASSERT(cond) is borrowed from FreeBSD. If 'cond' is False,
compilation is aborted with message "size of array is negative". Even
though the message is not very helpful, it is the simplest workaround
to have compile-time assertion without enabling c11 standard.

Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx>
---
  include/uk/essentials.h | 7 +++++++
  1 file changed, 7 insertions(+)

diff --git a/include/uk/essentials.h b/include/uk/essentials.h
index d9b24fcb..2cbb6aef 100644
--- a/include/uk/essentials.h
+++ b/include/uk/essentials.h
@@ -250,6 +250,13 @@ extern "C" {
  #endif
  #endif /* !__containerof */
+#ifndef UK_CTASSERT
+#define UK_CTASSERT(x)             _UK_CTASSERT(x, __LINE__)
+#define _UK_CTASSERT(x, y)         __UK_CTASSERT(x, y)
+#define __UK_CTASSERT(x, y)        typedef __maybe_unused \
+       char __assert_ ## y [(x) ? 1 : -1]
+#endif /* UK_CTASSERT */
+
  #ifdef __cplusplus
  }
  #endif


--
Dr. Florian Schmidt
フローリアン・シュミット
Research Scientist,
Systems and Machine Learning Group
NEC Laboratories Europe
Kurfürsten-Anlage 36, D-69115 Heidelberg
Tel.     +49 (0)6221 4342-265
Fax:     +49 (0)6221 4342-155
e-mail:  florian.schmidt@xxxxxxxxx
============================================================
Registered at Amtsgericht Mannheim, Germany, HRB728558

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.