Ruby 3.5.0dev (2025-01-10 revision 5fab31b15e32622c4b71d1d347a41937e9f9c212)
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"
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 */
Defines RBIMPL_HAS_BUILTIN.
C99 shim for <stdbool.h>