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
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
36#include "ruby/internal/cast.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
56ID rb_intern(const char*);
57ID rb_intern2(const char*, long);
59const char *rb_id2name(ID);
60ID rb_check_id(volatile VALUE *);
65VALUE rb_check_symbol(volatile VALUE *namep);
67
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
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 */
Defines RBIMPL_CAST.
Defines RBIMPL_CONSTANT_P.
struct RIMemo * ptr
Definition: debug.c:88
Tewaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
uint8_t len
Definition: escape.c:17
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
#define rb_intern_str(string)
Definition: generator.h:16
Thin wrapper to ruby/config.h.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_check_symbol(volatile VALUE *namep)
Returns Symbol for the given name if it is interned already, or nil.
Definition: symbol.c:1114
VALUE rb_id2sym(ID)
Definition: symbol.c:919
const char * rb_id2name(ID)
Definition: symbol.c:944
VALUE rb_sym2str(VALUE)
Definition: symbol.c:927
ID rb_intern2(const char *, long)
Definition: symbol.c:778
ID rb_intern(const char *)
Definition: symbol.c:785
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
Definition: symbol.c:1069
ID rb_sym2id(VALUE)
Definition: symbol.c:885
VALUE rb_to_symbol(VALUE name)
Definition: string.c:11511
ID rb_to_id(VALUE)
Definition: string.c:11501
const char * name
Definition: nkf.c:208
Defines RBIMPL_ATTR_NOALIAS.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition: noalias.h:55
Defines RBIMPL_ATTR_NONNULL.
#define RBIMPL_ATTR_NONNULL(list)
Wraps (or simulates) __attribute__((nonnull))
Definition: nonnull.h:29
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE()
Wraps (or simulates) __attribute__((pure))
Definition: pure.h:33
size_t strlen(const char *)
#define const
Definition: strftime.c:108
Defines VALUE and ID.
unsigned long VALUE
Definition: value.h:38
unsigned long ID
Definition: value.h:39
#define rb_id2str(id)
Definition: vm_backtrace.c:30