timeout_ext 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/COPYING +510 -0
  4. data/MANIFEST +51 -0
  5. data/README +15 -0
  6. data/Rakefile +28 -0
  7. data/ext/timeout_ext/.gitignore +3 -0
  8. data/ext/timeout_ext/ccan-bits.c +7 -0
  9. data/ext/timeout_ext/ccan/array_size/LICENSE +28 -0
  10. data/ext/timeout_ext/ccan/array_size/_info +46 -0
  11. data/ext/timeout_ext/ccan/array_size/array_size.h +26 -0
  12. data/ext/timeout_ext/ccan/build_assert/LICENSE +28 -0
  13. data/ext/timeout_ext/ccan/build_assert/_info +49 -0
  14. data/ext/timeout_ext/ccan/build_assert/build_assert.h +40 -0
  15. data/ext/timeout_ext/ccan/check_type/LICENSE +28 -0
  16. data/ext/timeout_ext/ccan/check_type/_info +33 -0
  17. data/ext/timeout_ext/ccan/check_type/check_type.h +64 -0
  18. data/ext/timeout_ext/ccan/compiler/LICENSE +28 -0
  19. data/ext/timeout_ext/ccan/compiler/_info +64 -0
  20. data/ext/timeout_ext/ccan/compiler/compiler.h +231 -0
  21. data/ext/timeout_ext/ccan/container_of/LICENSE +28 -0
  22. data/ext/timeout_ext/ccan/container_of/_info +65 -0
  23. data/ext/timeout_ext/ccan/container_of/container_of.h +145 -0
  24. data/ext/timeout_ext/ccan/ilog/LICENSE +28 -0
  25. data/ext/timeout_ext/ccan/ilog/_info +50 -0
  26. data/ext/timeout_ext/ccan/ilog/ilog.c +141 -0
  27. data/ext/timeout_ext/ccan/ilog/ilog.h +151 -0
  28. data/ext/timeout_ext/ccan/list/LICENSE +17 -0
  29. data/ext/timeout_ext/ccan/list/_info +72 -0
  30. data/ext/timeout_ext/ccan/list/list.h +842 -0
  31. data/ext/timeout_ext/ccan/str/LICENSE +28 -0
  32. data/ext/timeout_ext/ccan/str/_info +52 -0
  33. data/ext/timeout_ext/ccan/str/str.h +228 -0
  34. data/ext/timeout_ext/ccan/str/str_debug.h +30 -0
  35. data/ext/timeout_ext/ccan/time/LICENSE +17 -0
  36. data/ext/timeout_ext/ccan/time/_info +57 -0
  37. data/ext/timeout_ext/ccan/time/time.c +138 -0
  38. data/ext/timeout_ext/ccan/time/time.h +753 -0
  39. data/ext/timeout_ext/ccan/timer/LICENSE +510 -0
  40. data/ext/timeout_ext/ccan/timer/_info +79 -0
  41. data/ext/timeout_ext/ccan/timer/design.txt +76 -0
  42. data/ext/timeout_ext/ccan/timer/timer.c +524 -0
  43. data/ext/timeout_ext/ccan/timer/timer.h +211 -0
  44. data/ext/timeout_ext/depend +17 -0
  45. data/ext/timeout_ext/extconf.rb +50 -0
  46. data/ext/timeout_ext/licenses/BSD-MIT +17 -0
  47. data/ext/timeout_ext/licenses/CC0 +28 -0
  48. data/ext/timeout_ext/licenses/LGPL-2.1 +510 -0
  49. data/ext/timeout_ext/missing/stdbool/stdbool.h +20 -0
  50. data/ext/timeout_ext/timeout_ext.c +114 -0
  51. data/test/test_timeout_ext.rb +44 -0
  52. data/timeout_ext.gemspec +30 -0
  53. metadata +126 -0
data/MANIFEST ADDED
@@ -0,0 +1,51 @@
1
+ .gitignore
2
+ COPYING
3
+ MANIFEST
4
+ README
5
+ Rakefile
6
+ ext/timeout_ext/.gitignore
7
+ ext/timeout_ext/ccan-bits.c
8
+ ext/timeout_ext/ccan/array_size/LICENSE
9
+ ext/timeout_ext/ccan/array_size/_info
10
+ ext/timeout_ext/ccan/array_size/array_size.h
11
+ ext/timeout_ext/ccan/build_assert/LICENSE
12
+ ext/timeout_ext/ccan/build_assert/_info
13
+ ext/timeout_ext/ccan/build_assert/build_assert.h
14
+ ext/timeout_ext/ccan/check_type/LICENSE
15
+ ext/timeout_ext/ccan/check_type/_info
16
+ ext/timeout_ext/ccan/check_type/check_type.h
17
+ ext/timeout_ext/ccan/compiler/LICENSE
18
+ ext/timeout_ext/ccan/compiler/_info
19
+ ext/timeout_ext/ccan/compiler/compiler.h
20
+ ext/timeout_ext/ccan/container_of/LICENSE
21
+ ext/timeout_ext/ccan/container_of/_info
22
+ ext/timeout_ext/ccan/container_of/container_of.h
23
+ ext/timeout_ext/ccan/ilog/LICENSE
24
+ ext/timeout_ext/ccan/ilog/_info
25
+ ext/timeout_ext/ccan/ilog/ilog.c
26
+ ext/timeout_ext/ccan/ilog/ilog.h
27
+ ext/timeout_ext/ccan/list/LICENSE
28
+ ext/timeout_ext/ccan/list/_info
29
+ ext/timeout_ext/ccan/list/list.h
30
+ ext/timeout_ext/ccan/str/LICENSE
31
+ ext/timeout_ext/ccan/str/_info
32
+ ext/timeout_ext/ccan/str/str.h
33
+ ext/timeout_ext/ccan/str/str_debug.h
34
+ ext/timeout_ext/ccan/time/LICENSE
35
+ ext/timeout_ext/ccan/time/_info
36
+ ext/timeout_ext/ccan/time/time.c
37
+ ext/timeout_ext/ccan/time/time.h
38
+ ext/timeout_ext/ccan/timer/LICENSE
39
+ ext/timeout_ext/ccan/timer/_info
40
+ ext/timeout_ext/ccan/timer/design.txt
41
+ ext/timeout_ext/ccan/timer/timer.c
42
+ ext/timeout_ext/ccan/timer/timer.h
43
+ ext/timeout_ext/depend
44
+ ext/timeout_ext/extconf.rb
45
+ ext/timeout_ext/licenses/BSD-MIT
46
+ ext/timeout_ext/licenses/CC0
47
+ ext/timeout_ext/licenses/LGPL-2.1
48
+ ext/timeout_ext/missing/stdbool/stdbool.h
49
+ ext/timeout_ext/timeout_ext.c
50
+ test/test_timeout_ext.rb
51
+ timeout_ext.gemspec
data/README ADDED
@@ -0,0 +1,15 @@
1
+ timeout_ext - LGPL enhancement to timeout.rb in the Ruby stdlib
2
+
3
+ Uses the CCAN timer implementation and hooks in the main Ruby VM
4
+ to speed up timeout.rb
5
+
6
+ https://ccodearchive.net/info/timer.html
7
+ https://git.ruby-lang.org/ruby.git/
8
+ https://bugs.ruby-lang.org/
9
+
10
+ Contact: Eric Wong <normal@ruby-lang.org>
11
+ <ruby-core@ruby-lang.org>
12
+
13
+ Source: git clone https://80x24.org/timeout_ext.git
14
+
15
+ License: LGPL-2.1+
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rake/testtask'
2
+ begin
3
+ require 'rake/extensiontask'
4
+ Rake::ExtensionTask.new('timeout_ext')
5
+ rescue LoadError
6
+ warn 'rake-compiler not available, cross compiling disabled'
7
+ end
8
+
9
+ Rake::TestTask.new(:test)
10
+ task :test => :compile
11
+ task :default => :compile
12
+
13
+ c_files = File.readlines('MANIFEST').grep(%r{ext/.*\.[ch]$}).map!(&:chomp!)
14
+ task 'compile:timeout_ext' => c_files
15
+ task('test:ruby_src' => :compile) do
16
+ if ruby_src = ENV['RUBY_SRC']
17
+ cmd = %W(--disable=gems -Ilib:#{ruby_src}/test/lib -rtimeout -rtimeout_ext
18
+ #{ruby_src}/test/test_timeout.rb)
19
+ if opt = ENV['TEST_OPTS']
20
+ require 'shellwords'
21
+ cmd.concat(Shellwords.split(opt))
22
+ end
23
+ ruby(*cmd)
24
+ else
25
+ warn 'RUBY_SRC not defined for #{RUBY_SRC}/test/test_timeout.rb'
26
+ end
27
+ end
28
+ task :test_all => %w(test test:ruby_src)
@@ -0,0 +1,3 @@
1
+ *.o
2
+ *.so
3
+ Makefile
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright (C) 2018 Ruby contributors <ruby-core@ruby-lang.org>
3
+ * License: LGPL-2.1+ <https://www.gnu.org/licenses/lgpl-2.1.txt>
4
+ */
5
+ #include "ccan/time/time.c"
6
+ #include "ccan/ilog/ilog.c"
7
+ #include "ccan/timer/timer.c"
@@ -0,0 +1,28 @@
1
+ Statement of Purpose
2
+
3
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
4
+
5
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
6
+
7
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
8
+
9
+ 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
10
+
11
+ the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
12
+ moral rights retained by the original author(s) and/or performer(s);
13
+ publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
14
+ rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
15
+ rights protecting the extraction, dissemination, use and reuse of data in a Work;
16
+ database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
17
+ other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
18
+
19
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
20
+
21
+ 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
22
+
23
+ 4. Limitations and Disclaimers.
24
+
25
+ No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
26
+ Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
27
+ Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
28
+ Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
@@ -0,0 +1,46 @@
1
+ #include "config.h"
2
+ #include <stdio.h>
3
+ #include <string.h>
4
+
5
+ /**
6
+ * array_size - routine for safely deriving the size of a visible array.
7
+ *
8
+ * This provides a simple ARRAY_SIZE() macro, which (given a good compiler)
9
+ * will also break compile if you try to use it on a pointer.
10
+ *
11
+ * This can ensure your code is robust to changes, without needing a gratuitous
12
+ * macro or constant.
13
+ *
14
+ * Example:
15
+ * // Outputs "Initialized 32 values\n"
16
+ * #include <ccan/array_size/array_size.h>
17
+ * #include <stdlib.h>
18
+ * #include <stdio.h>
19
+ *
20
+ * // We currently use 32 random values.
21
+ * static unsigned int vals[32];
22
+ *
23
+ * int main(void)
24
+ * {
25
+ * unsigned int i;
26
+ * for (i = 0; i < ARRAY_SIZE(vals); i++)
27
+ * vals[i] = random();
28
+ * printf("Initialized %u values\n", i);
29
+ * return 0;
30
+ * }
31
+ *
32
+ * License: CC0 (Public domain)
33
+ * Author: Rusty Russell <rusty@rustcorp.com.au>
34
+ */
35
+ int main(int argc, char *argv[])
36
+ {
37
+ if (argc != 2)
38
+ return 1;
39
+
40
+ if (strcmp(argv[1], "depends") == 0) {
41
+ printf("ccan/build_assert\n");
42
+ return 0;
43
+ }
44
+
45
+ return 1;
46
+ }
@@ -0,0 +1,26 @@
1
+ /* CC0 (Public domain) - see LICENSE file for details */
2
+ #ifndef CCAN_ARRAY_SIZE_H
3
+ #define CCAN_ARRAY_SIZE_H
4
+ #include "config.h"
5
+ #include <ccan/build_assert/build_assert.h>
6
+
7
+ /**
8
+ * ARRAY_SIZE - get the number of elements in a visible array
9
+ * @arr: the array whose size you want.
10
+ *
11
+ * This does not work on pointers, or arrays declared as [], or
12
+ * function parameters. With correct compiler support, such usage
13
+ * will cause a build error (see build_assert).
14
+ */
15
+ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr))
16
+
17
+ #if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF
18
+ /* Two gcc extensions.
19
+ * &a[0] degrades to a pointer: a different type from an array */
20
+ #define _array_size_chk(arr) \
21
+ BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \
22
+ typeof(&(arr)[0])))
23
+ #else
24
+ #define _array_size_chk(arr) 0
25
+ #endif
26
+ #endif /* CCAN_ALIGNOF_H */
@@ -0,0 +1,28 @@
1
+ Statement of Purpose
2
+
3
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
4
+
5
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
6
+
7
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
8
+
9
+ 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
10
+
11
+ the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
12
+ moral rights retained by the original author(s) and/or performer(s);
13
+ publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
14
+ rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
15
+ rights protecting the extraction, dissemination, use and reuse of data in a Work;
16
+ database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
17
+ other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
18
+
19
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
20
+
21
+ 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
22
+
23
+ 4. Limitations and Disclaimers.
24
+
25
+ No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
26
+ Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
27
+ Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
28
+ Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
@@ -0,0 +1,49 @@
1
+ #include "config.h"
2
+ #include <stdio.h>
3
+ #include <string.h>
4
+
5
+ /**
6
+ * build_assert - routines for build-time assertions
7
+ *
8
+ * This code provides routines which will cause compilation to fail should some
9
+ * assertion be untrue: such failures are preferable to run-time assertions,
10
+ * but much more limited since they can only depends on compile-time constants.
11
+ *
12
+ * These assertions are most useful when two parts of the code must be kept in
13
+ * sync: it is better to avoid such cases if possible, but seconds best is to
14
+ * detect invalid changes at build time.
15
+ *
16
+ * For example, a tricky piece of code might rely on a certain element being at
17
+ * the start of the structure. To ensure that future changes don't break it,
18
+ * you would catch such changes in your code like so:
19
+ *
20
+ * Example:
21
+ * #include <stddef.h>
22
+ * #include <ccan/build_assert/build_assert.h>
23
+ *
24
+ * struct foo {
25
+ * char string[5];
26
+ * int x;
27
+ * };
28
+ *
29
+ * static char *foo_string(struct foo *foo)
30
+ * {
31
+ * // This trick requires that the string be first in the structure
32
+ * BUILD_ASSERT(offsetof(struct foo, string) == 0);
33
+ * return (char *)foo;
34
+ * }
35
+ *
36
+ * License: CC0 (Public domain)
37
+ * Author: Rusty Russell <rusty@rustcorp.com.au>
38
+ */
39
+ int main(int argc, char *argv[])
40
+ {
41
+ if (argc != 2)
42
+ return 1;
43
+
44
+ if (strcmp(argv[1], "depends") == 0)
45
+ /* Nothing. */
46
+ return 0;
47
+
48
+ return 1;
49
+ }
@@ -0,0 +1,40 @@
1
+ /* CC0 (Public domain) - see LICENSE file for details */
2
+ #ifndef CCAN_BUILD_ASSERT_H
3
+ #define CCAN_BUILD_ASSERT_H
4
+
5
+ /**
6
+ * BUILD_ASSERT - assert a build-time dependency.
7
+ * @cond: the compile-time condition which must be true.
8
+ *
9
+ * Your compile will fail if the condition isn't true, or can't be evaluated
10
+ * by the compiler. This can only be used within a function.
11
+ *
12
+ * Example:
13
+ * #include <stddef.h>
14
+ * ...
15
+ * static char *foo_to_char(struct foo *foo)
16
+ * {
17
+ * // This code needs string to be at start of foo.
18
+ * BUILD_ASSERT(offsetof(struct foo, string) == 0);
19
+ * return (char *)foo;
20
+ * }
21
+ */
22
+ #define BUILD_ASSERT(cond) \
23
+ do { (void) sizeof(char [1 - 2*!(cond)]); } while(0)
24
+
25
+ /**
26
+ * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression.
27
+ * @cond: the compile-time condition which must be true.
28
+ *
29
+ * Your compile will fail if the condition isn't true, or can't be evaluated
30
+ * by the compiler. This can be used in an expression: its value is "0".
31
+ *
32
+ * Example:
33
+ * #define foo_to_char(foo) \
34
+ * ((char *)(foo) \
35
+ * + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0))
36
+ */
37
+ #define BUILD_ASSERT_OR_ZERO(cond) \
38
+ (sizeof(char [1 - 2*!(cond)]) - 1)
39
+
40
+ #endif /* CCAN_BUILD_ASSERT_H */
@@ -0,0 +1,28 @@
1
+ Statement of Purpose
2
+
3
+ The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").
4
+
5
+ Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.
6
+
7
+ For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.
8
+
9
+ 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:
10
+
11
+ the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
12
+ moral rights retained by the original author(s) and/or performer(s);
13
+ publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
14
+ rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
15
+ rights protecting the extraction, dissemination, use and reuse of data in a Work;
16
+ database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
17
+ other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.
18
+
19
+ 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.
20
+
21
+ 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.
22
+
23
+ 4. Limitations and Disclaimers.
24
+
25
+ No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
26
+ Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
27
+ Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
28
+ Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.
@@ -0,0 +1,33 @@
1
+ #include "config.h"
2
+ #include <stdio.h>
3
+ #include <string.h>
4
+
5
+ /**
6
+ * check_type - routines for compile time type checking
7
+ *
8
+ * C has fairly weak typing: ints get automatically converted to longs, signed
9
+ * to unsigned, etc. There are some cases where this is best avoided, and
10
+ * these macros provide methods for evoking warnings (or build errors) when
11
+ * a precise type isn't used.
12
+ *
13
+ * On compilers which don't support typeof() these routines are less effective,
14
+ * since they have to use sizeof() which can only distiguish between types of
15
+ * different size.
16
+ *
17
+ * License: CC0 (Public domain)
18
+ * Author: Rusty Russell <rusty@rustcorp.com.au>
19
+ */
20
+ int main(int argc, char *argv[])
21
+ {
22
+ if (argc != 2)
23
+ return 1;
24
+
25
+ if (strcmp(argv[1], "depends") == 0) {
26
+ #if !HAVE_TYPEOF
27
+ printf("ccan/build_assert\n");
28
+ #endif
29
+ return 0;
30
+ }
31
+
32
+ return 1;
33
+ }
@@ -0,0 +1,64 @@
1
+ /* CC0 (Public domain) - see LICENSE file for details */
2
+ #ifndef CCAN_CHECK_TYPE_H
3
+ #define CCAN_CHECK_TYPE_H
4
+ #include "config.h"
5
+
6
+ /**
7
+ * check_type - issue a warning or build failure if type is not correct.
8
+ * @expr: the expression whose type we should check (not evaluated).
9
+ * @type: the exact type we expect the expression to be.
10
+ *
11
+ * This macro is usually used within other macros to try to ensure that a macro
12
+ * argument is of the expected type. No type promotion of the expression is
13
+ * done: an unsigned int is not the same as an int!
14
+ *
15
+ * check_type() always evaluates to 0.
16
+ *
17
+ * If your compiler does not support typeof, then the best we can do is fail
18
+ * to compile if the sizes of the types are unequal (a less complete check).
19
+ *
20
+ * Example:
21
+ * // They should always pass a 64-bit value to _set_some_value!
22
+ * #define set_some_value(expr) \
23
+ * _set_some_value((check_type((expr), uint64_t), (expr)))
24
+ */
25
+
26
+ /**
27
+ * check_types_match - issue a warning or build failure if types are not same.
28
+ * @expr1: the first expression (not evaluated).
29
+ * @expr2: the second expression (not evaluated).
30
+ *
31
+ * This macro is usually used within other macros to try to ensure that
32
+ * arguments are of identical types. No type promotion of the expressions is
33
+ * done: an unsigned int is not the same as an int!
34
+ *
35
+ * check_types_match() always evaluates to 0.
36
+ *
37
+ * If your compiler does not support typeof, then the best we can do is fail
38
+ * to compile if the sizes of the types are unequal (a less complete check).
39
+ *
40
+ * Example:
41
+ * // Do subtraction to get to enclosing type, but make sure that
42
+ * // pointer is of correct type for that member.
43
+ * #define container_of(mbr_ptr, encl_type, mbr) \
44
+ * (check_types_match((mbr_ptr), &((encl_type *)0)->mbr), \
45
+ * ((encl_type *) \
46
+ * ((char *)(mbr_ptr) - offsetof(encl_type, mbr))))
47
+ */
48
+ #if HAVE_TYPEOF
49
+ #define check_type(expr, type) \
50
+ ((typeof(expr) *)0 != (type *)0)
51
+
52
+ #define check_types_match(expr1, expr2) \
53
+ ((typeof(expr1) *)0 != (typeof(expr2) *)0)
54
+ #else
55
+ #include <ccan/build_assert/build_assert.h>
56
+ /* Without typeof, we can only test the sizes. */
57
+ #define check_type(expr, type) \
58
+ BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type))
59
+
60
+ #define check_types_match(expr1, expr2) \
61
+ BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2))
62
+ #endif /* HAVE_TYPEOF */
63
+
64
+ #endif /* CCAN_CHECK_TYPE_H */