datadog-ruby_core_source 3.4.0 → 3.4.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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.datadog.md +4 -0
  3. data/README.md +8 -5
  4. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/build_assert/build_assert.h +40 -0
  5. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/check_type/check_type.h +63 -0
  6. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/container_of/container_of.h +142 -0
  7. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/list/list.h +791 -0
  8. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ccan/str/str.h +17 -0
  9. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/id.h +352 -0
  10. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/id_table.h +39 -0
  11. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/array.h +152 -0
  12. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/basic_operators.h +65 -0
  13. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/bignum.h +244 -0
  14. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/bits.h +650 -0
  15. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/class.h +283 -0
  16. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/cmdlineopt.h +61 -0
  17. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compar.h +29 -0
  18. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compile.h +34 -0
  19. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/compilers.h +107 -0
  20. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/complex.h +29 -0
  21. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/cont.h +35 -0
  22. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/dir.h +16 -0
  23. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enc.h +19 -0
  24. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/encoding.h +38 -0
  25. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enum.h +18 -0
  26. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/enumerator.h +21 -0
  27. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/error.h +244 -0
  28. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/eval.h +33 -0
  29. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/file.h +38 -0
  30. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/fixnum.h +185 -0
  31. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/gc.h +333 -0
  32. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/hash.h +193 -0
  33. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/imemo.h +257 -0
  34. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/inits.h +47 -0
  35. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/io.h +143 -0
  36. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/load.h +18 -0
  37. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/loadpath.h +16 -0
  38. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/math.h +23 -0
  39. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/missing.h +19 -0
  40. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/numeric.h +274 -0
  41. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/object.h +63 -0
  42. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/parse.h +131 -0
  43. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/proc.h +30 -0
  44. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/process.h +124 -0
  45. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/ractor.h +10 -0
  46. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/random.h +17 -0
  47. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/range.h +40 -0
  48. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/rational.h +71 -0
  49. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/re.h +28 -0
  50. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/ruby_parser.h +102 -0
  51. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/sanitizers.h +330 -0
  52. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/serial.h +23 -0
  53. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/signal.h +24 -0
  54. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/st.h +11 -0
  55. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/static_assert.h +16 -0
  56. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/string.h +199 -0
  57. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/struct.h +119 -0
  58. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/symbol.h +47 -0
  59. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/thread.h +108 -0
  60. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/time.h +37 -0
  61. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/transcode.h +23 -0
  62. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/util.h +27 -0
  63. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/variable.h +70 -0
  64. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/vm.h +137 -0
  65. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal/warnings.h +16 -0
  66. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/internal.h +108 -0
  67. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/iseq.h +351 -0
  68. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/method.h +258 -0
  69. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/node.h +122 -0
  70. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/parser_st.h +162 -0
  71. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/parser_value.h +106 -0
  72. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/ast.h +7964 -0
  73. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/defines.h +260 -0
  74. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/diagnostic.h +451 -0
  75. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/encoding.h +283 -0
  76. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/extension.h +19 -0
  77. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/node.h +129 -0
  78. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/options.h +442 -0
  79. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/pack.h +163 -0
  80. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/parser.h +933 -0
  81. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/prettyprint.h +34 -0
  82. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/prism.h +383 -0
  83. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/regexp.h +43 -0
  84. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/static_literals.h +121 -0
  85. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_buffer.h +228 -0
  86. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_char.h +204 -0
  87. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_constant_pool.h +218 -0
  88. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_integer.h +126 -0
  89. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_list.h +97 -0
  90. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_memchr.h +29 -0
  91. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_newline_list.h +113 -0
  92. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_string.h +190 -0
  93. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_strncasecmp.h +32 -0
  94. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/util/pm_strpbrk.h +46 -0
  95. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism/version.h +29 -0
  96. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/prism_compile.h +105 -0
  97. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ractor_core.h +382 -0
  98. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ruby_assert.h +14 -0
  99. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/ruby_atomic.h +23 -0
  100. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/rubyparser.h +1380 -0
  101. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/shape.h +234 -0
  102. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/thread_none.h +21 -0
  103. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/thread_pthread.h +167 -0
  104. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_core.h +2235 -0
  105. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_debug.h +124 -0
  106. data/lib/datadog/ruby_core_source/ruby-3.5.0-preview1/vm_opts.h +67 -0
  107. data/lib/datadog/ruby_core_source/version.rb +1 -1
  108. metadata +105 -2
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @file pm_integer.h
3
+ *
4
+ * This module provides functions for working with arbitrary-sized integers.
5
+ */
6
+ #ifndef PRISM_NUMBER_H
7
+ #define PRISM_NUMBER_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_buffer.h"
11
+
12
+ #include <assert.h>
13
+ #include <stdbool.h>
14
+ #include <stdint.h>
15
+ #include <stdlib.h>
16
+
17
+ /**
18
+ * A structure represents an arbitrary-sized integer.
19
+ */
20
+ typedef struct {
21
+ /**
22
+ * The number of allocated values. length is set to 0 if the integer fits
23
+ * into uint32_t.
24
+ */
25
+ size_t length;
26
+
27
+ /**
28
+ * List of 32-bit integers. Set to NULL if the integer fits into uint32_t.
29
+ */
30
+ uint32_t *values;
31
+
32
+ /**
33
+ * Embedded value for small integer. This value is set to 0 if the value
34
+ * does not fit into uint32_t.
35
+ */
36
+ uint32_t value;
37
+
38
+ /**
39
+ * Whether or not the integer is negative. It is stored this way so that a
40
+ * zeroed pm_integer_t is always positive zero.
41
+ */
42
+ bool negative;
43
+ } pm_integer_t;
44
+
45
+ /**
46
+ * An enum controlling the base of an integer. It is expected that the base is
47
+ * already known before parsing the integer, even though it could be derived
48
+ * from the string itself.
49
+ */
50
+ typedef enum {
51
+ /** The default decimal base, with no prefix. Leading 0s will be ignored. */
52
+ PM_INTEGER_BASE_DEFAULT,
53
+
54
+ /** The binary base, indicated by a 0b or 0B prefix. */
55
+ PM_INTEGER_BASE_BINARY,
56
+
57
+ /** The octal base, indicated by a 0, 0o, or 0O prefix. */
58
+ PM_INTEGER_BASE_OCTAL,
59
+
60
+ /** The decimal base, indicated by a 0d, 0D, or empty prefix. */
61
+ PM_INTEGER_BASE_DECIMAL,
62
+
63
+ /** The hexadecimal base, indicated by a 0x or 0X prefix. */
64
+ PM_INTEGER_BASE_HEXADECIMAL,
65
+
66
+ /**
67
+ * An unknown base, in which case pm_integer_parse will derive it based on
68
+ * the content of the string. This is less efficient and does more
69
+ * comparisons, so if callers know the base ahead of time, they should use
70
+ * that instead.
71
+ */
72
+ PM_INTEGER_BASE_UNKNOWN
73
+ } pm_integer_base_t;
74
+
75
+ /**
76
+ * Parse an integer from a string. This assumes that the format of the integer
77
+ * has already been validated, as internal validation checks are not performed
78
+ * here.
79
+ *
80
+ * @param integer The integer to parse into.
81
+ * @param base The base of the integer.
82
+ * @param start The start of the string.
83
+ * @param end The end of the string.
84
+ */
85
+ void pm_integer_parse(pm_integer_t *integer, pm_integer_base_t base, const uint8_t *start, const uint8_t *end);
86
+
87
+ /**
88
+ * Compare two integers. This function returns -1 if the left integer is less
89
+ * than the right integer, 0 if they are equal, and 1 if the left integer is
90
+ * greater than the right integer.
91
+ *
92
+ * @param left The left integer to compare.
93
+ * @param right The right integer to compare.
94
+ * @return The result of the comparison.
95
+ */
96
+ int pm_integer_compare(const pm_integer_t *left, const pm_integer_t *right);
97
+
98
+ /**
99
+ * Reduce a ratio of integers to its simplest form.
100
+ *
101
+ * If either the numerator or denominator do not fit into a 32-bit integer, then
102
+ * this function is a no-op. In the future, we may consider reducing even the
103
+ * larger numbers, but for now we're going to keep it simple.
104
+ *
105
+ * @param numerator The numerator of the ratio.
106
+ * @param denominator The denominator of the ratio.
107
+ */
108
+ void pm_integers_reduce(pm_integer_t *numerator, pm_integer_t *denominator);
109
+
110
+ /**
111
+ * Convert an integer to a decimal string.
112
+ *
113
+ * @param buffer The buffer to append the string to.
114
+ * @param integer The integer to convert to a string.
115
+ */
116
+ PRISM_EXPORTED_FUNCTION void pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer);
117
+
118
+ /**
119
+ * Free the internal memory of an integer. This memory will only be allocated if
120
+ * the integer exceeds the size of a single node in the linked list.
121
+ *
122
+ * @param integer The integer to free.
123
+ */
124
+ PRISM_EXPORTED_FUNCTION void pm_integer_free(pm_integer_t *integer);
125
+
126
+ #endif
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @file pm_list.h
3
+ *
4
+ * An abstract linked list.
5
+ */
6
+ #ifndef PRISM_LIST_H
7
+ #define PRISM_LIST_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <stdbool.h>
12
+ #include <stddef.h>
13
+ #include <stdint.h>
14
+ #include <stdlib.h>
15
+
16
+ /**
17
+ * This struct represents an abstract linked list that provides common
18
+ * functionality. It is meant to be used any time a linked list is necessary to
19
+ * store data.
20
+ *
21
+ * The linked list itself operates off a set of pointers. Because the pointers
22
+ * are not necessarily sequential, they can be of any size. We use this fact to
23
+ * allow the consumer of this linked list to extend the node struct to include
24
+ * any data they want. This is done by using the pm_list_node_t as the first
25
+ * member of the struct.
26
+ *
27
+ * For example, if we want to store a list of integers, we can do the following:
28
+ *
29
+ * ```c
30
+ * typedef struct {
31
+ * pm_list_node_t node;
32
+ * int value;
33
+ * } pm_int_node_t;
34
+ *
35
+ * pm_list_t list = { 0 };
36
+ * pm_int_node_t *node = xmalloc(sizeof(pm_int_node_t));
37
+ * node->value = 5;
38
+ *
39
+ * pm_list_append(&list, &node->node);
40
+ * ```
41
+ *
42
+ * The pm_list_t struct is used to represent the overall linked list. It
43
+ * contains a pointer to the head and tail of the list. This allows for easy
44
+ * iteration and appending of new nodes.
45
+ */
46
+ typedef struct pm_list_node {
47
+ /** A pointer to the next node in the list. */
48
+ struct pm_list_node *next;
49
+ } pm_list_node_t;
50
+
51
+ /**
52
+ * This represents the overall linked list. It keeps a pointer to the head and
53
+ * tail so that iteration is easy and pushing new nodes is easy.
54
+ */
55
+ typedef struct {
56
+ /** The size of the list. */
57
+ size_t size;
58
+
59
+ /** A pointer to the head of the list. */
60
+ pm_list_node_t *head;
61
+
62
+ /** A pointer to the tail of the list. */
63
+ pm_list_node_t *tail;
64
+ } pm_list_t;
65
+
66
+ /**
67
+ * Returns true if the given list is empty.
68
+ *
69
+ * @param list The list to check.
70
+ * @return True if the given list is empty, otherwise false.
71
+ */
72
+ PRISM_EXPORTED_FUNCTION bool pm_list_empty_p(pm_list_t *list);
73
+
74
+ /**
75
+ * Returns the size of the list.
76
+ *
77
+ * @param list The list to check.
78
+ * @return The size of the list.
79
+ */
80
+ PRISM_EXPORTED_FUNCTION size_t pm_list_size(pm_list_t *list);
81
+
82
+ /**
83
+ * Append a node to the given list.
84
+ *
85
+ * @param list The list to append to.
86
+ * @param node The node to append.
87
+ */
88
+ void pm_list_append(pm_list_t *list, pm_list_node_t *node);
89
+
90
+ /**
91
+ * Deallocate the internal state of the given list.
92
+ *
93
+ * @param list The list to free.
94
+ */
95
+ PRISM_EXPORTED_FUNCTION void pm_list_free(pm_list_t *list);
96
+
97
+ #endif
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @file pm_memchr.h
3
+ *
4
+ * A custom memchr implementation.
5
+ */
6
+ #ifndef PRISM_MEMCHR_H
7
+ #define PRISM_MEMCHR_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/encoding.h"
11
+
12
+ #include <stddef.h>
13
+
14
+ /**
15
+ * We need to roll our own memchr to handle cases where the encoding changes and
16
+ * we need to search for a character in a buffer that could be the trailing byte
17
+ * of a multibyte character.
18
+ *
19
+ * @param source The source string.
20
+ * @param character The character to search for.
21
+ * @param number The maximum number of bytes to search.
22
+ * @param encoding_changed Whether the encoding changed.
23
+ * @param encoding A pointer to the encoding.
24
+ * @return A pointer to the first occurrence of the character in the source
25
+ * string, or NULL if no such character exists.
26
+ */
27
+ void * pm_memchr(const void *source, int character, size_t number, bool encoding_changed, const pm_encoding_t *encoding);
28
+
29
+ #endif
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @file pm_newline_list.h
3
+ *
4
+ * A list of byte offsets of newlines in a string.
5
+ *
6
+ * When compiling the syntax tree, it's necessary to know the line and column
7
+ * of many nodes. This is necessary to support things like error messages,
8
+ * tracepoints, etc.
9
+ *
10
+ * It's possible that we could store the start line, start column, end line, and
11
+ * end column on every node in addition to the offsets that we already store,
12
+ * but that would be quite a lot of memory overhead.
13
+ */
14
+ #ifndef PRISM_NEWLINE_LIST_H
15
+ #define PRISM_NEWLINE_LIST_H
16
+
17
+ #include "prism/defines.h"
18
+
19
+ #include <assert.h>
20
+ #include <stdbool.h>
21
+ #include <stddef.h>
22
+ #include <stdlib.h>
23
+
24
+ /**
25
+ * A list of offsets of newlines in a string. The offsets are assumed to be
26
+ * sorted/inserted in ascending order.
27
+ */
28
+ typedef struct {
29
+ /** A pointer to the start of the source string. */
30
+ const uint8_t *start;
31
+
32
+ /** The number of offsets in the list. */
33
+ size_t size;
34
+
35
+ /** The capacity of the list that has been allocated. */
36
+ size_t capacity;
37
+
38
+ /** The list of offsets. */
39
+ size_t *offsets;
40
+ } pm_newline_list_t;
41
+
42
+ /**
43
+ * A line and column in a string.
44
+ */
45
+ typedef struct {
46
+ /** The line number. */
47
+ int32_t line;
48
+
49
+ /** The column number. */
50
+ uint32_t column;
51
+ } pm_line_column_t;
52
+
53
+ /**
54
+ * Initialize a new newline list with the given capacity. Returns true if the
55
+ * allocation of the offsets succeeds, otherwise returns false.
56
+ *
57
+ * @param list The list to initialize.
58
+ * @param start A pointer to the start of the source string.
59
+ * @param capacity The initial capacity of the list.
60
+ * @return True if the allocation of the offsets succeeds, otherwise false.
61
+ */
62
+ bool pm_newline_list_init(pm_newline_list_t *list, const uint8_t *start, size_t capacity);
63
+
64
+ /**
65
+ * Clear out the newlines that have been appended to the list.
66
+ *
67
+ * @param list The list to clear.
68
+ */
69
+ void
70
+ pm_newline_list_clear(pm_newline_list_t *list);
71
+
72
+ /**
73
+ * Append a new offset to the newline list. Returns true if the reallocation of
74
+ * the offsets succeeds (if one was necessary), otherwise returns false.
75
+ *
76
+ * @param list The list to append to.
77
+ * @param cursor A pointer to the offset to append.
78
+ * @return True if the reallocation of the offsets succeeds (if one was
79
+ * necessary), otherwise false.
80
+ */
81
+ bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor);
82
+
83
+ /**
84
+ * Returns the line of the given offset. If the offset is not in the list, the
85
+ * line of the closest offset less than the given offset is returned.
86
+ *
87
+ * @param list The list to search.
88
+ * @param cursor A pointer to the offset to search for.
89
+ * @param start_line The line to start counting from.
90
+ * @return The line of the given offset.
91
+ */
92
+ int32_t pm_newline_list_line(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line);
93
+
94
+ /**
95
+ * Returns the line and column of the given offset. If the offset is not in the
96
+ * list, the line and column of the closest offset less than the given offset
97
+ * are returned.
98
+ *
99
+ * @param list The list to search.
100
+ * @param cursor A pointer to the offset to search for.
101
+ * @param start_line The line to start counting from.
102
+ * @return The line and column of the given offset.
103
+ */
104
+ pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor, int32_t start_line);
105
+
106
+ /**
107
+ * Free the internal memory allocated for the newline list.
108
+ *
109
+ * @param list The list to free.
110
+ */
111
+ void pm_newline_list_free(pm_newline_list_t *list);
112
+
113
+ #endif
@@ -0,0 +1,190 @@
1
+ /**
2
+ * @file pm_string.h
3
+ *
4
+ * A generic string type that can have various ownership semantics.
5
+ */
6
+ #ifndef PRISM_STRING_H
7
+ #define PRISM_STRING_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <assert.h>
12
+ #include <errno.h>
13
+ #include <stdbool.h>
14
+ #include <stddef.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+
18
+ // The following headers are necessary to read files using demand paging.
19
+ #ifdef _WIN32
20
+ #include <windows.h>
21
+ #elif defined(_POSIX_MAPPED_FILES)
22
+ #include <fcntl.h>
23
+ #include <sys/mman.h>
24
+ #include <sys/stat.h>
25
+ #elif defined(PRISM_HAS_FILESYSTEM)
26
+ #include <fcntl.h>
27
+ #include <sys/stat.h>
28
+ #endif
29
+
30
+ /**
31
+ * A generic string type that can have various ownership semantics.
32
+ */
33
+ typedef struct {
34
+ /** A pointer to the start of the string. */
35
+ const uint8_t *source;
36
+
37
+ /** The length of the string in bytes of memory. */
38
+ size_t length;
39
+
40
+ /** The type of the string. This field determines how the string should be freed. */
41
+ enum {
42
+ /** This string is a constant string, and should not be freed. */
43
+ PM_STRING_CONSTANT,
44
+
45
+ /** This is a slice of another string, and should not be freed. */
46
+ PM_STRING_SHARED,
47
+
48
+ /** This string owns its memory, and should be freed using `pm_string_free`. */
49
+ PM_STRING_OWNED,
50
+
51
+ #ifdef PRISM_HAS_MMAP
52
+ /** This string is a memory-mapped file, and should be freed using `pm_string_free`. */
53
+ PM_STRING_MAPPED
54
+ #endif
55
+ } type;
56
+ } pm_string_t;
57
+
58
+ /**
59
+ * Returns the size of the pm_string_t struct. This is necessary to allocate the
60
+ * correct amount of memory in the FFI backend.
61
+ *
62
+ * @return The size of the pm_string_t struct.
63
+ */
64
+ PRISM_EXPORTED_FUNCTION size_t pm_string_sizeof(void);
65
+
66
+ /**
67
+ * Defines an empty string. This is useful for initializing a string that will
68
+ * be filled in later.
69
+ */
70
+ #define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 })
71
+
72
+ /**
73
+ * Initialize a shared string that is based on initial input.
74
+ *
75
+ * @param string The string to initialize.
76
+ * @param start The start of the string.
77
+ * @param end The end of the string.
78
+ */
79
+ void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end);
80
+
81
+ /**
82
+ * Initialize an owned string that is responsible for freeing allocated memory.
83
+ *
84
+ * @param string The string to initialize.
85
+ * @param source The source of the string.
86
+ * @param length The length of the string.
87
+ */
88
+ void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length);
89
+
90
+ /**
91
+ * Initialize a constant string that doesn't own its memory source.
92
+ *
93
+ * @param string The string to initialize.
94
+ * @param source The source of the string.
95
+ * @param length The length of the string.
96
+ */
97
+ void pm_string_constant_init(pm_string_t *string, const char *source, size_t length);
98
+
99
+ /**
100
+ * Represents the result of calling pm_string_mapped_init or
101
+ * pm_string_file_init. We need this additional information because there is
102
+ * not a platform-agnostic way to indicate that the file that was attempted to
103
+ * be opened was a directory.
104
+ */
105
+ typedef enum {
106
+ /** Indicates that the string was successfully initialized. */
107
+ PM_STRING_INIT_SUCCESS = 0,
108
+ /**
109
+ * Indicates a generic error from a string_*_init function, where the type
110
+ * of error should be read from `errno` or `GetLastError()`.
111
+ */
112
+ PM_STRING_INIT_ERROR_GENERIC = 1,
113
+ /**
114
+ * Indicates that the file that was attempted to be opened was a directory.
115
+ */
116
+ PM_STRING_INIT_ERROR_DIRECTORY = 2
117
+ } pm_string_init_result_t;
118
+
119
+ /**
120
+ * Read the file indicated by the filepath parameter into source and load its
121
+ * contents and size into the given `pm_string_t`. The given `pm_string_t`
122
+ * should be freed using `pm_string_free` when it is no longer used.
123
+ *
124
+ * We want to use demand paging as much as possible in order to avoid having to
125
+ * read the entire file into memory (which could be detrimental to performance
126
+ * for large files). This means that if we're on windows we'll use
127
+ * `MapViewOfFile`, on POSIX systems that have access to `mmap` we'll use
128
+ * `mmap`, and on other POSIX systems we'll use `read`.
129
+ *
130
+ * @param string The string to initialize.
131
+ * @param filepath The filepath to read.
132
+ * @return The success of the read, indicated by the value of the enum.
133
+ */
134
+ PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_mapped_init(pm_string_t *string, const char *filepath);
135
+
136
+ /**
137
+ * Read the file indicated by the filepath parameter into source and load its
138
+ * contents and size into the given `pm_string_t`. The given `pm_string_t`
139
+ * should be freed using `pm_string_free` when it is no longer used.
140
+ *
141
+ * @param string The string to initialize.
142
+ * @param filepath The filepath to read.
143
+ * @return The success of the read, indicated by the value of the enum.
144
+ */
145
+ PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_file_init(pm_string_t *string, const char *filepath);
146
+
147
+ /**
148
+ * Ensure the string is owned. If it is not, then reinitialize it as owned and
149
+ * copy over the previous source.
150
+ *
151
+ * @param string The string to ensure is owned.
152
+ */
153
+ void pm_string_ensure_owned(pm_string_t *string);
154
+
155
+ /**
156
+ * Compare the underlying lengths and bytes of two strings. Returns 0 if the
157
+ * strings are equal, a negative number if the left string is less than the
158
+ * right string, and a positive number if the left string is greater than the
159
+ * right string.
160
+ *
161
+ * @param left The left string to compare.
162
+ * @param right The right string to compare.
163
+ * @return The comparison result.
164
+ */
165
+ int pm_string_compare(const pm_string_t *left, const pm_string_t *right);
166
+
167
+ /**
168
+ * Returns the length associated with the string.
169
+ *
170
+ * @param string The string to get the length of.
171
+ * @return The length of the string.
172
+ */
173
+ PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string);
174
+
175
+ /**
176
+ * Returns the start pointer associated with the string.
177
+ *
178
+ * @param string The string to get the start pointer of.
179
+ * @return The start pointer of the string.
180
+ */
181
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string);
182
+
183
+ /**
184
+ * Free the associated memory of the given string.
185
+ *
186
+ * @param string The string to free.
187
+ */
188
+ PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string);
189
+
190
+ #endif
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @file pm_strncasecmp.h
3
+ *
4
+ * A custom strncasecmp implementation.
5
+ */
6
+ #ifndef PRISM_STRNCASECMP_H
7
+ #define PRISM_STRNCASECMP_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <ctype.h>
12
+ #include <stddef.h>
13
+ #include <stdint.h>
14
+
15
+ /**
16
+ * Compare two strings, ignoring case, up to the given length. Returns 0 if the
17
+ * strings are equal, a negative number if string1 is less than string2, or a
18
+ * positive number if string1 is greater than string2.
19
+ *
20
+ * Note that this is effectively our own implementation of strncasecmp, but it's
21
+ * not available on all of the platforms we want to support so we're rolling it
22
+ * here.
23
+ *
24
+ * @param string1 The first string to compare.
25
+ * @param string2 The second string to compare
26
+ * @param length The maximum number of characters to compare.
27
+ * @return 0 if the strings are equal, a negative number if string1 is less than
28
+ * string2, or a positive number if string1 is greater than string2.
29
+ */
30
+ int pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length);
31
+
32
+ #endif
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file pm_strpbrk.h
3
+ *
4
+ * A custom strpbrk implementation.
5
+ */
6
+ #ifndef PRISM_STRPBRK_H
7
+ #define PRISM_STRPBRK_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/diagnostic.h"
11
+ #include "prism/parser.h"
12
+
13
+ #include <stddef.h>
14
+ #include <string.h>
15
+
16
+ /**
17
+ * Here we have rolled our own version of strpbrk. The standard library strpbrk
18
+ * has undefined behavior when the source string is not null-terminated. We want
19
+ * to support strings that are not null-terminated because pm_parse does not
20
+ * have the contract that the string is null-terminated. (This is desirable
21
+ * because it means the extension can call pm_parse with the result of a call to
22
+ * mmap).
23
+ *
24
+ * The standard library strpbrk also does not support passing a maximum length
25
+ * to search. We want to support this for the reason mentioned above, but we
26
+ * also don't want it to stop on null bytes. Ruby actually allows null bytes
27
+ * within strings, comments, regular expressions, etc. So we need to be able to
28
+ * skip past them.
29
+ *
30
+ * Finally, we want to support encodings wherein the charset could contain
31
+ * characters that are trailing bytes of multi-byte characters. For example, in
32
+ * Shift-JIS, the backslash character can be a trailing byte. In that case we
33
+ * need to take a slower path and iterate one multi-byte character at a time.
34
+ *
35
+ * @param parser The parser.
36
+ * @param source The source to search.
37
+ * @param charset The charset to search for.
38
+ * @param length The maximum number of bytes to search.
39
+ * @param validate Whether to validate that the source string is valid in the
40
+ * current encoding of the parser.
41
+ * @return A pointer to the first character in the source string that is in the
42
+ * charset, or NULL if no such character exists.
43
+ */
44
+ const uint8_t * pm_strpbrk(pm_parser_t *parser, const uint8_t *source, const uint8_t *charset, ptrdiff_t length, bool validate);
45
+
46
+ #endif
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @file version.h
3
+ *
4
+ * The version of the Prism library.
5
+ */
6
+ #ifndef PRISM_VERSION_H
7
+ #define PRISM_VERSION_H
8
+
9
+ /**
10
+ * The major version of the Prism library as an int.
11
+ */
12
+ #define PRISM_VERSION_MAJOR 1
13
+
14
+ /**
15
+ * The minor version of the Prism library as an int.
16
+ */
17
+ #define PRISM_VERSION_MINOR 4
18
+
19
+ /**
20
+ * The patch version of the Prism library as an int.
21
+ */
22
+ #define PRISM_VERSION_PATCH 0
23
+
24
+ /**
25
+ * The version of the Prism library as a constant string.
26
+ */
27
+ #define PRISM_VERSION "1.4.0"
28
+
29
+ #endif