Ruby 4.1.0dev (2026-04-04 revision 3b6245536cf55da9e8bfcdb03c845fe9ef931d7f)
xmalloc.h
Go to the documentation of this file.
1#ifndef RBIMPL_XMALLOC_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_XMALLOC_H
23#include "ruby/internal/config.h"
24
25#ifdef STDC_HEADERS
26# include <stddef.h>
27#endif
28
29#ifdef HAVE_STDLIB_H
30# include <stdlib.h>
31#endif
32
39
49#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS
50# define USE_GC_MALLOC_OBJ_INFO_DETAILS 0
51#endif
52
53#define xmalloc ruby_xmalloc
54#define xmalloc2 ruby_xmalloc2
55#define xcalloc ruby_xcalloc
56#define xrealloc ruby_xrealloc
57#define xrealloc2 ruby_xrealloc2
58#define xfree ruby_xfree
60#define xfree_sized ruby_xfree_sized
61#define xrealloc_sized ruby_xrealloc_sized
62#define xrealloc2_sized ruby_xrealloc2_sized
63
65
90void *ruby_xmalloc(size_t size)
91RBIMPL_ATTR_NOEXCEPT(malloc(size))
92;
93
121void *ruby_xmalloc2(size_t nelems, size_t elemsiz)
122RBIMPL_ATTR_NOEXCEPT(malloc(nelems * elemsiz))
123;
124
151void *ruby_xcalloc(size_t nelems, size_t elemsiz)
152RBIMPL_ATTR_NOEXCEPT(calloc(nelems, elemsiz))
153;
154
197void *ruby_xrealloc(void *ptr, size_t newsiz)
198RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newsiz))
199;
200
249void *ruby_xrealloc_sized(void *ptr, size_t newsiz, size_t oldsiz)
250RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newsiz))
251;
252
306void *ruby_xrealloc2(void *ptr, size_t newelems, size_t newsiz)
307RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz))
308;
309
364void *ruby_xrealloc2_sized(void *ptr, size_t newelems, size_t newsiz, size_t oldelems)
365RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz))
366;
367
396void ruby_xfree(void *ptr)
397RBIMPL_ATTR_NOEXCEPT(free(ptr))
398;
399
432void ruby_xfree_sized(void *ptr, size_t size)
433RBIMPL_ATTR_NOEXCEPT(free(ptr))
434;
435
436
438
439#endif /* RBIMPL_XMALLOC_H */
Defines RBIMPL_ATTR_ALLOC_SIZE.
#define RBIMPL_ATTR_ALLOC_SIZE(tuple)
Wraps (or simulates) __attribute__((alloc_size))
Definition alloc_size.h:29
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
Defines RBIMPL_ATTR_NODISCARD.
#define RBIMPL_ATTR_NODISCARD()
Wraps (or simulates) [[nodiscard]].
Definition nodiscard.h:42
Defines RBIMPL_ATTR_NOEXCEPT.
#define RBIMPL_ATTR_NOEXCEPT(_)
Wraps (or simulates) C++11 noexcept
Definition noexcept.h:85
Defines RBIMPL_ATTR_RESTRICT.
#define RBIMPL_ATTR_RESTRICT()
Wraps (or simulates) __declspec(restrict)
Definition restrict.h:41
Defines RBIMPL_ATTR_RETURNS_NONNULL.
#define RBIMPL_ATTR_RETURNS_NONNULL()
Wraps (or simulates) __attribute__((returns_nonnull))
void * ruby_xrealloc(void *ptr, size_t newsiz)
Resize the storage instance.
Definition gc.c:5448
void * ruby_xrealloc2(void *ptr, size_t newelems, size_t newsiz)
Identical to ruby_xrealloc(), except it resizes the given storage instance to newelems * newsiz bytes...
Definition gc.c:5472
void ruby_xfree(void *ptr)
Deallocates a storage instance.
Definition gc.c:5497
void * ruby_xrealloc_sized(void *ptr, size_t newsiz, size_t oldsiz)
Identical to ruby_xrealloc(), except that it takes the old storage size as third argument.
Definition gc.c:5432
void * ruby_xmalloc2(size_t nelems, size_t elemsiz)
Identical to ruby_xmalloc(), except it allocates nelems * elemsiz bytes.
Definition gc.c:5401
void * ruby_xmalloc(size_t size)
Allocates a storage instance.
Definition gc.c:5359
void * ruby_xcalloc(size_t nelems, size_t elemsiz)
Identical to ruby_xmalloc2(), except it returns a zero-filled storage instance.
Definition gc.c:5415
void * ruby_xrealloc2_sized(void *ptr, size_t newelems, size_t newsiz, size_t oldelems)
Identical to ruby_xrealloc2(), except it takes the old elements count.
Definition gc.c:5459