Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b132e1

Browse files
author
Yorick Peterse
committedMay 8, 2015
Boilerplate code for rb_absint_size()
1 parent fb79894 commit 6b132e1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

Diff for: ‎vm/capi/bignum.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,19 @@ extern "C" {
164164
INTEGER_PACK_LSWORD_FIRST | INTEGER_PACK_NATIVE_BYTE_ORDER |
165165
INTEGER_PACK_2COMP);
166166
}
167+
168+
size_t rb_absint_size(VALUE val, int *nlz_bits_ret)
169+
{
170+
VALUE abs = capi_fast_call(val, rb_intern("abs"), 0);
171+
size_t size;
172+
173+
if(FIXNUM_P(abs)) {
174+
size = 0;
175+
// Bignum
176+
} else {
177+
size = rb_big_bytes_used(abs);
178+
}
179+
180+
return size;
181+
}
167182
}

Diff for: ‎vm/include/capi/ruby/ruby.h

+3
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,9 @@ struct RTypedData {
11061106
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);
11071107

11081108
int rb_big_sign(VALUE obj);
1109+
1110+
size_t rb_absint_size(VALUE val, int *nlz_bits_ret);
1111+
11091112
#define RBIGNUM_SIGN(obj) rb_big_sign(obj)
11101113
#define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
11111114
#define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))

0 commit comments

Comments
 (0)
Please sign in to comment.