1 #ifndef RBIMPL_DLLEXPORT_H /*-*-C++-*-vi:se ft=cpp:*/
2 #define RBIMPL_DLLEXPORT_H
5 * @author Ruby developers <ruby-core@ruby-lang.org>
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
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 Tweaking visibility of C variables/functions.
23 #include "ruby/internal/config.h"
24 #include "ruby/internal/compiler_is.h"
27 * Declaration of externally visible global variables. Here "externally" means
28 * they should be visible from extension libraries. Depending on operating
29 * systems (dynamic linkers, to be precise), global variables inside of a DLL
30 * may or may not be visible form outside of that DLL by default. This
31 * declaration manually tweaks that default and ensures the declared variable
32 * be truly globally visible.
35 * extern VALUE foo; // hidden on some OS
36 * RUBY_EXTERN VALUE foo; // ensure visible
40 #if defined(MJIT_HEADER) && defined(_WIN32)
41 # define RUBY_EXTERN extern __declspec(dllimport)
42 #elif defined(RUBY_EXPORT)
43 # define RUBY_EXTERN extern
45 # define RUBY_EXTERN extern __declspec(dllimport)
47 # define RUBY_EXTERN extern
50 #ifndef RUBY_SYMBOL_EXPORT_BEGIN
51 # define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
54 #ifndef RUBY_SYMBOL_EXPORT_END
55 # define RUBY_SYMBOL_EXPORT_END /* end */
58 #ifndef RUBY_FUNC_EXPORTED
59 # define RUBY_FUNC_EXPORTED /* void */
63 * @cond INTERNAL_MACRO
65 * These MJIT related macros are placed here because translate_mjit_header can
66 * need them. Extension libraries should not touch.
69 /* These macros are used for functions which are exported only for MJIT
70 and NOT ensured to be exported in future versions. */
72 /* On mswin, MJIT header transformation can't be used since cl.exe can't output
73 preprocessed output preserving macros. So this `MJIT_STATIC` is needed
74 to force non-static function to static on MJIT header to avoid symbol conflict. */
76 # define MJIT_STATIC static
83 /** Shortcut macro equivalent to `RUBY_SYMBOL_EXPORT_BEGIN extern "C" {`.
84 * \@shyouhei finds it handy. */
85 #if defined(__DOXYGEN__)
86 # define RBIMPL_SYMBOL_EXPORT_BEGIN() /* void */
87 #elif defined(__cplusplus)
88 # define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN extern "C" {
90 # define RBIMPL_SYMBOL_EXPORT_BEGIN() RUBY_SYMBOL_EXPORT_BEGIN
93 /** Counterpart of #RBIMPL_SYMBOL_EXPORT_BEGIN */
94 #if defined(__DOXYGEN__)
95 # define RBIMPL_SYMBOL_EXPORT_END() /* void */
96 #elif defined(__cplusplus)
97 # define RBIMPL_SYMBOL_EXPORT_END() } RUBY_SYMBOL_EXPORT_END
99 # define RBIMPL_SYMBOL_EXPORT_END() RUBY_SYMBOL_EXPORT_END
101 #endif /* RBIMPL_DLLEXPORT_H */