Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
|
Memory management stuff. More...
#include "ruby/internal/config.h"
#include "ruby/internal/attr/alloc_size.h"
#include "ruby/internal/attr/const.h"
#include "ruby/internal/attr/constexpr.h"
#include "ruby/internal/attr/noalias.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/attr/restrict.h"
#include "ruby/internal/attr/returns_nonnull.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/has/builtin.h"
#include "ruby/internal/stdalign.h"
#include "ruby/internal/stdbool.h"
#include "ruby/internal/xmalloc.h"
#include "ruby/backward/2/limits.h"
#include "ruby/backward/2/long_long.h"
#include "ruby/backward/2/assume.h"
#include "ruby/defines.h"
Go to the source code of this file.
Data Structures | |
struct | rbimpl_size_mul_overflow_tag |
Macros | |
#define | DSIZE_T unsigned LONG_LONG |
#define | RUBY_ALLOCV_LIMIT 1024 |
#define | RB_GC_GUARD(v) |
#define | RB_ALLOC_N(type, n) RBIMPL_CAST((type *)ruby_xmalloc2((n), sizeof(type))) |
#define | RB_ALLOC(type) RBIMPL_CAST((type *)ruby_xmalloc(sizeof(type))) |
#define | RB_ZALLOC_N(type, n) RBIMPL_CAST((type *)ruby_xcalloc((n), sizeof(type))) |
#define | RB_ZALLOC(type) (RB_ZALLOC_N(type, 1)) |
#define | RB_REALLOC_N(var, type, n) ((var) = RBIMPL_CAST((type *)ruby_xrealloc2((void *)(var), (n), sizeof(type)))) |
#define | ALLOCA_N(type, n) RBIMPL_CAST((type *)(!(n) ? NULL : alloca(rbimpl_size_mul_or_raise(sizeof(type), (n))))) |
#define | RB_ALLOCV(v, n) |
#define | RB_ALLOCV_N(type, v, n) |
#define | RB_ALLOCV_END(v) rb_free_tmp_buffer(&(v)) |
#define | MEMZERO(p, type, n) memset((p), 0, rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define | MEMCPY(p1, p2, type, n) memcpy((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define | MEMMOVE(p1, p2, type, n) memmove((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define | MEMCMP(p1, p2, type, n) memcmp((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define | ALLOC_N RB_ALLOC_N |
#define | ALLOC RB_ALLOC |
#define | ZALLOC_N RB_ZALLOC_N |
#define | ZALLOC RB_ZALLOC |
#define | REALLOC_N RB_REALLOC_N |
#define | ALLOCV RB_ALLOCV |
#define | ALLOCV_N RB_ALLOCV_N |
#define | ALLOCV_END RB_ALLOCV_END |
#define | memcpy ruby_nonempty_memcpy |
Functions | |
void * | alloca (size_t) |
void * | rb_alloc_tmp_buffer (volatile VALUE *store, long len) |
void * | rb_alloc_tmp_buffer_with_count (volatile VALUE *store, size_t len, size_t count) |
void | rb_free_tmp_buffer (volatile VALUE *store) |
void | ruby_malloc_size_overflow (size_t, size_t) |
Memory management stuff.
RBIMPL
or rbimpl
are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will. __VA_ARGS__
is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98. Definition in file memory.h.
#define ALLOC_N RB_ALLOC_N |
#define ALLOCV_END RB_ALLOCV_END |
#define ALLOCV_N RB_ALLOCV_N |
#define MEMCMP | ( | p1, | |
p2, | |||
type, | |||
n | |||
) | memcmp((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define MEMCPY | ( | p1, | |
p2, | |||
type, | |||
n | |||
) | memcpy((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define MEMMOVE | ( | p1, | |
p2, | |||
type, | |||
n | |||
) | memmove((p1), (p2), rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define MEMZERO | ( | p, | |
type, | |||
n | |||
) | memset((p), 0, rbimpl_size_mul_or_raise(sizeof(type), (n))) |
#define RB_ALLOC | ( | type | ) | RBIMPL_CAST((type *)ruby_xmalloc(sizeof(type))) |
#define RB_ALLOC_N | ( | type, | |
n | |||
) | RBIMPL_CAST((type *)ruby_xmalloc2((n), sizeof(type))) |
#define RB_ALLOCV | ( | v, | |
n | |||
) |
#define RB_ALLOCV_END | ( | v | ) | rb_free_tmp_buffer(&(v)) |
#define RB_ALLOCV_N | ( | type, | |
v, | |||
n | |||
) |
#define RB_GC_GUARD | ( | v | ) |
#define RB_REALLOC_N | ( | var, | |
type, | |||
n | |||
) | ((var) = RBIMPL_CAST((type *)ruby_xrealloc2((void *)(var), (n), sizeof(type)))) |
#define RB_ZALLOC | ( | type | ) | (RB_ZALLOC_N(type, 1)) |
#define RB_ZALLOC_N | ( | type, | |
n | |||
) | RBIMPL_CAST((type *)ruby_xcalloc((n), sizeof(type))) |
#define REALLOC_N RB_REALLOC_N |
#define ZALLOC_N RB_ZALLOC_N |
void * alloca | ( | size_t | ) |
Definition at line 11007 of file gc.c.
References cnt, len, rb_alloc_tmp_buffer_with_count(), rb_eArgError, rb_raise(), and roomof.
void * rb_alloc_tmp_buffer_with_count | ( | volatile VALUE * | store, |
size_t | len, | ||
size_t | count | ||
) |
Definition at line 10989 of file gc.c.
References rb_imemo_tmpbuf_struct::cnt, cnt, imemo, NULL, ptr, and rb_imemo_tmpbuf_struct::ptr.
Referenced by rb_alloc_tmp_buffer().
void rb_free_tmp_buffer | ( | volatile VALUE * | store | ) |
Definition at line 11019 of file gc.c.
References ATOMIC_PTR_EXCHANGE, ATOMIC_VALUE_EXCHANGE, rb_imemo_tmpbuf_struct::cnt, ptr, rb_imemo_tmpbuf_struct::ptr, and ruby_xfree().
void ruby_malloc_size_overflow | ( | size_t | count, |
size_t | elsize | ||
) |
Definition at line 10838 of file gc.c.
References count, PRIuSIZE, rb_eArgError, and rb_raise().