mirror of https://github.com/swig/swig
Improve description of cast macros for Ruby
The macros for casting function pointers are now fully described and also clarify why the macros act transparently for C even before Ruby 2.7. In addition, an "if (CPlusPlus)" was removed in the code generator for global variables in order to keep the distinction between C and C++ in one place, which is at the definition of said macros.
This commit is contained in:
parent
5542cc228a
commit
f5908eca76
|
@ -98,17 +98,33 @@
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Need to be very careful about how these macros are defined, especially
|
* The following macros are used for providing the correct type of a
|
||||||
* when compiling C++ code or C code with an ANSI C compiler.
|
* function pointer to the Ruby C API.
|
||||||
|
* Starting with Ruby 2.7 (corresponding to RB_METHOD_DEFINITION_DECL being
|
||||||
|
* defined) these macros act transparently due to Ruby's moving away from
|
||||||
|
* ANYARGS and instead employing strict function signatures.
|
||||||
*
|
*
|
||||||
* VALUEFUNC(f) is a macro used to typecast a C function that implements
|
* Note: In case of C (not C++) the macros are transparent even before
|
||||||
* a Ruby method so that it can be passed as an argument to API functions
|
* Ruby 2.7 due to the fact that the Ruby C API used function declarators
|
||||||
* like rb_define_method() and rb_define_singleton_method().
|
* with empty parentheses, which allows for an unspecified number of
|
||||||
|
* arguments.
|
||||||
*
|
*
|
||||||
* VOIDFUNC(f) is a macro used to typecast a C function that implements
|
* PROTECTFUNC(f) is used for the function pointer argument of the Ruby
|
||||||
* either the "mark" or "free" stuff for a Ruby Data object, so that it
|
* C API function rb_protect().
|
||||||
* can be passed as an argument to API functions like Data_Wrap_Struct()
|
*
|
||||||
|
* VALUEFUNC(f) is used for the function pointer argument(s) of Ruby C API
|
||||||
|
* functions like rb_define_method() and rb_define_singleton_method().
|
||||||
|
*
|
||||||
|
* VOIDFUNC(f) is used to typecast a C function that implements either
|
||||||
|
* the "mark" or "free" stuff for a Ruby Data object, so that it can be
|
||||||
|
* passed as an argument to Ruby C API functions like Data_Wrap_Struct()
|
||||||
* and Data_Make_Struct().
|
* and Data_Make_Struct().
|
||||||
|
*
|
||||||
|
* SWIG_RUBY_VOID_ANYARGS_FUNC(f) is used for the function pointer
|
||||||
|
* argument(s) of Ruby C API functions like rb_define_virtual_variable().
|
||||||
|
*
|
||||||
|
* SWIG_RUBY_INT_ANYARGS_FUNC(f) is used for the function pointer
|
||||||
|
* argument(s) of Ruby C API functions like st_foreach().
|
||||||
*/
|
*/
|
||||||
#if defined(__cplusplus) && !defined(RB_METHOD_DEFINITION_DECL)
|
#if defined(__cplusplus) && !defined(RB_METHOD_DEFINITION_DECL)
|
||||||
# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
|
# define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
|
||||||
|
|
|
@ -2270,13 +2270,11 @@ public:
|
||||||
Delete(setname);
|
Delete(setname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* define accessor method */
|
/* define accessor methods */
|
||||||
if (CPlusPlus) {
|
Insert(getfname, 0, "VALUEFUNC(");
|
||||||
Insert(getfname, 0, "VALUEFUNC(");
|
Append(getfname, ")");
|
||||||
Append(getfname, ")");
|
Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
|
||||||
Insert(setfname, 0, (use_virtual_var) ? "SWIG_RUBY_VOID_ANYARGS_FUNC(" : "VALUEFUNC(");
|
Append(setfname, ")");
|
||||||
Append(setfname, ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
String *s = NewString("");
|
String *s = NewString("");
|
||||||
switch (current) {
|
switch (current) {
|
||||||
|
|
Loading…
Reference in New Issue