1#ifndef RBIMPL_XMALLOC_H
2#define RBIMPL_XMALLOC_H
23#include "ruby/internal/config.h"
49#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS
50# define USE_GC_MALLOC_OBJ_INFO_DETAILS 0
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
286#if USE_GC_MALLOC_OBJ_INFO_DETAILS
287# define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__)
288# define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__)
289# define ruby_xcalloc(s1, s2) ruby_xcalloc_with_location(s1, s2, __FILE__, __LINE__)
290# define ruby_xrealloc(ptr, s1) ruby_xrealloc_with_location(ptr, s1, __FILE__, __LINE__)
291# define ruby_xrealloc2(ptr, s1, s2) ruby_xrealloc2_with_location(ptr, s1, s2, __FILE__, __LINE__)
297void *ruby_xmalloc_body(
size_t size)
305void *ruby_xmalloc2_body(
size_t nelems,
size_t elemsiz)
313void *ruby_xcalloc_body(
size_t nelems,
size_t elemsiz)
320void *ruby_xrealloc_body(
void *ptr,
size_t newsiz)
327void *ruby_xrealloc2_body(
void *ptr,
size_t newelems,
size_t newsiz)
335ruby_xmalloc_with_location(
size_t s, const
char *file,
int line)
338 ruby_malloc_info_file = file;
339 ruby_malloc_info_line = line;
340 ptr = ruby_xmalloc_body(s);
341 ruby_malloc_info_file = NULL;
346ruby_xmalloc2_with_location(
size_t s1,
size_t s2,
const char *file,
int line)
349 ruby_malloc_info_file = file;
350 ruby_malloc_info_line = line;
351 ptr = ruby_xmalloc2_body(s1, s2);
352 ruby_malloc_info_file = NULL;
357ruby_xcalloc_with_location(
size_t s1,
size_t s2,
const char *file,
int line)
360 ruby_malloc_info_file = file;
361 ruby_malloc_info_line = line;
362 ptr = ruby_xcalloc_body(s1, s2);
363 ruby_malloc_info_file = NULL;
368ruby_xrealloc_with_location(
void *ptr,
size_t s,
const char *file,
int line)
371 ruby_malloc_info_file = file;
372 ruby_malloc_info_line = line;
373 rptr = ruby_xrealloc_body(ptr, s);
374 ruby_malloc_info_file = NULL;
379ruby_xrealloc2_with_location(
void *ptr,
size_t s1,
size_t s2,
const char *file,
int line)
382 ruby_malloc_info_file = file;
383 ruby_malloc_info_line = line;
384 rptr = ruby_xrealloc2_body(ptr, s1, s2);
385 ruby_malloc_info_file = NULL;
Defines RBIMPL_ATTR_ALLOC_SIZE.
#define RBIMPL_ATTR_ALLOC_SIZE(tuple)
Wraps (or simulates) __attribute__((alloc_size))
Tweaking visibility of C variables/functions.
#define RUBY_EXTERN
Declaration of externally visible global variables.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Defines RBIMPL_ATTR_NODISCARD.
#define RBIMPL_ATTR_NODISCARD()
Wraps (or simulates) [[nodiscard]].
Defines RBIMPL_ATTR_NOEXCEPT.
#define RBIMPL_ATTR_NOEXCEPT(_)
Wraps (or simulates) C++11 noexcept
Defines RBIMPL_ATTR_RESTRICT.
#define RBIMPL_ATTR_RESTRICT()
Wraps (or simulates) __declspec(restrict)
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.
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...
void ruby_xfree(void *ptr)
Deallocates a storage instance.
void * ruby_xmalloc2(size_t nelems, size_t elemsiz)
Identical to ruby_xmalloc(), except it allocates nelems * elemsiz bytes.
void * ruby_xmalloc(size_t size)
Allocates a storage instance.
void * ruby_xcalloc(size_t nelems, size_t elemsiz)
Identical to ruby_xmalloc2(), except it returns a zero-filled storage instance.