debase-ruby_core_source 0.10.12 → 0.10.14
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.
- checksums.yaml +4 -4
- data/debase-ruby_core_source.gemspec +1 -1
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/addr2line.h +20 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/builtin.h +84 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ccan/build_assert/build_assert.h +40 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ccan/check_type/check_type.h +63 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ccan/container_of/container_of.h +142 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ccan/list/list.h +788 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ccan/str/str.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/constant.h +55 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/darray.h +198 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/debug_counter.h +469 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/dln.h +31 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/encindex.h +70 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/eval_intern.h +335 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/gc.h +141 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/hrtime.h +168 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/id.h +293 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/id_table.h +36 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/insns.inc +249 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/insns_info.inc +9063 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/array.h +113 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/bignum.h +246 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/bits.h +565 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/class.h +196 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/compar.h +49 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/compile.h +35 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/compilers.h +107 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/complex.h +29 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/cont.h +24 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/dir.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/enc.h +19 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/encoding.h +30 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/enum.h +18 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/enumerator.h +21 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/error.h +191 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/eval.h +32 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/file.h +38 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/fixnum.h +184 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/gc.h +186 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/hash.h +243 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/imemo.h +243 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/inits.h +50 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/io.h +38 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/load.h +18 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/loadpath.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/math.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/missing.h +18 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/numeric.h +271 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/object.h +83 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/parse.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/proc.h +32 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/process.h +137 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/random.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/range.h +40 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/rational.h +72 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/re.h +30 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/sanitizers.h +190 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/serial.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/signal.h +21 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/static_assert.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/string.h +141 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/struct.h +153 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/symbol.h +41 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/thread.h +53 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/time.h +34 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/transcode.h +20 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/util.h +27 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/variable.h +83 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/vm.h +133 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal/warnings.h +16 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/internal.h +109 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/iseq.h +322 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/known_errors.inc +791 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/method.h +253 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/mjit.h +231 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/mjit_compile.inc +8322 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/node.h +510 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/node_name.inc +208 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/opt_sc.inc +109 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/optinsn.inc +128 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/optunifs.inc +43 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/parse.h +214 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/probes_helper.h +44 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ractor_core.h +346 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/regenc.h +254 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/regint.h +942 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/regparse.h +370 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/revision.h +2 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ruby_assert.h +14 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/ruby_atomic.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/siphash.h +48 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/symbol.h +119 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/thread_pthread.h +115 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/thread_win32.h +61 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/timev.h +57 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/transcode_data.h +138 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/transient_heap.h +65 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/variable.h +21 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/version.h +88 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm.inc +5470 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_call_iseq_optimized.inc +244 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_callinfo.h +487 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_core.h +2107 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_debug.h +124 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_exec.h +197 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_insnhelper.h +265 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_opts.h +73 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vm_sync.h +137 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/vmtc.inc +243 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/yjit.h +73 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/yjit_asm.h +408 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/yjit_codegen.h +23 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/yjit_core.h +307 -0
- data/lib/debase/ruby_core_source/ruby-3.1.0-p0/yjit_iface.h +38 -0
- data/lib/debase/ruby_core_source/version.rb +1 -1
- metadata +117 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* CC0 (Public domain) - see ccan/licenses/CC0 file for details */
|
|
2
|
+
#ifndef CCAN_STR_H
|
|
3
|
+
#define CCAN_STR_H
|
|
4
|
+
/**
|
|
5
|
+
* stringify - Turn expression into a string literal
|
|
6
|
+
* @expr: any C expression
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* #define PRINT_COND_IF_FALSE(cond) \
|
|
10
|
+
* ((cond) || printf("%s is false!", stringify(cond)))
|
|
11
|
+
*/
|
|
12
|
+
#define stringify(expr) stringify_1(expr)
|
|
13
|
+
/* Double-indirection required to stringify expansions */
|
|
14
|
+
#define stringify_1(expr) #expr
|
|
15
|
+
|
|
16
|
+
#endif /* CCAN_STR_H */
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#ifndef CONSTANT_H
|
|
2
|
+
#define CONSTANT_H
|
|
3
|
+
/**********************************************************************
|
|
4
|
+
|
|
5
|
+
constant.h -
|
|
6
|
+
|
|
7
|
+
$Author$
|
|
8
|
+
created at: Sun Nov 15 00:09:33 2009
|
|
9
|
+
|
|
10
|
+
Copyright (C) 2009 Yusuke Endoh
|
|
11
|
+
|
|
12
|
+
**********************************************************************/
|
|
13
|
+
#include "ruby/ruby.h"
|
|
14
|
+
#include "id_table.h"
|
|
15
|
+
|
|
16
|
+
typedef enum {
|
|
17
|
+
CONST_DEPRECATED = 0x100,
|
|
18
|
+
|
|
19
|
+
CONST_VISIBILITY_MASK = 0xff,
|
|
20
|
+
CONST_PUBLIC = 0x00,
|
|
21
|
+
CONST_PRIVATE,
|
|
22
|
+
CONST_VISIBILITY_MAX
|
|
23
|
+
} rb_const_flag_t;
|
|
24
|
+
|
|
25
|
+
#define RB_CONST_PRIVATE_P(ce) \
|
|
26
|
+
(((ce)->flag & CONST_VISIBILITY_MASK) == CONST_PRIVATE)
|
|
27
|
+
#define RB_CONST_PUBLIC_P(ce) \
|
|
28
|
+
(((ce)->flag & CONST_VISIBILITY_MASK) == CONST_PUBLIC)
|
|
29
|
+
|
|
30
|
+
#define RB_CONST_DEPRECATED_P(ce) \
|
|
31
|
+
((ce)->flag & CONST_DEPRECATED)
|
|
32
|
+
|
|
33
|
+
typedef struct rb_const_entry_struct {
|
|
34
|
+
rb_const_flag_t flag;
|
|
35
|
+
int line;
|
|
36
|
+
VALUE value; /* should be mark */
|
|
37
|
+
VALUE file; /* should be mark */
|
|
38
|
+
} rb_const_entry_t;
|
|
39
|
+
|
|
40
|
+
VALUE rb_mod_private_constant(int argc, const VALUE *argv, VALUE obj);
|
|
41
|
+
VALUE rb_mod_public_constant(int argc, const VALUE *argv, VALUE obj);
|
|
42
|
+
VALUE rb_mod_deprecate_constant(int argc, const VALUE *argv, VALUE obj);
|
|
43
|
+
void rb_free_const_table(struct rb_id_table *tbl);
|
|
44
|
+
VALUE rb_const_source_location(VALUE, ID);
|
|
45
|
+
|
|
46
|
+
MJIT_SYMBOL_EXPORT_BEGIN
|
|
47
|
+
int rb_autoloading_value(VALUE mod, ID id, VALUE *value, rb_const_flag_t *flag);
|
|
48
|
+
rb_const_entry_t *rb_const_lookup(VALUE klass, ID id);
|
|
49
|
+
VALUE rb_public_const_get_at(VALUE klass, ID id);
|
|
50
|
+
VALUE rb_public_const_get_from(VALUE klass, ID id);
|
|
51
|
+
int rb_public_const_defined_from(VALUE klass, ID id);
|
|
52
|
+
VALUE rb_const_source_location_at(VALUE, ID);
|
|
53
|
+
MJIT_SYMBOL_EXPORT_END
|
|
54
|
+
|
|
55
|
+
#endif /* CONSTANT_H */
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#ifndef RUBY_DARRAY_H
|
|
2
|
+
#define RUBY_DARRAY_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
|
|
8
|
+
// Type for a dynamic array. Use to declare a dynamic array.
|
|
9
|
+
// It is a pointer so it fits in st_table nicely. Designed
|
|
10
|
+
// to be fairly type-safe.
|
|
11
|
+
//
|
|
12
|
+
// NULL is a valid empty dynamic array.
|
|
13
|
+
//
|
|
14
|
+
// Example:
|
|
15
|
+
// rb_darray(char) char_array = NULL;
|
|
16
|
+
// if (!rb_darray_append(&char_array, 'e')) abort();
|
|
17
|
+
// printf("pushed %c\n", *rb_darray_ref(char_array, 0));
|
|
18
|
+
// rb_darray_free(char_array);
|
|
19
|
+
//
|
|
20
|
+
#define rb_darray(T) struct { rb_darray_meta_t meta; T data[]; } *
|
|
21
|
+
|
|
22
|
+
// Copy an element out of the array. Warning: not bounds checked.
|
|
23
|
+
//
|
|
24
|
+
// T rb_darray_get(rb_darray(T) ary, int32_t idx);
|
|
25
|
+
//
|
|
26
|
+
#define rb_darray_get(ary, idx) ((ary)->data[(idx)])
|
|
27
|
+
|
|
28
|
+
// Assign to an element. Warning: not bounds checked.
|
|
29
|
+
//
|
|
30
|
+
// void rb_darray_set(rb_darray(T) ary, int32_t idx, T element);
|
|
31
|
+
//
|
|
32
|
+
#define rb_darray_set(ary, idx, element) ((ary)->data[(idx)] = (element))
|
|
33
|
+
|
|
34
|
+
// Get a pointer to an element. Warning: not bounds checked.
|
|
35
|
+
//
|
|
36
|
+
// T *rb_darray_ref(rb_darray(T) ary, int32_t idx);
|
|
37
|
+
//
|
|
38
|
+
#define rb_darray_ref(ary, idx) (&((ary)->data[(idx)]))
|
|
39
|
+
|
|
40
|
+
// Copy a new element into the array. Return 1 on success and 0 on failure.
|
|
41
|
+
// ptr_to_ary is evaluated multiple times.
|
|
42
|
+
//
|
|
43
|
+
// bool rb_darray_append(rb_darray(T) *ptr_to_ary, T element);
|
|
44
|
+
//
|
|
45
|
+
#define rb_darray_append(ptr_to_ary, element) ( \
|
|
46
|
+
rb_darray_ensure_space((ptr_to_ary), sizeof(**(ptr_to_ary)), sizeof((*(ptr_to_ary))->data[0])) ? ( \
|
|
47
|
+
rb_darray_set(*(ptr_to_ary), \
|
|
48
|
+
(*(ptr_to_ary))->meta.size, \
|
|
49
|
+
(element)), \
|
|
50
|
+
++((*(ptr_to_ary))->meta.size), \
|
|
51
|
+
1 \
|
|
52
|
+
) : 0)
|
|
53
|
+
|
|
54
|
+
// Last element of the array
|
|
55
|
+
//
|
|
56
|
+
#define rb_darray_back(ary) ((ary)->data[(ary)->meta.size - 1])
|
|
57
|
+
|
|
58
|
+
// Remove the last element of the array.
|
|
59
|
+
//
|
|
60
|
+
#define rb_darray_pop_back(ary) ((ary)->meta.size--)
|
|
61
|
+
|
|
62
|
+
// Remove element at idx and replace it by the last element
|
|
63
|
+
#define rb_darray_remove_unordered(ary, idx) do { \
|
|
64
|
+
rb_darray_set(ary, idx, rb_darray_back(ary)); \
|
|
65
|
+
rb_darray_pop_back(ary); \
|
|
66
|
+
} while (0);
|
|
67
|
+
|
|
68
|
+
// Iterate over items of the array in a for loop
|
|
69
|
+
//
|
|
70
|
+
#define rb_darray_foreach(ary, idx_name, elem_ptr_var) \
|
|
71
|
+
for (int idx_name = 0; idx_name < rb_darray_size(ary) && ((elem_ptr_var) = rb_darray_ref(ary, idx_name)); ++idx_name)
|
|
72
|
+
|
|
73
|
+
// Iterate over valid indicies in the array in a for loop
|
|
74
|
+
//
|
|
75
|
+
#define rb_darray_for(ary, idx_name) \
|
|
76
|
+
for (int idx_name = 0; idx_name < rb_darray_size(ary); ++idx_name)
|
|
77
|
+
|
|
78
|
+
// Make a dynamic array of a certain size. All bytes backing the elements are set to zero.
|
|
79
|
+
// Return 1 on success and 0 on failure.
|
|
80
|
+
//
|
|
81
|
+
// Note that NULL is a valid empty dynamic array.
|
|
82
|
+
//
|
|
83
|
+
// bool rb_darray_make(rb_darray(T) *ptr_to_ary, int32_t size);
|
|
84
|
+
//
|
|
85
|
+
#define rb_darray_make(ptr_to_ary, size) rb_darray_make_impl((ptr_to_ary), size, sizeof(**(ptr_to_ary)), sizeof((*(ptr_to_ary))->data[0]))
|
|
86
|
+
|
|
87
|
+
// Set the size of the array to zero without freeing the backing memory.
|
|
88
|
+
// Allows reusing the same array.
|
|
89
|
+
//
|
|
90
|
+
#define rb_darray_clear(ary) (ary->meta.size = 0)
|
|
91
|
+
|
|
92
|
+
typedef struct rb_darray_meta {
|
|
93
|
+
int32_t size;
|
|
94
|
+
int32_t capa;
|
|
95
|
+
} rb_darray_meta_t;
|
|
96
|
+
|
|
97
|
+
// Get the size of the dynamic array.
|
|
98
|
+
//
|
|
99
|
+
static inline int32_t
|
|
100
|
+
rb_darray_size(const void *ary)
|
|
101
|
+
{
|
|
102
|
+
const rb_darray_meta_t *meta = ary;
|
|
103
|
+
return meta ? meta->size : 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Get the capacity of the dynamic array.
|
|
107
|
+
//
|
|
108
|
+
static inline int32_t
|
|
109
|
+
rb_darray_capa(const void *ary)
|
|
110
|
+
{
|
|
111
|
+
const rb_darray_meta_t *meta = ary;
|
|
112
|
+
return meta ? meta->capa : 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Free the dynamic array.
|
|
116
|
+
//
|
|
117
|
+
static inline void
|
|
118
|
+
rb_darray_free(void *ary)
|
|
119
|
+
{
|
|
120
|
+
free(ary);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Internal function. Calculate buffer size on malloc heap.
|
|
124
|
+
static inline size_t
|
|
125
|
+
rb_darray_buffer_size(int32_t capacity, size_t header_size, size_t element_size)
|
|
126
|
+
{
|
|
127
|
+
if (capacity == 0) return 0;
|
|
128
|
+
return header_size + (size_t)capacity * element_size;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Internal function
|
|
132
|
+
// Ensure there is space for one more element. Return 1 on success and 0 on failure.
|
|
133
|
+
// Note: header_size can be bigger than sizeof(rb_darray_meta_t) when T is __int128_t, for example.
|
|
134
|
+
static inline int
|
|
135
|
+
rb_darray_ensure_space(void *ptr_to_ary, size_t header_size, size_t element_size)
|
|
136
|
+
{
|
|
137
|
+
rb_darray_meta_t **ptr_to_ptr_to_meta = ptr_to_ary;
|
|
138
|
+
rb_darray_meta_t *meta = *ptr_to_ptr_to_meta;
|
|
139
|
+
int32_t current_capa = rb_darray_capa(meta);
|
|
140
|
+
if (rb_darray_size(meta) < current_capa) return 1;
|
|
141
|
+
|
|
142
|
+
int32_t new_capa;
|
|
143
|
+
// Calculate new capacity
|
|
144
|
+
if (current_capa == 0) {
|
|
145
|
+
new_capa = 1;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
int64_t doubled = 2 * (int64_t)current_capa;
|
|
149
|
+
new_capa = (int32_t)doubled;
|
|
150
|
+
if (new_capa != doubled) return 0;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Calculate new buffer size
|
|
154
|
+
size_t current_buffer_size = rb_darray_buffer_size(current_capa, header_size, element_size);
|
|
155
|
+
size_t new_buffer_size = rb_darray_buffer_size(new_capa, header_size, element_size);
|
|
156
|
+
if (new_buffer_size <= current_buffer_size) return 0;
|
|
157
|
+
|
|
158
|
+
rb_darray_meta_t *doubled_ary = realloc(meta, new_buffer_size);
|
|
159
|
+
if (!doubled_ary) return 0;
|
|
160
|
+
|
|
161
|
+
if (meta == NULL) {
|
|
162
|
+
// First allocation. Initialize size. On subsequence allocations
|
|
163
|
+
// realloc takes care of carrying over the size.
|
|
164
|
+
doubled_ary->size = 0;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
doubled_ary->capa = new_capa;
|
|
168
|
+
|
|
169
|
+
// We don't have access to the type of the dynamic array in function context.
|
|
170
|
+
// Write out result with memcpy to avoid strict aliasing issue.
|
|
171
|
+
memcpy(ptr_to_ary, &doubled_ary, sizeof(doubled_ary));
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static inline int
|
|
176
|
+
rb_darray_make_impl(void *ptr_to_ary, int32_t array_size, size_t header_size, size_t element_size)
|
|
177
|
+
{
|
|
178
|
+
rb_darray_meta_t **ptr_to_ptr_to_meta = ptr_to_ary;
|
|
179
|
+
if (array_size < 0) return 0;
|
|
180
|
+
if (array_size == 0) {
|
|
181
|
+
*ptr_to_ptr_to_meta = NULL;
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
size_t buffer_size = rb_darray_buffer_size(array_size, header_size, element_size);
|
|
186
|
+
rb_darray_meta_t *meta = calloc(buffer_size, 1);
|
|
187
|
+
if (!meta) return 0;
|
|
188
|
+
|
|
189
|
+
meta->size = array_size;
|
|
190
|
+
meta->capa = array_size;
|
|
191
|
+
|
|
192
|
+
// We don't have access to the type of the dynamic array in function context.
|
|
193
|
+
// Write out result with memcpy to avoid strict aliasing issue.
|
|
194
|
+
memcpy(ptr_to_ary, &meta, sizeof(meta));
|
|
195
|
+
return 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#endif /* RUBY_DARRAY_H */
|