Skip to content

Commit 6b94472

Browse files
nobujacob-shops
authored andcommitted
[ruby/strscan] Deprecate undocumented toplevel constant ScanError
ruby/strscan@b4ddc3a2a6
1 parent ac4b9fd commit 6b94472

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

ext/strscan/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
$INCFLAGS << " -I$(top_srcdir)" if $extmk
55
have_func("onig_region_memsize(NULL)")
66
have_func("rb_reg_onig_match", "ruby/re.h")
7+
have_func("rb_deprecate_constant")
78
create_makefile 'strscan'
89
else
910
File.write('Makefile', dummy_makefile("").join)

ext/strscan/strscan.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ extern size_t onig_region_memsize(const struct re_registers *regs);
2424

2525
#define STRSCAN_VERSION "3.1.6.dev"
2626

27+
28+
#ifdef HAVE_RB_DEPRECATE_CONSTANT
29+
/* In ruby 3.0, defined but exposed in external headers */
30+
extern void rb_deprecate_constant(VALUE mod, const char *name);
31+
#else
32+
# define rb_deprecate_constant(mod, name) ((void)0)
33+
#endif
34+
2735
/* =======================================================================
2836
Data Type Definitions
2937
======================================================================= */
@@ -1604,7 +1612,7 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name
16041612
(const unsigned char* )name_end,
16051613
regs);
16061614
if (num >= 1) {
1607-
return num;
1615+
return num;
16081616
}
16091617
}
16101618
rb_enc_raise(enc, rb_eIndexError, "undefined group name reference: %.*s",
@@ -2210,6 +2218,7 @@ Init_strscan(void)
22102218
ScanError = rb_define_class_under(StringScanner, "Error", rb_eStandardError);
22112219
if (!rb_const_defined(rb_cObject, id_scanerr)) {
22122220
rb_const_set(rb_cObject, id_scanerr, ScanError);
2221+
rb_deprecate_constant(rb_cObject, "ScanError");
22132222
}
22142223
tmp = rb_str_new2(STRSCAN_VERSION);
22152224
rb_obj_freeze(tmp);

test/strscan/test_stringscanner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ def test_unscan
875875
assert_equal({}, s.named_captures)
876876
assert_equal("te", s.scan(/../))
877877
assert_equal(nil, s.scan(/\d/))
878-
assert_raise(ScanError) { s.unscan }
878+
assert_raise(StringScanner::Error) { s.unscan }
879879
end
880880

881881
def test_rest

0 commit comments

Comments
 (0)