Ruby  3.4.0dev (2024-11-22 revision 0989400a925cd201defdca9eb28eb87200b30785)
Macros
anyargs.h File Reference

(0989400a925cd201defdca9eb28eb87200b30785)

Function overloads to issue warnings around ANYARGS. More...

#include "ruby/internal/attr/maybe_unused.h"
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/weakref.h"
#include "ruby/internal/cast.h"
#include "ruby/internal/config.h"
#include "ruby/internal/has/attribute.h"
#include "ruby/internal/intern/class.h"
#include "ruby/internal/intern/vm.h"
#include "ruby/internal/method.h"
#include "ruby/internal/value.h"
#include "ruby/backward/2/stdarg.h"
#include "ruby/backward/cxxanyargs.hpp"
Include dependency graph for anyargs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RUBY_METHOD_FUNC(func)   RBIMPL_CAST((VALUE (*)(ANYARGS))(func))
 This macro is to properly cast a function parameter of *_define_method family. More...
 

Detailed Description

Function overloads to issue warnings around ANYARGS.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org
Warning
Symbols prefixed with either RBIMPL or rbimpl are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.
Note
To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance __VA_ARGS__ is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

For instance rb_define_method takes a pointer to ANYARGS -ed functions, which in fact varies 18 different prototypes. We still need to preserve ANYARGS for storages but why not check the consistencies if possible. With those complex macro overlays defined in this header file, use of a function pointer gets checked against the corresponding arity argument.

Q&A

Definition in file anyargs.h.

Macro Definition Documentation

◆ RUBY_METHOD_FUNC

#define RUBY_METHOD_FUNC (   func)    RBIMPL_CAST((VALUE (*)(ANYARGS))(func))

This macro is to properly cast a function parameter of *_define_method family.

It has been around since 1.x era so you can maximise backwards compatibility by using it.

rb_define_method(klass, "method", RUBY_METHOD_FUNC(func), arity);
#define RUBY_METHOD_FUNC(func)
This macro is to properly cast a function parameter of *_define_method family.
Definition: anyargs.h:363
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
Definition: class.c:2142
Parameters
funcA pointer to a function that implements a method.

Definition at line 363 of file anyargs.h.