Skip to content

Commit

Permalink
Merge 6b7cdfb into 152af3c
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchas116 committed Dec 24, 2014
2 parents 152af3c + 6b7cdfb commit 088a912
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ext/qml/extconf.rb
Expand Up @@ -91,7 +91,10 @@ def configure_extension
end
$CPPFLAGS += " -DHAVE_RUBY_THREAD_H" if have_header('ruby/thread.h')

$CPPFLAGS += " -std=c++11 -Wall -Wextra -pipe"
have_func('rb_rational_num')
have_func('rb_rational_den')

$CPPFLAGS += " -std=c++11 -Wall -Wextra -pipe -Wno-reserved-user-defined-literal"
if @debug_enabled
$CPPFLAGS += " -O0 -ggdb3"
else
Expand Down
20 changes: 19 additions & 1 deletion ext/qml/rubyvalue.cpp
Expand Up @@ -17,6 +17,24 @@
#include <QSet>
#include <QJSValue>

#ifndef HAVE_RB_RATIONAL_NUM

VALUE rb_rational_num(VALUE rat)
{
return RRATIONAL(rat)->num;
}

#endif

#ifndef HAVE_RB_RATIONAL_DEN

VALUE rb_rational_den(VALUE rat)
{
return RRATIONAL(rat)->den;
}

#endif

namespace RubyQml {

namespace detail {
Expand Down Expand Up @@ -152,7 +170,7 @@ template <> QDateTime Conversion<QDateTime>::from(RubyValue time)
offset = time.send(RUBYQML_INTERN("gmt_offset")).to<int>();
} else { // DateTime
VALUE dayOffset = time.send(RUBYQML_INTERN("offset"));
offset = RubyValue(RRATIONAL(dayOffset)->num).to<int>() * 24 * 60 * 60 / RubyValue(RRATIONAL(dayOffset)->den).to<int>();
offset = RubyValue(rb_rational_num(dayOffset)).to<int>() * 24 * 60 * 60 / RubyValue(rb_rational_den(dayOffset)).to<int>();
time = time.send(RUBYQML_INTERN("to_time"));
}
timeval at = rb_time_timeval(time);
Expand Down

0 comments on commit 088a912

Please sign in to comment.