mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
split internal.h into files
One day, I could not resist the way it was written. I finally started to make the code clean. This changeset is the beginning of a series of housekeeping commits. It is a simple refactoring; split internal.h into files, so that we can divide and concur in the upcoming commits. No lines of codes are either added or removed, except the obvious file headers/footers. The generated binary is identical to the one before.
This commit is contained in:
parent
ba78bf9778
commit
b739a63eb4
Notes:
git
2019-12-26 20:46:08 +09:00
55 changed files with 3449 additions and 2656 deletions
87
internal/compilers.h
Normal file
87
internal/compilers.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
#ifndef INTERNAL_COMPILERS_H /* -*- C -*- */
|
||||
#define INTERNAL_COMPILERS_H
|
||||
/**
|
||||
* @file
|
||||
* @brief Internal header absorbing C compipler differences.
|
||||
* @author \@shyouhei
|
||||
* @copyright This file is a part of the programming language Ruby.
|
||||
* Permission is hereby granted, to either redistribute and/or
|
||||
* modify this file, provided that the conditions mentioned in the
|
||||
* file COPYING are met. Consult the file for details.
|
||||
*/
|
||||
|
||||
#ifndef MAYBE_UNUSED
|
||||
# define MAYBE_UNUSED(x) x
|
||||
#endif
|
||||
|
||||
#ifndef WARN_UNUSED_RESULT
|
||||
# define WARN_UNUSED_RESULT(x) x
|
||||
#endif
|
||||
|
||||
#ifndef __has_feature
|
||||
# define __has_feature(x) 0
|
||||
#endif
|
||||
|
||||
#ifndef __has_extension
|
||||
# define __has_extension __has_feature
|
||||
#endif
|
||||
|
||||
#define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
|
||||
#define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
|
||||
#ifdef __GNUC__
|
||||
#define rb_obj_builtin_type(obj) \
|
||||
__extension__({ \
|
||||
VALUE arg_obj = (obj); \
|
||||
RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
|
||||
RB_BUILTIN_TYPE(arg_obj); \
|
||||
})
|
||||
#else
|
||||
static inline int
|
||||
rb_obj_builtin_type(VALUE obj)
|
||||
{
|
||||
return RB_SPECIAL_CONST_P(obj) ? -1 :
|
||||
RB_BUILTIN_TYPE(obj);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||
# define FLEX_ARY_LEN /* VALUE ary[]; */
|
||||
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
# define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
|
||||
#else
|
||||
# define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For declaring bitfields out of non-unsigned int types:
|
||||
* struct date {
|
||||
* BITFIELD(enum months, month, 4);
|
||||
* ...
|
||||
* };
|
||||
*/
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||
# define BITFIELD(type, name, size) type name : size
|
||||
#else
|
||||
# define BITFIELD(type, name, size) unsigned int name : size
|
||||
#endif
|
||||
|
||||
#if defined(USE_UNALIGNED_MEMBER_ACCESS) && USE_UNALIGNED_MEMBER_ACCESS && \
|
||||
(defined(__clang__) || GCC_VERSION_SINCE(9, 0, 0))
|
||||
#include "warnings.h"
|
||||
# define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \
|
||||
COMPILER_WARNING_PUSH; \
|
||||
COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \
|
||||
typeof(expr) unaligned_member_access_result = (expr); \
|
||||
COMPILER_WARNING_POP; \
|
||||
unaligned_member_access_result; \
|
||||
})
|
||||
#else
|
||||
# define UNALIGNED_MEMBER_ACCESS(expr) expr
|
||||
#endif
|
||||
#define UNALIGNED_MEMBER_PTR(ptr, mem) UNALIGNED_MEMBER_ACCESS(&(ptr)->mem)
|
||||
|
||||
#undef RB_OBJ_WRITE
|
||||
#define RB_OBJ_WRITE(a, slot, b) UNALIGNED_MEMBER_ACCESS(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__))
|
||||
|
||||
#endif /* INTERNAL_COMPILERS_H */
|
Loading…
Add table
Add a link
Reference in a new issue