Skip to content

External format of integers (OTP-8540) #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
= 1.2.0 / 2010-10-02
* Minor Changes
* OTP-8540 (http://erlang.org/download/otp_src_R14B.readme):
"External format of integers changed to make full use of
all 32 bits of INTEGER_EXT"

= 1.1.2 / 2010-02-08
* Bug fixes
* Fix bignum handling on 256 byte boundary
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.2.0
7 changes: 6 additions & 1 deletion ext/bert/c/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#define ERL_STRING 107
#define ERL_LIST 108
#define ERL_BIN 109
#define RB_MAX_FIXNUM (1 << 30) - 1
#define RB_MIN_FIXNUM -(1 << 30)

static VALUE mBERT;
static VALUE cDecode;
Expand Down Expand Up @@ -287,7 +289,10 @@ VALUE read_int(unsigned char **pData) {
value = (value - ((long long) 1 << 32));
}

return INT2FIX(value);
if(value < RB_MIN_FIXNUM || value > RB_MAX_FIXNUM)
return INT2NUM(value);
else
return INT2FIX(value);
}

VALUE read_small_bignum(unsigned char **pData) {
Expand Down
6 changes: 5 additions & 1 deletion lib/bert/decode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ def read_int
value = read_4
negative = (value >> 31)[0] == 1
value = (value - (1 << 32)) if negative
value = Fixnum.induced_from(value)
if value < RB_MIN_FIXNUM or value > RB_MAX_FIXNUM
value = Bignum.induced_from(value)
else
value = Fixnum.induced_from(value)
end
end

def read_small_bignum
Expand Down
6 changes: 4 additions & 2 deletions lib/bert/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module Types
FUN = 117
NEW_FUN = 112
MAGIC = 131
MAX_INT = (1 << 27) -1
MIN_INT = -(1 << 27)
MAX_INT = (1 << 31) - 1
MIN_INT = -(1 << 31)
RB_MAX_FIXNUM = (1 << 30) - 1
RB_MIN_FIXNUM = -(1 << 30)
end
end