Ruby: pm_string_t Struct Reference

Ruby 3.4.8p72 (2025-12-17 revision 995b59f66677d44767ce9faac6957e5543617ff9)

Public Types | Public Member Functions | Data Fields
pm_string_t Struct Reference

A generic string type that can have various ownership semantics. More...

`#include <pm_string.h>`

## Public Types
enum | { PM_STRING_CONSTANT , PM_STRING_SHARED , PM_STRING_OWNED }
| The type of the string. More...

## Public Member Functions
PRISM_EXPORTED_FUNCTION pm_string_init_result_t | pm_string_mapped_init (pm_string_t *string, const char *filepath)
| Read the file indicated by the filepath parameter into source and load its contents and size into the given `pm_string_t`.
PRISM_EXPORTED_FUNCTION pm_string_init_result_t | pm_string_file_init (pm_string_t *string, const char *filepath)
| Read the file indicated by the filepath parameter into source and load its contents and size into the given `pm_string_t`.
PRISM_EXPORTED_FUNCTION size_t | pm_string_length (const pm_string_t *string)
| Returns the length associated with the string.
PRISM_EXPORTED_FUNCTION const uint8_t * | pm_string_source (const pm_string_t *string)
| Returns the start pointer associated with the string.
PRISM_EXPORTED_FUNCTION void | pm_string_free (pm_string_t *string)
| Free the associated memory of the given string.

## Data Fields
const uint8_t * | source
| A pointer to the start of the string.
size_t | length
| The length of the string in bytes of memory.
enum pm_string_t:: { ... } | type
| The type of the string.

## Detailed Description

A generic string type that can have various ownership semantics.

Definition at line 33 of file pm_string.h.

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum

The type of the string.

This field determines how the string should be freed.

Enumerator
PM_STRING_CONSTANT | This string is a constant string, and should not be freed.
PM_STRING_SHARED | This is a slice of another string, and should not be freed.
PM_STRING_OWNED | This string owns its memory, and should be freed using `pm_string_free()`.

Definition at line 41 of file pm_string.h.

## Member Function Documentation

## ◆ pm_string_file_init()

PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_file_init | ( | pm_string_t * | string,
|  | const char * | filepath
| ) |  |

Read the file indicated by the filepath parameter into source and load its contents and size into the given `pm_string_t`.

The given `pm_string_t` should be freed using `pm_string_free` when it is no longer used.

Parameters

  string | The string to initialize.
  filepath | The filepath to read.

Returns
  The success of the read, indicated by the value of the enum.

Definition at line 210 of file pm_string.c.

## ◆ pm_string_free()

PRISM_EXPORTED_FUNCTION void pm_string_free | ( | pm_string_t * | string | ) |

Free the associated memory of the given string.

Parameters

  string | The string to free.

Definition at line 367 of file pm_string.c.

## ◆ pm_string_length()

PRISM_EXPORTED_FUNCTION size_t pm_string_length | ( | const pm_string_t * | string | ) |

Returns the length associated with the string.

Parameters

  string | The string to get the length of.

Returns
  The length of the string.

Definition at line 351 of file pm_string.c.

## ◆ pm_string_mapped_init()

PRISM_EXPORTED_FUNCTION pm_string_init_result_t pm_string_mapped_init | ( | pm_string_t * | string,
|  | const char * | filepath
| ) |  |

Read the file indicated by the filepath parameter into source and load its contents and size into the given `pm_string_t`.

The given `pm_string_t` should be freed using `pm_string_free` when it is no longer used.

We want to use demand paging as much as possible in order to avoid having to read the entire file into memory (which could be detrimental to performance for large files). This means that if we're on windows we'll use `MapViewOfFile`, on POSIX systems that have access to `mmap` we'll use `mmap`, and on other POSIX systems we'll use `read`.

Parameters

  string | The string to initialize.
  filepath | The filepath to read.

Returns
  The success of the read, indicated by the value of the enum.

Definition at line 120 of file pm_string.c.

## ◆ pm_string_source()

PRISM_EXPORTED_FUNCTION const uint8_t * pm_string_source | ( | const pm_string_t * | string | ) |

Returns the start pointer associated with the string.

Parameters

  string | The string to get the start pointer of.

Returns
  The start pointer of the string.

Definition at line 359 of file pm_string.c.

## Field Documentation

## ◆ length

size_t pm_string_t::length

The length of the string in bytes of memory.

Definition at line 38 of file pm_string.h.

Referenced by pm_string_free().

## ◆ source

const uint8_t* pm_string_t::source

A pointer to the start of the string.

Definition at line 35 of file pm_string.h.

Referenced by pm_string_ensure_owned(), and pm_string_free().

## ◆ []

enum { ... } pm_string_t::type

The type of the string.

This field determines how the string should be freed.

Referenced by pm_string_ensure_owned(), and pm_string_free().

The documentation for this struct was generated from the following file:

- prism/util/pm_string.h