1 #ifndef RUBY_BACKWARD_CXXANYARGS_HPP
2 #define RUBY_BACKWARD_CXXANYARGS_HPP
13 #include "ruby/internal/config.h"
54 namespace cxxanyargs {
64 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
80 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
88 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
103 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
117 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
126 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
143 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
151 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
166 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
180 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
194 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
212 RUBY_CXX_DEPRECATED(
"by rb_block_call since 1.9")
220 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
246 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
264 func1_t *t =
reinterpret_cast<func1_t*
>(q);
265 func2_t *y =
reinterpret_cast<func2_t*
>(e);
269 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
288 func1_t *t =
reinterpret_cast<func1_t*
>(q);
289 func2_t *y =
reinterpret_cast<func2_t*
>(e);
297 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
313 func1_t *t =
reinterpret_cast<func1_t*
>(q);
314 func1_t *y =
reinterpret_cast<func1_t*
>(e);
318 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
345 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
368 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
384 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
400 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
412 typedef VALUE ptr_t(
void*);
413 ptr_t *e =
reinterpret_cast<ptr_t*
>(q);
421 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
434 st_foreach_callback_func *r =
435 reinterpret_cast<st_foreach_callback_func*
>(w);
439 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
452 st_foreach_check_callback_func *t =
453 reinterpret_cast<st_foreach_check_callback_func*
>(w);
457 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
468 st_foreach_callback_func *r =
469 reinterpret_cast<st_foreach_callback_func*
>(w);
473 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
484 st_foreach_callback_func *r =
485 reinterpret_cast<st_foreach_callback_func*
>(w);
489 RUBY_CXX_DEPRECATED(
"Use of ANYARGS in this function is deprecated")
500 st_foreach_callback_func *r =
501 reinterpret_cast<st_foreach_callback_func*
>(w);
514 namespace define_method {
522 template<
typename T,
void (*F)(VALUE klass, T m
id, type *func,
int arity)>
528 template<
int N,
typename U>
540 #if (RUBY_API_VERSION_MAJOR * 100 + RUBY_API_VERSION_MINOR) >= 301
541 RUBY_CXX_DEPRECATED(
"use of ANYARGS is deprecated")
548 F(klass, mid, func, N);
558 F(klass, mid,
reinterpret_cast<type *
>(func), N);
565 F(klass, mid,
reinterpret_cast<type *
>(func), N);
570 template<
int N,
bool = false>
struct specific :
public engine<N, type *> {};
571 template<
bool b>
struct specific<15, b> :
public engine<15, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
572 template<
bool b>
struct specific<14, b> :
public engine<14, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
573 template<
bool b>
struct specific<13, b> :
public engine<13, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
574 template<
bool b>
struct specific<12, b> :
public engine<12, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
575 template<
bool b>
struct specific<11, b> :
public engine<11, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
576 template<
bool b>
struct specific<10, b> :
public engine<10, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
577 template<
bool b>
struct specific< 9, b> :
public engine< 9, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
578 template<
bool b>
struct specific< 8, b> :
public engine< 8, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
579 template<
bool b>
struct specific< 7, b> :
public engine< 7, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
580 template<
bool b>
struct specific< 6, b> :
public engine< 6, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
581 template<
bool b>
struct specific< 5, b> :
public engine< 5, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
582 template<
bool b>
struct specific< 4, b> :
public engine< 4, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE)> {};
583 template<
bool b>
struct specific< 3, b> :
public engine< 3, VALUE(*)(VALUE, VALUE, VALUE, VALUE)> {};
584 template<
bool b>
struct specific< 2, b> :
public engine< 2, VALUE(*)(VALUE, VALUE, VALUE)> {};
585 template<
bool b>
struct specific< 1, b> :
public engine< 1, VALUE(*)(VALUE, VALUE)> {};
586 template<
bool b>
struct specific< 0, b> :
public engine< 0, VALUE(*)(VALUE)> {};
587 template<
bool b>
struct specific<-1, b> :
public engine<-1, VALUE(*)(int argc, VALUE *argv, VALUE self)> {
589 static inline void define(
VALUE c, T m,
VALUE(*f)(
int argc,
const VALUE *argv,
VALUE self)) { F(c, m,
reinterpret_cast<type *
>(f), -1); }
591 template<
bool b>
struct specific<-2, b> :
public engine<-2, VALUE(*)(VALUE, VALUE)> {};
598 template<
typename T,
void (*F)(T m
id, type func,
int arity)>
604 template<
int N,
typename U>
606 RUBY_CXX_DEPRECATED(
"use of ANYARGS is deprecated")
621 F(mid,
reinterpret_cast<type *
>(func), N);
629 F(mid,
reinterpret_cast<type *
>(func), N);
634 template<
int N,
bool = false>
struct specific :
public engine<N, type *> {};
635 template<
bool b>
struct specific<15, b> :
public engine<15, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
636 template<
bool b>
struct specific<14, b> :
public engine<14, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
637 template<
bool b>
struct specific<13, b> :
public engine<13, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
638 template<
bool b>
struct specific<12, b> :
public engine<12, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
639 template<
bool b>
struct specific<11, b> :
public engine<11, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
640 template<
bool b>
struct specific<10, b> :
public engine<10, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
641 template<
bool b>
struct specific< 9, b> :
public engine< 9, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
642 template<
bool b>
struct specific< 8, b> :
public engine< 8, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
643 template<
bool b>
struct specific< 7, b> :
public engine< 7, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
644 template<
bool b>
struct specific< 6, b> :
public engine< 6, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
645 template<
bool b>
struct specific< 5, b> :
public engine< 5, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)> {};
646 template<
bool b>
struct specific< 4, b> :
public engine< 4, VALUE(*)(VALUE, VALUE, VALUE, VALUE, VALUE)> {};
647 template<
bool b>
struct specific< 3, b> :
public engine< 3, VALUE(*)(VALUE, VALUE, VALUE, VALUE)> {};
648 template<
bool b>
struct specific< 2, b> :
public engine< 2, VALUE(*)(VALUE, VALUE, VALUE)> {};
649 template<
bool b>
struct specific< 1, b> :
public engine< 1, VALUE(*)(VALUE, VALUE)> {};
650 template<
bool b>
struct specific< 0, b> :
public engine< 0, VALUE(*)(VALUE)> {};
651 template<
bool b>
struct specific<-1, b> :
public engine<-1, VALUE(*)(int argc, VALUE *argv, VALUE self)> {
653 static inline void define(T m,
VALUE(*f)(
int argc,
const VALUE *argv,
VALUE self)) { F(m,
reinterpret_cast<type *
>(f), -1); }
655 template<
bool b>
struct specific<-2, b> :
public engine<-2, VALUE(*)(VALUE, VALUE)> {};
670 #define rb_define_method(klass, mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_method::specific<arity>::define(klass, mid, func)
673 #define rb_define_method_id(klass, mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_method_id::specific<arity>::define(klass, mid, func)
677 #define rb_define_private_method(klass, mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_private_method::specific<arity>::define(klass, mid, func)
681 #define rb_define_protected_method(klass, mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_protected_method::specific<arity>::define(klass, mid, func)
685 #define rb_define_singleton_method(klass, mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_singleton_method::specific<arity>::define(klass, mid, func)
689 #define rb_define_module_function(klass, mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_module_function::specific<arity>::define(klass, mid, func)
695 #define rb_define_global_function(mid, func, arity) ::ruby::backward::cxxanyargs::define_method::rb_define_global_function::specific<arity>::define(mid, func)
VALUE rb_vrescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2, va_list args)
Identical to rb_rescue2(), except it takes va_list instead of variadic number of arguments.
Public APIs related to rb_cClass/rb_cModule.
Public APIs related to rb_cFiber.
VALUE rb_fiber_new(rb_block_call_func_t func, VALUE callback_obj)
Creates a Fiber instance from a C-backended block.
Public APIs related to rb_cHash.
Public APIs related to rb_cProc.
VALUE rb_proc_new(rb_block_call_func_t func, VALUE callback_arg)
This is an rb_iterate() + rb_block_proc() combo.
Public APIs related to rb_cThread.
VALUE rb_thread_create(VALUE(*f)(void *g), void *g)
Creates a Ruby thread that is backended by a C function.
Public APIs related to names inside of a Ruby program.
Public APIs related to rb_cRubyVM.
Creation and modification of Ruby methods.
Declares rb_define_variable().
void rb_gvar_setter_t(VALUE val, ID id, VALUE *data)
Type that represents a global variable setter function.
VALUE rb_gvar_getter_t(ID id, VALUE *data)
Type that represents a global variable getter function.
VALUE rb_catch_obj(VALUE tag, rb_block_call_func_t func, VALUE data)
Identical to rb_catch(), except it catches arbitrary Ruby objects.
VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2)
Identical to rb_funcallv(), except it additionally passes a function as a block.
rb_block_call_func * rb_block_call_func_t
Shorthand type that represents an iterator-written-in-C function pointer.
VALUE rb_catch(const char *tag, rb_block_call_func_t func, VALUE data)
Executes the passed block and catches values thrown from inside of it.
VALUE notimpl_type(int, const VALUE *, VALUE, VALUE)
Type of rb_f_notimplement().
Provides ANYARGS deprecation warnings.
VALUE onearg_type(VALUE)
Single-argumented function type.
VALUE rb_catch_obj(VALUE q, type *w, VALUE e)
An equivalent of Kernel#catch.
VALUE rb_catch(const char *q, type *w, VALUE e)
An equivalent of Kernel#catch.
void rb_define_hooked_variable(const char *q, VALUE *w, type *e, void_type *r)
Define a function-backended global variable.
VALUE rb_thread_create(type *q, void *w)
Creates a rb_cThread instance.
int int_type(ANYARGS)
ANYARGS-ed function type, int variant.
void void_type(ANYARGS)
ANYARGS-ed function type, void variant.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_proc_new(type *q, VALUE w)
Creates a rb_cProc instance.
VALUE rb_iterate(onearg_type *q, VALUE w, type *e, VALUE r)
Old way to implement iterators.
VALUE type(ANYARGS)
ANYARGS-ed function type.
VALUE rb_fiber_new(type *q, VALUE w)
Creates a rb_cFiber instance.
void st_foreach_safe(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
void rb_hash_foreach(VALUE q, int_type *w, VALUE e)
Iteration over the given hash.
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
void rb_ivar_foreach(VALUE q, int_type *w, VALUE e)
Iteration over each instance variable of the object.
VALUE rb_rescue2(type *q, VALUE w, type *e, VALUE r,...)
An equivalent of rescue clause.
VALUE rb_rescue(type *q, VALUE w, type *e, VALUE r)
An equivalent of rescue clause.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
int st_foreach_check(st_table *q, int_type *w, st_data_t e, st_data_t)
Iteration over the given table.
static VALUE rb_iterate_deprecated(VALUE(*iter)(VALUE), VALUE data1, rb_block_call_func_t bl, VALUE data2)
Old way to iterate a block.
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
#define ANYARGS
Functions declared using this macro take arbitrary arguments, including void.
static void define(T mid, type func)
Defines Kernel::mid as func, whose arity is N.
static void define(T mid, notimpl_type func)
Defines Kernel::mid as func, whose arity is N.
static void define(T mid, U func)
Defines Kernel::mid as func, whose arity is N.
Template metaprogramming to generate function prototypes.
static void define(VALUE klass, T mid, type func)
Defines klass::mid as func, whose arity is N.
static void define(VALUE klass, T mid, U func)
Defines klass::mid as func, whose arity is N.
static void define(VALUE klass, T mid, notimpl_type func)
Defines klass::mid as func, whose arity is N.
Template metaprogramming to generate function prototypes.
Dispatches appropriate driver for rb_define_global_function.
Dispatches appropriate driver for rb_define_method_id.
Dispatches appropriate driver for rb_define_method.
Dispatches appropriate driver for rb_define_module_function.
Dispatches appropriate driver for rb_define_private_method.
Dispatches appropriate driver for rb_define_protected_method.
Dispatches appropriate driver for rb_define_singleton_method.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.