qr_reader-native 0.0.1

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 (95) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-mruby.txt +22 -0
  3. data/LICENSE-spinel.txt +19 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +61 -0
  6. data/ext/qr_reader_native/SPINEL_VERSION +1 -0
  7. data/ext/qr_reader_native/extconf.rb +8 -0
  8. data/ext/qr_reader_native/mruby/error.h +13 -0
  9. data/ext/qr_reader_native/mruby/internal.h +145 -0
  10. data/ext/qr_reader_native/mruby/string.h +22 -0
  11. data/ext/qr_reader_native/mruby.h +93 -0
  12. data/ext/qr_reader_native/mruby_shim.h +118 -0
  13. data/ext/qr_reader_native/qr_reader_native.c +13513 -0
  14. data/ext/qr_reader_native/qr_reader_native.h +29 -0
  15. data/ext/qr_reader_native/qr_reader_native_ext.c +598 -0
  16. data/ext/qr_reader_native/re_cased.h +71 -0
  17. data/ext/qr_reader_native/re_compile.c +5784 -0
  18. data/ext/qr_reader_native/re_ctype.h +3540 -0
  19. data/ext/qr_reader_native/re_exec.c +2190 -0
  20. data/ext/qr_reader_native/re_internal.h +671 -0
  21. data/ext/qr_reader_native/re_prop.h +4629 -0
  22. data/ext/qr_reader_native/re_spinel.c +363 -0
  23. data/ext/qr_reader_native/re_spinel.h +22 -0
  24. data/ext/qr_reader_native/re_spinel_utf8.inc +97 -0
  25. data/ext/qr_reader_native/re_utf8.c +156 -0
  26. data/ext/qr_reader_native/sp_alloc.c +1447 -0
  27. data/ext/qr_reader_native/sp_alloc.h +1196 -0
  28. data/ext/qr_reader_native/sp_argf.h +33 -0
  29. data/ext/qr_reader_native/sp_array.c +1052 -0
  30. data/ext/qr_reader_native/sp_array.h +456 -0
  31. data/ext/qr_reader_native/sp_bigint.c +5826 -0
  32. data/ext/qr_reader_native/sp_bigint.h +117 -0
  33. data/ext/qr_reader_native/sp_cold.c +5259 -0
  34. data/ext/qr_reader_native/sp_compat.h +402 -0
  35. data/ext/qr_reader_native/sp_core.c +818 -0
  36. data/ext/qr_reader_native/sp_core.h +56 -0
  37. data/ext/qr_reader_native/sp_crypto.c +877 -0
  38. data/ext/qr_reader_native/sp_crypto.h +169 -0
  39. data/ext/qr_reader_native/sp_dtoa.c +1533 -0
  40. data/ext/qr_reader_native/sp_dtoa.h +29 -0
  41. data/ext/qr_reader_native/sp_encoding_names.h +172 -0
  42. data/ext/qr_reader_native/sp_enum.h +86 -0
  43. data/ext/qr_reader_native/sp_exc.c +1185 -0
  44. data/ext/qr_reader_native/sp_exc.h +186 -0
  45. data/ext/qr_reader_native/sp_exc_ctx.h +56 -0
  46. data/ext/qr_reader_native/sp_fiber.c +889 -0
  47. data/ext/qr_reader_native/sp_fiber.h +162 -0
  48. data/ext/qr_reader_native/sp_fiber_ctx.h +84 -0
  49. data/ext/qr_reader_native/sp_format.c +695 -0
  50. data/ext/qr_reader_native/sp_format.h +83 -0
  51. data/ext/qr_reader_native/sp_gc.c +1793 -0
  52. data/ext/qr_reader_native/sp_gc.h +762 -0
  53. data/ext/qr_reader_native/sp_hash.c +131 -0
  54. data/ext/qr_reader_native/sp_hash.h +131 -0
  55. data/ext/qr_reader_native/sp_inspect.c +215 -0
  56. data/ext/qr_reader_native/sp_inspect.h +128 -0
  57. data/ext/qr_reader_native/sp_io.c +1676 -0
  58. data/ext/qr_reader_native/sp_io.h +272 -0
  59. data/ext/qr_reader_native/sp_iobuffer.c +1014 -0
  60. data/ext/qr_reader_native/sp_iobuffer.h +167 -0
  61. data/ext/qr_reader_native/sp_marshal.c +487 -0
  62. data/ext/qr_reader_native/sp_marshal.h +60 -0
  63. data/ext/qr_reader_native/sp_net.c +1029 -0
  64. data/ext/qr_reader_native/sp_net.h +205 -0
  65. data/ext/qr_reader_native/sp_pack.c +1254 -0
  66. data/ext/qr_reader_native/sp_poly_cold.c +1220 -0
  67. data/ext/qr_reader_native/sp_proc.c +410 -0
  68. data/ext/qr_reader_native/sp_proc.h +327 -0
  69. data/ext/qr_reader_native/sp_process.c +547 -0
  70. data/ext/qr_reader_native/sp_process_status.c +211 -0
  71. data/ext/qr_reader_native/sp_process_status.h +66 -0
  72. data/ext/qr_reader_native/sp_random.c +287 -0
  73. data/ext/qr_reader_native/sp_random.h +52 -0
  74. data/ext/qr_reader_native/sp_range.h +144 -0
  75. data/ext/qr_reader_native/sp_re.c +1379 -0
  76. data/ext/qr_reader_native/sp_re.h +186 -0
  77. data/ext/qr_reader_native/sp_re_names.h +59 -0
  78. data/ext/qr_reader_native/sp_sched.c +4044 -0
  79. data/ext/qr_reader_native/sp_sched.h +295 -0
  80. data/ext/qr_reader_native/sp_slab.c +1507 -0
  81. data/ext/qr_reader_native/sp_str.c +1462 -0
  82. data/ext/qr_reader_native/sp_str.h +306 -0
  83. data/ext/qr_reader_native/sp_str_crypt.c +23 -0
  84. data/ext/qr_reader_native/sp_string.c +92 -0
  85. data/ext/qr_reader_native/sp_string.h +253 -0
  86. data/ext/qr_reader_native/sp_system.c +78 -0
  87. data/ext/qr_reader_native/sp_system.h +18 -0
  88. data/ext/qr_reader_native/sp_time.c +860 -0
  89. data/ext/qr_reader_native/sp_time.h +100 -0
  90. data/ext/qr_reader_native/sp_types.h +292 -0
  91. data/ext/qr_reader_native/spinel_rt.h +19017 -0
  92. data/ext/qr_reader_native/unicase.c +399 -0
  93. data/ext/qr_reader_native/unicase.h +901 -0
  94. data/lib/qr_reader/native.rb +6 -0
  95. metadata +153 -0
@@ -0,0 +1,186 @@
1
+ #ifndef SP_EXC_H
2
+ #define SP_EXC_H
3
+ /* sp_exc.h -- sp_Exception struct + cold ops.
4
+ *
5
+ * sp_user_exc_parent_fn is a function-pointer HOOK (like
6
+ * sp_gc_mark_globals_hook): codegen's emitted main() sets it to the
7
+ * per-program sp_user_exc_parent (`sp_user_exc_parent_fn =
8
+ * sp_user_exc_parent;`), which stays static/resident since its body is
9
+ * program-specific. Everything that reaches the user exception hierarchy
10
+ * only needs the POINTER, resolved at runtime -- not the per-program
11
+ * function itself -- so it's a real cross-archive dependency, not a
12
+ * program-generated-code blocker. sp_pending_exc_recv/key/val/flags (the
13
+ * raise-site introspection staging slots) are the same shape: already
14
+ * SP_TLS globals, just needed `static` removed.
15
+ *
16
+ * sp_exc_sym_slot/sp_exc_recover_named (need sp_sym_intern, a REAL
17
+ * program-generated function whose body differs per compiled program --
18
+ * not a hook) stay in spinel_rt.h,
19
+ * along with sp_exc_reason_acc/sp_exc_tag_acc (the two accessors that
20
+ * call sp_exc_sym_slot) and the raise/longjmp control flow
21
+ * (sp_raise_exc/sp_raise_cls and friends), which threads through the
22
+ * TU-local exception-stack globals.
23
+ *
24
+ * 0 optcarrot uses for every function below.
25
+ */
26
+ #include "sp_types.h" /* sp_int, sp_bool */
27
+ #include "sp_gc.h" /* sp_RbVal, sp_gc_alloc, sp_gc_mark, sp_mark_string */
28
+ #include "sp_alloc.h" /* sp_box_nil/int, sp_str_empty, sp_raise_cls, sp_sprintf */
29
+ #include <signal.h> /* SIGINT for sp_exc_new's Interrupt#signo default */
30
+
31
+ typedef struct sp_Exception_s {
32
+ const char *cls_name;
33
+ const char *parent_cls_name; /* builtin ancestor for user subclasses, or NULL */
34
+ const char *msg;
35
+ struct sp_Exception_s *cause; /* the exception being handled when this was raised, or NULL */
36
+ sp_RbVal result; /* StopIteration#result (the iteration's return value); nil otherwise */
37
+ sp_RbVal xname; /* NameError/NoMethodError#name (the missing name); nil otherwise */
38
+ sp_RbVal xkey; /* KeyError#key / UncaughtThrowError#tag / LocalJumpError#reason /
39
+ NoMethodError#args; nil otherwise */
40
+ sp_RbVal xrecv; /* KeyError/NameError/NoMethodError/FrozenError#receiver; nil otherwise */
41
+ sp_bool has_recv; /* was a receiver actually recorded? nil is a legal
42
+ receiver (nil.foo), so the box cannot say (#3036) */
43
+ sp_bool has_key; /* likewise for KeyError#key (#3030) */
44
+ sp_bool priv_call; /* NoMethodError#private_call? (#3042) */
45
+ sp_StrArray *backtrace; /* an attached backtrace set by #set_backtrace; nil
46
+ means "no caller ever set one" (CRuby answers
47
+ nil for the unset case). The GC mark visits it
48
+ alongside the boxed fields. */
49
+ void *msg_h; /* the message as a shared String handle (an
50
+ sp_String *), or NULL: a program built
51
+ --share-strings raises with the String it
52
+ was given, which #message answers itself
53
+ (sp_exc_attach_msg). Read the message
54
+ through sp_exc_message / sp_exc_msg_text. */
55
+ } sp_Exception;
56
+
57
+ extern const char *(*sp_user_exc_parent_fn)(const char *); /* set by the generated main() */
58
+ /* The modules a class includes, NULL-terminated, or NULL for none. Ruby's type
59
+ hierarchy is not a chain -- `rescue IO::WaitReadable` and `e.is_a?(Retryable)`
60
+ both ask about a MODULE, which a single-parent walk cannot answer. Same shape
61
+ as the parent hook: a builtin table plus a per-program hook. */
62
+ extern const char *const *(*sp_user_exc_modules_fn)(const char *);
63
+ const char *const *sp_exc_modules_of_name(const char *cls);
64
+ /* CRuby aliases some exception classes to one object (Errno::EWOULDBLOCK IS
65
+ Errno::EAGAIN). Names cannot express identity, so both sides of a match are
66
+ canonicalized first. Returns `cls` itself when it has no alias. */
67
+ const char *sp_exc_canonical_name(const char *cls);
68
+ extern SP_TLS sp_RbVal sp_pending_exc_recv, sp_pending_exc_key, sp_pending_exc_val;
69
+ extern SP_TLS unsigned char sp_pending_exc_flags;
70
+
71
+ int sp_exc_cls_matches(const char *raised, const char *target);
72
+ sp_bool sp_exc_has_acc(sp_Exception *e, const char *acc); /* has the class-gated accessor */
73
+ int sp_exc_nearest_cls(const char *raised, const char *const *targets, int n);
74
+ SP_COLD void sp_exc_acc_gate(sp_Exception *e, const char *cls, const char *acc);
75
+ int sp_exc_is_standard_error(const char *raised);
76
+ sp_Exception *sp_exc_new_for_catch(const char *cls, const char *msg);
77
+ /* The message a bare `raise` carries: empty, and distinct from "no message
78
+ given" (which falls back to the class name, as Exception.new does) (#3711). */
79
+ extern const char *const sp_exc_no_msg;
80
+ /* The same for an explicitly given empty literal (`raise C, ""`), whose
81
+ message CRuby keeps frozen: also "" to every reader of the raw message,
82
+ and an exception built from it holds a frozen "". */
83
+ extern const char *const sp_exc_no_msg_frozen;
84
+ /* Is m one of the two explicit-empty sentinels? A raise's message is
85
+ laundered onto the heap unless it is one, which keeps its identity. */
86
+ static inline int sp_exc_msg_empty_given(const char *m) {
87
+ return m == sp_exc_no_msg || m == sp_exc_no_msg_frozen;
88
+ }
89
+ /* An explicitly given raise message: an empty one stays empty rather than
90
+ falling back to the class name the way a message-less raise does. */
91
+ const char *sp_exc_msg_counted(const char *m, size_t n); /* lib/sp_exc.c */
92
+ const char *sp_exc_msg_counted_frozen(const char *m, size_t n); /* the same, for a frozen String */
93
+ const char *sp_exc_msg_plain(const char *m); /* a frozen counted message as frozen text */
94
+ const char *sp_exc_cat(int n, ...); /* parts joined by byte length, NULs kept */
95
+ const char *sp_exc_full_text(volatile sp_Exception *e, const char *msg); /* "Class: msg" */
96
+ const char *sp_exc_detailed_text(volatile sp_Exception *e, const char *msg); /* "msg (Class)" */
97
+ /* m is a Spinel String here (the generated code gives only those), so its header's
98
+ length is safe to read; a NUL inside it travels as a counted message (#7556). */
99
+ static inline const char *sp_exc_msg_given(const char *m) {
100
+ if (!m) return m;
101
+ size_t n = sp_str_byte_len(m);
102
+ /* a frozen String (a literal) travels counted with its frozen mark, an
103
+ empty one as the frozen empty sentinel */
104
+ if (sp_str_is_frozen_val(m)) return n == 0 ? sp_exc_no_msg_frozen : sp_exc_msg_counted_frozen(m, n);
105
+ if (n == 0) return sp_exc_no_msg;
106
+ return memchr(m, 0, n) ? sp_exc_msg_counted(m, n) : m;
107
+ }
108
+ void *sp_exc_new_sub_sized(size_t sz, const char *cls_name, const char *msg);
109
+
110
+ void sp_exc_gc_scan(void *p);
111
+ sp_Exception *sp_exc_new(const char *cls_name, const char *msg);
112
+ sp_bool sp_exc_eq(sp_Exception *a, sp_Exception *b);
113
+ /* Exception#set_backtrace: attach (or replace) the backtrace array. The
114
+ * StrArray is GC-managed; the sp_Exception holds a single owner reference
115
+ * and is updated in place. Returns the boxed value so chained assignments
116
+ * (`e = e.set_backtrace(bt)`) work. */
117
+ sp_RbVal sp_Exception_set_backtrace(sp_Exception *e, sp_StrArray *bt);
118
+ sp_Exception *sp_exc_new_sub(const char *cls_name, const char *parent_cls, const char *msg);
119
+ sp_Exception *sp_exc_dup(sp_Exception *e);
120
+ void *sp_exc_apply_staged(const char *cls, const char *msg, void *obj);
121
+ int sp_exc_exit_status(void *obj);
122
+ sp_Exception *sp_exc_exception(sp_Exception *e, const char *msg);
123
+ const char *sp_exc_class_name(volatile sp_Exception *ve);
124
+ const char *sp_exc_message(volatile sp_Exception *ve);
125
+ /* the message's text now, not to be kept (a handle's live buffer) */
126
+ const char *sp_exc_msg_text(volatile sp_Exception *ve);
127
+ /* e with the String handle h as its message (sp_Exception.msg_h); answers e */
128
+ void *sp_exc_attach_msg(void *e, void *h);
129
+ /* #to_s as #inspect renders it: a user override (the generated program's
130
+ sp_user_exc_to_s, installed in the hook) else the stored message */
131
+ extern const char *(*sp_user_exc_to_s_fn)(sp_Exception *);
132
+ const char *sp_exc_to_s_text(sp_Exception *e);
133
+ const char *sp_exc_inspect(void *p); /* #<Cls: msg>, for the inspect dispatch */
134
+ sp_Exception *sp_exc_cause(volatile sp_Exception *ve);
135
+ sp_RbVal sp_exc_result(volatile sp_Exception *ve);
136
+ const char *sp_errno_class_name(int e); /* "Errno::ENOENT" for ENOENT; the parent for an unlisted one */
137
+ sp_RbVal sp_exc_errno_acc(sp_Exception *e); /* SystemCallError#errno */
138
+ enum { SP_SYSERR_NONE, SP_SYSERR_NUM, SP_SYSERR_BASE, SP_SYSERR_BARE };
139
+ int sp_syserr_kind(const char *cls, sp_int *num); /* where cls stands in the SystemCallError family */
140
+ const char *sp_syserr_text(int has_num, sp_int num, const char *func, const char *msg);
141
+ void sp_exc_syserr_init(sp_Exception *e); /* #errno from the class's Errno ancestor */
142
+ sp_int sp_errno_num(const char *cls); /* Errno::ENOENT::Errno */
143
+ const char *sp_exc_parent_of_name(const char *cls);
144
+ sp_RbVal sp_exc_name_acc(sp_Exception *e);
145
+ sp_RbVal sp_exc_key_acc(sp_Exception *e);
146
+ sp_RbVal sp_exc_receiver_acc(sp_Exception *e);
147
+ sp_RbVal sp_exc_args_acc(sp_Exception *e);
148
+ sp_RbVal sp_exc_path_acc(sp_Exception *e); /* LoadError#path */
149
+ sp_bool sp_exc_private_call_acc(sp_Exception *e);
150
+ sp_RbVal sp_exc_exit_value_acc(sp_Exception *e);
151
+ sp_RbVal sp_exc_throw_value_acc(sp_Exception *e);
152
+ sp_int sp_exc_status_acc(sp_Exception *e);
153
+ sp_bool sp_exc_success_acc(sp_Exception *e);
154
+ sp_int sp_exc_signo_acc(sp_Exception *e);
155
+ const char *sp_exc_signm_acc(sp_Exception *e);
156
+
157
+ /* ---- Signal/Interrupt exception constructors: relocated from
158
+ spinel_rt.h (0 optcarrot uses). sp_signal_resolve/sp_signal_signame
159
+ are already non-static (resolved at the final link). ---- */
160
+ int sp_signal_resolve(sp_RbVal sig);
161
+ const char *sp_signal_signame(sp_int no);
162
+ sp_Exception *sp_signal_exc_new_m(sp_RbVal sig, const char *msg);
163
+ sp_Exception *sp_signal_exc_new(sp_RbVal sig);
164
+ sp_Exception *sp_interrupt_new(const char *msg);
165
+
166
+ /* ---- The arity ArgumentError every binder raises: CRuby's words for a
167
+ positional count the callee cannot take (rb_arity_error_new): `given G,
168
+ expected N` for an exact count, `N..M` with optionals, `N+` past a rest
169
+ (max < 0). `kw` is NULL or the "; required keyword(s): a, b" CRuby appends
170
+ for a callee with required keywords (argument_arity_error, vm_args.c) --
171
+ a fact of the signature the compiler spells (arity_kw_suffix), so the
172
+ run-time count and the compile-time one read the same. ---- */
173
+ SP_NORETURN void sp_raise_arity(sp_int given, sp_int min, sp_int max, const char *kw);
174
+ static inline void sp_arity_check(sp_int given, sp_int min, sp_int max, const char *kw) {
175
+ if (given < min || (max >= 0 && given > max)) sp_raise_arity(given, min, max, kw);
176
+ }
177
+ /* The keyword ArgumentErrors in CRuby's words (argument_kw_error): `kind`
178
+ "missing" or "unknown", naming the `count` keywords in `names`, each
179
+ already inspected and joined by ", ". */
180
+ SP_NORETURN void sp_raise_kw_error(const char *kind, sp_int count, const char *names);
181
+ /* Exception#is_a?(ClassName), modules and the user hierarchy included. */
182
+ sp_int sp_exc_is_a(volatile sp_Exception *ve, const char *cn);
183
+ /* A fixed-depth handler stack overflowed: CRuby's words on stderr, then exit. */
184
+ SP_NORETURN SP_COLD void sp_stack_too_deep(void);
185
+
186
+ #endif
@@ -0,0 +1,56 @@
1
+ #ifndef SP_EXC_CTX_H
2
+ #define SP_EXC_CTX_H
3
+ /* sp_exc_ctx.h -- the per-fiber exception/catch handler context (#1474) and
4
+ * the proc-return home node whose chain it carries.
5
+ *
6
+ * Types only, plus the three context operations that touch nothing else
7
+ * (sp_exc_ctx_new/free/mark, lib/sp_exc.c). sp_exc_ctx_save/load copy the
8
+ * handler stacks in and out, and those stacks are TU-local statics of
9
+ * spinel_rt.h, so the two stay there. */
10
+ #include <setjmp.h>
11
+ #include "sp_types.h" /* sp_int */
12
+ #include "sp_gc.h" /* sp_RbVal */
13
+ #include "sp_inspect.h" /* sp_poly_recur_frame */
14
+
15
+ /* A non-lambda proc's home method: a node on that method's C stack, linked
16
+ onto the per-fiber chain sp_proc_ret_head (see the proc-return machinery in
17
+ spinel_rt.h). */
18
+ typedef struct sp_proc_home {
19
+ jmp_buf jb; /* the home method's setjmp target (on its C stack) */
20
+ sp_RbVal val; /* the in-flight return value (nil until delivered) */
21
+ int exc_top; /* sp_exc_top at the method's entry */
22
+ int catch_top; /* sp_catch_top at the method's entry */
23
+ int recur_mark; /* walk-path depth at the method's entry (see sp_poly_recur_mark) */
24
+ sp_int id; /* fresh id captured by the home's returning procs */
25
+ struct sp_proc_home *prev; /* enclosing home, forming the per-fiber chain */
26
+ } sp_proc_home;
27
+
28
+ /* The live prefix of every handler array, saved into the outgoing fiber's
29
+ context and loaded from the incoming one's at each switch. */
30
+ typedef struct {
31
+ jmp_buf *es; const char **em; const char **ec; void **eo; int en, ecap;
32
+ jmp_buf *cs; const char **ct; unsigned char *ctk; sp_RbVal *cv; int *cet; int cn, ccap;
33
+ jmp_buf *bs; sp_RbVal *bv; sp_int *bser; int *bet; int bn, bcap; /* break scopes */
34
+ sp_proc_home *prhead; /* this fiber's proc-return chain head (nodes on its C stack) */
35
+ int uk, ut, ue; sp_proc_home *uh; /* transient unwind state (in flight only while running ensures) */
36
+ void **shand; int rn, rcap; /* sp_exc_handling prefix [0..sp_rescue_sp) */
37
+ void *pcause; /* sp_pending_cause */
38
+ void *icause; /* sp_inflight_cause: the exception an ensure body runs for */
39
+ sp_poly_recur_frame *rrf; int rrn, rrcap; /* sp_poly_recur_stack prefix [0..sp_poly_recur_top) */
40
+ int *rrem, *rrcm, *rrbm; /* the walk-path marks of the exception, catch and break arms */
41
+ int *erm, *ersm, *crm; /* the GC-root and rescue-stack watermarks of the exception
42
+ arms and the GC-root watermark of the catch arms: what a
43
+ handler restores sp_gc_nroots / sp_rescue_sp to. They are
44
+ per worker like the arms, so without travelling with the
45
+ context a green thread that parked inside a begin and
46
+ resumed after another fiber's arm sat at the same index
47
+ restored the OTHER fiber's watermark: a raise's dead root
48
+ stayed on the list and the next collection read a stack
49
+ slot that was no longer a string (#4546) */
50
+ } sp_exc_ctx_t;
51
+
52
+ void *sp_exc_ctx_new(void);
53
+ void sp_exc_ctx_free(void *p);
54
+ void sp_exc_ctx_mark(void *p); /* GC: a suspended fiber's carried exc objects */
55
+
56
+ #endif