Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2013-01-03 Thread Lennart Poettering
On Sat, 29.12.12 02:10, Thomas H.P. Andersen (pho...@gmail.com) wrote:

 Another item from the todo

Heya!

Hmm, so I commited a patch for using assert_static() a few days before
you did your patches but unfortunately never commited it.

It works a bit differently from your patch, i.e. keeps assert_cc() as
special version of assert_static() around which only takes one rather
than two parameters and generates the message from the passed
expression.

I am tempted to just leave this code now as I commited it, since having
to pass an explicit string to assert_static() is sometimes a bit
redundant i'd say, and doesn't really make things more readable unless
the expression that is tested is really complicated.

Hence, I'd say that we should use assert_cc() and assert_static() from
now on like this:

assert_cc() for simple expressions where the expression is readable
enough as is.

assert_static() for complex expressions where it is worth specifying a
human readable string.

I hope this makes sense?

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2013-01-03 Thread Lennart Poettering
On Thu, 03.01.13 22:34, Lennart Poettering (lenn...@poettering.net) wrote:

 
 On Sat, 29.12.12 02:10, Thomas H.P. Andersen (pho...@gmail.com) wrote:
 
  Another item from the todo
 
 Heya!
 
 Hmm, so I commited a patch for using assert_static() a few days before
 you did your patches but unfortunately never commited it.
   ^^^ pushed

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2013-01-03 Thread Thomas H.P. Andersen
On Thu, Jan 3, 2013 at 10:34 PM, Lennart Poettering
lenn...@poettering.net wrote:
 On Sat, 29.12.12 02:10, Thomas H.P. Andersen (pho...@gmail.com) wrote:

 Another item from the todo

 Heya!

 Hmm, so I commited a patch for using assert_static() a few days before
 you did your patches but unfortunately never commited it.

 It works a bit differently from your patch, i.e. keeps assert_cc() as
 special version of assert_static() around which only takes one rather
 than two parameters and generates the message from the passed
 expression.

 I am tempted to just leave this code now as I commited it, since having
 to pass an explicit string to assert_static() is sometimes a bit
 redundant i'd say, and doesn't really make things more readable unless
 the expression that is tested is really complicated.

 Hence, I'd say that we should use assert_cc() and assert_static() from
 now on like this:

 assert_cc() for simple expressions where the expression is readable
 enough as is.

 assert_static() for complex expressions where it is worth specifying a
 human readable string.

 I hope this makes sense?

yeah, makes sense. It also does not break the build for older
compilers :) Do you see warnings about mixed declarations and code? I
had to move some of the asserts to avoid that with my patch.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2013-01-03 Thread Lennart Poettering
On Thu, 03.01.13 22:47, Thomas H.P. Andersen (pho...@gmail.com) wrote:

  assert_cc() for simple expressions where the expression is readable
  enough as is.
 
  assert_static() for complex expressions where it is worth specifying a
  human readable string.
 
  I hope this makes sense?
 
 yeah, makes sense. It also does not break the build for older
 compilers :) Do you see warnings about mixed declarations and code? I
 had to move some of the asserts to avoid that with my patch.

Yes, I did see those. And my dirty workaround was to simply enclose the
assert_static() in a do { } while(false) block... That way it's always
at the beginning of a {} block but still behaves like an individual
expression.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2012-12-30 Thread Zbigniew Jędrzejewski-Szmek
On Sat, Dec 29, 2012 at 11:14:15PM +0100, Thomas H.P. Andersen wrote:
 On Sat, Dec 29, 2012 at 5:04 PM, Zbigniew Jędrzejewski-Szmek
 zbys...@in.waw.pl wrote:
  On Sat, Dec 29, 2012 at 02:10:27AM +0100, Thomas H.P. Andersen wrote:
  Another item from the todo
  Hi,
 
  the patch looks great, but it raises compatibility problems. AFAICT,
  required gcc version to raised to 4.6. Debian/squeeze has 4.4.
 
 According to http://gcc.gnu.org/projects/cxx0x.html static_assert
 should be supported from gcc 4.3
Hm, testing (with 4.4) shows that neither static_assert nor _Static_assert
are available. With 4.6 _Static_assert is available.

Michael Biebl says that Debian/squeeze doesn't have to be supported.
This probably means that it's enough to have gcc-4.6 supported.
This means that we don't need to support compilers which don't
support _Static_assert.

  clang has _Static_assert, not static_assert. I think that a compile
  time check is in order. Support for old gcc versions is less
  important, so it might be enough to document the requirement in
  README, and then maybe provide a fallback if people complain. OTOH
  clang compilation support is useful (and used), so it should be kept.
 
 It builds with clang here. That is with clang version 3.1
 (branches/release_31) from F18.
static_assert is provided by /usr/include/assert.h (from glibc).
since http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=839e283ec
(Jan 01 2012). This version hasn't been officially released yet,
AFAICT.  The define is trivial, and could be easily provided in
missing.h.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2012-12-30 Thread Thomas H.P. Andersen
On Sun, Dec 30, 2012 at 4:32 PM, Zbigniew Jędrzejewski-Szmek
zbys...@in.waw.pl wrote:
 On Sat, Dec 29, 2012 at 11:14:15PM +0100, Thomas H.P. Andersen wrote:
 On Sat, Dec 29, 2012 at 5:04 PM, Zbigniew Jędrzejewski-Szmek
 zbys...@in.waw.pl wrote:
  On Sat, Dec 29, 2012 at 02:10:27AM +0100, Thomas H.P. Andersen wrote:
  Another item from the todo
  Hi,
 
  the patch looks great, but it raises compatibility problems. AFAICT,
  required gcc version to raised to 4.6. Debian/squeeze has 4.4.

 According to http://gcc.gnu.org/projects/cxx0x.html static_assert
 should be supported from gcc 4.3
 Hm, testing (with 4.4) shows that neither static_assert nor _Static_assert
 are available. With 4.6 _Static_assert is available.

 Michael Biebl says that Debian/squeeze doesn't have to be supported.
 This probably means that it's enough to have gcc-4.6 supported.
 This means that we don't need to support compilers which don't
 support _Static_assert.

  clang has _Static_assert, not static_assert. I think that a compile
  time check is in order. Support for old gcc versions is less
  important, so it might be enough to document the requirement in
  README, and then maybe provide a fallback if people complain. OTOH
  clang compilation support is useful (and used), so it should be kept.

 It builds with clang here. That is with clang version 3.1
 (branches/release_31) from F18.
 static_assert is provided by /usr/include/assert.h (from glibc).
 since http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=839e283ec
 (Jan 01 2012). This version hasn't been officially released yet,
 AFAICT.  The define is trivial, and could be easily provided in
 missing.h.

Something like this?

The added part is:
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -257,3 +257,7 @@ static inline int name_to_handle_at(int fd, const
char *name, struct file_handle
 #ifndef TFD_TIMER_CANCEL_ON_SET
 #define TFD_TIMER_CANCEL_ON_SET (1  1)
 #endif
+
+#ifndef static_assert
+#define static_assert _Static_assert
+#endif


0001-use-static_assert-instead-of-assert_cc.patch
Description: Binary data
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] use static_assert instead of assert_cc

2012-12-29 Thread Zbigniew Jędrzejewski-Szmek
On Sat, Dec 29, 2012 at 02:10:27AM +0100, Thomas H.P. Andersen wrote:
 Another item from the todo
Hi,

the patch looks great, but it raises compatibility problems. AFAICT,
required gcc version to raised to 4.6. Debian/squeeze has 4.4. Also,
clang has _Static_assert, not static_assert. I think that a compile
time check is in order. Support for old gcc versions is less
important, so it might be enough to document the requirement in
README, and then maybe provide a fallback if people complain. OTOH
clang compilation support is useful (and used), so it should be kept.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel