From 55d7b962e29e73ce43d7f9460170b2c0b348b827 Mon Sep 17 00:00:00 2001 From: Stephen Checkoway Date: Fri, 20 Nov 2020 18:38:03 -0500 Subject: [PATCH] Add test for #150 Test that Ruby objects created in C do not get garbage collected. --- CHANGELOG.md | 1 + test/test_nokogumbo.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2c39597..b2b4d2d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Deprecated ### Removed ### Fixed +- Fixed crash where Ruby objects constructed in C can be garbage collected. ### Security ## [2.0.2] - 2019-11-19 diff --git a/test/test_nokogumbo.rb b/test/test_nokogumbo.rb index 5586c976..6db2da2c 100644 --- a/test/test_nokogumbo.rb +++ b/test/test_nokogumbo.rb @@ -1,5 +1,12 @@ # encoding: utf-8 require 'nokogumbo' + +# Make sure that Ruby objects constructed in C are treated as GC roots. +# See: https://github.com/rubys/nokogumbo/pull/150 +if GC.respond_to?(:verify_compaction_references) + GC.verify_compaction_references(toward: :empty, double_heap: true) +end + require 'minitest/autorun' class TestNokogumbo < Minitest::Test