zscan 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
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,73 @@
1
+ #ifndef RBIMPL_RMATCH_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_RMATCH_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 Defines struct ::RMatch.
22
+ */
23
+ #include "ruby/internal/attr/artificial.h"
24
+ #include "ruby/internal/attr/pure.h"
25
+ #include "ruby/internal/attr/returns_nonnull.h"
26
+ #include "ruby/internal/cast.h"
27
+ #include "ruby/internal/core/rbasic.h"
28
+ #include "ruby/internal/value.h"
29
+ #include "ruby/internal/value_type.h"
30
+ #include "ruby/assert.h"
31
+
32
+ #define RMATCH(obj) RBIMPL_CAST((struct RMatch *)(obj))
33
+ /** @cond INTERNAL_MACRO */
34
+ #define RMATCH_REGS RMATCH_REGS
35
+ /** @endcond */
36
+
37
+ struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
38
+ struct re_registers; /* Also in onigmo.h */
39
+
40
+ /* @shyouhei wonders: is anyone actively using this typedef ...? */
41
+ typedef struct re_pattern_buffer Regexp;
42
+
43
+ struct rmatch_offset {
44
+ long beg;
45
+ long end;
46
+ };
47
+
48
+ struct rmatch {
49
+ struct re_registers regs;
50
+
51
+ struct rmatch_offset *char_offset;
52
+ int char_offset_num_allocated;
53
+ };
54
+
55
+ struct RMatch {
56
+ struct RBasic basic;
57
+ VALUE str;
58
+ struct rmatch *rmatch;
59
+ VALUE regexp; /* RRegexp */
60
+ };
61
+
62
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
63
+ RBIMPL_ATTR_RETURNS_NONNULL()
64
+ RBIMPL_ATTR_ARTIFICIAL()
65
+ static inline struct re_registers *
66
+ RMATCH_REGS(VALUE match)
67
+ {
68
+ RBIMPL_ASSERT_TYPE(match, RUBY_T_MATCH);
69
+ RBIMPL_ASSERT_OR_ASSUME(RMATCH(match)->rmatch != NULL);
70
+ return &RMATCH(match)->rmatch->regs;
71
+ }
72
+
73
+ #endif /* RBIMPL_RMATCH_H */
@@ -0,0 +1,97 @@
1
+ #ifndef RBIMPL_ROBJECT_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_ROBJECT_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 Defines struct ::RObject.
22
+ */
23
+ #include "ruby/internal/config.h"
24
+
25
+ #ifdef HAVE_STDINT_H
26
+ # include <stdint.h>
27
+ #endif
28
+
29
+ #include "ruby/internal/attr/artificial.h"
30
+ #include "ruby/internal/attr/pure.h"
31
+ #include "ruby/internal/cast.h"
32
+ #include "ruby/internal/fl_type.h"
33
+ #include "ruby/internal/value.h"
34
+ #include "ruby/internal/value_type.h"
35
+
36
+ #define ROBJECT(obj) RBIMPL_CAST((struct RObject *)(obj))
37
+ #define ROBJECT_EMBED_LEN_MAX ROBJECT_EMBED_LEN_MAX
38
+ #define ROBJECT_EMBED ROBJECT_EMBED
39
+ /** @cond INTERNAL_MACRO */
40
+ #define ROBJECT_NUMIV ROBJECT_NUMIV
41
+ #define ROBJECT_IVPTR ROBJECT_IVPTR
42
+ /** @endcond */
43
+
44
+ enum ruby_robject_flags { ROBJECT_EMBED = RUBY_FL_USER1 };
45
+
46
+ enum ruby_robject_consts { ROBJECT_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(VALUE) };
47
+
48
+ struct RObject {
49
+ struct RBasic basic;
50
+ union {
51
+ struct {
52
+ uint32_t numiv;
53
+ VALUE *ivptr;
54
+ void *iv_index_tbl; /* shortcut for RCLASS_IV_INDEX_TBL(rb_obj_class(obj)) */
55
+ } heap;
56
+ VALUE ary[ROBJECT_EMBED_LEN_MAX];
57
+ } as;
58
+ };
59
+
60
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
61
+ RBIMPL_ATTR_ARTIFICIAL()
62
+ static inline uint32_t
63
+ ROBJECT_NUMIV(VALUE obj)
64
+ {
65
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
66
+
67
+ if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
68
+ return ROBJECT_EMBED_LEN_MAX;
69
+ }
70
+ else {
71
+ return ROBJECT(obj)->as.heap.numiv;
72
+ }
73
+ }
74
+
75
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
76
+ RBIMPL_ATTR_ARTIFICIAL()
77
+ static inline VALUE *
78
+ ROBJECT_IVPTR(VALUE obj)
79
+ {
80
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
81
+
82
+ struct RObject *const ptr = ROBJECT(obj);
83
+
84
+ if (RB_FL_ANY_RAW(obj, ROBJECT_EMBED)) {
85
+ return ptr->as.ary;
86
+ }
87
+ else {
88
+ return ptr->as.heap.ivptr;
89
+ }
90
+ }
91
+
92
+ #define ROBJECT_IV_INDEX_TBL(o) \
93
+ ((RBASIC(o)->flags & ROBJECT_EMBED) ? \
94
+ RCLASS_IV_INDEX_TBL(rb_obj_class(o)) : \
95
+ ROBJECT(o)->as.heap.iv_index_tbl)
96
+
97
+ #endif /* RBIMPL_ROBJECT_H */
@@ -0,0 +1,84 @@
1
+ #ifndef RBIMPL_RREGEXP_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_RREGEXP_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 Defines struct ::RRegexp.
22
+ */
23
+ #include "ruby/internal/attr/artificial.h"
24
+ #include "ruby/internal/attr/pure.h"
25
+ #include "ruby/internal/cast.h"
26
+ #include "ruby/internal/core/rbasic.h"
27
+ #include "ruby/internal/core/rstring.h"
28
+ #include "ruby/internal/value.h"
29
+ #include "ruby/internal/value_type.h"
30
+
31
+ #define RREGEXP(obj) RBIMPL_CAST((struct RRegexp *)(obj))
32
+ #define RREGEXP_PTR(obj) (RREGEXP(obj)->ptr)
33
+ /** @cond INTERNAL_MACRO */
34
+ #define RREGEXP_SRC RREGEXP_SRC
35
+ #define RREGEXP_SRC_PTR RREGEXP_SRC_PTR
36
+ #define RREGEXP_SRC_LEN RREGEXP_SRC_LEN
37
+ #define RREGEXP_SRC_END RREGEXP_SRC_END
38
+ /** @endcond */
39
+
40
+ struct re_patter_buffer; /* a.k.a. OnigRegexType, defined in onigmo.h */
41
+
42
+ struct RRegexp {
43
+ struct RBasic basic;
44
+ struct re_pattern_buffer *ptr;
45
+ const VALUE src;
46
+ unsigned long usecnt;
47
+ };
48
+
49
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
50
+ RBIMPL_ATTR_ARTIFICIAL()
51
+ static inline VALUE
52
+ RREGEXP_SRC(VALUE rexp)
53
+ {
54
+ RBIMPL_ASSERT_TYPE(rexp, RUBY_T_REGEXP);
55
+ VALUE ret = RREGEXP(rexp)->src;
56
+ RBIMPL_ASSERT_TYPE(ret, RUBY_T_STRING);
57
+ return ret;
58
+ }
59
+
60
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
61
+ RBIMPL_ATTR_ARTIFICIAL()
62
+ static inline char *
63
+ RREGEXP_SRC_PTR(VALUE rexp)
64
+ {
65
+ return RSTRING_PTR(RREGEXP_SRC(rexp));
66
+ }
67
+
68
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
69
+ RBIMPL_ATTR_ARTIFICIAL()
70
+ static inline long
71
+ RREGEXP_SRC_LEN(VALUE rexp)
72
+ {
73
+ return RSTRING_LEN(RREGEXP_SRC(rexp));
74
+ }
75
+
76
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
77
+ RBIMPL_ATTR_ARTIFICIAL()
78
+ static inline char *
79
+ RREGEXP_SRC_END(VALUE rexp)
80
+ {
81
+ return RSTRING_END(RREGEXP_SRC(rexp));
82
+ }
83
+
84
+ #endif /* RBIMPL_RREGEXP_H */
@@ -0,0 +1,215 @@
1
+ #ifndef RBIMPL_RSTRING_H /*-*-C++-*-vi:se ft=cpp:*/
2
+ #define RBIMPL_RSTRING_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 Defines struct ::RString.
22
+ */
23
+ #include "ruby/internal/config.h"
24
+ #include "ruby/internal/arithmetic/long.h"
25
+ #include "ruby/internal/attr/artificial.h"
26
+ #include "ruby/internal/attr/pure.h"
27
+ #include "ruby/internal/cast.h"
28
+ #include "ruby/internal/core/rbasic.h"
29
+ #include "ruby/internal/dllexport.h"
30
+ #include "ruby/internal/fl_type.h"
31
+ #include "ruby/internal/value_type.h"
32
+ #include "ruby/internal/warning_push.h"
33
+ #include "ruby/assert.h"
34
+
35
+ #define RSTRING(obj) RBIMPL_CAST((struct RString *)(obj))
36
+ #define RSTRING_NOEMBED RSTRING_NOEMBED
37
+ #define RSTRING_EMBED_LEN_MASK RSTRING_EMBED_LEN_MASK
38
+ #define RSTRING_EMBED_LEN_SHIFT RSTRING_EMBED_LEN_SHIFT
39
+ #define RSTRING_EMBED_LEN_MAX RSTRING_EMBED_LEN_MAX
40
+ #define RSTRING_FSTR RSTRING_FSTR
41
+
42
+ /** @cond INTERNAL_MACRO */
43
+ #define RSTRING_EMBED_LEN RSTRING_EMBED_LEN
44
+ #define RSTRING_LEN RSTRING_LEN
45
+ #define RSTRING_LENINT RSTRING_LENINT
46
+ #define RSTRING_PTR RSTRING_PTR
47
+ #define RSTRING_END RSTRING_END
48
+ /** @endcond */
49
+
50
+ #define StringValue(v) rb_string_value(&(v))
51
+ #define StringValuePtr(v) rb_string_value_ptr(&(v))
52
+ #define StringValueCStr(v) rb_string_value_cstr(&(v))
53
+ #define SafeStringValue(v) StringValue(v)
54
+ #define ExportStringValue(v) do { \
55
+ StringValue(v); \
56
+ (v) = rb_str_export(v); \
57
+ } while (0)
58
+
59
+ enum ruby_rstring_flags {
60
+ RSTRING_NOEMBED = RUBY_FL_USER1,
61
+ RSTRING_EMBED_LEN_MASK = RUBY_FL_USER2 | RUBY_FL_USER3 | RUBY_FL_USER4 |
62
+ RUBY_FL_USER5 | RUBY_FL_USER6,
63
+ /* Actually, string encodings are also encoded into the flags, using
64
+ * remaining bits.*/
65
+ RSTRING_FSTR = RUBY_FL_USER17
66
+ };
67
+
68
+ enum ruby_rstring_consts {
69
+ RSTRING_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 2,
70
+ RSTRING_EMBED_LEN_MAX = RBIMPL_EMBED_LEN_MAX_OF(char) - 1
71
+ };
72
+
73
+ struct RString {
74
+ struct RBasic basic;
75
+ union {
76
+ struct {
77
+ long len;
78
+ char *ptr;
79
+ union {
80
+ long capa;
81
+ VALUE shared;
82
+ } aux;
83
+ } heap;
84
+ char ary[RSTRING_EMBED_LEN_MAX + 1];
85
+ } as;
86
+ };
87
+
88
+ RBIMPL_SYMBOL_EXPORT_BEGIN()
89
+ VALUE rb_str_to_str(VALUE);
90
+ VALUE rb_string_value(volatile VALUE*);
91
+ char *rb_string_value_ptr(volatile VALUE*);
92
+ char *rb_string_value_cstr(volatile VALUE*);
93
+ VALUE rb_str_export(VALUE);
94
+ VALUE rb_str_export_locale(VALUE);
95
+
96
+ RBIMPL_ATTR_ERROR(("rb_check_safe_str() and Check_SafeStr() are obsolete; use StringValue() instead"))
97
+ void rb_check_safe_str(VALUE);
98
+ #define Check_SafeStr(v) rb_check_safe_str(RBIMPL_CAST((VALUE)(v)))
99
+ RBIMPL_SYMBOL_EXPORT_END()
100
+
101
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
102
+ RBIMPL_ATTR_ARTIFICIAL()
103
+ static inline long
104
+ RSTRING_EMBED_LEN(VALUE str)
105
+ {
106
+ RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING);
107
+ RBIMPL_ASSERT_OR_ASSUME(! RB_FL_ANY_RAW(str, RSTRING_NOEMBED));
108
+
109
+ VALUE f = RBASIC(str)->flags;
110
+ f &= RSTRING_EMBED_LEN_MASK;
111
+ f >>= RSTRING_EMBED_LEN_SHIFT;
112
+ return RBIMPL_CAST((long)f);
113
+ }
114
+
115
+ RBIMPL_WARNING_PUSH()
116
+ #if RBIMPL_COMPILER_IS(Intel)
117
+ RBIMPL_WARNING_IGNORED(413)
118
+ #endif
119
+
120
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
121
+ RBIMPL_ATTR_ARTIFICIAL()
122
+ static inline struct RString
123
+ rbimpl_rstring_getmem(VALUE str)
124
+ {
125
+ RBIMPL_ASSERT_TYPE(str, RUBY_T_STRING);
126
+
127
+ if (RB_FL_ANY_RAW(str, RSTRING_NOEMBED)) {
128
+ return *RSTRING(str);
129
+ }
130
+ else {
131
+ /* Expecting compilers to optimize this on-stack struct away. */
132
+ struct RString retval;
133
+ retval.as.heap.len = RSTRING_EMBED_LEN(str);
134
+ retval.as.heap.ptr = RSTRING(str)->as.ary;
135
+ return retval;
136
+ }
137
+ }
138
+
139
+ RBIMPL_WARNING_POP()
140
+
141
+ RBIMPL_ATTR_PURE_ON_NDEBUG()
142
+ RBIMPL_ATTR_ARTIFICIAL()
143
+ static inline long
144
+ RSTRING_LEN(VALUE str)
145
+ {
146
+ return rbimpl_rstring_getmem(str).as.heap.len;
147
+ }
148
+
149
+ RBIMPL_ATTR_ARTIFICIAL()
150
+ static inline char *
151
+ RSTRING_PTR(VALUE str)
152
+ {
153
+ char *ptr = rbimpl_rstring_getmem(str).as.heap.ptr;
154
+
155
+ if (RB_UNLIKELY(! ptr)) {
156
+ /* :BEWARE: @shyouhei thinks that currently, there are rooms for this
157
+ * function to return NULL. In the 20th century that was a pointless
158
+ * concern. However struct RString can hold fake strings nowadays. It
159
+ * seems no check against NULL are exercised around handling of them
160
+ * (one of such usages is located in marshal.c, which scares
161
+ * @shyouhei). Better check here for maximum safety.
162
+ *
163
+ * Also, this is not rb_warn() because RSTRING_PTR() can be called
164
+ * during GC (see what obj_info() does). rb_warn() needs to allocate
165
+ * Ruby objects. That is not possible at this moment. */
166
+ fprintf(stderr, "%s\n",
167
+ "RSTRING_PTR is returning NULL!! "
168
+ "SIGSEGV is highly expected to follow immediately. "
169
+ "If you could reproduce, attach your debugger here, "
170
+ "and look at the passed string."
171
+ );
172
+ }
173
+
174
+ return ptr;
175
+ }
176
+
177
+ RBIMPL_ATTR_ARTIFICIAL()
178
+ static inline char *
179
+ RSTRING_END(VALUE str)
180
+ {
181
+ struct RString buf = rbimpl_rstring_getmem(str);
182
+
183
+ if (RB_UNLIKELY(! buf.as.heap.ptr)) {
184
+ /* Ditto. */
185
+ fprintf(stderr, "%s\n",
186
+ "RSTRING_END is returning NULL!! "
187
+ "SIGSEGV is highly expected to follow immediately. "
188
+ "If you could reproduce, attach your debugger here, "
189
+ "and look at the passed string."
190
+ );
191
+ }
192
+
193
+ return &buf.as.heap.ptr[buf.as.heap.len];
194
+ }
195
+
196
+ RBIMPL_ATTR_ARTIFICIAL()
197
+ static inline int
198
+ RSTRING_LENINT(VALUE str)
199
+ {
200
+ return rb_long2int(RSTRING_LEN(str));
201
+ }
202
+
203
+ #ifdef HAVE_STMT_AND_DECL_IN_EXPR
204
+ # define RSTRING_GETMEM(str, ptrvar, lenvar) \
205
+ __extension__ ({ \
206
+ struct RString rbimpl_str = rbimpl_rstring_getmem(str); \
207
+ (ptrvar) = rbimpl_str.as.heap.ptr; \
208
+ (lenvar) = rbimpl_str.as.heap.len; \
209
+ })
210
+ #else
211
+ # define RSTRING_GETMEM(str, ptrvar, lenvar) \
212
+ ((ptrvar) = RSTRING_PTR(str), \
213
+ (lenvar) = RSTRING_LEN(str))
214
+ #endif /* HAVE_STMT_AND_DECL_IN_EXPR */
215
+ #endif /* RBIMPL_RSTRING_H */