Ruby 4.1.0dev (2026-04-01 revision 9c827a49ccefc0b945b25a479cdd9ba0a156a21c)
source.h
Go to the documentation of this file.
1
7#ifndef PRISM_SOURCE_H
8#define PRISM_SOURCE_H
9
14
15#include <stddef.h>
16#include <stdint.h>
17
21typedef struct pm_source_t pm_source_t;
22
28typedef char * (pm_source_stream_fgets_t)(char *string, int size, void *stream);
29
34typedef int (pm_source_stream_feof_t)(void *stream);
35
60
70
80
90
99
114
124
131
139
146PRISM_EXPORTED_FUNCTION const uint8_t * pm_source_source(const pm_source_t *source) PRISM_NONNULL(1);
147
148#endif
#define PRISM_EXPORTED_FUNCTION
By default, we compile with -fvisibility=hidden.
Definition exported.h:20
Platform detection for mmap and filesystem support.
#define PRISM_NODISCARD
Mark the return value of a function as important so that the compiler warns if a caller ignores it.
Definition nodiscard.h:15
#define PRISM_NONNULL(...)
Mark the parameters of a function as non-null.
Definition nonnull.h:13
PRISM_EXPORTED_FUNCTION const uint8_t * pm_source_source(const pm_source_t *source) PRISM_NONNULL(1)
Returns a pointer to the source data.
Definition source.c:489
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_file_new(const char *filepath, pm_source_init_result_t *result) PRISM_NONNULL(1
Create a new source by reading a file into a heap-allocated buffer.
int() pm_source_stream_feof_t(void *stream)
This function is used to check whether a stream is at EOF.
Definition source.h:34
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_stream_new(void *stream, pm_source_stream_fgets_t *fgets, pm_source_stream_feof_t *feof)
Create a new source by reading from a stream using the provided callbacks.
Definition source.c:347
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_constant_new(const uint8_t *data, size_t length)
Create a new source that wraps existing constant memory.
Definition source.c:44
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_owned_new(uint8_t *data, size_t length)
Create a new source that owns its memory.
Definition source.c:60
char *() pm_source_stream_fgets_t(char *string, int size, void *stream)
This function is used to retrieve a line of input from a stream.
Definition source.h:28
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_mapped_new(const char *filepath, int open_flags, pm_source_init_result_t *result) PRISM_NONNULL(1
Create a new source by memory-mapping a file.
PRISM_EXPORTED_FUNCTION size_t pm_source_length(const pm_source_t *source) PRISM_NONNULL(1)
Returns the length of the source data in bytes.
Definition source.c:481
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_source_t * pm_source_shared_new(const uint8_t *data, size_t length)
Create a new source that wraps existing shared memory.
Definition source.c:52
PRISM_EXPORTED_FUNCTION void pm_source_free(pm_source_t *source) PRISM_NONNULL(1)
Free the given source and any memory it owns.
Definition source.c:449
pm_source_init_result_t
Represents the result of initializing a source from a file.
Definition source.h:39
@ PM_SOURCE_INIT_ERROR_GENERIC
Indicates a generic error from a source init function, where the type of error should be read from er...
Definition source.h:47
@ PM_SOURCE_INIT_SUCCESS
Indicates that the source was successfully initialized.
Definition source.h:41
@ PM_SOURCE_INIT_ERROR_NON_REGULAR
Indicates that the file is not a regular file (e.g.
Definition source.h:58
@ PM_SOURCE_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
Definition source.h:52