-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from ruby-rice/dev
Various updates
- Loading branch information
Showing
23 changed files
with
1,892 additions
and
630 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require "version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef Rice__stl__exception__hpp_ | ||
#define Rice__stl__exception__hpp_ | ||
|
||
#include "exception.ipp" | ||
|
||
#endif // Rice__stl__exception__hpp_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <exception> | ||
|
||
// Libraries sometime inherit custom exception objects from std::exception, | ||
// so define it for Ruby if necessary | ||
namespace Rice | ||
{ | ||
namespace stl | ||
{ | ||
inline Data_Type<std::exception> define_stl_exception() | ||
{ | ||
Module rb_mRice = define_module("Rice"); | ||
Module rb_mmap = define_module_under(rb_mRice, "Std"); | ||
Data_Type<std::exception> rb_cStlException = define_class_under<std::exception>(rb_mmap, "Exception"); | ||
rb_cStlException. | ||
define_constructor(Constructor<std::exception>()). | ||
define_method("what", &std::exception::what); | ||
return rb_cStlException; | ||
} | ||
} | ||
} | ||
|
||
namespace Rice::detail | ||
{ | ||
template<> | ||
struct Type<std::exception> | ||
{ | ||
static bool verify() | ||
{ | ||
Rice::stl::define_stl_exception(); | ||
return true; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef Rice__stl__type_index__hpp_ | ||
#define Rice__stl__type_index__hpp_ | ||
|
||
#include "type_index.ipp" | ||
|
||
#endif // Rice__stl__type_index__hpp_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <typeindex> | ||
|
||
namespace Rice::detail | ||
{ | ||
template<> | ||
struct Type<std::type_index> | ||
{ | ||
constexpr static bool verify() | ||
{ | ||
return true; | ||
} | ||
}; | ||
|
||
template<> | ||
class To_Ruby<std::type_index> | ||
{ | ||
public: | ||
VALUE convert(const std::type_index& _) | ||
{ | ||
throw std::runtime_error("std::type_index support is not yet implemented"); | ||
return Qnil; | ||
} | ||
}; | ||
|
||
template<> | ||
class To_Ruby<std::type_index&> | ||
{ | ||
public: | ||
static VALUE convert(const std::type_index& data, bool takeOwnership = false) | ||
{ | ||
throw std::runtime_error("std::type_index support is not yet implemented"); | ||
return Qnil; | ||
} | ||
}; | ||
|
||
template<> | ||
class From_Ruby<std::type_index&> | ||
{ | ||
public: | ||
Convertible is_convertible(VALUE value) | ||
{ | ||
return Convertible::None; | ||
} | ||
|
||
std::type_index& convert(VALUE value) | ||
{ | ||
throw std::runtime_error("std::type_index support is not yet implemented"); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <complex> | ||
#include <memory> | ||
|
||
#include "unittest.hpp" | ||
#include "embed_ruby.hpp" | ||
#include <rice/rice.hpp> | ||
#include <rice/stl.hpp> | ||
|
||
using namespace Rice; | ||
|
||
TESTSUITE(StlException); | ||
|
||
SETUP(StlException) | ||
{ | ||
embed_ruby(); | ||
} | ||
|
||
TEARDOWN(StlException) | ||
{ | ||
rb_gc_start(); | ||
} | ||
|
||
namespace | ||
{ | ||
class MyException: public std::exception | ||
{ | ||
public: | ||
std::string hello() | ||
{ | ||
return "Hello"; | ||
} | ||
}; | ||
} | ||
|
||
TESTCASE(StlExceptionCreate) | ||
{ | ||
Module m = define_module("Testing"); | ||
Class c = define_class<MyException, std::exception>("MyException"). | ||
define_constructor(Constructor<MyException>()). | ||
define_method("hello", &MyException::hello); | ||
|
||
Object exception = c.create(); | ||
Object result = exception.call("hello"); | ||
ASSERT_EQUAL("Hello", detail::From_Ruby<std::string>().convert(result.value())); | ||
|
||
#ifdef _MSC_VER | ||
std::string expected = "Uknown exception"; | ||
#else | ||
std::string expected = "std::exception"; | ||
#endif | ||
|
||
result = exception.call("what"); | ||
ASSERT_EQUAL(expected, detail::From_Ruby<std::string>().convert(result.value())); | ||
} |
Oops, something went wrong.