Ruby 4.1.0dev (2026-04-17 revision 11e3c78b61da705c783dd12fb7f158c0d256ede0)
stringy.h
Go to the documentation of this file.
1
6#ifndef PRISM_STRINGY_H
7#define PRISM_STRINGY_H
8
11
12#include <stddef.h>
13#include <stdint.h>
14
18typedef struct {
20 const uint8_t *source;
21
23 size_t length;
24
26 enum {
29
32
34 PM_STRING_OWNED
35 } type;
37
45PRISM_EXPORTED_FUNCTION void pm_string_constant_init(pm_string_t *string, const char *source, size_t length) PRISM_NONNULL(1);
46
54PRISM_EXPORTED_FUNCTION void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length) PRISM_NONNULL(1, 2);
55
63
71
72#endif
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition exported.h:20
#define PRISM_NONNULL(...)
Mark the parameters of a function as non-null.
Definition nonnull.h:13
PRISM_EXPORTED_FUNCTION void pm_string_constant_init(pm_string_t *string, const char *source, size_t length) PRISM_NONNULL(1)
Initialize a constant string that doesn't own its memory source.
Definition stringy.c:39
PRISM_EXPORTED_FUNCTION void PRISM_EXPORTED_FUNCTION size_t pm_string_length(const pm_string_t *string) PRISM_NONNULL(1)
Returns the length associated with the string.
Definition stringy.c:71
PRISM_EXPORTED_FUNCTION void pm_string_owned_init(pm_string_t *string, uint8_t *source, size_t length) PRISM_NONNULL(1
Initialize an owned string that is responsible for freeing allocated memory.
PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source(const pm_string_t *string) PRISM_NONNULL(1)
Returns the start pointer associated with the string.
Definition stringy.c:79
A generic string type that can have various ownership semantics.
Definition stringy.h:18
const uint8_t * source
A pointer to the start of the string.
Definition stringy.h:20
size_t length
The length of the string in bytes of memory.
Definition stringy.h:23
@ PM_STRING_CONSTANT
This string is a constant string, and should not be freed.
Definition stringy.h:28
@ PM_STRING_SHARED
This is a slice of another string, and should not be freed.
Definition stringy.h:31