Skip to content

Commit

Permalink
Merge pull request #2306 from herwinw/gc_enable_disable
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m authored Nov 8, 2024
2 parents b06f81e + 3756066 commit aaae1fc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 9 deletions.
11 changes: 2 additions & 9 deletions include/natalie/gc_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ namespace Natalie {

class GCModule : public Object {
public:
static bool enable() {
Heap::the().gc_enable();
return true;
}

static bool disable() {
Heap::the().gc_disable();
return true;
}
static bool disable();
static bool enable();

static Value start(Env *env) {
Heap::the().collect();
Expand Down
18 changes: 18 additions & 0 deletions spec/core/gc/disable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative '../../spec_helper'

describe "GC.disable" do
after :each do
GC.enable
end

it "returns true if and only if the garbage collection was previously disabled" do
GC.enable
GC.disable.should == false
GC.disable.should == true
GC.disable.should == true
GC.enable
GC.disable.should == false
GC.disable.should == true
end

end
13 changes: 13 additions & 0 deletions spec/core/gc/enable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative '../../spec_helper'

describe "GC.enable" do

it "returns true if and only if the garbage collection was already disabled" do
GC.enable
GC.enable.should == false
GC.disable
GC.enable.should == true
GC.enable.should == false
end

end
19 changes: 19 additions & 0 deletions src/gc_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "natalie/gc_module.hpp"

namespace Natalie {

bool GCModule::disable() {
if (!Heap::the().gc_enabled())
return true;
Heap::the().gc_disable();
return false;
}

bool GCModule::enable() {
if (Heap::the().gc_enabled())
return false;
Heap::the().gc_enable();
return true;
}

}

0 comments on commit aaae1fc

Please sign in to comment.