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

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

symbol.h
Go to the documentation of this file.
1#ifndef RBIMPL_SYMBOL_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_SYMBOL_H
23#include "ruby/internal/config.h"
24
25#ifdef HAVE_STDDEF_H
26# include <stddef.h>
27#endif
28
29#ifdef HAVE_STRING_H
30# include <string.h>
31#endif
32
33#include "ruby/internal/attr/nonnull.h"
34#include "ruby/internal/attr/pure.h"
35#include "ruby/internal/attr/noalias.h"
36#include "ruby/internal/cast.h"
37#include "ruby/internal/constant_p.h"
38#include "ruby/internal/dllexport.h"
39#include "ruby/internal/has/builtin.h"
40#include "ruby/internal/value.h"
41
42#define RB_ID2SYM rb_id2sym
43#define RB_SYM2ID rb_sym2id
44#define ID2SYM RB_ID2SYM
45#define SYM2ID RB_SYM2ID
46#define CONST_ID_CACHE RUBY_CONST_ID_CACHE
47#define CONST_ID RUBY_CONST_ID
48
50#define rb_intern_const rb_intern_const
53 RBIMPL_SYMBOL_EXPORT_BEGIN()
54 ID rb_sym2id(VALUE);
55 VALUE rb_id2sym(ID);
56 ID rb_intern(const char*);
57 ID rb_intern2(const char*, long);
58 ID rb_intern_str(VALUE str);
59 const char *rb_id2name(ID);
60 ID rb_check_id(volatile VALUE *);
61 ID rb_to_id(VALUE);
62 VALUE rb_id2str(ID);
63 VALUE rb_sym2str(VALUE);
64 VALUE rb_to_symbol(VALUE name);
65 VALUE rb_check_symbol(volatile VALUE *namep);
66 RBIMPL_SYMBOL_EXPORT_END()
67
68 RBIMPL_ATTR_PURE()
69 RBIMPL_ATTR_NONNULL(())
70static inline ID
71rb_intern_const(const char *str)
72{
73 size_t len = strlen(str);
74 return rb_intern2(str, RBIMPL_CAST((long)len));
75}
76
77 RBIMPL_ATTR_NOALIAS()
78 RBIMPL_ATTR_NONNULL(())
79static inline ID
80rbimpl_intern_const(ID *ptr, const char *str)
81{
82 while (! *ptr) {
83 *ptr = rb_intern_const(str);
84 }
85
86 return *ptr;
87}
88
89/* Does anyone use it? Preserved for backward compat. */
90#define RUBY_CONST_ID_CACHE(result, str) \
91 { \
92 static ID rb_intern_id_cache; \
93 rbimpl_intern_const(&rb_intern_id_cache, (str)); \
94 result rb_intern_id_cache; \
95 }
96#define RUBY_CONST_ID(var, str) \
97 do { \
98 static ID rbimpl_id; \
99 (var) = rbimpl_intern_const(&rbimpl_id, (str)); \
100 } while (0)
101
102#if defined(HAVE_STMT_AND_DECL_IN_EXPR)
103/* __builtin_constant_p and statement expression is available
104 * since gcc-2.7.2.3 at least. */
105#define rb_intern(str) \
106 (RBIMPL_CONSTANT_P(str) ? \
107 __extension__ ({ \
108 static ID rbimpl_id; \
109 rbimpl_intern_const(&rbimpl_id, (str)); \
110 }) : \
111 (rb_intern)(str))
112#endif
113
114#endif /* RBIMPL_SYMBOL_H */
cast.h
Defines RBIMPL_CAST.
constant_p.h
Defines RBIMPL_CONSTANT_P.
ptr
struct RIMemo * ptr
Definition: debug.c:88
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
len
uint8_t len
Definition: escape.c:17
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_intern_str
#define rb_intern_str(string)
Definition: generator.h:16
config.h
Thin wrapper to ruby/config.h.
builtin.h
Defines RBIMPL_HAS_BUILTIN.
rb_check_symbol
VALUE rb_check_symbol(volatile VALUE *namep)
Returns Symbol for the given name if it is interned already, or nil.
Definition: symbol.c:1114
rb_id2sym
VALUE rb_id2sym(ID)
Definition: symbol.c:919
rb_id2name
const char * rb_id2name(ID)
Definition: symbol.c:944
rb_sym2str
VALUE rb_sym2str(VALUE)
Definition: symbol.c:927
rb_intern2
ID rb_intern2(const char *, long)
Definition: symbol.c:778
rb_intern
ID rb_intern(const char *)
Definition: symbol.c:785
rb_check_id
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
Definition: symbol.c:1069
rb_sym2id
ID rb_sym2id(VALUE)
Definition: symbol.c:885
rb_to_symbol
VALUE rb_to_symbol(VALUE name)
Definition: string.c:11511
rb_to_id
ID rb_to_id(VALUE)
Definition: string.c:11501
name
const char * name
Definition: nkf.c:208
noalias.h
Defines RBIMPL_ATTR_NOALIAS.
RBIMPL_ATTR_NOALIAS
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition: noalias.h:55
nonnull.h
Defines RBIMPL_ATTR_NONNULL.
RBIMPL_ATTR_NONNULL
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:29
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE
#define RBIMPL_ATTR_PURE()
Wraps (or simulates) __attribute__((pure))
Definition: pure.h:33
strlen
size_t strlen(const char *)
const
#define const
Definition: strftime.c:108
value.h
Defines VALUE and ID.
VALUE
unsigned long VALUE
Definition: value.h:38
ID
unsigned long ID
Definition: value.h:39
rb_id2str
#define rb_id2str(id)
Definition: vm_backtrace.c:30