[macruby-changes] [1711] MacRuby/branches/fp-optimized-experimental
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 3 13:41:11 PDT 2009
Revision: 1711
http://trac.macosforge.org/projects/ruby/changeset/1711
Author: pthomson at apple.com
Date: 2009-06-03 13:41:10 -0700 (Wed, 03 Jun 2009)
Log Message:
-----------
Removed the union casting, opting instead to create a union inline. This works on both C and C++.
Modified Paths:
--------------
MacRuby/branches/fp-optimized-experimental/compiler.cpp
MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h
Modified: MacRuby/branches/fp-optimized-experimental/compiler.cpp
===================================================================
--- MacRuby/branches/fp-optimized-experimental/compiler.cpp 2009-06-03 20:31:50 UTC (rev 1710)
+++ MacRuby/branches/fp-optimized-experimental/compiler.cpp 2009-06-03 20:41:10 UTC (rev 1711)
@@ -4301,12 +4301,7 @@
static inline double
rval_to_double(VALUE rval)
{
- // workaround for C++'s refusal to cast union types.
- VALUE r = rb_Float(bool_to_fix(rval));
- if (FIXFLOAT_P(r)) {
- return *(double*)(&r);
- }
- return RFLOAT(r)->float_value;
+ return RFLOAT_VALUE(rb_Float(bool_to_fix(rval)));
}
extern "C"
Modified: MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h
===================================================================
--- MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h 2009-06-03 20:31:50 UTC (rev 1710)
+++ MacRuby/branches/fp-optimized-experimental/include/ruby/ruby.h 2009-06-03 20:41:10 UTC (rev 1711)
@@ -238,7 +238,7 @@
#define DBL2FIXFLOAT(d) (VOODOO_DOUBLE(d) | FIXFLOAT_FLAG)
#define FIXABLE_DBL(d) (!(VOODOO_DOUBLE(d) & FIXFLOAT_FLAG))
#define FIXFLOAT_P(v) (((VALUE)v & FIXFLOAT_FLAG) == FIXFLOAT_FLAG)
-#define FIXFLOAT2DBL(v) coerce_ptr_to_double((__coerced_value_double_t)v)
+#define FIXFLOAT2DBL(v) coerce_ptr_to_double((VALUE)v)
#if WITH_OBJC
# define SYMBOL_P(x) (TYPE(x) == T_SYMBOL)
@@ -268,13 +268,11 @@
// We can't directly cast a void* to a double, so we cast it to a union
// and then extract its double member. Hacky, but effective.
-// This doesn't work in C++, though. I need suggestions on how to do it there.
-typedef union {VALUE val; void* vd; double d;} __coerced_value_double_t;
-
-static inline double coerce_ptr_to_double(__coerced_value_double_t h)
+static inline double coerce_ptr_to_double(VALUE v)
{
- h.val ^= RUBY_FIXFLOAT_FLAG; // unset the last two bits.
- return h.d;
+ union {VALUE val; double d;} coerced_value;
+ coerced_value.val = v ^ RUBY_FIXFLOAT_FLAG; // unset the last two bits.
+ return coerced_value.d;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090603/530adbb9/attachment-0001.html>
More information about the macruby-changes
mailing list