debase-ruby_core_source 3.3.0 → 3.3.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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Rakefile +2 -1
  4. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/ast.h +4612 -0
  5. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/defines.h +94 -0
  6. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/diagnostic.h +297 -0
  7. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/encoding.h +248 -0
  8. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/extension.h +18 -0
  9. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/node.h +57 -0
  10. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/options.h +204 -0
  11. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/pack.h +152 -0
  12. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/parser.h +716 -0
  13. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/prettyprint.h +26 -0
  14. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/prism.h +272 -0
  15. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/regexp.h +33 -0
  16. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_buffer.h +146 -0
  17. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_char.h +205 -0
  18. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_constant_pool.h +191 -0
  19. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_list.h +97 -0
  20. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_memchr.h +29 -0
  21. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_newline_list.h +104 -0
  22. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_state_stack.h +42 -0
  23. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_string.h +150 -0
  24. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_string_list.h +44 -0
  25. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_strncasecmp.h +32 -0
  26. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_strpbrk.h +43 -0
  27. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/version.h +29 -0
  28. data/lib/debase/ruby_core_source/version.rb +1 -1
  29. metadata +30 -6
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @file pm_constant_pool.h
3
+ *
4
+ * A data structure that stores a set of strings.
5
+ *
6
+ * Each string is assigned a unique id, which can be used to compare strings for
7
+ * equality. This comparison ends up being much faster than strcmp, since it
8
+ * only requires a single integer comparison.
9
+ */
10
+ #ifndef PRISM_CONSTANT_POOL_H
11
+ #define PRISM_CONSTANT_POOL_H
12
+
13
+ #include "prism/defines.h"
14
+
15
+ #include <assert.h>
16
+ #include <stdbool.h>
17
+ #include <stdint.h>
18
+ #include <stdlib.h>
19
+ #include <string.h>
20
+
21
+ /**
22
+ * A constant id is a unique identifier for a constant in the constant pool.
23
+ */
24
+ typedef uint32_t pm_constant_id_t;
25
+
26
+ /**
27
+ * A list of constant IDs. Usually used to represent a set of locals.
28
+ */
29
+ typedef struct {
30
+ /** The number of constant ids in the list. */
31
+ size_t size;
32
+
33
+ /** The number of constant ids that have been allocated in the list. */
34
+ size_t capacity;
35
+
36
+ /** The constant ids in the list. */
37
+ pm_constant_id_t *ids;
38
+ } pm_constant_id_list_t;
39
+
40
+ /**
41
+ * Initialize a list of constant ids.
42
+ *
43
+ * @param list The list to initialize.
44
+ */
45
+ void pm_constant_id_list_init(pm_constant_id_list_t *list);
46
+
47
+ /**
48
+ * Append a constant id to a list of constant ids. Returns false if any
49
+ * potential reallocations fail.
50
+ *
51
+ * @param list The list to append to.
52
+ * @param id The id to append.
53
+ * @return Whether the append succeeded.
54
+ */
55
+ bool pm_constant_id_list_append(pm_constant_id_list_t *list, pm_constant_id_t id);
56
+
57
+ /**
58
+ * Checks if the current constant id list includes the given constant id.
59
+ *
60
+ * @param list The list to check.
61
+ * @param id The id to check for.
62
+ * @return Whether the list includes the given id.
63
+ */
64
+ bool pm_constant_id_list_includes(pm_constant_id_list_t *list, pm_constant_id_t id);
65
+
66
+ /**
67
+ * Get the memory size of a list of constant ids.
68
+ *
69
+ * @param list The list to get the memory size of.
70
+ * @return The memory size of the list.
71
+ */
72
+ size_t pm_constant_id_list_memsize(pm_constant_id_list_t *list);
73
+
74
+ /**
75
+ * Free the memory associated with a list of constant ids.
76
+ *
77
+ * @param list The list to free.
78
+ */
79
+ void pm_constant_id_list_free(pm_constant_id_list_t *list);
80
+
81
+ /**
82
+ * The type of bucket in the constant pool hash map. This determines how the
83
+ * bucket should be freed.
84
+ */
85
+ typedef unsigned int pm_constant_pool_bucket_type_t;
86
+
87
+ /** By default, each constant is a slice of the source. */
88
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_DEFAULT = 0;
89
+
90
+ /** An owned constant is one for which memory has been allocated. */
91
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_OWNED = 1;
92
+
93
+ /** A constant constant is known at compile time. */
94
+ static const pm_constant_pool_bucket_type_t PM_CONSTANT_POOL_BUCKET_CONSTANT = 2;
95
+
96
+ /** A bucket in the hash map. */
97
+ typedef struct {
98
+ /** The incremental ID used for indexing back into the pool. */
99
+ unsigned int id: 30;
100
+
101
+ /** The type of the bucket, which determines how to free it. */
102
+ pm_constant_pool_bucket_type_t type: 2;
103
+
104
+ /** The hash of the bucket. */
105
+ uint32_t hash;
106
+ } pm_constant_pool_bucket_t;
107
+
108
+ /** A constant in the pool which effectively stores a string. */
109
+ typedef struct {
110
+ /** A pointer to the start of the string. */
111
+ const uint8_t *start;
112
+
113
+ /** The length of the string. */
114
+ size_t length;
115
+ } pm_constant_t;
116
+
117
+ /** The overall constant pool, which stores constants found while parsing. */
118
+ typedef struct {
119
+ /** The buckets in the hash map. */
120
+ pm_constant_pool_bucket_t *buckets;
121
+
122
+ /** The constants that are stored in the buckets. */
123
+ pm_constant_t *constants;
124
+
125
+ /** The number of buckets in the hash map. */
126
+ uint32_t size;
127
+
128
+ /** The number of buckets that have been allocated in the hash map. */
129
+ uint32_t capacity;
130
+ } pm_constant_pool_t;
131
+
132
+ /**
133
+ * Initialize a new constant pool with a given capacity.
134
+ *
135
+ * @param pool The pool to initialize.
136
+ * @param capacity The initial capacity of the pool.
137
+ * @return Whether the initialization succeeded.
138
+ */
139
+ bool pm_constant_pool_init(pm_constant_pool_t *pool, uint32_t capacity);
140
+
141
+ /**
142
+ * Return a pointer to the constant indicated by the given constant id.
143
+ *
144
+ * @param pool The pool to get the constant from.
145
+ * @param constant_id The id of the constant to get.
146
+ * @return A pointer to the constant.
147
+ */
148
+ pm_constant_t * pm_constant_pool_id_to_constant(const pm_constant_pool_t *pool, pm_constant_id_t constant_id);
149
+
150
+ /**
151
+ * Insert a constant into a constant pool that is a slice of a source string.
152
+ * Returns the id of the constant, or 0 if any potential calls to resize fail.
153
+ *
154
+ * @param pool The pool to insert the constant into.
155
+ * @param start A pointer to the start of the constant.
156
+ * @param length The length of the constant.
157
+ * @return The id of the constant.
158
+ */
159
+ pm_constant_id_t pm_constant_pool_insert_shared(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
160
+
161
+ /**
162
+ * Insert a constant into a constant pool from memory that is now owned by the
163
+ * constant pool. Returns the id of the constant, or 0 if any potential calls to
164
+ * resize fail.
165
+ *
166
+ * @param pool The pool to insert the constant into.
167
+ * @param start A pointer to the start of the constant.
168
+ * @param length The length of the constant.
169
+ * @return The id of the constant.
170
+ */
171
+ pm_constant_id_t pm_constant_pool_insert_owned(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
172
+
173
+ /**
174
+ * Insert a constant into a constant pool from memory that is constant. Returns
175
+ * the id of the constant, or 0 if any potential calls to resize fail.
176
+ *
177
+ * @param pool The pool to insert the constant into.
178
+ * @param start A pointer to the start of the constant.
179
+ * @param length The length of the constant.
180
+ * @return The id of the constant.
181
+ */
182
+ pm_constant_id_t pm_constant_pool_insert_constant(pm_constant_pool_t *pool, const uint8_t *start, size_t length);
183
+
184
+ /**
185
+ * Free the memory associated with a constant pool.
186
+ *
187
+ * @param pool The pool to free.
188
+ */
189
+ void pm_constant_pool_free(pm_constant_pool_t *pool);
190
+
191
+ #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 = malloc(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,104 @@
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
+ size_t line;
48
+
49
+ /** The column number. */
50
+ size_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
+ * Append a new offset to the newline list. Returns true if the reallocation of
66
+ * the offsets succeeds (if one was necessary), otherwise returns false.
67
+ *
68
+ * @param list The list to append to.
69
+ * @param cursor A pointer to the offset to append.
70
+ * @return True if the reallocation of the offsets succeeds (if one was
71
+ * necessary), otherwise false.
72
+ */
73
+ bool pm_newline_list_append(pm_newline_list_t *list, const uint8_t *cursor);
74
+
75
+ /**
76
+ * Conditionally append a new offset to the newline list, if the value passed in
77
+ * is a newline.
78
+ *
79
+ * @param list The list to append to.
80
+ * @param cursor A pointer to the offset to append.
81
+ * @return True if the reallocation of the offsets succeeds (if one was
82
+ * necessary), otherwise false.
83
+ */
84
+ bool pm_newline_list_check_append(pm_newline_list_t *list, const uint8_t *cursor);
85
+
86
+ /**
87
+ * Returns the line and column of the given offset. If the offset is not in the
88
+ * list, the line and column of the closest offset less than the given offset
89
+ * are returned.
90
+ *
91
+ * @param list The list to search.
92
+ * @param cursor A pointer to the offset to search for.
93
+ * @return The line and column of the given offset.
94
+ */
95
+ pm_line_column_t pm_newline_list_line_column(const pm_newline_list_t *list, const uint8_t *cursor);
96
+
97
+ /**
98
+ * Free the internal memory allocated for the newline list.
99
+ *
100
+ * @param list The list to free.
101
+ */
102
+ void pm_newline_list_free(pm_newline_list_t *list);
103
+
104
+ #endif
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @file pm_state_stack.h
3
+ *
4
+ * A stack of boolean values.
5
+ */
6
+ #ifndef PRISM_STATE_STACK_H
7
+ #define PRISM_STATE_STACK_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <stdbool.h>
12
+ #include <stdint.h>
13
+
14
+ /**
15
+ * A struct that represents a stack of boolean values.
16
+ */
17
+ typedef uint32_t pm_state_stack_t;
18
+
19
+ /**
20
+ * Pushes a value onto the stack.
21
+ *
22
+ * @param stack The stack to push the value onto.
23
+ * @param value The value to push onto the stack.
24
+ */
25
+ void pm_state_stack_push(pm_state_stack_t *stack, bool value);
26
+
27
+ /**
28
+ * Pops a value off the stack.
29
+ *
30
+ * @param stack The stack to pop the value off of.
31
+ */
32
+ void pm_state_stack_pop(pm_state_stack_t *stack);
33
+
34
+ /**
35
+ * Returns the value at the top of the stack.
36
+ *
37
+ * @param stack The stack to get the value from.
38
+ * @return The value at the top of the stack.
39
+ */
40
+ bool pm_state_stack_p(pm_state_stack_t *stack);
41
+
42
+ #endif
@@ -0,0 +1,150 @@
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 <stdbool.h>
13
+ #include <stddef.h>
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+
17
+ // The following headers are necessary to read files using demand paging.
18
+ #ifdef _WIN32
19
+ #include <windows.h>
20
+ #else
21
+ #include <fcntl.h>
22
+ #include <sys/mman.h>
23
+ #include <sys/stat.h>
24
+ #include <unistd.h>
25
+ #endif
26
+
27
+ /**
28
+ * A generic string type that can have various ownership semantics.
29
+ */
30
+ typedef struct {
31
+ /** A pointer to the start of the string. */
32
+ const uint8_t *source;
33
+
34
+ /** The length of the string in bytes of memory. */
35
+ size_t length;
36
+
37
+ /** The type of the string. This field determines how the string should be freed. */
38
+ enum {
39
+ /** This string is a constant string, and should not be freed. */
40
+ PM_STRING_CONSTANT,
41
+
42
+ /** This is a slice of another string, and should not be freed. */
43
+ PM_STRING_SHARED,
44
+
45
+ /** This string owns its memory, and should be freed using `pm_string_free`. */
46
+ PM_STRING_OWNED,
47
+
48
+ /** This string is a memory-mapped file, and should be freed using `pm_string_free`. */
49
+ PM_STRING_MAPPED
50
+ } type;
51
+ } pm_string_t;
52
+
53
+ /**
54
+ * Returns the size of the pm_string_t struct. This is necessary to allocate the
55
+ * correct amount of memory in the FFI backend.
56
+ *
57
+ * @return The size of the pm_string_t struct.
58
+ */
59
+ PRISM_EXPORTED_FUNCTION size_t pm_string_sizeof(void);
60
+
61
+ /**
62
+ * Defines an empty string. This is useful for initializing a string that will
63
+ * be filled in later.
64
+ */
65
+ #define PM_STRING_EMPTY ((pm_string_t) { .type = PM_STRING_CONSTANT, .source = NULL, .length = 0 })
66
+
67
+ /**
68
+ * Initialize a shared string that is based on initial input.
69
+ *
70
+ * @param string The string to initialize.
71
+ * @param start The start of the string.
72
+ * @param end The end of the string.
73
+ */
74
+ void pm_string_shared_init(pm_string_t *string, const uint8_t *start, const uint8_t *end);
75
+
76
+ /**
77
+ * Initialize an owned string that is responsible for freeing allocated memory.
78
+ *
79
+ * @param string The string to initialize.
80
+ * @param source The source of the string.
81
+ * @param length The length of the string.
82
+ */
83
+ void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length);
84
+
85
+ /**
86
+ * Initialize a constant string that doesn't own its memory source.
87
+ *
88
+ * @param string The string to initialize.
89
+ * @param source The source of the string.
90
+ * @param length The length of the string.
91
+ */
92
+ void pm_string_constant_init(pm_string_t *string, const char *source, size_t length);
93
+
94
+ /**
95
+ * Read the file indicated by the filepath parameter into source and load its
96
+ * contents and size into the given `pm_string_t`. The given `pm_string_t`
97
+ * should be freed using `pm_string_free` when it is no longer used.
98
+ *
99
+ * We want to use demand paging as much as possible in order to avoid having to
100
+ * read the entire file into memory (which could be detrimental to performance
101
+ * for large files). This means that if we're on windows we'll use
102
+ * `MapViewOfFile`, on POSIX systems that have access to `mmap` we'll use
103
+ * `mmap`, and on other POSIX systems we'll use `read`.
104
+ *
105
+ * @param string The string to initialize.
106
+ * @param filepath The filepath to read.
107
+ * @return Whether or not the file was successfully mapped.
108
+ */
109
+ PRISM_EXPORTED_FUNCTION bool pm_string_mapped_init(pm_string_t *string, const char *filepath);
110
+
111
+ /**
112
+ * Returns the memory size associated with the string.
113
+ *
114
+ * @param string The string to get the memory size of.
115
+ * @return The size of the memory associated with the string.
116
+ */
117
+ size_t pm_string_memsize(const pm_string_t *string);
118
+
119
+ /**
120
+ * Ensure the string is owned. If it is not, then reinitialize it as owned and
121
+ * copy over the previous source.
122
+ *
123
+ * @param string The string to ensure is owned.
124
+ */
125
+ void pm_string_ensure_owned(pm_string_t *string);
126
+
127
+ /**
128
+ * Returns the length associated with the string.
129
+ *
130
+ * @param string The string to get the length of.
131
+ * @return The length of the string.
132
+ */
133
+ PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string);
134
+
135
+ /**
136
+ * Returns the start pointer associated with the string.
137
+ *
138
+ * @param string The string to get the start pointer of.
139
+ * @return The start pointer of the string.
140
+ */
141
+ PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string);
142
+
143
+ /**
144
+ * Free the associated memory of the given string.
145
+ *
146
+ * @param string The string to free.
147
+ */
148
+ PRISM_EXPORTED_FUNCTION void pm_string_free(pm_string_t *string);
149
+
150
+ #endif
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @file pm_string_list.h
3
+ *
4
+ * A list of strings.
5
+ */
6
+ #ifndef PRISM_STRING_LIST_H
7
+ #define PRISM_STRING_LIST_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_string.h"
11
+
12
+ #include <stddef.h>
13
+ #include <stdlib.h>
14
+
15
+ /**
16
+ * A list of strings.
17
+ */
18
+ typedef struct {
19
+ /** The length of the string list. */
20
+ size_t length;
21
+
22
+ /** The capacity of the string list that has been allocated. */
23
+ size_t capacity;
24
+
25
+ /** A pointer to the start of the string list. */
26
+ pm_string_t *strings;
27
+ } pm_string_list_t;
28
+
29
+ /**
30
+ * Append a pm_string_t to the given string list.
31
+ *
32
+ * @param string_list The string list to append to.
33
+ * @param string The string to append.
34
+ */
35
+ void pm_string_list_append(pm_string_list_t *string_list, pm_string_t *string);
36
+
37
+ /**
38
+ * Free the memory associated with the string list.
39
+ *
40
+ * @param string_list The string list to free.
41
+ */
42
+ PRISM_EXPORTED_FUNCTION void pm_string_list_free(pm_string_list_t *string_list);
43
+
44
+ #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