mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 08:25:20 +08:00
Use rb_len_t for String and Array lengths in psych
The lengths that libyaml and libfyaml report as size_t are cast to rb_len_t instead of long when they become String lengths. It falls back to long on Ruby versions that do not define HAVE_RB_LEN_T. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
829e47d2f3
commit
5ed647fe15
5 files changed
+11
-7
Notes:
git
2026-10-10 23:11:42 +00:00
No files matched your search
@@ -4,6 +4,10 @@
|
||||
#include <ruby.h>
|
||||
#include <ruby/encoding.h>
|
||||
|
||||
#ifndef HAVE_RB_LEN_T
|
||||
typedef long rb_len_t;
|
||||
#endif
|
||||
|
||||
#ifdef PSYCH_USE_LIBFYAML
|
||||
#include <libfyaml.h>
|
||||
#else
|
||||
|
||||
@@ -25,7 +25,7 @@ static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
|
||||
static int writer(void *ctx, unsigned char *buffer, size_t size)
|
||||
{
|
||||
VALUE self = (VALUE)ctx, io = rb_attr_get(self, id_io);
|
||||
VALUE str = rb_enc_str_new((const char *)buffer, (long)size, rb_utf8_encoding());
|
||||
VALUE str = rb_enc_str_new((const char *)buffer, (rb_len_t)size, rb_utf8_encoding());
|
||||
VALUE wrote = rb_funcall(io, id_write, 1, str);
|
||||
return (int)NUM2INT(wrote);
|
||||
}
|
||||
@@ -172,8 +172,8 @@ static VALUE start_document_try(VALUE d)
|
||||
}
|
||||
|
||||
if(RTEST(tags)) {
|
||||
long i = 0;
|
||||
long len;
|
||||
rb_len_t i = 0;
|
||||
rb_len_t len;
|
||||
rb_encoding * encoding = rb_utf8_encoding();
|
||||
|
||||
Check_Type(tags, T_ARRAY);
|
||||
|
||||
@@ -33,7 +33,7 @@ static int emitter_output(struct fy_emitter *emit, enum fy_emitter_write_type ty
|
||||
{
|
||||
VALUE self = (VALUE)userdata;
|
||||
VALUE io = rb_attr_get(self, id_io);
|
||||
VALUE s = rb_enc_str_new(str, (long)len, rb_utf8_encoding());
|
||||
VALUE s = rb_enc_str_new(str, (rb_len_t)len, rb_utf8_encoding());
|
||||
rb_funcall(io, id_write, 1, s);
|
||||
return len;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ static VALUE start_document_try(VALUE d)
|
||||
|
||||
if (RTEST(tags)) {
|
||||
rb_encoding *encoding = rb_utf8_encoding();
|
||||
long i, len;
|
||||
rb_len_t i, len;
|
||||
Check_Type(tags, T_ARRAY);
|
||||
len = RARRAY_LEN(tags);
|
||||
if (len > 0) {
|
||||
|
||||
@@ -419,7 +419,7 @@ static VALUE parse_body(VALUE ptr)
|
||||
VALUE plain_implicit, quoted_implicit, style;
|
||||
VALUE val = rb_str_new(
|
||||
(const char *)event.data.scalar.value,
|
||||
(long)event.data.scalar.length
|
||||
(rb_len_t)event.data.scalar.length
|
||||
);
|
||||
|
||||
PSYCH_TRANSCODE(val, encoding, internal_enc);
|
||||
|
||||
@@ -256,7 +256,7 @@ static VALUE token_to_str(struct fy_token *tok, int encoding, rb_encoding *inter
|
||||
if (!text) {
|
||||
return Qnil;
|
||||
}
|
||||
VALUE str = rb_str_new(text, (long)len);
|
||||
VALUE str = rb_str_new(text, (rb_len_t)len);
|
||||
PSYCH_TRANSCODE(str, encoding, internal_enc);
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user