Skip to content

Commit

Permalink
Merge branch 'sverker/erl_interface-32intfix/OTP-8945' into dev
Browse files Browse the repository at this point in the history
* sverker/erl_interface-32intfix/OTP-8945:
  Fix ei_decode_SUITE:test_ei_decode_long for halfword vm
  erl_interface: Fix erl_term_len for integers and refs
  • Loading branch information
sverker committed Dec 1, 2010
2 parents b26d90c + af9ee16 commit c7fa778
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
18 changes: 6 additions & 12 deletions lib/erl_interface/src/legacy/erl_marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,29 +511,28 @@ static int erl_term_len_helper(ETERM *ep, int dist)

case ERL_INTEGER:
i = ep->uval.ival.i;
if ((i > ERL_MAX) || (i < ERL_MIN)) len = 7;
else if ((i < 256) && (i >= 0)) len = 2;
if ((i < 256) && (i >= 0)) len = 2;
else len = 5;
break;

case ERL_U_INTEGER:
u = ep->uval.uival.u;
if (u > ERL_MAX) len = 7;
if ((int)u < 0) len = 7;
else if (u < 256) len = 2;
else len = 5;
break;

case ERL_LONGLONG:
l = ep->uval.llval.i;
if ((l > ((long long) ERL_MAX)) ||
(l < ((long long) ERL_MIN))) len = 11;
if ((l > ((long long) INT_MAX)) ||
(l < ((long long) INT_MIN))) len = 11;
else if ((l < 256) && (l >= 0)) len = 2;
else len = 5;
break;

case ERL_U_LONGLONG:
ul = ep->uval.ullval.u;
if (ul > ((unsigned long long) ERL_MAX)) len = 11;
if (ul > ((unsigned long long) INT_MAX)) len = 11;
else if (ul < 256) len = 2;
else len = 5;
break;
Expand All @@ -546,12 +545,7 @@ static int erl_term_len_helper(ETERM *ep, int dist)

case ERL_REF:
i = strlen((char *)ERL_REF_NODE(ep));
if (dist >= 4 && ERL_REF_LEN(ep) > 1) {
len = 1 + 2 + (i+3) + 1 + ERL_REF_LEN(ep) * 4;
} else {
/* 1 + N + 4 + 1 where N = 3 + strlen */
len = 9 + i;
}
len = 1 + 2 + (i+3) + 1 + ERL_REF_LEN(ep) * 4;
break;

case ERL_PORT:
Expand Down
2 changes: 1 addition & 1 deletion lib/erl_interface/test/ei_decode_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ send_integers(P) ->
?line send_term_as_binary(P, 16#80000000), % SMALL_BIG_EXT new smallest pos(*)
?line send_term_as_binary(P,-16#80000001), % SMALL_BIG_EXT new largest neg (*)

case erlang:system_info(wordsize) of
case erlang:system_info({wordsize,external}) of
4 ->
?line send_term_as_binary(P, 16#80000000),% SMALL_BIG_EXT u32
?line send_term_as_binary(P, 16#ffffffff),% SMALL_BIG_EXT largest u32
Expand Down
20 changes: 18 additions & 2 deletions lib/erl_interface/test/erl_eterm_SUITE_data/eterm_test.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* %CopyrightBegin%
*
* Copyright Ericsson AB 1997-2009. All Rights Reserved.
* Copyright Ericsson AB 1997-2010. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
Expand Down Expand Up @@ -98,14 +98,30 @@ static void encode_decode(ETERM* original, const char* text)
{
static unsigned char encoded[16*1024];
ETERM* new_terms;
int bytes = erl_encode(original, encoded);
ETERM* head;
int bytes;
int len;

/* If a list, check the elements one by one first */
head = erl_hd(original);
if (head != NULL) {
encode_decode(head, "CAR");
encode_decode(erl_tl(original), "CDR");
}

bytes = erl_encode(original, encoded);
if (bytes == 0) {
fail("failed to encode terms");
}
else if (bytes > sizeof(encoded)) {
fail("encoded terms buffer overflow");
}
else if (bytes != (len=erl_term_len(original))) {
fprintf(stderr, "bytes(%d) != len(%d) for term ", bytes, len);
erl_print_term(stderr, original);
fprintf(stderr, " [%s]\r\n", text);
fail("erl_encode and erl_term_len do not agree");
}
else if ((new_terms = erl_decode(encoded)) == NULL) {
fail("failed to decode terms");
}
Expand Down

0 comments on commit c7fa778

Please sign in to comment.