Ruby: include/ruby/internal/stdckdint.h Source File

Ruby 3.4.1p0 (2024-12-25 revision 48d4efcb85000e1ebae42004e963b5d0cedddcf2)

stdckdint.h
1#ifndef RBIMPL_STDCKDINT_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_STDCKDINT_H
22#include "ruby/internal/config.h"
23#include "ruby/internal/cast.h"
24#include "ruby/internal/has/builtin.h"
25#include "ruby/internal/stdbool.h"
26
27#ifdef __has_include
28# if __has_include(<stdckdint.h>)
29# /* Conforming C23 situation; e.g. recent clang */
30# define RBIMPL_HAVE_STDCKDINT_H
31# endif
32#endif
33
34#ifdef HAVE_STDCKDINT_H
35# /* Some OSes (most notably FreeBSD) have this file. */
36# define RBIMPL_HAVE_STDCKDINT_H
37#endif
38
39#ifdef __cplusplus
40# /* It seems OS/Compiler provided stdckdint.h tend not support C++ yet.
41# * Situations could improve someday but in a meantime let us work around.
42# */
43# undef RBIMPL_HAVE_STDCKDINT_H
44#endif
45
46#ifdef RBIMPL_HAVE_STDCKDINT_H
47# /* Take that. */
48# include <stdckdint.h>
49
50#elif RBIMPL_HAS_BUILTIN(__builtin_add_overflow)
51# define ckd_add(x, y, z) RBIMPL_CAST((bool)__builtin_add_overflow((y), (z), (x)))
52# define ckd_sub(x, y, z) RBIMPL_CAST((bool)__builtin_sub_overflow((y), (z), (x)))
53# define ckd_mul(x, y, z) RBIMPL_CAST((bool)__builtin_mul_overflow((y), (z), (x)))
54# define __STDC_VERSION_STDCKDINT_H__ 202311L
55
56#/* elif defined(__cplusplus) */
57#/* :TODO: if we assume C++11 we can use `<type_traits>` to implement them. */
58
59#else
60# /* intentionally leave them undefined */
61# /* to make `#ifdef ckd_add` etc. work as intended. */
62# undef ckd_add
63# undef ckd_sub
64# undef ckd_mul
65# undef __STDC_VERSION_STDCKDINT_H__
66#endif
67
68#endif /* RBIMPL_STDCKDINT_H */
builtin.h
Defines RBIMPL_HAS_BUILTIN.
stdbool.h
C99 shim for <stdbool.h>