Shugo Maeda
c8817d6a3e
Add String#byteindex, String#byterindex, and MatchData#byteoffset ( #5518 )
...
* Add String#byteindex, String#byterindex, and MatchData#byteoffset [Feature #13110 ]
Co-authored-by: NARUSE, Yui <naruse@airemix.jp>
2022-02-19 19:10:00 +09:00
Shugo Maeda
cda5aee74e
LONG2NUM() should be used for rmatch_offset::{beg,end}
...
https://github.com/ruby/ruby/pull/5518#discussion_r809645406
2022-02-18 22:13:45 +09:00
Nobuyoshi Nakada
16fdc1ff46
[DOC] Fix broken links to literals.rdoc
2022-02-08 01:27:52 +09:00
S-H-GAMELINKS
804a714971
Replace to RBOOL macro
2022-01-17 13:49:37 +09:00
Burdette Lamar
28fb6d6b9e
Adding links to literals and Kernel ( #5192 )
...
* Adding links to literals and Kernel
2021-12-03 07:12:28 -06:00
S.H
dc9112cf10
Using NIL_P macro instead of `== Qnil`
2021-10-03 22:34:45 +09:00
Jeremy Evans
abc0304cb2
Avoid race condition in Regexp#match
...
In certain conditions, Regexp#match could return a MatchData with
missing captures. This seems to require at the least, multiple
threads calling a method that calls the same block/proc/lambda
which calls Regexp#match.
The race condition happens because the MatchData is passed from
indirectly via the backref, and other threads can modify the
backref.
Fix the issue by:
1. Not reusing the existing MatchData from the backref, and always
allocating a new MatchData.
2. Passing the MatchData directly to the caller using a VALUE*,
instead of indirectly through the backref.
It's likely that variants of this issue exist for other Regexp
methods. Anywhere that MatchData is passed implicitly through
the backref is probably vulnerable to this issue.
Fixes [Bug #17507 ]
2021-10-01 19:50:19 -09:00
Nobuyoshi Nakada
f2cb6288bc
[Feature #18172 ] Add MatchData#match_length
...
The method to return the length of the matched substring
corresponding to the given argument.
2021-09-16 19:55:06 +09:00
Nobuyoshi Nakada
09d724e6f8
[Feature #18172 ] Add MatchData#match
...
The method to return the single matched substring corresponding to
the given argument.
2021-09-16 19:55:06 +09:00
S.H
b8c3a84bdd
Refactor and Using RBOOL macro
2021-09-15 08:11:05 +09:00
Nobuyoshi Nakada
c5570a7c11
Extract backref_number_check
2021-09-12 11:16:51 +09:00
Nobuyoshi Nakada
99d8c4832a
Preserve the encoding of the argument in IndexError [Bug #18160 ]
2021-09-12 11:16:51 +09:00
Martin Dürst
f2ffa88964
Show default argument explicitly for Rexexp#match? [ci skip]
2021-09-01 09:37:13 +09:00
Martin Dürst
45b8846bec
Fix minor grammar issue in documentation of Regexp#match? [ci skip]
2021-09-01 09:24:34 +09:00
S.H
378e8cdad6
Using RBOOL macro
2021-08-02 12:06:44 +09:00
Nobuyoshi Nakada
9f3888d6a3
Warn more duplicate literal hash keys
...
Following non-special_const literals:
* T_REGEXP
2021-06-03 15:11:18 +09:00
S.H
d627b75e01
Add static modifier to C function in re.c ( #3153 )
...
* add static modifier for rb_reg_eqq func
* add static modifier for rb_check_regexp_type func
2021-06-01 00:59:33 -07:00
Nobuyoshi Nakada
947d93b715
[DOC] {Array,MatchData}#values_at understand ranges [ci skip]
2021-02-07 10:30:43 +09:00
Marcus Stollsteimer
3108ad7bf3
[DOC] Fix grammar: "is same as" -> "is the same as"
2021-01-05 15:13:53 +01:00
Jeremy Evans
05313c914b
Use category: :deprecated in warnings that are related to deprecation
...
Also document that both :deprecated and :experimental are supported
:category option values.
The locations where warnings were marked as deprecation warnings
was previously reviewed by shyouhei.
Comment a couple locations where deprecation warnings should probably
be used but are not currently used because deprecation warning
enablement has not occurred at the time they are called
(RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K).
Add assert_deprecated_warn to test assertions. Use this to simplify
some tests, and fix failing tests after marking some warnings with
deprecated category.
2020-12-18 09:54:11 -08:00
Nobuyoshi Nakada
85aabef023
[Feature #17136 ] Remove special behavior from $KCODE
2020-11-28 18:51:36 +09:00
Koichi Sasada
7ad56fd87b
freeze dynamic regexp literals
...
Regexp literals are frozen, and also dynamically comppiled Regexp
literals (/#{expr}/) are frozen.
2020-10-27 01:45:57 +09:00
Koichi Sasada
99310e3eb5
Some global variables can be accessed from ractors
...
Some global variables should be used from non-main Ractors.
[Bug #17268 ]
```ruby
# ractor-local (derived from created ractor): debug
'$DEBUG' => $DEBUG,
'$-d' => $-d,
# ractor-local (derived from created ractor): verbose
'$VERBOSE' => $VERBOSE,
'$-w' => $-w,
'$-W' => $-W,
'$-v' => $-v,
# process-local (readonly): other commandline parameters
'$-p' => $-p,
'$-l' => $-l,
'$-a' => $-a,
# process-local (readonly): getpid
'$$' => $$,
# thread local: process result
'$?' => $?,
# scope local: match
'$~' => $~.inspect,
'$&' => $&,
'$`' => $`,
'$\'' => $',
'$+' => $+,
'$1' => $1,
# scope local: last line
'$_' => $_,
# scope local: last backtrace
'$@' => $@,
'$!' => $!,
# ractor local: stdin, out, err
'$stdin' => $stdin.inspect,
'$stdout' => $stdout.inspect,
'$stderr' => $stderr.inspect,
```
2020-10-20 15:38:54 +09:00
Kazuhiro NISHIYAMA
1c138327e0
Try to fix compile error on windows
...
https://github.com/ruby/ruby/runs/1041040167?check_suite_focus=true#step:11:177
```
compiling ../src/re.c
re.c
../src/re.c(317): error C2057: expected constant expression
../src/re.c(317): error C2466: cannot allocate an array of constant size 0
../src/re.c(467): error C2057: expected constant expression
../src/re.c(467): error C2466: cannot allocate an array of constant size 0
../src/re.c(467): error C2133: 'opts': unknown size
../src/re.c(559): error C2057: expected constant expression
../src/re.c(559): error C2466: cannot allocate an array of constant size 0
../src/re.c(559): error C2133: 'optbuf': unknown size
../src/re.c(673): error C2057: expected constant expression
../src/re.c(673): error C2466: cannot allocate an array of constant size 0
../src/re.c(673): error C2133: 'opts': unknown size
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\bin\HostX64\x64\cl.EXE"' : return code '0x2'
Stop.
```
2020-08-28 22:03:06 +09:00
Nobuyoshi Nakada
75c4e9b72e
Named the magic number for regexp option buffer size
...
In `rb_enc_reg_error_desc`, no longer kcode option is added.
2020-08-28 19:29:16 +09:00
Nobuyoshi Nakada
e658040266
RSTRING_LEN was not used
2020-08-14 16:12:58 +09:00
Yusuke Endoh
4318aba9c9
re.c: prevent "warning: variable 'n' set but not used"
...
by adding MAYBE_UNUSED.
2020-08-14 08:51:14 +09:00
Nobuyoshi Nakada
787cb0fd86
Replace repeated RSTRING_PTR and RSTRING_LEN with RSTRING_GETMEM
...
As now RSTRING_PTR and RSTRING_LEN are functions, they very bother
stepping in/out during debugging.
2020-08-13 20:56:23 +09:00
卜部昌平
9e41a75255
sed -i 's|ruby/impl|ruby/internal|'
...
To fix build failures.
2020-05-11 09:24:08 +09:00
卜部昌平
d7f4d732c1
sed -i s|ruby/3|ruby/impl|g
...
This shall fix compile errors.
2020-05-11 09:24:08 +09:00
Kazuhiro NISHIYAMA
c79e3a5957
Add {Regexp,String}#match with block to call-seq [ci skip]
2020-04-14 12:39:16 +09:00
卜部昌平
9e6e39c351
Merge pull request #2991 from shyouhei/ruby.h
...
Split ruby.h
2020-04-08 13:28:13 +09:00
Nobuyoshi Nakada
bc646e6715
[DOC] get rid of parsing as TIDYLINK unintentionally
2020-04-07 13:59:38 +09:00
Nobuyoshi Nakada
4f19666e8b
`Regexp` in `MatchData` can be `nil`
...
`String#sub` with a string pattern defers creating a `Regexp`
until `MatchData#regexp` creates a `Regexp` from the matched
string. `Regexp#last_match(group_name)` accessed its content
without creating the `Regexp` though. [Bug #16508 ]
2020-01-16 11:32:11 +09:00
Jean Boussier
98ef38ada4
Freeze Regexp literals
...
[Feature #8948 ] [Feature #16377 ]
Since Regexp literals always reference the same instance,
allowing to mutate them can lead to state leak.
2020-01-15 10:38:47 +09:00
卜部昌平
5e22f873ed
decouple internal.h headers
...
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead. This would significantly
speed up incremental builds.
We take the following inclusion order in this changeset:
1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very
first thing among everything).
2. RUBY_EXTCONF_H if any.
3. Standard C headers, sorted alphabetically.
4. Other system headers, maybe guarded by #ifdef
5. Everything else, sorted alphabetically.
Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
NARUSE, Yui
8852fa8760
Revert "Regexp#match{?} with nil raises TypeError as String, Symbol ( #1506 )"
...
This reverts commit 2a22a6b2d8
.
Revert [Feature #13083 ]
2019-12-04 06:40:54 +09:00
NARUSE, Yui
08074eb712
Revert "Revert nil error and adding deprecation message"
...
This reverts commit 452bee3ee8
.
2019-12-04 06:40:54 +09:00
NARUSE, Yui
a705f6472c
Revert "Improve warning message"
...
This reverts commit 31110d820c
.
2019-12-04 06:40:54 +09:00
Jeremy Evans
ffd0820ab3
Deprecate taint/trust and related methods, and make the methods no-ops
...
This removes the related tests, and puts the related specs behind
version guards. This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Nobuyoshi Nakada
aa94245a09
Undefine MatchData.allocate [Feature #16294 ]
2019-11-06 08:54:32 +09:00
Kenichi Kamiya
31110d820c
Improve warning message
...
https://github.com/ruby/ruby/pull/2637#discussion_r341812475
2019-11-03 11:03:04 +01:00
Kenichi Kamiya
452bee3ee8
Revert nil error and adding deprecation message
2019-11-03 11:03:04 +01:00
Alan Wu
c56d8deaff
Mention correct class name in uninitialized error
...
I think this meant to mention `MatchData`? This is a breaking change, but
should be a minor one.
2019-11-01 18:37:57 +09:00
Kenichi Kamiya
2a22a6b2d8
Regexp#match{?} with nil raises TypeError as String, Symbol ( #1506 )
...
* {String|Symbol}#match{?} with nil returns falsy
To improve consistency with Regexp#match{?}
* String#match(nil) returns `nil` instead of TypeError
* String#match?(nil) returns `false` instead of TypeError
* Symbol#match(nil) returns `nil` instead of TypeError
* Symbol#match?(nil) returns `false` instead of TypeError
* Prefer exception
* Follow empty ENV
* Drop outdated specs
* Write ruby/spec for above
https://github.com/ruby/ruby/pull/1506/files#r183242981
* Fix merge miss
2019-10-17 17:44:46 +09:00
Yusuke Endoh
ebc2198d9f
re.c (match_set_string): add a check for memory allocation
...
Found by Coverity Scan
2019-10-12 22:44:23 +09:00
卜部昌平
3df37259d8
drop-in type check for rb_define_singleton_method
...
We can check the function pointer passed to
rb_define_singleton_method like how we do so in rb_define_method.
Doing so revealed many arity mismatches.
2019-08-29 18:34:09 +09:00
卜部昌平
1663d347c9
delete `$` sign from C identifiers
...
They lack portability. See also
https://travis-ci.org/shyouhei/ruby/jobs/577164015
2019-08-27 15:52:26 +09:00
卜部昌平
ae2dc3f217
rb_define_hooked_variable now free from ANYARGS
...
After 5e86b005c0
, I now think ANYARGS is
dangerous and should be extinct. This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies. Some of them were literally decades old, going back
to dda5dc00cf
.
2019-08-27 15:52:26 +09:00
Nobuyoshi Nakada
1d1f98d49c
Reuse match data
...
* string.c (rb_str_split_m): reuse occupied match data. [Bug #16024 ]
2019-07-28 07:33:21 +09:00