Skip to content

Commit

Permalink
Merge pull request #227 from ruby-rice/gc
Browse files Browse the repository at this point in the history
Run GC After Tests
  • Loading branch information
cfis authored Nov 27, 2024
2 parents e21a71f + 3e8c4a3 commit b57347a
Show file tree
Hide file tree
Showing 40 changed files with 198 additions and 9 deletions.
11 changes: 9 additions & 2 deletions rice/cpp_api/Class.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace Rice
return std::string(buffer);
}


inline Class define_class_under(Object module, char const* name, const Class& superclass)
{
VALUE klass = detail::protect(rb_define_class_under, module.value(), name, superclass.value());
Expand All @@ -47,7 +46,15 @@ namespace Rice

inline Class anonymous_class()
{
return detail::protect(rb_class_new, rb_cObject);
VALUE klass = detail::protect(rb_class_new, rb_cObject);
VALUE singleton = detail::protect(rb_singleton_class, klass);

// Ruby will reuse addresses previously assigned to other modules
// that have subsequently been garbage collected
detail::Registries::instance.natives.reset(klass);
detail::Registries::instance.natives.reset(singleton);

return klass;
}
}

Expand Down
10 changes: 9 additions & 1 deletion rice/cpp_api/Module.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ namespace Rice

inline Module anonymous_module()
{
return detail::protect(rb_module_new);
VALUE klass = detail::protect(rb_module_new);
VALUE singleton = detail::protect(rb_singleton_class, klass);

// Ruby will reuse addresses previously assigned to other modules
// that have subsequently been garbage collected
detail::Registries::instance.natives.reset(klass);
detail::Registries::instance.natives.reset(singleton);

return klass;
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/test_Address_Registration_Guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Address_Registration_Guard)
embed_ruby();
}

TEARDOWN(Address_Registration_Guard)
{
rb_gc_start();
}

TESTCASE(register_address)
{
VALUE v = Qnil;
Expand Down
5 changes: 5 additions & 0 deletions test/test_Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ SETUP(Array)
embed_ruby();
}

TEARDOWN(Array)
{
rb_gc_start();
}

TESTCASE(default_construct)
{
Array a;
Expand Down
1 change: 1 addition & 0 deletions test/test_Attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SETUP(Attribute)
TEARDOWN(Attribute)
{
Rice::detail::Registries::instance.types.clearUnverifiedTypes();
rb_gc_start();
}

namespace
Expand Down
5 changes: 5 additions & 0 deletions test/test_Builtin_Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Builtin_Object)
embed_ruby();
}

TEARDOWN(Builtin_Object)
{
rb_gc_start();
}

TESTCASE(construct_with_object)
{
Class c(rb_cObject);
Expand Down
5 changes: 5 additions & 0 deletions test/test_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Class)
embed_ruby();
}

TEARDOWN(Class)
{
rb_gc_start();
}

TESTCASE(construct)
{
Class c(rb_cObject);
Expand Down
5 changes: 5 additions & 0 deletions test/test_Constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ SETUP(Construtor)
embed_ruby();
}

TEARDOWN(Constructor)
{
rb_gc_start();
}

namespace
{
class Default_Constructible
Expand Down
7 changes: 6 additions & 1 deletion test/test_Data_Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ SETUP(Data_Object)
if (!Data_Type<MyDataType>::is_bound())
{
Class object(rb_cObject);
if(object.const_defined("MyDataType"))
if (object.const_defined("MyDataType"))
{
object.remove_const("MyDataType");
}
Expand All @@ -58,6 +58,11 @@ SETUP(Data_Object)
}
}

TEARDOWN(Data_Object)
{
rb_gc_start();
}

TESTCASE(construct_from_pointer)
{
MyDataType* myDataType = new MyDataType;
Expand Down
1 change: 1 addition & 0 deletions test/test_Data_Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SETUP(Data_Type)
TEARDOWN(Data_Type)
{
Rice::detail::Registries::instance.types.clearUnverifiedTypes();
rb_gc_start();
}

namespace
Expand Down
15 changes: 10 additions & 5 deletions test/test_Director.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ using namespace Rice;

TESTSUITE(Director);

SETUP(Director)
{
embed_ruby();
}

TEARDOWN(Director)
{
rb_gc_start();
}

namespace {
/**
* Abstract base class
Expand Down Expand Up @@ -93,11 +103,6 @@ namespace {
};
};

SETUP(Director)
{
embed_ruby();
}

TESTCASE(exposes_worker_as_instantiatable_class)
{
define_class<Worker>("Worker")
Expand Down
1 change: 1 addition & 0 deletions test/test_Enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SETUP(Enum)
TEARDOWN(Enum)
{
Rice::detail::Registries::instance.types.clearUnverifiedTypes();
rb_gc_start();
}


Expand Down
5 changes: 5 additions & 0 deletions test/test_Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Exception)
embed_ruby();
}

TEARDOWN(Exception)
{
rb_gc_start();
}

TESTCASE(construct_from_exception_object)
{
VALUE v = detail::protect(rb_exc_new2, rb_eRuntimeError, "foo");
Expand Down
5 changes: 5 additions & 0 deletions test/test_Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ SETUP(Hash)
embed_ruby();
}

TEARDOWN(Hash)
{
rb_gc_start();
}

TESTCASE(default_construct)
{
Hash h;
Expand Down
5 changes: 5 additions & 0 deletions test/test_Inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ SETUP(Inheritance)
Data_Type<PushNotification>::unbind();
}

TEARDOWN(Inheritance)
{
rb_gc_start();
}

TESTCASE(return_base_pointer)
{
Class rcNotification = define_class<Notification>("Notification");
Expand Down
5 changes: 5 additions & 0 deletions test/test_Iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Iterator)
embed_ruby();
}

TEARDOWN(Iterator)
{
rb_gc_start();
}

namespace
{
class Container
Expand Down
5 changes: 5 additions & 0 deletions test/test_Jump_Tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ SETUP(Jump_Tag)
{
}

TEARDOWN(Jump_Tag)
{
rb_gc_start();
}

TESTCASE(construct)
{
Jump_Tag jump_tag(42);
Expand Down
5 changes: 5 additions & 0 deletions test/test_Keep_Alive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ SETUP(Keep_Alive)
embed_ruby();
}

TEARDOWN(Keep_Alive)
{
rb_gc_start();
}

TESTCASE(test_arg)
{
define_class<Listener>("Listener")
Expand Down
5 changes: 5 additions & 0 deletions test/test_Keep_Alive_No_Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ SETUP(Keep_Alive_No_Wrapper)
embed_ruby();
}

TEARDOWN(Keep_Alive_No_Wrapper)
{
rb_gc_start();
}

TESTCASE(test_keep_alive_no_wrapper)
{
define_class<Animal>("Animal")
Expand Down
5 changes: 5 additions & 0 deletions test/test_Memory_Management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Memory_Management)
embed_ruby();
}

TEARDOWN(Memory_Management)
{
rb_gc_start();
}

namespace
{
class TestClass {
Expand Down
5 changes: 5 additions & 0 deletions test/test_Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ SETUP(Module)
embed_ruby();
}

TEARDOWN(Module)
{
rb_gc_start();
}

TESTCASE(FromConstant)
{
Module m(rb_mEnumerable);
Expand Down
5 changes: 5 additions & 0 deletions test/test_Native_Registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ SETUP(NativeRegistry)
embed_ruby();
}

TEARDOWN(NativeRegistry)
{
rb_gc_start();
}

TESTCASE(collisions)
{
std::array<Class, 100> classes;
Expand Down
5 changes: 5 additions & 0 deletions test/test_Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ SETUP(Object)
embed_ruby();
}

TEARDOWN(Object)
{
rb_gc_start();
}

TESTCASE(default_construct)
{
Object o;
Expand Down
5 changes: 5 additions & 0 deletions test/test_Overloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ SETUP(Overloads)
embed_ruby();
}

TEARDOWN(Overloads)
{
rb_gc_start();
}

namespace
{
std::string run()
Expand Down
5 changes: 5 additions & 0 deletions test/test_Ownership.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ SETUP(Ownership)
define_method("keep_reference", &Factory::keepReference);
}

TEARDOWN(Ownership)
{
rb_gc_start();
}

TESTCASE(TransferPointer)
{
Factory::reset();
Expand Down
5 changes: 5 additions & 0 deletions test/test_Self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ SETUP(Self)
});
}

TEARDOWN(Self)
{
rb_gc_start();
}

TESTCASE(SelfPointer)
{
SelfClass::reset();
Expand Down
5 changes: 5 additions & 0 deletions test/test_Stl_Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ SETUP(Map)
embed_ruby();
}

TEARDOWN(Map)
{
rb_gc_start();
}

namespace
{

Expand Down
5 changes: 5 additions & 0 deletions test/test_Stl_Optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ SETUP(Optional)
makeOptionalClass();
}

TEARDOWN(Optional)
{
rb_gc_start();
}

TESTCASE(OptionalReturn)
{
Module m = define_module("Testing");
Expand Down
5 changes: 5 additions & 0 deletions test/test_Stl_Pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ SETUP(Pair)
embed_ruby();
}

TEARDOWN(Pair)
{
rb_gc_start();
}

TESTCASE(CreatePair)
{
Module m = define_module("Testing");
Expand Down
5 changes: 5 additions & 0 deletions test/test_Stl_Reference_Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ SETUP(ReferenceWrapper)
makeReferenceWrapperClass();
}

TEARDOWN(ReferenceWrapper)
{
rb_gc_start();
}

TESTCASE(Return)
{
Module m = define_module("Testing");
Expand Down
Loading

0 comments on commit b57347a

Please sign in to comment.