Ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5ad0e4688e963d9de019557c78feed9)
defines.h
Go to the documentation of this file.
1/************************************************
2
3 defines.h -
4
5 $Author$
6 created at: Wed May 18 00:21:44 JST 1994
7
8************************************************/
9
10#ifndef RUBY_DEFINES_H
11#define RUBY_DEFINES_H 1
12
13#if defined(__cplusplus)
14extern "C" {
15#if 0
16} /* satisfy cc-mode */
17#endif
18#endif
19
20#include "ruby/config.h"
21#ifdef RUBY_EXTCONF_H
22#include RUBY_EXTCONF_H
23#endif
24
25/* function attributes */
26#ifndef CONSTFUNC
27# define CONSTFUNC(x) x
28#endif
29#ifndef PUREFUNC
30# define PUREFUNC(x) x
31#endif
32#ifndef DEPRECATED
33# define DEPRECATED(x) x
34#endif
35#ifndef DEPRECATED_BY
36# define DEPRECATED_BY(n,x) DEPRECATED(x)
37#endif
38#ifndef DEPRECATED_TYPE
39# define DEPRECATED_TYPE(mesg, decl) decl
40#endif
41#ifndef RUBY_CXX_DEPRECATED
42# define RUBY_CXX_DEPRECATED(mesg) /* nothing */
43#endif
44#ifndef NOINLINE
45# define NOINLINE(x) x
46#endif
47#ifndef ALWAYS_INLINE
48# define ALWAYS_INLINE(x) x
49#endif
50#ifndef ERRORFUNC
51# define HAVE_ATTRIBUTE_ERRORFUNC 0
52# define ERRORFUNC(mesg, x) x
53#else
54# define HAVE_ATTRIBUTE_ERRORFUNC 1
55#endif
56#ifndef WARNINGFUNC
57# define HAVE_ATTRIBUTE_WARNINGFUNC 0
58# define WARNINGFUNC(mesg, x) x
59#else
60# define HAVE_ATTRIBUTE_WARNINGFUNC 1
61#endif
62
63#ifndef GCC_VERSION_SINCE
64# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
65# define GCC_VERSION_SINCE(major, minor, patchlevel) \
66 ((__GNUC__ > (major)) || \
67 ((__GNUC__ == (major) && \
68 ((__GNUC_MINOR__ > (minor)) || \
69 (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))))
70# else
71# define GCC_VERSION_SINCE(major, minor, patchlevel) 0
72# endif
73#endif
74#ifndef GCC_VERSION_BEFORE
75# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
76# define GCC_VERSION_BEFORE(major, minor, patchlevel) \
77 ((__GNUC__ < (major)) || \
78 ((__GNUC__ == (major) && \
79 ((__GNUC_MINOR__ < (minor)) || \
80 (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ <= (patchlevel))))))
81# else
82# define GCC_VERSION_BEFORE(major, minor, patchlevel) 0
83# endif
84#endif
85
86/* likely */
87#if __GNUC__ >= 3
88#define RB_LIKELY(x) (__builtin_expect(!!(x), 1))
89#define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0))
90#else /* __GNUC__ >= 3 */
91#define RB_LIKELY(x) (x)
92#define RB_UNLIKELY(x) (x)
93#endif /* __GNUC__ >= 3 */
94
95/*
96 cold attribute for code layout improvements
97 RUBY_FUNC_ATTRIBUTE not used because MSVC does not like nested func macros
98 */
99#if defined(__clang__) || GCC_VERSION_SINCE(4, 3, 0)
100#define COLDFUNC __attribute__((cold))
101#else
102#define COLDFUNC
103#endif
104
105#ifdef __GNUC__
106#if defined __MINGW_PRINTF_FORMAT
107#define PRINTF_ARGS(decl, string_index, first_to_check) \
108 decl __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check)))
109#else
110#define PRINTF_ARGS(decl, string_index, first_to_check) \
111 decl __attribute__((format(printf, string_index, first_to_check)))
112#endif
113#else
114#define PRINTF_ARGS(decl, string_index, first_to_check) decl
115#endif
116
117#ifdef __GNUC__
118#define RB_GNUC_EXTENSION __extension__
119#define RB_GNUC_EXTENSION_BLOCK(x) __extension__ ({ x; })
120#else
121#define RB_GNUC_EXTENSION
122#define RB_GNUC_EXTENSION_BLOCK(x) (x)
123#endif
124
125/* AC_INCLUDES_DEFAULT */
126#include <stdio.h>
127#ifdef HAVE_SYS_TYPES_H
128# include <sys/types.h>
129#endif
130#ifdef HAVE_SYS_STAT_H
131# include <sys/stat.h>
132#endif
133#ifdef STDC_HEADERS
134# include <stdlib.h>
135# include <stddef.h>
136#else
137# ifdef HAVE_STDLIB_H
138# include <stdlib.h>
139# endif
140#endif
141#ifdef HAVE_STRING_H
142# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
143# include <memory.h>
144# endif
145# include <string.h>
146#endif
147#ifdef HAVE_STRINGS_H
148# include <strings.h>
149#endif
150#ifdef HAVE_INTTYPES_H
151# include <inttypes.h>
152#endif
153#ifdef HAVE_STDINT_H
154# include <stdint.h>
155#endif
156#ifdef HAVE_STDALIGN_H
157# include <stdalign.h>
158#endif
159#ifdef HAVE_UNISTD_H
160# include <unistd.h>
161#endif
162
163#ifdef HAVE_SYS_SELECT_H
164# include <sys/select.h>
165#endif
166
167#ifdef RUBY_USE_SETJMPEX
168#include <setjmpex.h>
169#endif
170
171#include "ruby/missing.h"
172
173#define RUBY
174
175#ifdef __cplusplus
176# ifndef HAVE_PROTOTYPES
177# define HAVE_PROTOTYPES 1
178# endif
179# ifndef HAVE_STDARG_PROTOTYPES
180# define HAVE_STDARG_PROTOTYPES 1
181# endif
182#endif
183
184#undef _
185#ifdef HAVE_PROTOTYPES
186# define _(args) args
187#else
188# define _(args) ()
189#endif
190
191#undef __
192#ifdef HAVE_STDARG_PROTOTYPES
193# define __(args) args
194#else
195# define __(args) ()
196#endif
197
198#ifdef __cplusplus
199#define ANYARGS ...
200#else
201#define ANYARGS
202#endif
203
204#ifndef RUBY_SYMBOL_EXPORT_BEGIN
205# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
206# define RUBY_SYMBOL_EXPORT_END /* end */
207#endif
208
210
211#define xmalloc ruby_xmalloc
212#define xmalloc2 ruby_xmalloc2
213#define xcalloc ruby_xcalloc
214#define xrealloc ruby_xrealloc
215#define xrealloc2 ruby_xrealloc2
216#define xfree ruby_xfree
217
218#if GCC_VERSION_SINCE(4,3,0)
219# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((alloc_size params))
220#elif defined(__has_attribute)
221# if __has_attribute(alloc_size)
222# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__((__alloc_size__ params))
223# endif
224#endif
225#ifndef RUBY_ATTR_ALLOC_SIZE
226# define RUBY_ATTR_ALLOC_SIZE(params)
227#endif
228
229#ifdef __has_attribute
230# if __has_attribute(malloc)
231# define RUBY_ATTR_MALLOC __attribute__((__malloc__))
232# endif
233#endif
234#ifndef RUBY_ATTR_MALLOC
235# define RUBY_ATTR_MALLOC
236#endif
237
238#ifdef __has_attribute
239# if __has_attribute(returns_nonnull)
240# define RUBY_ATTR_RETURNS_NONNULL __attribute__((__returns_nonnull__))
241# endif
242#endif
243#ifndef RUBY_ATTR_RETURNS_NONNULL
244# define RUBY_ATTR_RETURNS_NONNULL
245#endif
246
252void ruby_xfree(void*);
253
254#ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS
255#define USE_GC_MALLOC_OBJ_INFO_DETAILS 0
256#endif
257
258#if USE_GC_MALLOC_OBJ_INFO_DETAILS
259
265
266#define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__)
267#define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__)
268#define ruby_xcalloc(s1, s2) ruby_xcalloc_with_location(s1, s2, __FILE__, __LINE__)
269#define ruby_xrealloc(ptr, s1) ruby_xrealloc_with_location(ptr, s1, __FILE__, __LINE__)
270#define ruby_xrealloc2(ptr, s1, s2) ruby_xrealloc2_with_location(ptr, s1, s2, __FILE__, __LINE__)
271
272extern const char *ruby_malloc_info_file;
273extern int ruby_malloc_info_line;
274
275static inline void *
276ruby_xmalloc_with_location(size_t s, const char *file, int line)
277{
278 void *ptr;
279 ruby_malloc_info_file = file;
280 ruby_malloc_info_line = line;
282 ruby_malloc_info_file = NULL;
283 return ptr;
284}
285
286static inline void *
287ruby_xmalloc2_with_location(size_t s1, size_t s2, const char *file, int line)
288{
289 void *ptr;
290 ruby_malloc_info_file = file;
291 ruby_malloc_info_line = line;
293 ruby_malloc_info_file = NULL;
294 return ptr;
295}
296
297static inline void *
298ruby_xcalloc_with_location(size_t s1, size_t s2, const char *file, int line)
299{
300 void *ptr;
301 ruby_malloc_info_file = file;
302 ruby_malloc_info_line = line;
303 ptr = ruby_xcalloc_body(s1, s2);
304 ruby_malloc_info_file = NULL;
305 return ptr;
306}
307
308static inline void *
309ruby_xrealloc_with_location(void *ptr, size_t s, const char *file, int line)
310{
311 void *rptr;
312 ruby_malloc_info_file = file;
313 ruby_malloc_info_line = line;
314 rptr = ruby_xrealloc_body(ptr, s);
315 ruby_malloc_info_file = NULL;
316 return rptr;
317}
318
319static inline void *
320ruby_xrealloc2_with_location(void *ptr, size_t s1, size_t s2, const char *file, int line)
321{
322 void *rptr;
323 ruby_malloc_info_file = file;
324 ruby_malloc_info_line = line;
325 rptr = ruby_xrealloc2_body(ptr, s1, s2);
326 ruby_malloc_info_file = NULL;
327 return rptr;
328}
329#endif
330
331#define STRINGIZE(expr) STRINGIZE0(expr)
332#ifndef STRINGIZE0
333#define STRINGIZE0(expr) #expr
334#endif
335
336#ifdef HAVE_LONG_LONG
337# define HAVE_TRUE_LONG_LONG 1
338#endif
339
340#if SIZEOF_LONG_LONG > 0
341# define LONG_LONG long long
342#elif SIZEOF___INT64 > 0
343# define HAVE_LONG_LONG 1
344# define LONG_LONG __int64
345# undef SIZEOF_LONG_LONG
346# define SIZEOF_LONG_LONG SIZEOF___INT64
347#endif
348
349#ifdef __CYGWIN__
350#undef _WIN32
351#endif
352
353#if defined(_WIN32)
354/*
355 DOSISH mean MS-Windows style filesystem.
356 But you should use more precise macros like DOSISH_DRIVE_LETTER, PATH_SEP,
357 ENV_IGNORECASE or CASEFOLD_FILESYSTEM.
358 */
359#define DOSISH 1
360# define DOSISH_DRIVE_LETTER
361#endif
362
363#ifdef AC_APPLE_UNIVERSAL_BUILD
364#undef WORDS_BIGENDIAN
365#ifdef __BIG_ENDIAN__
366#define WORDS_BIGENDIAN
367#endif
368#endif
369
370#ifdef _WIN32
371#include "ruby/win32.h"
372#endif
373
374#ifdef RUBY_EXPORT
375#undef RUBY_EXTERN
376
377#ifndef FALSE
378# define FALSE 0
379#elif FALSE
380# error FALSE must be false
381#endif
382#ifndef TRUE
383# define TRUE 1
384#elif !TRUE
385# error TRUE must be true
386#endif
387
388#endif
389
390#ifndef RUBY_FUNC_EXPORTED
391#define RUBY_FUNC_EXPORTED
392#endif
393
394/* These macros are used for functions which are exported only for MJIT
395 and NOT ensured to be exported in future versions. */
396#define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED
397#define MJIT_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN
398#define MJIT_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END
399
400#if defined(MJIT_HEADER) && defined(_MSC_VER)
401# undef MJIT_FUNC_EXPORTED
402# define MJIT_FUNC_EXPORTED static
403#endif
404
405#ifndef RUBY_EXTERN
406#define RUBY_EXTERN extern
407#endif
408
409#ifndef EXTERN
410# if defined __GNUC__
411# define EXTERN _Pragma("message \"EXTERN is deprecated, use RUBY_EXTERN instead\""); \
412 RUBY_EXTERN
413# elif defined _MSC_VER
414# define EXTERN __pragma(message(__FILE__"("STRINGIZE(__LINE__)"): warning: "\
415 "EXTERN is deprecated, use RUBY_EXTERN instead")); \
416 RUBY_EXTERN
417# else
418# define EXTERN <-<-"EXTERN is deprecated, use RUBY_EXTERN instead"->->
419# endif
420#endif
421
422#ifndef RUBY_MBCHAR_MAXSIZE
423#define RUBY_MBCHAR_MAXSIZE INT_MAX
424 /* MB_CUR_MAX will not work well in C locale */
425#endif
426
427#if defined(__sparc)
429# define FLUSH_REGISTER_WINDOWS rb_sparc_flush_register_windows()
430#else
431# define FLUSH_REGISTER_WINDOWS ((void)0)
432#endif
433
434#if defined(DOSISH)
435#define PATH_SEP ";"
436#else
437#define PATH_SEP ":"
438#endif
439#define PATH_SEP_CHAR PATH_SEP[0]
440
441#define PATH_ENV "PATH"
442
443#if defined(DOSISH)
444#define ENV_IGNORECASE
445#endif
446
447#ifndef CASEFOLD_FILESYSTEM
448# if defined DOSISH
449# define CASEFOLD_FILESYSTEM 1
450# else
451# define CASEFOLD_FILESYSTEM 0
452# endif
453#endif
454
455#ifndef DLEXT_MAXLEN
456#define DLEXT_MAXLEN 4
457#endif
458
459#ifndef RUBY_PLATFORM
460#define RUBY_PLATFORM "unknown-unknown"
461#endif
462
463#ifndef FUNC_MINIMIZED
464#define FUNC_MINIMIZED(x) x
465#endif
466#ifndef FUNC_UNOPTIMIZED
467#define FUNC_UNOPTIMIZED(x) x
468#endif
469#ifndef RUBY_ALIAS_FUNCTION_TYPE
470#define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) \
471 FUNC_MINIMIZED(type prot) {return (type)name args;}
472#endif
473#ifndef RUBY_ALIAS_FUNCTION_VOID
474#define RUBY_ALIAS_FUNCTION_VOID(prot, name, args) \
475 FUNC_MINIMIZED(void prot) {name args;}
476#endif
477#ifndef RUBY_ALIAS_FUNCTION
478#define RUBY_ALIAS_FUNCTION(prot, name, args) \
479 RUBY_ALIAS_FUNCTION_TYPE(VALUE, prot, name, args)
480#endif
481#ifndef RUBY_FUNC_NONNULL
482#define RUBY_FUNC_NONNULL(n, x) x
483#endif
484
485#ifndef UNALIGNED_WORD_ACCESS
486# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
487 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
488 defined(__powerpc64__) || \
489 defined(__aarch64__) || \
490 defined(__mc68020__)
491# define UNALIGNED_WORD_ACCESS 1
492# else
493# define UNALIGNED_WORD_ACCESS 0
494# endif
495#endif
496#ifndef PACKED_STRUCT
497# define PACKED_STRUCT(x) x
498#endif
499#ifndef PACKED_STRUCT_UNALIGNED
500# if UNALIGNED_WORD_ACCESS
501# define PACKED_STRUCT_UNALIGNED(x) PACKED_STRUCT(x)
502# else
503# define PACKED_STRUCT_UNALIGNED(x) x
504# endif
505#endif
506
507#ifndef RUBY_ALIGNAS
508#define RUBY_ALIGNAS(x) /* x */
509#endif
510
511#ifdef RUBY_ALIGNOF
512/* OK, take that definition */
513#elif defined(__cplusplus) && (__cplusplus >= 201103L)
514#define RUBY_ALIGNOF alignof
515#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
516#define RUBY_ALIGNOF _Alignof
517#else
518#define RUBY_ALIGNOF(type) ((size_t)offsetof(struct { char f1; type f2; }, f2))
519#endif
520
521#define NORETURN_STYLE_NEW 1
522#ifdef NORETURN
523/* OK, take that definition */
524#elif defined(__cplusplus) && (__cplusplus >= 201103L)
525#define NORETURN(x) [[ noreturn ]] x
526#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
527#define NORETURN(x) _Noreturn x
528#else
529#define NORETURN(x) x
530#endif
531
533
534#if defined(__cplusplus)
535#if 0
536{ /* satisfy cc-mode */
537#endif
538} /* extern "C" { */
539#endif
540
541#endif /* RUBY_DEFINES_H */
struct RIMemo * ptr
Definition: debug.c:65
#define RUBY_ATTR_ALLOC_SIZE(params)
Definition: defines.h:226
void * ruby_xrealloc2(void *, size_t, size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2
void void void * ruby_xrealloc(void *, size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2))
Definition: gc.c:12038
void void * ruby_xcalloc(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1
#define RUBY_ATTR_MALLOC
Definition: defines.h:235
#define RUBY_ATTR_RETURNS_NONNULL
Definition: defines.h:244
void * ruby_xmalloc(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1))
Definition: gc.c:12008
void * ruby_xmalloc2(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1
void void ruby_xfree(void *)
Definition: gc.c:10183
void * ruby_xmalloc2_body(size_t n, size_t size)
Definition: gc.c:10115
void * ruby_xrealloc_body(void *ptr, size_t new_size)
Definition: gc.c:10150
void * ruby_xmalloc_body(size_t size)
Definition: gc.c:10098
void * ruby_xcalloc_body(size_t n, size_t size)
Definition: gc.c:10131
void * ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
Definition: gc.c:10166
#define NULL
#define RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_END
const char * s2
void rb_sparc_flush_register_windows(void)
Definition: sparc.c:13