From 1feef7530bee1ddad7a854c336b39a83fcc47b03 Mon Sep 17 00:00:00 2001 From: Lyle Johnson Date: Tue, 17 Aug 2004 00:38:52 +0000 Subject: [PATCH] Minor fix for the cpp_enum.i test case, which was broken. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6099 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/ruby/ruby.swg | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Lib/ruby/ruby.swg b/Lib/ruby/ruby.swg index a047385fa..4426d75a6 100644 --- a/Lib/ruby/ruby.swg +++ b/Lib/ruby/ruby.swg @@ -20,6 +20,13 @@ #define %mixin %feature("mixin") #define %predicate %feature("predicate", "1") +%{ +static void SWIG_AsVal(VALUE obj, int *val) +{ + *val = (int) NUM2INT(obj); +} +%} + /* ---------------------------------------------------------------------- * Standard Typemaps * ---------------------------------------------------------------------- */ @@ -235,7 +242,13 @@ %typemap(varin) long long "$1 = NUM2LL($input);"; %typemap(varin) unsigned long long "$1 = NUM2ULL($input);"; -%typemap(varin) enum SWIGTYPE "$1 = ($1_type) NUM2INT($input);"; +%typemap(varin) enum SWIGTYPE { + // $1 = ($1_type) NUM2INT($input); + if (sizeof(int) != sizeof($1)) { + rb_raise(rb_eTypeError, "enum variable '$name' can not be set."); + } + SWIG_AsVal($input, (int *)(void *) &$1); +} /* A string */ #ifdef __cplusplus