zscan 2.0.8 → 2.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/ext/pack/pack-27.c +1 -0
  3. data/ext/pack/pack.c +1 -0
  4. data/ext/pack/ruby/backward/2/assume.h +43 -0
  5. data/ext/pack/ruby/backward/2/attributes.h +157 -0
  6. data/ext/pack/ruby/backward/2/bool.h +37 -0
  7. data/ext/pack/ruby/backward/2/extern.h +46 -0
  8. data/ext/pack/ruby/backward/2/gcc_version_since.h +38 -0
  9. data/ext/pack/ruby/backward/2/inttypes.h +132 -0
  10. data/ext/pack/ruby/backward/2/limits.h +100 -0
  11. data/ext/pack/ruby/backward/2/long_long.h +65 -0
  12. data/ext/pack/ruby/backward/2/r_cast.h +27 -0
  13. data/ext/pack/ruby/backward/2/rmodule.h +31 -0
  14. data/ext/pack/ruby/backward/2/stdalign.h +30 -0
  15. data/ext/pack/ruby/backward/2/stdarg.h +47 -0
  16. data/ext/pack/ruby/backward/classext.h +25 -0
  17. data/ext/pack/ruby/backward/rubyio.h +18 -0
  18. data/ext/pack/ruby/backward/rubysig.h +26 -0
  19. data/ext/pack/ruby/backward/st.h +18 -0
  20. data/ext/pack/ruby/backward/util.h +18 -0
  21. data/ext/pack/ruby/internal/anyargs.h +375 -0
  22. data/ext/pack/ruby/internal/arithmetic.h +38 -0
  23. data/ext/pack/ruby/internal/arithmetic/char.h +58 -0
  24. data/ext/pack/ruby/internal/arithmetic/double.h +39 -0
  25. data/ext/pack/ruby/internal/arithmetic/fixnum.h +44 -0
  26. data/ext/pack/ruby/internal/arithmetic/gid_t.h +34 -0
  27. data/ext/pack/ruby/internal/arithmetic/int.h +163 -0
  28. data/ext/pack/ruby/internal/arithmetic/intptr_t.h +42 -0
  29. data/ext/pack/ruby/internal/arithmetic/long.h +244 -0
  30. data/ext/pack/ruby/internal/arithmetic/long_long.h +53 -0
  31. data/ext/pack/ruby/internal/arithmetic/mode_t.h +34 -0
  32. data/ext/pack/ruby/internal/arithmetic/off_t.h +49 -0
  33. data/ext/pack/ruby/internal/arithmetic/pid_t.h +34 -0
  34. data/ext/pack/ruby/internal/arithmetic/short.h +54 -0
  35. data/ext/pack/ruby/internal/arithmetic/size_t.h +51 -0
  36. data/ext/pack/ruby/internal/arithmetic/st_data_t.h +59 -0
  37. data/ext/pack/ruby/internal/arithmetic/uid_t.h +34 -0
  38. data/ext/pack/ruby/internal/assume.h +90 -0
  39. data/ext/pack/ruby/internal/attr/alloc_size.h +32 -0
  40. data/ext/pack/ruby/internal/attr/artificial.h +46 -0
  41. data/ext/pack/ruby/internal/attr/cold.h +37 -0
  42. data/ext/pack/ruby/internal/attr/const.h +46 -0
  43. data/ext/pack/ruby/internal/attr/constexpr.h +85 -0
  44. data/ext/pack/ruby/internal/attr/deprecated.h +59 -0
  45. data/ext/pack/ruby/internal/attr/diagnose_if.h +42 -0
  46. data/ext/pack/ruby/internal/attr/enum_extensibility.h +32 -0
  47. data/ext/pack/ruby/internal/attr/error.h +32 -0
  48. data/ext/pack/ruby/internal/attr/flag_enum.h +33 -0
  49. data/ext/pack/ruby/internal/attr/forceinline.h +40 -0
  50. data/ext/pack/ruby/internal/attr/format.h +38 -0
  51. data/ext/pack/ruby/internal/attr/maybe_unused.h +38 -0
  52. data/ext/pack/ruby/internal/attr/noalias.h +58 -0
  53. data/ext/pack/ruby/internal/attr/nodiscard.h +45 -0
  54. data/ext/pack/ruby/internal/attr/noexcept.h +91 -0
  55. data/ext/pack/ruby/internal/attr/noinline.h +35 -0
  56. data/ext/pack/ruby/internal/attr/nonnull.h +32 -0
  57. data/ext/pack/ruby/internal/attr/noreturn.h +48 -0
  58. data/ext/pack/ruby/internal/attr/pure.h +43 -0
  59. data/ext/pack/ruby/internal/attr/restrict.h +45 -0
  60. data/ext/pack/ruby/internal/attr/returns_nonnull.h +37 -0
  61. data/ext/pack/ruby/internal/attr/warning.h +32 -0
  62. data/ext/pack/ruby/internal/attr/weakref.h +32 -0
  63. data/ext/pack/ruby/internal/cast.h +53 -0
  64. data/ext/pack/ruby/internal/compiler_is.h +45 -0
  65. data/ext/pack/ruby/internal/compiler_is/apple.h +41 -0
  66. data/ext/pack/ruby/internal/compiler_is/clang.h +38 -0
  67. data/ext/pack/ruby/internal/compiler_is/gcc.h +46 -0
  68. data/ext/pack/ruby/internal/compiler_is/intel.h +41 -0
  69. data/ext/pack/ruby/internal/compiler_is/msvc.h +57 -0
  70. data/ext/pack/ruby/internal/compiler_is/sunpro.h +55 -0
  71. data/ext/pack/ruby/internal/compiler_since.h +61 -0
  72. data/ext/pack/ruby/internal/config.h +131 -0
  73. data/ext/pack/ruby/internal/constant_p.h +37 -0
  74. data/ext/pack/ruby/internal/core.h +35 -0
  75. data/ext/pack/ruby/internal/core/rarray.h +275 -0
  76. data/ext/pack/ruby/internal/core/rbasic.h +85 -0
  77. data/ext/pack/ruby/internal/core/rbignum.h +51 -0
  78. data/ext/pack/ruby/internal/core/rclass.h +47 -0
  79. data/ext/pack/ruby/internal/core/rdata.h +174 -0
  80. data/ext/pack/ruby/internal/core/rfile.h +36 -0
  81. data/ext/pack/ruby/internal/core/rhash.h +62 -0
  82. data/ext/pack/ruby/internal/core/rmatch.h +73 -0
  83. data/ext/pack/ruby/internal/core/robject.h +97 -0
  84. data/ext/pack/ruby/internal/core/rregexp.h +84 -0
  85. data/ext/pack/ruby/internal/core/rstring.h +215 -0
  86. data/ext/pack/ruby/internal/core/rstruct.h +73 -0
  87. data/ext/pack/ruby/internal/core/rtypeddata.h +184 -0
  88. data/ext/pack/ruby/internal/ctype.h +203 -0
  89. data/ext/pack/ruby/internal/dllexport.h +92 -0
  90. data/ext/pack/ruby/internal/dosish.h +63 -0
  91. data/ext/pack/ruby/internal/error.h +74 -0
  92. data/ext/pack/ruby/internal/eval.h +50 -0
  93. data/ext/pack/ruby/internal/event.h +75 -0
  94. data/ext/pack/ruby/internal/fl_type.h +469 -0
  95. data/ext/pack/ruby/internal/gc.h +35 -0
  96. data/ext/pack/ruby/internal/glob.h +35 -0
  97. data/ext/pack/ruby/internal/globals.h +159 -0
  98. data/ext/pack/ruby/internal/has/attribute.h +164 -0
  99. data/ext/pack/ruby/internal/has/builtin.h +105 -0
  100. data/ext/pack/ruby/internal/has/c_attribute.h +38 -0
  101. data/ext/pack/ruby/internal/has/cpp_attribute.h +79 -0
  102. data/ext/pack/ruby/internal/has/declspec_attribute.h +48 -0
  103. data/ext/pack/ruby/internal/has/extension.h +33 -0
  104. data/ext/pack/ruby/internal/has/feature.h +31 -0
  105. data/ext/pack/ruby/internal/has/warning.h +31 -0
  106. data/ext/pack/ruby/internal/intern/array.h +78 -0
  107. data/ext/pack/ruby/internal/intern/bignum.h +105 -0
  108. data/ext/pack/ruby/internal/intern/class.h +57 -0
  109. data/ext/pack/ruby/internal/intern/compar.h +34 -0
  110. data/ext/pack/ruby/internal/intern/complex.h +60 -0
  111. data/ext/pack/ruby/internal/intern/cont.h +40 -0
  112. data/ext/pack/ruby/internal/intern/dir.h +33 -0
  113. data/ext/pack/ruby/internal/intern/enum.h +33 -0
  114. data/ext/pack/ruby/internal/intern/enumerator.h +79 -0
  115. data/ext/pack/ruby/internal/intern/error.h +82 -0
  116. data/ext/pack/ruby/internal/intern/eval.h +59 -0
  117. data/ext/pack/ruby/internal/intern/file.h +44 -0
  118. data/ext/pack/ruby/internal/intern/gc.h +57 -0
  119. data/ext/pack/ruby/internal/intern/hash.h +59 -0
  120. data/ext/pack/ruby/internal/intern/io.h +70 -0
  121. data/ext/pack/ruby/internal/intern/load.h +39 -0
  122. data/ext/pack/ruby/internal/intern/marshal.h +35 -0
  123. data/ext/pack/ruby/internal/intern/numeric.h +42 -0
  124. data/ext/pack/ruby/internal/intern/object.h +90 -0
  125. data/ext/pack/ruby/internal/intern/parse.h +64 -0
  126. data/ext/pack/ruby/internal/intern/proc.h +53 -0
  127. data/ext/pack/ruby/internal/intern/process.h +46 -0
  128. data/ext/pack/ruby/internal/intern/random.h +45 -0
  129. data/ext/pack/ruby/internal/intern/range.h +35 -0
  130. data/ext/pack/ruby/internal/intern/rational.h +46 -0
  131. data/ext/pack/ruby/internal/intern/re.h +50 -0
  132. data/ext/pack/ruby/internal/intern/ruby.h +37 -0
  133. data/ext/pack/ruby/internal/intern/select.h +52 -0
  134. data/ext/pack/ruby/internal/intern/select/largesize.h +103 -0
  135. data/ext/pack/ruby/internal/intern/select/posix.h +82 -0
  136. data/ext/pack/ruby/internal/intern/select/win32.h +124 -0
  137. data/ext/pack/ruby/internal/intern/signal.h +40 -0
  138. data/ext/pack/ruby/internal/intern/sprintf.h +43 -0
  139. data/ext/pack/ruby/internal/intern/string.h +290 -0
  140. data/ext/pack/ruby/internal/intern/struct.h +47 -0
  141. data/ext/pack/ruby/internal/intern/thread.h +76 -0
  142. data/ext/pack/ruby/internal/intern/time.h +52 -0
  143. data/ext/pack/ruby/internal/intern/variable.h +83 -0
  144. data/ext/pack/ruby/internal/intern/vm.h +77 -0
  145. data/ext/pack/ruby/internal/interpreter.h +94 -0
  146. data/ext/pack/ruby/internal/iterator.h +65 -0
  147. data/ext/pack/ruby/internal/memory.h +286 -0
  148. data/ext/pack/ruby/internal/method.h +39 -0
  149. data/ext/pack/ruby/internal/module.h +39 -0
  150. data/ext/pack/ruby/internal/newobj.h +73 -0
  151. data/ext/pack/ruby/internal/rgengc.h +199 -0
  152. data/ext/pack/ruby/internal/scan_args.h +394 -0
  153. data/ext/pack/ruby/internal/special_consts.h +204 -0
  154. data/ext/pack/ruby/internal/static_assert.h +77 -0
  155. data/ext/pack/ruby/internal/stdalign.h +124 -0
  156. data/ext/pack/ruby/internal/stdbool.h +51 -0
  157. data/ext/pack/ruby/internal/symbol.h +114 -0
  158. data/ext/pack/ruby/internal/token_paste.h +75 -0
  159. data/ext/pack/ruby/internal/value.h +66 -0
  160. data/ext/pack/ruby/internal/value_type.h +354 -0
  161. data/ext/pack/ruby/internal/variable.h +62 -0
  162. data/ext/pack/ruby/internal/warning_push.h +91 -0
  163. data/ext/pack/ruby/internal/xmalloc.h +201 -0
  164. data/lib/zscan.rb +1 -1
  165. data/readme.md +2 -0
  166. data/zscan.gemspec +1 -1
  167. metadata +162 -2
@@ -0,0 +1,38 @@
1
+ #ifndef RBIMPL_ARITHMETIC_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Conversion between C's arithmtic types and Ruby's numeric types.
22
+ */
23
+ #include "ruby/internal/arithmetic/char.h"
24
+ #include "ruby/internal/arithmetic/double.h"
25
+ #include "ruby/internal/arithmetic/fixnum.h"
26
+ #include "ruby/internal/arithmetic/gid_t.h"
27
+ #include "ruby/internal/arithmetic/int.h"
28
+ #include "ruby/internal/arithmetic/intptr_t.h"
29
+ #include "ruby/internal/arithmetic/long.h"
30
+ #include "ruby/internal/arithmetic/long_long.h"
31
+ #include "ruby/internal/arithmetic/mode_t.h"
32
+ #include "ruby/internal/arithmetic/off_t.h"
33
+ #include "ruby/internal/arithmetic/pid_t.h"
34
+ #include "ruby/internal/arithmetic/short.h"
35
+ #include "ruby/internal/arithmetic/size_t.h"
36
+ #include "ruby/internal/arithmetic/st_data_t.h"
37
+ #include "ruby/internal/arithmetic/uid_t.h"
38
+ #endif /* RBIMPL_ARITHMETIC_H */
@@ -0,0 +1,58 @@
1
+ #ifndef RBIMPL_ARITHMETIC_CHAR_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_CHAR_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Arithmetic conversion between C's `char` and Ruby's.
22
+ */
23
+ #include "ruby/internal/arithmetic/int.h" /* NUM2INT is here, but */
24
+ #include "ruby/internal/arithmetic/long.h" /* INT2FIX is here.*/
25
+ #include "ruby/internal/attr/artificial.h"
26
+ #include "ruby/internal/attr/const.h"
27
+ #include "ruby/internal/attr/constexpr.h"
28
+ #include "ruby/internal/cast.h"
29
+ #include "ruby/internal/core/rstring.h"
30
+ #include "ruby/internal/value_type.h"
31
+
32
+ #define RB_NUM2CHR rb_num2char_inline
33
+ #define NUM2CHR RB_NUM2CHR
34
+ #define CHR2FIX RB_CHR2FIX
35
+
36
+ /** @cond INTERNAL_MACRO */
37
+ #define RB_CHR2FIX RB_CHR2FIX
38
+ /** @endcond */
39
+
40
+ RBIMPL_ATTR_CONST_ON_NDEBUG()
41
+ RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14)
42
+ RBIMPL_ATTR_ARTIFICIAL()
43
+ static inline VALUE
44
+ RB_CHR2FIX(unsigned char c)
45
+ {
46
+ return RB_INT2FIX(c);
47
+ }
48
+
49
+ static inline char
50
+ rb_num2char_inline(VALUE x)
51
+ {
52
+ if (RB_TYPE_P(x, RUBY_T_STRING) && (RSTRING_LEN(x)>=1))
53
+ return RSTRING_PTR(x)[0];
54
+ else
55
+ return RBIMPL_CAST((char)RB_NUM2INT(x));
56
+ }
57
+
58
+ #endif /* RBIMPL_ARITHMETIC_CHAR_H */
@@ -0,0 +1,39 @@
1
+ #ifndef RBIMPL_ARITHMETIC_DOUBLE_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_DOUBLE_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Arithmetic conversion between C's `double` and Ruby's.
22
+ */
23
+ #include "ruby/internal/attr/pure.h"
24
+ #include "ruby/internal/dllexport.h"
25
+ #include "ruby/internal/value.h"
26
+
27
+ #define NUM2DBL rb_num2dbl
28
+ #define RFLOAT_VALUE rb_float_value
29
+ #define DBL2NUM rb_float_new
30
+
31
+ RBIMPL_SYMBOL_EXPORT_BEGIN()
32
+ double rb_num2dbl(VALUE);
33
+ RBIMPL_ATTR_PURE()
34
+ double rb_float_value(VALUE);
35
+ VALUE rb_float_new(double);
36
+ VALUE rb_float_new_in_heap(double);
37
+ RBIMPL_SYMBOL_EXPORT_END()
38
+
39
+ #endif /* RBIMPL_ARITHMETIC_DOUBLE_H */
@@ -0,0 +1,44 @@
1
+ #ifndef RBIMPL_ARITHMETIC_FIXNUM_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_FIXNUM_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Handling of integers formerly known as Fixnums.
22
+ */
23
+ #include "ruby/backward/2/limits.h"
24
+
25
+ #define FIXABLE RB_FIXABLE
26
+ #define FIXNUM_MAX RUBY_FIXNUM_MAX
27
+ #define FIXNUM_MIN RUBY_FIXNUM_MIN
28
+ #define NEGFIXABLE RB_NEGFIXABLE
29
+ #define POSFIXABLE RB_POSFIXABLE
30
+
31
+ /*
32
+ * FIXABLE can be applied to anything, from double to intmax_t. The problem is
33
+ * double. On a 64bit system RUBY_FIXNUM_MAX is 4,611,686,018,427,387,903,
34
+ * which is not representable by a double. The nearest value that a double can
35
+ * represent is 4,611,686,018,427,387,904, which is not fixable. The
36
+ * seemingly-stragne "< FIXNUM_MAX + 1" expression below is due to this.
37
+ */
38
+ #define RB_POSFIXABLE(_) ((_) < RUBY_FIXNUM_MAX + 1)
39
+ #define RB_NEGFIXABLE(_) ((_) >= RUBY_FIXNUM_MIN)
40
+ #define RB_FIXABLE(_) (RB_POSFIXABLE(_) && RB_NEGFIXABLE(_))
41
+ #define RUBY_FIXNUM_MAX (LONG_MAX / 2)
42
+ #define RUBY_FIXNUM_MIN (LONG_MIN / 2)
43
+
44
+ #endif /* RBIMPL_ARITHMETIC_FIXNUM_H */
@@ -0,0 +1,34 @@
1
+ #ifndef RBIMPL_ARITHMETIC_GID_T_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_GID_T_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Arithmetic conversion between C's `gid_t` and Ruby's.
22
+ */
23
+ #include "ruby/internal/config.h"
24
+ #include "ruby/internal/arithmetic/long.h"
25
+
26
+ #ifndef GIDT2NUM
27
+ # define GIDT2NUM RB_LONG2NUM
28
+ #endif
29
+
30
+ #ifndef NUM2GIDT
31
+ # define NUM2GIDT RB_NUM2LONG
32
+ #endif
33
+
34
+ #endif /* RBIMPL_ARITHMETIC_GID_T_H */
@@ -0,0 +1,163 @@
1
+ #ifndef RBIMPL_ARITHMETIC_INT_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_INT_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Arithmetic conversion between C's `int` and Ruby's.
22
+ */
23
+ #include "ruby/internal/config.h"
24
+ #include "ruby/internal/arithmetic/fixnum.h"
25
+ #include "ruby/internal/arithmetic/intptr_t.h"
26
+ #include "ruby/internal/arithmetic/long.h"
27
+ #include "ruby/internal/attr/artificial.h"
28
+ #include "ruby/internal/attr/const.h"
29
+ #include "ruby/internal/attr/constexpr.h"
30
+ #include "ruby/internal/compiler_is.h"
31
+ #include "ruby/internal/dllexport.h"
32
+ #include "ruby/internal/special_consts.h"
33
+ #include "ruby/internal/value.h"
34
+ #include "ruby/internal/warning_push.h"
35
+ #include "ruby/assert.h"
36
+
37
+ #define RB_INT2NUM rb_int2num_inline
38
+ #define RB_NUM2INT rb_num2int_inline
39
+ #define RB_UINT2NUM rb_uint2num_inline
40
+
41
+ #define FIX2INT RB_FIX2INT
42
+ #define FIX2UINT RB_FIX2UINT
43
+ #define INT2NUM RB_INT2NUM
44
+ #define NUM2INT RB_NUM2INT
45
+ #define NUM2UINT RB_NUM2UINT
46
+ #define UINT2NUM RB_UINT2NUM
47
+
48
+ /** @cond INTERNAL_MACRO */
49
+ #define RB_FIX2INT RB_FIX2INT
50
+ #define RB_NUM2UINT RB_NUM2UINT
51
+ #define RB_FIX2UINT RB_FIX2UINT
52
+ /** @endcond */
53
+
54
+ RBIMPL_SYMBOL_EXPORT_BEGIN()
55
+ long rb_num2int(VALUE);
56
+ long rb_fix2int(VALUE);
57
+ unsigned long rb_num2uint(VALUE);
58
+ unsigned long rb_fix2uint(VALUE);
59
+ RBIMPL_SYMBOL_EXPORT_END()
60
+
61
+ RBIMPL_ATTR_ARTIFICIAL()
62
+ static inline int
63
+ RB_FIX2INT(VALUE x)
64
+ {
65
+ /* "FIX2INT raises a TypeError if passed nil", says rubyspec. Not sure if
66
+ * that is a desired behaviour but just preserve backwards compatilibily.
67
+ */
68
+ #if 0
69
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
70
+ #endif
71
+ long ret;
72
+
73
+ if /* constexpr */ (sizeof(int) < sizeof(long)) {
74
+ ret = rb_fix2int(x);
75
+ }
76
+ else {
77
+ ret = RB_FIX2LONG(x);
78
+ }
79
+
80
+ return RBIMPL_CAST((int)ret);
81
+ }
82
+
83
+ static inline int
84
+ rb_num2int_inline(VALUE x)
85
+ {
86
+ long ret;
87
+
88
+ if /* constexpr */ (sizeof(int) == sizeof(long)) {
89
+ ret = RB_NUM2LONG(x);
90
+ }
91
+ else if (RB_FIXNUM_P(x)) {
92
+ ret = rb_fix2int(x);
93
+ }
94
+ else {
95
+ ret = rb_num2int(x);
96
+ }
97
+
98
+ return RBIMPL_CAST((int)ret);
99
+ }
100
+
101
+ RBIMPL_ATTR_ARTIFICIAL()
102
+ static inline unsigned int
103
+ RB_NUM2UINT(VALUE x)
104
+ {
105
+ unsigned long ret;
106
+
107
+ if /* constexpr */ (sizeof(int) < sizeof(long)) {
108
+ ret = rb_num2uint(x);
109
+ }
110
+ else {
111
+ ret = RB_NUM2ULONG(x);
112
+ }
113
+
114
+ return RBIMPL_CAST((unsigned int)ret);
115
+ }
116
+
117
+ RBIMPL_ATTR_ARTIFICIAL()
118
+ static inline unsigned int
119
+ RB_FIX2UINT(VALUE x)
120
+ {
121
+ #if 0 /* Ditto for RB_FIX2INT. */
122
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
123
+ #endif
124
+ unsigned long ret;
125
+
126
+ if /* constexpr */ (sizeof(int) < sizeof(long)) {
127
+ ret = rb_fix2uint(x);
128
+ }
129
+ else {
130
+ ret = RB_FIX2ULONG(x);
131
+ }
132
+
133
+ return RBIMPL_CAST((unsigned int)ret);
134
+ }
135
+
136
+ RBIMPL_WARNING_PUSH()
137
+ #if RBIMPL_COMPILER_IS(GCC)
138
+ RBIMPL_WARNING_IGNORED(-Wtype-limits) /* We can ignore them here. */
139
+ #elif RBIMPL_HAS_WARNING("-Wtautological-constant-out-of-range-compare")
140
+ RBIMPL_WARNING_IGNORED(-Wtautological-constant-out-of-range-compare)
141
+ #endif
142
+
143
+ static inline VALUE
144
+ rb_int2num_inline(int v)
145
+ {
146
+ if (RB_FIXABLE(v))
147
+ return RB_INT2FIX(v);
148
+ else
149
+ return rb_int2big(v);
150
+ }
151
+
152
+ static inline VALUE
153
+ rb_uint2num_inline(unsigned int v)
154
+ {
155
+ if (RB_POSFIXABLE(v))
156
+ return RB_LONG2FIX(v);
157
+ else
158
+ return rb_uint2big(v);
159
+ }
160
+
161
+ RBIMPL_WARNING_POP()
162
+
163
+ #endif /* RBIMPL_ARITHMETIC_INT_H */
@@ -0,0 +1,42 @@
1
+ #ifndef RBIMPL_ARITHMETIC_INTPTR_T_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_INTPTR_T_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Arithmetic conversion between C's `intptr_t` and Ruby's.
22
+ */
23
+ #include "ruby/internal/config.h"
24
+
25
+ #ifdef HAVE_STDINT_H
26
+ # include <stdint.h>
27
+ #endif
28
+
29
+ #include "ruby/internal/value.h"
30
+ #include "ruby/internal/dllexport.h"
31
+
32
+ #define rb_int_new rb_int2inum
33
+ #define rb_uint_new rb_uint2inum
34
+
35
+ RBIMPL_SYMBOL_EXPORT_BEGIN()
36
+ VALUE rb_int2big(intptr_t i);
37
+ VALUE rb_int2inum(intptr_t i);
38
+ VALUE rb_uint2big(uintptr_t i);
39
+ VALUE rb_uint2inum(uintptr_t i);
40
+ RBIMPL_SYMBOL_EXPORT_END()
41
+
42
+ #endif /* RBIMPL_ARITHMETIC_INTPTR_T_H */
@@ -0,0 +1,244 @@
1
+ #ifndef RBIMPL_ARITHMETIC_LONG_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ARITHMETIC_LONG_H
3
+ /**
4
+ * @file
5
+ * @author Ruby developers <ruby-core@ruby-lang.org>
6
+ * @copyright This file is a part of the programming language Ruby.
7
+ * Permission is hereby granted, to either redistribute and/or
8
+ * modify this file, provided that the conditions mentioned in the
9
+ * file COPYING are met. Consult the file for details.
10
+ * @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are
11
+ * implementation details. Don't take them as canon. They could
12
+ * rapidly appear then vanish. The name (path) of this header file
13
+ * is also an implementation detail. Do not expect it to persist
14
+ * at the place it is now. Developers are free to move it anywhere
15
+ * anytime at will.
16
+ * @note To ruby-core: remember that this header can be possibly
17
+ * recursively included from extension libraries written in C++.
18
+ * Do not expect for instance `__VA_ARGS__` is always available.
19
+ * We assume C99 for ruby itself but we don't assume languages of
20
+ * extension libraries. They could be written in C++98.
21
+ * @brief Arithmetic conversion between C's `long` and Ruby's.
22
+ *
23
+ * ### Q&A ###
24
+ *
25
+ * - Q: Why are INT2FIX etc. here, not in `int.h`?
26
+ *
27
+ * - A: Because they are in fact handling `long`. It seems someone did not
28
+ * understand the difference of `int` and `long` when they designed those
29
+ * macros.
30
+ */
31
+ #include "ruby/internal/config.h"
32
+ #include "ruby/internal/arithmetic/fixnum.h" /* FIXABLE */
33
+ #include "ruby/internal/arithmetic/intptr_t.h" /* rb_int2big etc.*/
34
+ #include "ruby/internal/assume.h"
35
+ #include "ruby/internal/attr/artificial.h"
36
+ #include "ruby/internal/attr/cold.h"
37
+ #include "ruby/internal/attr/const.h"
38
+ #include "ruby/internal/attr/constexpr.h"
39
+ #include "ruby/internal/attr/noreturn.h"
40
+ #include "ruby/internal/cast.h"
41
+ #include "ruby/internal/dllexport.h"
42
+ #include "ruby/internal/special_consts.h" /* FIXNUM_FLAG */
43
+ #include "ruby/internal/value.h"
44
+ #include "ruby/assert.h"
45
+
46
+ #define FIX2LONG RB_FIX2LONG
47
+ #define FIX2ULONG RB_FIX2ULONG
48
+ #define INT2FIX RB_INT2FIX
49
+ #define LONG2FIX RB_INT2FIX
50
+ #define LONG2NUM RB_LONG2NUM
51
+ #define NUM2LONG RB_NUM2LONG
52
+ #define NUM2ULONG RB_NUM2ULONG
53
+ #define RB_FIX2LONG rb_fix2long
54
+ #define RB_FIX2ULONG rb_fix2ulong
55
+ #define RB_LONG2FIX RB_INT2FIX
56
+ #define RB_LONG2NUM rb_long2num_inline
57
+ #define RB_NUM2LONG rb_num2long_inline
58
+ #define RB_NUM2ULONG rb_num2ulong_inline
59
+ #define RB_ULONG2NUM rb_ulong2num_inline
60
+ #define ULONG2NUM RB_ULONG2NUM
61
+ #define rb_fix_new RB_INT2FIX
62
+ #define rb_long2int rb_long2int_inline
63
+
64
+ /** @cond INTERNAL_MACRO */
65
+ #define RB_INT2FIX RB_INT2FIX
66
+ /** @endcond */
67
+
68
+ RBIMPL_SYMBOL_EXPORT_BEGIN()
69
+
70
+ RBIMPL_ATTR_NORETURN()
71
+ RBIMPL_ATTR_COLD()
72
+ void rb_out_of_int(SIGNED_VALUE num);
73
+
74
+ long rb_num2long(VALUE num);
75
+ unsigned long rb_num2ulong(VALUE num);
76
+ RBIMPL_SYMBOL_EXPORT_END()
77
+
78
+ RBIMPL_ATTR_CONST_ON_NDEBUG()
79
+ RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14)
80
+ RBIMPL_ATTR_ARTIFICIAL()
81
+ static inline VALUE
82
+ RB_INT2FIX(long i)
83
+ {
84
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(i));
85
+
86
+ /* :NOTE: VALUE can be wider than long. As j being unsigned, 2j+1 is fully
87
+ * defined. Also it can be compiled into a single LEA instruction. */
88
+ const unsigned long j = i;
89
+ const unsigned long k = 2 * j + RUBY_FIXNUM_FLAG;
90
+ const long l = k;
91
+ const SIGNED_VALUE m = l; /* Sign extend */
92
+ const VALUE n = m;
93
+
94
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(n));
95
+ return n;
96
+ }
97
+
98
+ static inline int
99
+ rb_long2int_inline(long n)
100
+ {
101
+ int i = RBIMPL_CAST((int)n);
102
+
103
+ if /* constexpr */ (sizeof(long) <= sizeof(int)) {
104
+ RBIMPL_ASSUME(i == n);
105
+ }
106
+
107
+ if (i != n)
108
+ rb_out_of_int(n);
109
+
110
+ return i;
111
+ }
112
+
113
+ RBIMPL_ATTR_CONST_ON_NDEBUG()
114
+ RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14)
115
+ static inline long
116
+ rbimpl_fix2long_by_idiv(VALUE x)
117
+ {
118
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
119
+
120
+ /* :NOTE: VALUE can be wider than long. (x-1)/2 never overflows because
121
+ * RB_FIXNUM_P(x) holds. Also it has no portability issue like y>>1
122
+ * below. */
123
+ const SIGNED_VALUE y = x - RUBY_FIXNUM_FLAG;
124
+ const SIGNED_VALUE z = y / 2;
125
+ const long w = RBIMPL_CAST((long)z);
126
+
127
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w));
128
+ return w;
129
+ }
130
+
131
+ RBIMPL_ATTR_CONST_ON_NDEBUG()
132
+ RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14)
133
+ static inline long
134
+ rbimpl_fix2long_by_shift(VALUE x)
135
+ {
136
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
137
+
138
+ /* :NOTE: VALUE can be wider than long. If right shift is arithmetic, this
139
+ * is noticeably faster than above. */
140
+ const SIGNED_VALUE y = x;
141
+ const SIGNED_VALUE z = y >> 1;
142
+ const long w = RBIMPL_CAST((long)z);
143
+
144
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(w));
145
+ return w;
146
+ }
147
+
148
+ RBIMPL_ATTR_CONST()
149
+ RBIMPL_ATTR_CONSTEXPR(CXX11)
150
+ static inline bool
151
+ rbimpl_right_shift_is_arithmetic_p(void)
152
+ {
153
+ return (-1 >> 1) == -1;
154
+ }
155
+
156
+ RBIMPL_ATTR_CONST_ON_NDEBUG()
157
+ RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14)
158
+ static inline long
159
+ rb_fix2long(VALUE x)
160
+ {
161
+ if /* constexpr */ (rbimpl_right_shift_is_arithmetic_p()) {
162
+ return rbimpl_fix2long_by_shift(x);
163
+ }
164
+ else {
165
+ return rbimpl_fix2long_by_idiv(x);
166
+ }
167
+ }
168
+
169
+ RBIMPL_ATTR_CONST_ON_NDEBUG()
170
+ RBIMPL_ATTR_CONSTEXPR_ON_NDEBUG(CXX14)
171
+ static inline unsigned long
172
+ rb_fix2ulong(VALUE x)
173
+ {
174
+ RBIMPL_ASSERT_OR_ASSUME(RB_FIXNUM_P(x));
175
+ return rb_fix2long(x);
176
+ }
177
+
178
+ static inline long
179
+ rb_num2long_inline(VALUE x)
180
+ {
181
+ if (RB_FIXNUM_P(x))
182
+ return RB_FIX2LONG(x);
183
+ else
184
+ return rb_num2long(x);
185
+ }
186
+
187
+ static inline unsigned long
188
+ rb_num2ulong_inline(VALUE x)
189
+ {
190
+ /* This (negative fixnum would become a large unsigned long while negative
191
+ * bignum is an exception) has been THE behaviour of NUM2ULONG since the
192
+ * beginning. It is strange, but we can no longer change how it works at
193
+ * this moment. We have to get by with it. See also:
194
+ * https://bugs.ruby-lang.org/issues/9089 */
195
+ if (RB_FIXNUM_P(x))
196
+ return RB_FIX2ULONG(x);
197
+ else
198
+ return rb_num2ulong(x);
199
+ }
200
+
201
+ static inline VALUE
202
+ rb_long2num_inline(long v)
203
+ {
204
+ if (RB_FIXABLE(v))
205
+ return RB_LONG2FIX(v);
206
+ else
207
+ return rb_int2big(v);
208
+ }
209
+
210
+ static inline VALUE
211
+ rb_ulong2num_inline(unsigned long v)
212
+ {
213
+ if (RB_POSFIXABLE(v))
214
+ return RB_LONG2FIX(v);
215
+ else
216
+ return rb_uint2big(v);
217
+ }
218
+
219
+ /**
220
+ * @cond INTERNAL_MACRO
221
+ *
222
+ * Following overload is necessary because sometimes INT2FIX is used as a enum
223
+ * value (e.g. `enum { FOO = INT2FIX(0) };`). THIS IS NG in theory because a
224
+ * VALUE does not fit into an enum (which must be a signed int). But we cannot
225
+ * break existing codes.
226
+ */
227
+ #if RBIMPL_HAS_ATTR_CONSTEXPR_CXX14
228
+ # /* C++ can write constexpr as enum values. */
229
+
230
+ #elif ! defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
231
+ # undef INT2FIX
232
+ # define INT2FIX(i) (RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG)
233
+
234
+ #else
235
+ # undef INT2FIX
236
+ # define INT2FIX(i) \
237
+ __builtin_choose_expr( \
238
+ __builtin_constant_p(i), \
239
+ RBIMPL_CAST((VALUE)(i)) << 1 | RUBY_FIXNUM_FLAG, \
240
+ RB_INT2FIX(i))
241
+ #endif
242
+ /** @endcond */
243
+
244
+ #endif /* RBIMPL_ARITHMETIC_LONG_H */