Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f9b67f4
[DOC] Doc for Pathname#parent
BurdetteLamar Jun 30, 2026
0ea1e09
Fix the gemspec error snippet on Windows drive-letter paths
hsbt Jul 1, 2026
1424fe4
[Tests] Add test cases for String#insert
aguspe Jul 1, 2026
8156920
Remove obsolete Windows skip guards from core tests
hsbt Jul 2, 2026
1dc4cb7
Give box_1 extension-loading test a longer timeout
hsbt Jul 2, 2026
ce089a3
[ruby/psych] Add experimental opt-in libfyaml backend
hsbt Jun 30, 2026
4e225df
[ruby/psych] Resolve booleans per YAML 1.2 on the libfyaml backend
hsbt Jun 30, 2026
0a66bb8
[ruby/psych] Improve libfyaml parser fidelity and error reporting
hsbt Jun 30, 2026
7a912af
[ruby/psych] Match libyaml scalar emission on the libfyaml backend
hsbt Jun 30, 2026
e88db7e
[ruby/psych] Transcode UTF-16 IO input to UTF-8 on the libfyaml backend
hsbt Jun 30, 2026
4968187
[ruby/psych] Free tag-directive buffers on the error path in start_do…
hsbt Jul 1, 2026
71c888d
[ruby/psych] Make the test suite backend-aware for the libfyaml backend
hsbt Jul 1, 2026
f230671
[ruby/psych] Harden the libfyaml backend after code review
hsbt Jul 1, 2026
a02377f
[ruby/psych] Add positive tests for the libfyaml backend
hsbt Jul 1, 2026
82ab14e
[ruby/psych] Address Copilot review feedback on the libfyaml backend
hsbt Jul 1, 2026
5ef8b6e
[ruby/psych] Require libfyaml 0.9 and build it from source in CI
hsbt Jul 1, 2026
988fbe0
Move EXTSTATIC check to PRE_LIBRUBY_UPDATE
nobu Jun 18, 2026
172bdf5
Fix static-linked-exts dependency
nobu Jun 18, 2026
d39d807
[ruby/rubygems] bundler: Fix Bundler::Fetcher for PQC support, adding…
junaruga Jun 23, 2026
c1134f8
[ruby/rubygems] Fix Artifice.deactivate to properly restore Gem::Net:…
junaruga Jun 29, 2026
b44dae0
[ruby/rubygems] Fix parallel_installer_spec by activating Artifice ex…
junaruga Jun 29, 2026
e021de1
Trivial refactor around rb_ary_subseq_step
nobu Jul 1, 2026
8e80193
[DOC] Doc for Pathname#opendir
BurdetteLamar Jul 2, 2026
cfb1a23
Make rb_shape_get_root_shape static
peterzhu2118 Jun 30, 2026
439c06b
Annotate Symbol#empty? as leaf (#17464)
sampokuokkanen Jul 2, 2026
89a5a0a
Update depend for psych
peterzhu2118 Jul 2, 2026
99ae28f
ZJIT: Merge C function specialization into type_specialize
tekknolagi Jun 26, 2026
45aef90
ZJIT: Specialize InvokeBuiltin in type_specialize
tekknolagi Jun 26, 2026
284ddba
ZJIT: Remove optimize_c_calls pass
tekknolagi Jun 26, 2026
80ca0b5
ZJIT: Add Function::guard_type_recompile
tekknolagi Jun 26, 2026
33e58bc
ZJIT: Clean up confusing comment
tekknolagi Jul 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,32 +1740,29 @@ rb_ary_entry(VALUE ary, long offset)
return rb_ary_entry_internal(ary, offset);
}

static VALUE
rb_ary_subseq_step(VALUE ary, long beg, long len, long step)
static long
ary_subseq_len(VALUE ary, long beg, long len)
{
VALUE klass;
long alen = RARRAY_LEN(ary);

if (beg > alen) return Qnil;
if (beg < 0 || len < 0) return Qnil;
if (beg > alen) return -1;
if (beg < 0 || len < 0) return -1;

if (alen < len || alen < beg + len) {
len = alen - beg;
}
klass = rb_cArray;
if (len == 0) return ary_new(klass, 0);
if (step == 0)
rb_raise(rb_eArgError, "slice step cannot be zero");
if (step == 1)
return ary_make_partial(ary, klass, beg, len);
else
return ary_make_partial_step(ary, klass, beg, len, step);
ASSUME(len >= 0);
return len;
}

VALUE
rb_ary_subseq(VALUE ary, long beg, long len)
{
return rb_ary_subseq_step(ary, beg, len, 1);
const VALUE klass = rb_cArray;
len = ary_subseq_len(ary, beg, len);
if (len < 0) return Qnil;
if (len == 0) return ary_new(klass, 0);
return ary_make_partial(ary, klass, beg, len);
}

static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
Expand Down Expand Up @@ -1913,6 +1910,7 @@ VALUE
rb_ary_aref1(VALUE ary, VALUE arg)
{
long beg, len, step;
const VALUE klass = rb_cArray;

/* special case - speeding up */
if (FIXNUM_P(arg)) {
Expand All @@ -1925,7 +1923,11 @@ rb_ary_aref1(VALUE ary, VALUE arg)
case Qnil:
return Qnil;
default:
return rb_ary_subseq_step(ary, beg, len, step);
if (step == 0) rb_raise(rb_eArgError, "slice step cannot be zero");
len = ary_subseq_len(ary, beg, len);
if (len == 0) return ary_new(klass, 0);
if (step == 1) return ary_make_partial(ary, klass, beg, len);
return ary_make_partial_step(ary, klass, beg, len, step);
}

return rb_ary_entry(ary, NUM2LONG(arg));
Expand Down
8 changes: 8 additions & 0 deletions benchmark/symbol_empty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prelude: |
sym0 = :""
sym8 = :abcdefgh
GC.disable
benchmark:
symbol_empty-0: sym0.empty?
symbol_empty-8: sym8.empty?
loop_count: 20000000
2 changes: 2 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ $(LIBRUBY_A): $(LIBRUBY_A_OBJS) $(MAINOBJ) $(INITOBJS) $(ARCHFILE)

$(LIBRUBY_SO): $(OBJS) $(DLDOBJS) $(LIBRUBY_A) $(PREP) $(BUILTIN_ENCOBJS)

$(LIBRUBY_A) $(LIBRUBY_SO): $(LIBRUBY_SO_UPDATE)

$(LIBRUBY_EXTS):
@$(NULLCMD) > $@

Expand Down
356 changes: 356 additions & 0 deletions ext/psych/depend

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions ext/psych/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@
# frozen_string_literal: true
require 'mkmf'

# Experimental, opt-in libfyaml backend. Only used when psych is built with
# --enable-libfyaml. Without the flag nothing below changes and the default
# libyaml backend is built exactly as before.
if enable_config("libfyaml", false)
if $mswin or $mingw or $cygwin
abort "The libfyaml backend (--enable-libfyaml) is not supported on Windows"
end
unless pkg_config('libfyaml')
abort "libfyaml was requested with --enable-libfyaml but was not found via pkg-config"
end
# libfyaml 0.8 and earlier crash psych's emitter, so require a known-good
# version rather than building something that segfaults at runtime.
pkgconfig = ENV["PKG_CONFIG"] || "pkg-config"
unless system(pkgconfig, "--atleast-version=0.9", "libfyaml")
abort "The libfyaml backend requires libfyaml 0.9 or newer"
end
$defs << "-DPSYCH_USE_LIBFYAML"

create_makefile 'psych'
return
end

if $mswin or $mingw or $cygwin
$CPPFLAGS << " -DYAML_DECLARE_STATIC"
end
Expand Down
16 changes: 14 additions & 2 deletions ext/psych/lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class ScalarScanner
|[-+]?(?:0|[1-9](?:[0-9]|,[0-9]|_[0-9])*) (?# base 10)
|[-+]?0x[_,]*[0-9a-fA-F][0-9a-fA-F_,]* (?# base 16))$/x

# YAML 1.1 treats yes/no/on/off as booleans in addition to true/false,
# while YAML 1.2's core schema only recognizes true/false. The default
# libyaml backend keeps the 1.1 set for backward compatibility; the
# experimental libfyaml backend follows 1.2.
if defined?(Psych::BACKEND) && Psych::BACKEND == 'libfyaml'
BOOLEAN_TRUE = /^true$/i
BOOLEAN_FALSE = /^false$/i
else
BOOLEAN_TRUE = /^(yes|true|on)$/i
BOOLEAN_FALSE = /^(no|false|off)$/i
end

attr_reader :class_loader

# Create a new scanner
Expand All @@ -48,9 +60,9 @@ def tokenize string
string
elsif string == '~' || string.match?(/^null$/i)
nil
elsif string.match?(/^(yes|true|on)$/i)
elsif string.match?(BOOLEAN_TRUE)
true
elsif string.match?(/^(no|false|off)$/i)
elsif string.match?(BOOLEAN_FALSE)
false
else
string
Expand Down
34 changes: 33 additions & 1 deletion ext/psych/psych.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

/* call-seq: Psych.libyaml_version
*
* Returns the version of libyaml being used
* Returns the version of the underlying YAML library as a three-element
* array. This is libyaml by default. On the experimental libfyaml backend,
* where libyaml is not linked, it reports the libfyaml version instead.
*/
static VALUE libyaml_version(VALUE module)
{
int major, minor, patch;
VALUE list[3];

#ifdef PSYCH_USE_LIBFYAML
/* Experimental libfyaml backend: there is no libyaml linked in. Report
* the libfyaml version so callers still receive a 3-element version. */
const struct fy_version *v = fy_version_default();
major = v ? v->major : 0;
minor = v ? v->minor : 0;
patch = 0;
#else
yaml_get_version(&major, &minor, &patch);
#endif

list[0] = INT2NUM(major);
list[1] = INT2NUM(minor);
Expand All @@ -18,6 +29,20 @@ static VALUE libyaml_version(VALUE module)
return rb_ary_new4((long)3, list);
}

#ifdef PSYCH_USE_LIBFYAML
/* call-seq: Psych.libfyaml_version
*
* Returns the libfyaml version string. This method is only defined when
* psych was built with the experimental libfyaml backend
* (+--enable-libfyaml+).
*/
static VALUE libfyaml_version(VALUE module)
{
const char *v = fy_library_version();
return v ? rb_usascii_str_new2(v) : Qnil;
}
#endif

VALUE mPsych;

void Init_psych(void)
Expand All @@ -29,6 +54,13 @@ void Init_psych(void)

rb_define_singleton_method(mPsych, "libyaml_version", libyaml_version, 0);

#ifdef PSYCH_USE_LIBFYAML
rb_define_singleton_method(mPsych, "libfyaml_version", libfyaml_version, 0);
rb_define_const(mPsych, "BACKEND", rb_usascii_str_new2("libfyaml"));
#else
rb_define_const(mPsych, "BACKEND", rb_usascii_str_new2("libyaml"));
#endif

Init_psych_parser();
Init_psych_emitter();
Init_psych_to_ruby();
Expand Down
4 changes: 4 additions & 0 deletions ext/psych/psych.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
#include <ruby.h>
#include <ruby/encoding.h>

#ifdef PSYCH_USE_LIBFYAML
#include <libfyaml.h>
#else
#include <yaml.h>
#endif

#include <psych_parser.h>
#include <psych_emitter.h>
Expand Down
4 changes: 4 additions & 0 deletions ext/psych/psych_emitter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <psych.h>

#ifndef PSYCH_USE_LIBFYAML

#if !defined(RARRAY_CONST_PTR)
#define RARRAY_CONST_PTR(s) (const VALUE *)RARRAY_PTR(s)
#endif
Expand Down Expand Up @@ -587,3 +589,5 @@ void Init_psych_emitter(void)
id_indentation = rb_intern("indentation");
id_canonical = rb_intern("canonical");
}

#endif /* PSYCH_USE_LIBFYAML */
Loading