Fix Ruby regression with missing rb_complex_new function.

Affects Ruby versions prior to 1.9 using std::complex wrappers if just using std::complex
as an output type. Also fix the Complex helper functions external visibility (to static by default).

Closes #52
This commit is contained in:
William S Fulton 2013-06-07 19:56:38 +01:00
commit 3834036e13
2 changed files with 17 additions and 7 deletions

View file

@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.11 (in progress) Version 2.0.11 (in progress)
============================ ============================
2013-07-07: wsfulton
[Ruby] Git issue #52. Fix regression with missing rb_complex_new function for Ruby
versions prior to 1.9 using std::complex wrappers if just using std::complex as an output type.
Also fix the Complex helper functions external visibility (to static by default).
2013-06-04: olly 2013-06-04: olly
[PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL [PHP] Fix SWIG_ZTS_ConvertResourcePtr() not to dereference NULL
if the type lookup fails. if the type lookup fails.

View file

@ -7,34 +7,39 @@
See the std_complex.i and ccomplex.i for concrete examples. See the std_complex.i and ccomplex.i for concrete examples.
*/ */
%fragment("SWIG_Complex_Numbers","header") %fragment("rb_complex_new","header")
{ {
%#if !defined(T_COMPLEX) %#if !defined(T_COMPLEX)
/* Ruby versions prior to 1.9 did not have native complex numbers. They were an extension in the STD library. */ /* Ruby versions prior to 1.9 did not have native complex numbers. They were an extension in the STD library. */
VALUE rb_complex_new(VALUE x, VALUE y) { SWIGINTERN VALUE rb_complex_new(VALUE x, VALUE y) {
static ID new_id = rb_intern("new"); static ID new_id = rb_intern("new");
static VALUE cComplex = rb_const_get(rb_cObject, rb_intern("Complex")); static VALUE cComplex = rb_const_get(rb_cObject, rb_intern("Complex"));
return rb_funcall(cComplex, new_id, 2, x, y); return rb_funcall(cComplex, new_id, 2, x, y);
} }
%#endif
}
static int SWIG_Is_Complex( VALUE obj ) { %fragment("SWIG_Complex_Numbers","header")
{
%#if !defined(T_COMPLEX)
SWIGINTERN int SWIG_Is_Complex( VALUE obj ) {
static ID real_id = rb_intern("real"); static ID real_id = rb_intern("real");
static ID imag_id = rb_intern("imag"); static ID imag_id = rb_intern("imag");
return ( (rb_respond_to( obj, real_id ) ) && return ( (rb_respond_to( obj, real_id ) ) &&
(rb_respond_to( obj, imag_id ) ) ); (rb_respond_to( obj, imag_id ) ) );
} }
%#else %#else
static int SWIG_Is_Complex( VALUE obj ) { SWIGINTERN int SWIG_Is_Complex( VALUE obj ) {
return TYPE(obj) == T_COMPLEX; return TYPE(obj) == T_COMPLEX;
} }
%#endif %#endif
VALUE SWIG_Complex_Real(VALUE obj) { SWIGINTERN VALUE SWIG_Complex_Real(VALUE obj) {
static ID real_id = rb_intern("real"); static ID real_id = rb_intern("real");
return rb_funcall(obj, real_id, 0); return rb_funcall(obj, real_id, 0);
} }
VALUE SWIG_Complex_Imaginary(VALUE obj) { SWIGINTERN VALUE SWIG_Complex_Imaginary(VALUE obj) {
static ID imag_id = rb_intern("imag"); static ID imag_id = rb_intern("imag");
return rb_funcall(obj, imag_id, 0); return rb_funcall(obj, imag_id, 0);
} }
@ -48,7 +53,7 @@ VALUE SWIG_Complex_Imaginary(VALUE obj) {
/* the common from converter */ /* the common from converter */
%define %swig_fromcplx_conv(Type, Real, Imag) %define %swig_fromcplx_conv(Type, Real, Imag)
%fragment(SWIG_From_frag(Type),"header") %fragment(SWIG_From_frag(Type),"header",fragment="rb_complex_new")
{ {
SWIGINTERNINLINE VALUE SWIGINTERNINLINE VALUE
SWIG_From(Type)(%ifcplusplus(const Type&, Type) c) SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)