| 1 |
#ifndef RBIMPL_ARITHMETIC_SIZE_T_H /*-*-C++-*-vi:se ft=cpp:*/ |
| 2 |
#define RBIMPL_ARITHMETIC_SIZE_T_H |
| 3 |
/** |
| 4 |
* @file |
| 5 |
* @author Ruby developers <[email protected]> |
| 6 |
* @copyright This file is a part of the programming language Ruby. |
| 7 |
* Permission is hereby granted, to either redistribute and/or |
| 8 |
* modify this file, provided that the conditions mentioned in the |
| 9 |
* file COPYING are met. Consult the file for details. |
| 10 |
* @warning Symbols prefixed with either `RBIMPL` or `rbimpl` are |
| 11 |
* implementation details. Don't take them as canon. They could |
| 12 |
* rapidly appear then vanish. The name (path) of this header file |
| 13 |
* is also an implementation detail. Do not expect it to persist |
| 14 |
* at the place it is now. Developers are free to move it anywhere |
| 15 |
* anytime at will. |
| 16 |
* @note To ruby-core: remember that this header can be possibly |
| 17 |
* recursively included from extension libraries written in C++. |
| 18 |
* Do not expect for instance `__VA_ARGS__` is always available. |
| 19 |
* We assume C99 for ruby itself but we don't assume languages of |
| 20 |
* extension libraries. They could be written in C++98. |
| 21 |
* @brief Arithmetic conversion between C's `size_t` and Ruby's. |
| 22 |
*/ |
| 23 |
#include "ruby/internal/config.h" |
| 24 |
#include "ruby/internal/arithmetic/int.h" |
| 25 |
#include "ruby/internal/arithmetic/long.h" |
| 26 |
#include "ruby/internal/arithmetic/long_long.h" |
| 27 |
#include "ruby/backward/2/long_long.h" |
| 28 |
|
| 29 |
#if defined(__DOXYGEN__) |
| 30 |
# /** Converts a C's `size_t` into an instance of ::rb_cInteger. */ |
| 31 |
# define RB_SIZE2NUM RB_ULONG2NUM |
| 32 |
# /** Converts a C's `ssize_t` into an instance of ::rb_cInteger. */ |
| 33 |
# define RB_SSIZE2NUM RB_LONG2NUM |
| 34 |
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG |
| 35 |
# define RB_SIZE2NUM RB_ULL2NUM |
| 36 |
# define RB_SSIZE2NUM RB_LL2NUM |
| 37 |
#elif SIZEOF_SIZE_T == SIZEOF_LONG |
| 38 |
# define RB_SIZE2NUM RB_ULONG2NUM |
| 39 |
# define RB_SSIZE2NUM RB_LONG2NUM |
| 40 |
#else |
| 41 |
# define RB_SIZE2NUM RB_UINT2NUM |
| 42 |
# define RB_SSIZE2NUM RB_INT2NUM |
| 43 |
#endif |
| 44 |
|
| 45 |
#if defined(__DOXYGEN__) |
| 46 |
# /** Converts an instance of ::rb_cInteger into C's `size_t`. */ |
| 47 |
# define RB_NUM2SIZE RB_NUM2ULONG |
| 48 |
# /** Converts an instance of ::rb_cInteger into C's `ssize_t`. */ |
| 49 |
# define RB_NUM2SSIZE RB_NUM2LONG |
| 50 |
#elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG |
| 51 |
# define RB_NUM2SIZE RB_NUM2ULL |
| 52 |
# define RB_NUM2SSIZE RB_NUM2LL |
| 53 |
#elif SIZEOF_SIZE_T == SIZEOF_LONG |
| 54 |
# define RB_NUM2SIZE RB_NUM2ULONG |
| 55 |
# define RB_NUM2SSIZE RB_NUM2LONG |
| 56 |
#else |
| 57 |
# define RB_NUM2SIZE RB_NUM2UINT |
| 58 |
# define RB_NUM2SSIZE RB_NUM2INT |
| 59 |
#endif |
| 60 |
|
| 61 |
#define NUM2SIZET RB_NUM2SIZE /**< @old{RB_NUM2SIZE} */ |
| 62 |
#define SIZET2NUM RB_SIZE2NUM /**< @old{RB_SIZE2NUM} */ |
| 63 |
#define NUM2SSIZET RB_NUM2SSIZE /**< @old{RB_NUM2SSIZE} */ |
| 64 |
#define SSIZET2NUM RB_SSIZE2NUM /**< @old{RB_SSIZE2NUM} */ |
| 65 |
|
| 66 |
#endif /* RBIMPL_ARITHMETIC_SIZE_T_H */ |