Ruby: include/ruby/io/buffer.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

buffer.h
Go to the documentation of this file.
1#ifndef RUBY_IO_BUFFER_H
2#define RUBY_IO_BUFFER_H
14#pragma once
15
16#include "ruby/ruby.h"
17#include "ruby/internal/config.h"
18
19 RBIMPL_SYMBOL_EXPORT_BEGIN()
20
21// WARNING: This entire interface is experimental and may change in the future!
22#define RB_IO_BUFFER_EXPERIMENTAL 1
23
24#define RUBY_IO_BUFFER_VERSION 2
25
26 RUBY_EXTERN VALUE rb_cIOBuffer;
27 RUBY_EXTERN size_t RUBY_IO_BUFFER_PAGE_SIZE;
28 RUBY_EXTERN size_t RUBY_IO_BUFFER_DEFAULT_SIZE;
29
30enum rb_io_buffer_flags {
31 // The memory in the buffer is owned by someone else.
32 // More specifically, it means that someone else owns the buffer and we shouldn't try to resize it.
33 RB_IO_BUFFER_EXTERNAL = 1,
34 // The memory in the buffer is allocated internally.
35 RB_IO_BUFFER_INTERNAL = 2,
36 // The memory in the buffer is mapped.
37 // A non-private mapping is marked as external.
38 RB_IO_BUFFER_MAPPED = 4,
39
40 // A mapped buffer that is also shared.
41 RB_IO_BUFFER_SHARED = 8,
42
43 // The buffer is locked and cannot be resized.
44 // More specifically, it means we can't change the base address or size.
45 // A buffer is typically locked before a system call that uses the data.
46 RB_IO_BUFFER_LOCKED = 32,
47
48 // The buffer mapping is private and will not impact other processes or the underlying file.
49 RB_IO_BUFFER_PRIVATE = 64,
50
51 // The buffer is read-only and cannot be modified.
52 RB_IO_BUFFER_READONLY = 128
53};
54
55enum rb_io_buffer_endian {
56 RB_IO_BUFFER_LITTLE_ENDIAN = 4,
57 RB_IO_BUFFER_BIG_ENDIAN = 8,
58
59#if defined(WORDS_BIGENDIAN)
60 RB_IO_BUFFER_HOST_ENDIAN = RB_IO_BUFFER_BIG_ENDIAN,
61#else
62 RB_IO_BUFFER_HOST_ENDIAN = RB_IO_BUFFER_LITTLE_ENDIAN,
63#endif
64
65 RB_IO_BUFFER_NETWORK_ENDIAN = RB_IO_BUFFER_BIG_ENDIAN
66};
67
68 VALUE rb_io_buffer_new(void *base, size_t size, enum rb_io_buffer_flags flags);
69 VALUE rb_io_buffer_map(VALUE io, size_t size, rb_off_t offset, enum rb_io_buffer_flags flags);
70
71 VALUE rb_io_buffer_lock(VALUE self);
72 VALUE rb_io_buffer_unlock(VALUE self);
73int rb_io_buffer_try_unlock(VALUE self);
74 VALUE rb_io_buffer_free(VALUE self);
75
76int rb_io_buffer_get_bytes(VALUE self, void **base, size_t *size);
77void rb_io_buffer_get_bytes_for_reading(VALUE self, const void **base, size_t *size);
78void rb_io_buffer_get_bytes_for_writing(VALUE self, void **base, size_t *size);
79
80 VALUE rb_io_buffer_transfer(VALUE self);
81void rb_io_buffer_resize(VALUE self, size_t size);
82void rb_io_buffer_clear(VALUE self, uint8_t value, size_t offset, size_t length);
83
84// The length is the minimum required length.
85 VALUE rb_io_buffer_read(VALUE self, VALUE io, size_t length, size_t offset);
86 VALUE rb_io_buffer_pread(VALUE self, VALUE io, rb_off_t from, size_t length, size_t offset);
87 VALUE rb_io_buffer_write(VALUE self, VALUE io, size_t length, size_t offset);
88 VALUE rb_io_buffer_pwrite(VALUE self, VALUE io, rb_off_t from, size_t length, size_t offset);
89
90 RBIMPL_SYMBOL_EXPORT_END()
91
92#endif /* RUBY_IO_BUFFER_H */
RUBY_EXTERN
#define RUBY_EXTERN
Declaration of externally visible global variables.
Definition dllexport.h:47
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:106
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:97
ruby.h
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40