Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ MRuby::Gem::Specification.new('mruby-cbor') do |spec|
spec.add_dependency 'mruby-string-is-utf8'
spec.add_dependency 'mruby-native-ext-type', github: 'Asmod4n/mruby-native-ext-type', branch: 'main'
spec.add_dependency 'mruby-str-constantize', github: 'Asmod4n/mruby-str-constantize', branch: 'main'
# The preprocessor cannot test for a name, so the header is read here:
# mruby renamed mrb_bint_from_bytes to mrb_bint_new_bytes and
# mrb_bint_size to mrb_bint_bytes_size on 2026-09-06 (mruby/mruby
# 053056f). src/mrb_cbor.c takes either name behind this define.
internal_h = "#{build.root}/include/mruby/internal.h"
if File.exist?(internal_h) && File.read(internal_h).include?('mrb_bint_new_bytes')
spec.cc.defines << 'MRB_CBOR_BINT_NEW_BYTES'
end

spec.add_test_dependency 'mruby-bigint'
spec.add_test_dependency 'mruby-random'
spec.add_test_dependency 'mruby-io'
Expand Down
21 changes: 17 additions & 4 deletions src/mrb_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
#include <mruby/class.h>
MRB_BEGIN_DECL
#include <mruby/internal.h>

/* mruby renamed the two Bignum byte entries on 2026-09-06 (mruby/mruby
053056f): mrb_bint_from_bytes is mrb_bint_new_bytes, and mrb_bint_size
is mrb_bint_bytes_size. Both names build here. mrbgem.rake reads the
header and defines MRB_CBOR_BINT_NEW_BYTES when the new names are
there, because the preprocessor cannot test for a name. */
#ifdef MRB_CBOR_BINT_NEW_BYTES
#define cbor_bint_new_bytes mrb_bint_new_bytes
#define cbor_bint_bytes_size mrb_bint_bytes_size
#else
#define cbor_bint_new_bytes mrb_bint_from_bytes
#define cbor_bint_bytes_size mrb_bint_size
#endif
MRB_END_DECL
#include <mruby/num_helpers.h>
#include <mruby/branch_pred.h>
Expand Down Expand Up @@ -609,7 +622,7 @@ decode_tagged_bignum(mrb_state* mrb, Reader* r, mrb_value src, mrb_value tag)
}
#endif

mrb_value n = mrb_bint_from_bytes(mrb, bigbuf, len);
mrb_value n = cbor_bint_new_bytes(mrb, bigbuf, len);
mrb_gc_arena_restore(mrb, idx);
mrb_gc_protect(mrb, n);

Expand All @@ -627,7 +640,7 @@ decode_tagged_bignum(mrb_state* mrb, Reader* r, mrb_value src, mrb_value tag)
mrb_gc_protect(mrb, ret);
return ret;
} else {
mrb_bug(mrb, "mrb_bint_from_bytes didnt return a int or bigint");
mrb_bug(mrb, "the Bignum byte entry did not answer with an Integer or a Bignum");
}
} else {
mrb_raise(mrb, E_RANGE_ERROR, "bignum payload length out of range");
Expand Down Expand Up @@ -1176,13 +1189,13 @@ encode_bignum_body(mrb_state *mrb, void *ud)
int idx = mrb_gc_arena_save(mrb);
mrb_int sign = mrb_bint_sign(mrb, obj);

if (mrb_bint_size(mrb, obj) <= 8 && sign >= 0) {
if (cbor_bint_bytes_size(mrb, obj) <= 8 && sign >= 0) {
encode_uint64(w, mrb_bint_as_uint64(mrb, obj));
mrb_gc_arena_restore(mrb, idx);
return mrb_nil_value();
}

if (mrb_bint_size(mrb, obj) <= 8 && sign < 0) {
if (cbor_bint_bytes_size(mrb, obj) <= 8 && sign < 0) {
mrb_value abs_obj = mrb_bint_abs(mrb, obj);
mrb_gc_protect(mrb, abs_obj);
uint64_t n = mrb_bint_as_uint64(mrb, abs_obj) - UINT64_C(1);
Expand Down
Loading