aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--erts/emulator/beam/atom.names2
-rw-r--r--erts/emulator/beam/dist.c8
-rw-r--r--erts/emulator/beam/dist.h4
-rw-r--r--erts/emulator/beam/erl_node_tables.c28
-rw-r--r--erts/emulator/beam/erl_node_tables.h2
-rw-r--r--erts/emulator/beam/erl_term.h10
-rw-r--r--erts/emulator/beam/erl_vm.h1
-rw-r--r--erts/emulator/beam/external.c190
-rw-r--r--erts/emulator/beam/external.h5
-rw-r--r--erts/emulator/test/node_container_SUITE.erl121
-rw-r--r--lib/common_test/test_server/ts.config4
-rw-r--r--lib/erl_interface/include/ei.h3
-rw-r--r--lib/erl_interface/include/erl_interface.h6
-rw-r--r--lib/erl_interface/src/connect/ei_connect.c3
-rw-r--r--lib/erl_interface/src/connect/ei_connect_int.h1
-rw-r--r--lib/erl_interface/src/decode/decode_pid.c10
-rw-r--r--lib/erl_interface/src/decode/decode_port.c10
-rw-r--r--lib/erl_interface/src/decode/decode_ref.c14
-rw-r--r--lib/erl_interface/src/decode/decode_skip.c3
-rw-r--r--lib/erl_interface/src/encode/encode_pid.c13
-rw-r--r--lib/erl_interface/src/encode/encode_port.c12
-rw-r--r--lib/erl_interface/src/encode/encode_ref.c10
-rw-r--r--lib/erl_interface/src/legacy/erl_eterm.c14
-rw-r--r--lib/erl_interface/src/legacy/erl_eterm.h6
-rw-r--r--lib/erl_interface/src/legacy/erl_marshal.c199
-rw-r--r--lib/erl_interface/src/misc/ei_decode_term.c48
-rw-r--r--lib/erl_interface/src/misc/ei_printterm.c3
-rw-r--r--lib/erl_interface/src/misc/get_type.c9
-rw-r--r--lib/erl_interface/src/misc/show_msg.c3
-rw-r--r--lib/erl_interface/test/all_SUITE_data/ei_runner.c11
-rw-r--r--lib/erl_interface/test/all_SUITE_data/ei_runner.h3
-rw-r--r--lib/erl_interface/test/ei_decode_encode_SUITE.erl103
-rw-r--r--lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c13
-rw-r--r--lib/erl_interface/test/ei_tmo_SUITE.erl14
-rw-r--r--lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c11
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/AbstractNode.java4
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPid.java54
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPort.java47
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangRef.java50
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpExternal.java3
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java46
-rw-r--r--lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java153
-rw-r--r--lib/jinterface/test/nc_SUITE.erl58
-rw-r--r--lib/kernel/include/dist.hrl1
-rw-r--r--lib/kernel/src/dist_util.erl3
45 files changed, 883 insertions, 433 deletions
diff --git a/erts/emulator/beam/atom.names b/erts/emulator/beam/atom.names
index 169b071cd7..2eb63febe7 100644
--- a/erts/emulator/beam/atom.names
+++ b/erts/emulator/beam/atom.names
@@ -43,7 +43,7 @@ atom false true
atom Underscore='_'
atom Noname='nonode@nohost'
atom EOT='$end_of_table'
-atom Cookie=''
+atom Empty=''
#
# Used in the Beam emulator loop. (Smaller literals usually means tighter code.)
diff --git a/erts/emulator/beam/dist.c b/erts/emulator/beam/dist.c
index fa385f105d..3a6da373c3 100644
--- a/erts/emulator/beam/dist.c
+++ b/erts/emulator/beam/dist.c
@@ -906,9 +906,9 @@ erts_dsig_send_msg(Eterm remote, Eterm message, ErtsSendContext* ctx)
if (token != NIL)
ctl = TUPLE4(&ctx->ctl_heap[0],
- make_small(DOP_SEND_TT), am_Cookie, remote, token);
+ make_small(DOP_SEND_TT), am_Empty, remote, token);
else
- ctl = TUPLE3(&ctx->ctl_heap[0], make_small(DOP_SEND), am_Cookie, remote);
+ ctl = TUPLE3(&ctx->ctl_heap[0], make_small(DOP_SEND), am_Empty, remote);
DTRACE6(message_send, sender_name, receiver_name,
msize, tok_label, tok_lastcnt, tok_serial);
DTRACE7(message_send_remote, sender_name, node_name, receiver_name,
@@ -963,10 +963,10 @@ erts_dsig_send_reg_msg(Eterm remote_name, Eterm message,
if (token != NIL)
ctl = TUPLE5(&ctx->ctl_heap[0], make_small(DOP_REG_SEND_TT),
- sender->common.id, am_Cookie, remote_name, token);
+ sender->common.id, am_Empty, remote_name, token);
else
ctl = TUPLE4(&ctx->ctl_heap[0], make_small(DOP_REG_SEND),
- sender->common.id, am_Cookie, remote_name);
+ sender->common.id, am_Empty, remote_name);
DTRACE6(message_send, sender_name, receiver_name,
msize, tok_label, tok_lastcnt, tok_serial);
DTRACE7(message_send_remote, sender_name, node_name, receiver_name,
diff --git a/erts/emulator/beam/dist.h b/erts/emulator/beam/dist.h
index fb777d9ac1..e3ff6ebad1 100644
--- a/erts/emulator/beam/dist.h
+++ b/erts/emulator/beam/dist.h
@@ -43,6 +43,7 @@
#define DFLAG_INTERNAL_TAGS 0x8000
#define DFLAG_UTF8_ATOMS 0x10000
#define DFLAG_MAP_TAG 0x20000
+#define DFLAG_BIG_CREATION 0x40000
/* All flags that should be enabled when term_to_binary/1 is used. */
#define TERM_TO_BINARY_DFLAGS (DFLAG_EXTENDED_REFERENCES \
@@ -51,7 +52,8 @@
| DFLAG_EXTENDED_PIDS_PORTS \
| DFLAG_EXPORT_PTR_TAG \
| DFLAG_BIT_BINARIES \
- | DFLAG_MAP_TAG)
+ | DFLAG_MAP_TAG \
+ | DFLAG_BIG_CREATION)
/* opcodes used in distribution messages */
#define DOP_LINK 1
diff --git a/erts/emulator/beam/erl_node_tables.c b/erts/emulator/beam/erl_node_tables.c
index 8617f42d7b..79da705e0f 100644
--- a/erts/emulator/beam/erl_node_tables.c
+++ b/erts/emulator/beam/erl_node_tables.c
@@ -497,31 +497,7 @@ node_table_hash(void *venp)
Uint32 cre = ((ErlNode *) venp)->creation;
HashValue h = atom_tab(atom_val(((ErlNode *) venp)->sysname))->slot.bucket.hvalue;
- h *= PRIME0;
- h += cre & 0xff;
-
-#if MAX_CREATION >= (1 << 8)
- h *= PRIME1;
- h += (cre >> 8) & 0xff;
-#endif
-
-#if MAX_CREATION >= (1 << 16)
- h *= PRIME2;
- h += (cre >> 16) & 0xff;
-#endif
-
-#if MAX_CREATION >= (1 << 24)
- h *= PRIME3;
- h += (cre >> 24) & 0xff;
-#endif
-
-#if 0
-/* XXX Problems in older versions of GCC */
- #if MAX_CREATION >= (1UL << 32)
- #error "MAX_CREATION larger than size of expected creation storage (Uint32)"
- #endif
-#endif
- return h;
+ return (h + cre) * PRIME0;
}
static int
@@ -599,7 +575,7 @@ erts_node_table_info(int to, void *to_arg)
}
-ErlNode *erts_find_or_insert_node(Eterm sysname, Uint creation)
+ErlNode *erts_find_or_insert_node(Eterm sysname, Uint32 creation)
{
ErlNode *res;
ErlNode ne;
diff --git a/erts/emulator/beam/erl_node_tables.h b/erts/emulator/beam/erl_node_tables.h
index fb2f2a5407..2b93f1f08a 100644
--- a/erts/emulator/beam/erl_node_tables.h
+++ b/erts/emulator/beam/erl_node_tables.h
@@ -182,7 +182,7 @@ Uint erts_dist_table_size(void);
void erts_dist_table_info(int, void *);
void erts_set_dist_entry_not_connected(DistEntry *);
void erts_set_dist_entry_connected(DistEntry *, Eterm, Uint);
-ErlNode *erts_find_or_insert_node(Eterm, Uint);
+ErlNode *erts_find_or_insert_node(Eterm, Uint32);
void erts_schedule_delete_node(ErlNode *);
void erts_set_this_node(Eterm, Uint);
Uint erts_node_table_size(void);
diff --git a/erts/emulator/beam/erl_term.h b/erts/emulator/beam/erl_term.h
index 0a71534790..fc58853b5e 100644
--- a/erts/emulator/beam/erl_term.h
+++ b/erts/emulator/beam/erl_term.h
@@ -558,14 +558,6 @@ _ET_DECLARE_CHECKED(Eterm*,tuple_val,Wterm)
#define _GETBITS(X,Pos,Size) (((X) >> (Pos)) & ~(~((Uint) 0) << (Size)))
-/*
- * Creation in node specific data (pids, ports, refs)
- */
-
-#define _CRE_SIZE 2
-
-/* MAX value for the creation field in pid, port and reference */
-#define MAX_CREATION (1 << _CRE_SIZE)
/*
* PID layout (internal pids):
@@ -579,7 +571,7 @@ _ET_DECLARE_CHECKED(Eterm*,tuple_val,Wterm)
*
* n : number
*
- * Old pid layout:
+ * Very old pid layout:
*
* |3 3 2 2 2 2 2 2|2 2 2 2 1 1 1 1|1 1 1 1 1 1 | |
* |1 0 9 8 7 6 5 4|3 2 1 0 9 8 7 6|5 4 3 2 1 0 9 8|7 6 5 4 3 2 1 0|
diff --git a/erts/emulator/beam/erl_vm.h b/erts/emulator/beam/erl_vm.h
index 98f27a1725..357094633e 100644
--- a/erts/emulator/beam/erl_vm.h
+++ b/erts/emulator/beam/erl_vm.h
@@ -165,7 +165,6 @@ extern int erts_atom_table_size;/* Atom table size */
extern int erts_pd_initial_size;/* Initial Process dictionary table size */
#define ORIG_CREATION 0
-#define INTERNAL_CREATION 255
/* macros for extracting bytes from uint16's */
diff --git a/erts/emulator/beam/external.c b/erts/emulator/beam/external.c
index 10f03636ec..5ea155f83f 100644
--- a/erts/emulator/beam/external.c
+++ b/erts/emulator/beam/external.c
@@ -51,7 +51,18 @@
#define MAX_STRING_LEN 0xffff
-#define is_valid_creation(Cre) ((unsigned)(Cre) < MAX_CREATION || (Cre) == INTERNAL_CREATION)
+/* MAX value for the creation field in pid, port and reference
+ for the local node and for the current external format.
+
+ Larger creation values than this are allowed in external pid, port and refs
+ encoded with NEW_PID_EXT, NEW_PORT_EXT and NEWER_REFERENCE_EXT.
+ The point here is to prepare for future upgrade to 32-bit creation.
+ OTP-19 (erts-8.0) can handle big creation values from other (newer) nodes,
+ but do not use big creation values for the local node yet,
+ as we still may have to communicate with older nodes.
+*/
+#define ERTS_MAX_LOCAL_CREATION (3)
+#define is_valid_creation(Cre) ((unsigned)(Cre) <= ERTS_MAX_LOCAL_CREATION)
#undef ERTS_DEBUG_USE_DIST_SEP
#ifdef DEBUG
@@ -97,7 +108,7 @@ static byte* enc_pid(ErtsAtomCacheMap *, Eterm, byte*, Uint32);
struct B2TContext_t;
static byte* dec_term(ErtsDistExternal*, ErtsHeapFactory*, byte*, Eterm*, struct B2TContext_t*);
static byte* dec_atom(ErtsDistExternal *, byte*, Eterm*);
-static byte* dec_pid(ErtsDistExternal *, ErtsHeapFactory*, byte*, Eterm*);
+static byte* dec_pid(ErtsDistExternal *, ErtsHeapFactory*, byte*, Eterm*, byte tag);
static Sint decoded_size(byte *ep, byte* endp, int internal_tags, struct B2TContext_t*);
static BIF_RETTYPE term_to_binary_trap_1(BIF_ALIST_1);
@@ -2152,12 +2163,13 @@ static byte*
enc_pid(ErtsAtomCacheMap *acmp, Eterm pid, byte* ep, Uint32 dflags)
{
Uint on, os;
+ Eterm sysname = ((is_internal_pid(pid) && (dflags & DFLAG_INTERNAL_TAGS))
+ ? am_Empty : pid_node_name(pid));
+ Uint32 creation = pid_creation(pid);
+ byte* tagp = ep++;
- *ep++ = PID_EXT;
/* insert atom here containing host and sysname */
- ep = enc_atom(acmp, pid_node_name(pid), ep, dflags);
-
- /* two bytes for each number and serial */
+ ep = enc_atom(acmp, sysname, ep, dflags);
on = pid_number(pid);
os = pid_serial(pid);
@@ -2166,8 +2178,15 @@ enc_pid(ErtsAtomCacheMap *acmp, Eterm pid, byte* ep, Uint32 dflags)
ep += 4;
put_int32(os, ep);
ep += 4;
- *ep++ = (is_internal_pid(pid) && (dflags & DFLAG_INTERNAL_TAGS)) ?
- INTERNAL_CREATION : pid_creation(pid);
+ if (creation <= ERTS_MAX_LOCAL_CREATION) {
+ *tagp = PID_EXT;
+ *ep++ = creation;
+ } else {
+ ASSERT(is_external_pid(pid));
+ *tagp = NEW_PID_EXT;
+ put_int32(creation, ep);
+ ep += 4;
+ }
return ep;
}
@@ -2247,27 +2266,27 @@ dec_atom(ErtsDistExternal *edep, byte* ep, Eterm* objp)
return ep;
}
-static ERTS_INLINE ErlNode* dec_get_node(Eterm sysname, Uint creation)
+static ERTS_INLINE ErlNode* dec_get_node(Eterm sysname, Uint32 creation)
{
- switch (creation) {
- case INTERNAL_CREATION:
+ if (sysname == am_Empty) /* && DFLAG_INTERNAL_TAGS */
return erts_this_node;
- case ORIG_CREATION:
- if (sysname == erts_this_node->sysname) {
- creation = erts_this_node->creation;
- }
- }
+
+ if (sysname == erts_this_node->sysname
+ && (creation == erts_this_node->creation || creation == ORIG_CREATION))
+ return erts_this_node;
+
return erts_find_or_insert_node(sysname,creation);
}
static byte*
-dec_pid(ErtsDistExternal *edep, ErtsHeapFactory* factory, byte* ep, Eterm* objp)
+dec_pid(ErtsDistExternal *edep, ErtsHeapFactory* factory, byte* ep,
+ Eterm* objp, byte tag)
{
Eterm sysname;
Uint data;
Uint num;
Uint ser;
- Uint cre;
+ Uint32 cre;
ErlNode *node;
*objp = NIL; /* In case we fail, don't leave a hole in the heap */
@@ -2283,12 +2302,19 @@ dec_pid(ErtsDistExternal *edep, ErtsHeapFactory* factory, byte* ep, Eterm* objp)
ep += 4;
if (ser > ERTS_MAX_PID_SERIAL)
return NULL;
- cre = get_int8(ep);
- ep += 1;
- if (!is_valid_creation(cre)) {
- return NULL;
+ if (tag == PID_EXT) {
+ cre = get_int8(ep);
+ ep += 1;
+ if (!is_valid_creation(cre)) {
+ return NULL;
+ }
+ } else {
+ ASSERT(tag == NEW_PID_EXT);
+ cre = get_int32(ep);
+ ep += 4;
}
+
data = make_pid_data(ser, num);
/*
@@ -2528,16 +2554,26 @@ enc_term_int(TTBEncodeContext* ctx, ErtsAtomCacheMap *acmp, Eterm obj, byte* ep,
case REF_DEF:
case EXTERNAL_REF_DEF: {
Uint32 *ref_num;
+ Eterm sysname = (((dflags & DFLAG_INTERNAL_TAGS) && is_internal_ref(obj))
+ ? am_Empty : ref_node_name(obj));
+ Uint32 creation = ref_creation(obj);
+ byte* tagp = ep++;
ASSERT(dflags & DFLAG_EXTENDED_REFERENCES);
- *ep++ = NEW_REFERENCE_EXT;
i = ref_no_of_numbers(obj);
put_int16(i, ep);
ep += 2;
- ep = enc_atom(acmp,ref_node_name(obj),ep,dflags);
- *ep++ = ((dflags & DFLAG_INTERNAL_TAGS) && is_internal_ref(obj)) ?
- INTERNAL_CREATION : ref_creation(obj);
+ ep = enc_atom(acmp, sysname, ep, dflags);
+ if (creation <= ERTS_MAX_LOCAL_CREATION) {
+ *tagp = NEW_REFERENCE_EXT;
+ *ep++ = creation;
+ } else {
+ ASSERT(is_external_ref(obj));
+ *tagp = NEWER_REFERENCE_EXT;
+ put_int32(creation, ep);
+ ep += 4;
+ }
ref_num = ref_numbers(obj);
for (j = 0; j < i; j++) {
put_int32(ref_num[j], ep);
@@ -2546,17 +2582,27 @@ enc_term_int(TTBEncodeContext* ctx, ErtsAtomCacheMap *acmp, Eterm obj, byte* ep,
break;
}
case PORT_DEF:
- case EXTERNAL_PORT_DEF:
+ case EXTERNAL_PORT_DEF: {
+ Eterm sysname = (((dflags & DFLAG_INTERNAL_TAGS) && is_internal_port(obj))
+ ? am_Empty : port_node_name(obj));
+ Uint32 creation = port_creation(obj);
+ byte* tagp = ep++;
- *ep++ = PORT_EXT;
- ep = enc_atom(acmp,port_node_name(obj),ep,dflags);
+ ep = enc_atom(acmp, sysname, ep, dflags);
j = port_number(obj);
put_int32(j, ep);
ep += 4;
- *ep++ = ((dflags & DFLAG_INTERNAL_TAGS) && is_internal_port(obj)) ?
- INTERNAL_CREATION : port_creation(obj);
+ if (creation <= ERTS_MAX_LOCAL_CREATION) {
+ *tagp = PORT_EXT;
+ *ep++ = creation;
+ } else {
+ ASSERT(is_external_port(obj));
+ *tagp = NEW_PORT_EXT;
+ put_int32(creation, ep);
+ ep += 4;
+ }
break;
-
+ }
case LIST_DEF:
{
int is_str;
@@ -3260,20 +3306,23 @@ dec_term_atom_common:
hp += FLOAT_SIZE_OBJECT;
break;
}
- case PID_EXT:
+ case PID_EXT:
+ case NEW_PID_EXT:
factory->hp = hp;
- ep = dec_pid(edep, factory, ep, objp);
+ ep = dec_pid(edep, factory, ep, objp, ep[-1]);
hp = factory->hp;
if (ep == NULL) {
goto error;
}
break;
- case PORT_EXT:
+ case PORT_EXT:
+ case NEW_PORT_EXT:
{
Eterm sysname;
ErlNode *node;
Uint num;
- Uint cre;
+ Uint32 cre;
+ byte tag = ep[-1];
if ((ep = dec_atom(edep, ep, &sysname)) == NULL) {
goto error;
@@ -3282,12 +3331,17 @@ dec_term_atom_common:
goto error;
}
ep += 4;
- cre = get_int8(ep);
- ep++;
- if (!is_valid_creation(cre)) {
- goto error;
- }
-
+ if (tag == PORT_EXT) {
+ cre = get_int8(ep);
+ ep++;
+ if (!is_valid_creation(cre)) {
+ goto error;
+ }
+ }
+ else {
+ cre = get_int32(ep);
+ ep += 4;
+ }
node = dec_get_node(sysname, cre);
if(node == erts_this_node) {
*objp = make_internal_port(num);
@@ -3312,7 +3366,7 @@ dec_term_atom_common:
Eterm sysname;
ErlNode *node;
int i;
- Uint cre;
+ Uint32 cre;
Uint32 *ref_num;
Uint32 r0;
Uint ref_words;
@@ -3336,9 +3390,6 @@ dec_term_atom_common:
ref_words = get_int16(ep);
ep += 2;
- if (ref_words > ERTS_MAX_REF_NUMBERS)
- goto error;
-
if ((ep = dec_atom(edep, ep, &sysname)) == NULL)
goto error;
@@ -3351,8 +3402,23 @@ dec_term_atom_common:
ep += 4;
if (r0 >= MAX_REFERENCE)
goto error;
+ goto ref_ext_common;
+
+ case NEWER_REFERENCE_EXT:
+ ref_words = get_int16(ep);
+ ep += 2;
+
+ if ((ep = dec_atom(edep, ep, &sysname)) == NULL)
+ goto error;
+
+ cre = get_int32(ep);
+ ep += 4;
+ r0 = get_int32(ep); /* allow full word */
+ ep += 4;
ref_ext_common:
+ if (ref_words > ERTS_MAX_REF_NUMBERS)
+ goto error;
node = dec_get_node(sysname, cre);
if(node == erts_this_node) {
@@ -3706,9 +3772,9 @@ dec_term_atom_common:
*objp = make_fun(funp);
/* Creator pid */
- if (*ep != PID_EXT
- || (ep = dec_pid(edep, factory, ++ep,
- &funp->creator))==NULL) {
+ if ((*ep != PID_EXT && *ep != NEW_PID_EXT)
+ || (ep = dec_pid(edep, factory, ep+1,
+ &funp->creator, *ep))==NULL) {
goto error;
}
@@ -4010,20 +4076,29 @@ encode_size_struct_int(TTBSizeContext* ctx, ErtsAtomCacheMap *acmp, Eterm obj,
else
result += 1 + 4 + 1 + i; /* tag,size,sign,digits */
break;
+ case EXTERNAL_PID_DEF:
+ if (external_pid_creation(obj) > ERTS_MAX_LOCAL_CREATION)
+ result += 3;
+ /*fall through*/
case PID_DEF:
- case EXTERNAL_PID_DEF:
result += (1 + encode_size_struct2(acmp, pid_node_name(obj), dflags) +
4 + 4 + 1);
break;
+ case EXTERNAL_REF_DEF:
+ if (external_ref_creation(obj) > ERTS_MAX_LOCAL_CREATION)
+ result += 3;
+ /*fall through*/
case REF_DEF:
- case EXTERNAL_REF_DEF:
ASSERT(dflags & DFLAG_EXTENDED_REFERENCES);
i = ref_no_of_numbers(obj);
result += (1 + 2 + encode_size_struct2(acmp, ref_node_name(obj), dflags) +
1 + 4*i);
break;
- case PORT_DEF:
- case EXTERNAL_PORT_DEF:
+ case EXTERNAL_PORT_DEF:
+ if (external_port_creation(obj) > ERTS_MAX_LOCAL_CREATION)
+ result += 3;
+ /*fall through*/
+ case PORT_DEF:
result += (1 + encode_size_struct2(acmp, port_node_name(obj), dflags) +
4 + 1);
break;
@@ -4350,19 +4425,22 @@ init_done:
SKIP(1+atom_extra_skip);
atom_extra_skip = 0;
break;
- case PID_EXT:
+ case PID_EXT:
+ case NEW_PID_EXT:
atom_extra_skip = 9;
/* In case it is an external pid */
heap_size += EXTERNAL_THING_HEAD_SIZE + 1;
terms++;
break;
- case PORT_EXT:
+ case PORT_EXT:
+ case NEW_PORT_EXT:
atom_extra_skip = 5;
/* In case it is an external port */
heap_size += EXTERNAL_THING_HEAD_SIZE + 1;
terms++;
break;
- case NEW_REFERENCE_EXT:
+ case NEW_REFERENCE_EXT:
+ case NEWER_REFERENCE_EXT:
{
int id_words;
diff --git a/erts/emulator/beam/external.h b/erts/emulator/beam/external.h
index 87eff2fe9f..49198fb47f 100644
--- a/erts/emulator/beam/external.h
+++ b/erts/emulator/beam/external.h
@@ -18,8 +18,6 @@
* %CopyrightEnd%
*/
-/* Same order as the ordering of terms in erlang */
-
/* Since there are 255 different External tag values to choose from
There is no reason to not be extravagant.
Hence, the different tags for large/small tuple e.t.c
@@ -37,9 +35,12 @@
#define SMALL_ATOM_EXT 's'
#define REFERENCE_EXT 'e'
#define NEW_REFERENCE_EXT 'r'
+#define NEWER_REFERENCE_EXT 'Z'
#define PORT_EXT 'f'
+#define NEW_PORT_EXT 'Y'
#define NEW_FLOAT_EXT 'F'
#define PID_EXT 'g'
+#define NEW_PID_EXT 'X'
#define SMALL_TUPLE_EXT 'h'
#define LARGE_TUPLE_EXT 'i'
#define NIL_EXT 'j'
diff --git a/erts/emulator/test/node_container_SUITE.erl b/erts/emulator/test/node_container_SUITE.erl
index 662e5423b9..d1f90c952a 100644
--- a/erts/emulator/test/node_container_SUITE.erl
+++ b/erts/emulator/test/node_container_SUITE.erl
@@ -124,7 +124,13 @@ term_to_binary_to_term_eq(Config) when is_list(Config) ->
LHLRef = binary_to_term(term_to_binary(LHLRef)),
LSRef = binary_to_term(term_to_binary(LSRef)),
% Get remote node containers
- RNode = {get_nodename(), 3},
+ ttbtteq_do_remote({get_nodename(), 3}),
+ ttbtteq_do_remote({get_nodename(), 4}),
+ ttbtteq_do_remote({get_nodename(), 16#adec0ded}),
+ nc_refc_check(node()),
+ ok.
+
+ttbtteq_do_remote(RNode) ->
RPid = mk_pid(RNode, 4711, 1),
RXPid = mk_pid(RNode, 32767, 8191),
RPort = mk_port(RNode, 4711),
@@ -140,7 +146,6 @@ term_to_binary_to_term_eq(Config) when is_list(Config) ->
RLRef = binary_to_term(term_to_binary(RLRef)),
RHLRef = binary_to_term(term_to_binary(RHLRef)),
RSRef = binary_to_term(term_to_binary(RSRef)),
- nc_refc_check(node()),
ok.
@@ -805,7 +810,7 @@ bad_nc(Config) when is_list(Config) ->
= (catch mk_ref(RemNode, [(1 bsl 18), 4711, 4711])),
{'EXIT', {badarg, mk_ref, _}}
= (catch mk_ref(RemNode, [4711, 4711, 4711, 4711, 4711, 4711, 4711])),
- BadNode = {x@y, 4},
+ BadNode = {x@y, bad_creation},
{'EXIT', {badarg, mk_pid, _}}
= (catch mk_pid(BadNode, 4711, 17)),
{'EXIT', {badarg, mk_port, _}}
@@ -1108,6 +1113,9 @@ get_nodename() ->
-define(PORT_EXT, 102).
-define(PID_EXT, 103).
-define(NEW_REFERENCE_EXT, 114).
+-define(NEW_PID_EXT, $X).
+-define(NEW_PORT_EXT, $Y).
+-define(NEWER_REFERENCE_EXT, $Z).
uint32_be(Uint) when is_integer(Uint), 0 =< Uint, Uint < 1 bsl 32 ->
[(Uint bsr 24) band 16#ff,
@@ -1130,51 +1138,65 @@ uint8(Uint) ->
exit({badarg, uint8, [Uint]}).
+pid_tag(bad_creation) -> ?PID_EXT;
+pid_tag(Creation) when Creation =< 3 -> ?PID_EXT;
+pid_tag(_Creation) -> ?NEW_PID_EXT.
+
+enc_creation(bad_creation) -> uint8(4);
+enc_creation(Creation) when Creation =< 3 -> uint8(Creation);
+enc_creation(Creation) -> uint32_be(Creation).
mk_pid({NodeName, Creation}, Number, Serial) when is_atom(NodeName) ->
mk_pid({atom_to_list(NodeName), Creation}, Number, Serial);
mk_pid({NodeName, Creation}, Number, Serial) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PID_EXT,
- ?ATOM_EXT,
- uint16_be(length(NodeName)),
- NodeName,
- uint32_be(Number),
- uint32_be(Serial),
- uint8(Creation)])) of
- Pid when is_pid(Pid) ->
- Pid;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_pid, [{NodeName, Creation}, Number, Serial]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ pid_tag(Creation),
+ ?ATOM_EXT,
+ uint16_be(length(NodeName)),
+ NodeName,
+ uint32_be(Number),
+ uint32_be(Serial),
+ enc_creation(Creation)])) of
+ Pid when is_pid(Pid) ->
+ Pid;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_pid, [{NodeName, Creation}, Number, Serial]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end.
+port_tag(bad_creation) -> ?PORT_EXT;
+port_tag(Creation) when Creation =< 3 -> ?PORT_EXT;
+port_tag(_Creation) -> ?NEW_PORT_EXT.
+
mk_port({NodeName, Creation}, Number) when is_atom(NodeName) ->
mk_port({atom_to_list(NodeName), Creation}, Number);
mk_port({NodeName, Creation}, Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PORT_EXT,
- ?ATOM_EXT,
- uint16_be(length(NodeName)),
- NodeName,
- uint32_be(Number),
- uint8(Creation)])) of
- Port when is_port(Port) ->
- Port;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_port, [{NodeName, Creation}, Number]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ port_tag(Creation),
+ ?ATOM_EXT,
+ uint16_be(length(NodeName)),
+ NodeName,
+ uint32_be(Number),
+ enc_creation(Creation)])) of
+ Port when is_port(Port) ->
+ Port;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_port, [{NodeName, Creation}, Number]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end.
+ref_tag(bad_creation) -> ?NEW_REFERENCE_EXT;
+ref_tag(Creation) when Creation =< 3 -> ?NEW_REFERENCE_EXT;
+ref_tag(_Creation) -> ?NEWER_REFERENCE_EXT.
+
mk_ref({NodeName, Creation}, Numbers) when is_atom(NodeName),
- is_integer(Creation),
- is_list(Numbers) ->
+ is_list(Numbers) ->
mk_ref({atom_to_list(NodeName), Creation}, Numbers);
mk_ref({NodeName, Creation}, [Number]) when is_list(NodeName),
- is_integer(Creation),
- is_integer(Number) ->
+ Creation =< 3,
+ is_integer(Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
?REFERENCE_EXT,
?ATOM_EXT,
@@ -1190,25 +1212,24 @@ mk_ref({NodeName, Creation}, [Number]) when is_list(NodeName),
exit({unexpected_binary_to_term_result, Other})
end;
mk_ref({NodeName, Creation}, Numbers) when is_list(NodeName),
- is_integer(Creation),
- is_list(Numbers) ->
+ is_list(Numbers) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?NEW_REFERENCE_EXT,
- uint16_be(length(Numbers)),
- ?ATOM_EXT,
- uint16_be(length(NodeName)),
- NodeName,
- uint8(Creation),
- lists:map(fun (N) ->
- uint32_be(N)
- end,
- Numbers)])) of
- Ref when is_reference(Ref) ->
- Ref;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_ref, [{NodeName, Creation}, Numbers]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ ref_tag(Creation),
+ uint16_be(length(Numbers)),
+ ?ATOM_EXT,
+ uint16_be(length(NodeName)),
+ NodeName,
+ enc_creation(Creation),
+ lists:map(fun (N) ->
+ uint32_be(N)
+ end,
+ Numbers)])) of
+ Ref when is_reference(Ref) ->
+ Ref;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_ref, [{NodeName, Creation}, Numbers]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end.
exec_loop() ->
diff --git a/lib/common_test/test_server/ts.config b/lib/common_test/test_server/ts.config
index cf3d269616..d05e4885fc 100644
--- a/lib/common_test/test_server/ts.config
+++ b/lib/common_test/test_server/ts.config
@@ -44,3 +44,7 @@
% {295,0,0,0,0,0,0,1},
% ["dummy6-ip6"]
% }}.
+
+%% Used by erl_interface tests
+%% Known hostname with an unreachable ip
+%{test_host_not_reachable, "ghost.mydomain.com"}.
diff --git a/lib/erl_interface/include/ei.h b/lib/erl_interface/include/ei.h
index c1dbc8470d..80815d42d4 100644
--- a/lib/erl_interface/include/ei.h
+++ b/lib/erl_interface/include/ei.h
@@ -121,8 +121,11 @@
#define ERL_SMALL_ATOM_UTF8_EXT 'w'
#define ERL_REFERENCE_EXT 'e'
#define ERL_NEW_REFERENCE_EXT 'r'
+#define ERL_NEWER_REFERENCE_EXT 'Z'
#define ERL_PORT_EXT 'f'
+#define ERL_NEW_PORT_EXT 'Y'
#define ERL_PID_EXT 'g'
+#define ERL_NEW_PID_EXT 'X'
#define ERL_SMALL_TUPLE_EXT 'h'
#define ERL_LARGE_TUPLE_EXT 'i'
#define ERL_NIL_EXT 'j'
diff --git a/lib/erl_interface/include/erl_interface.h b/lib/erl_interface/include/erl_interface.h
index 3f9804da7d..e1fabc8298 100644
--- a/lib/erl_interface/include/erl_interface.h
+++ b/lib/erl_interface/include/erl_interface.h
@@ -211,14 +211,14 @@ typedef struct {
Erl_Atom_data node;
unsigned int number;
unsigned int serial;
- unsigned char creation;
+ unsigned int creation;
} Erl_Pid;
typedef struct {
Erl_Header h;
Erl_Atom_data node;
unsigned int number;
- unsigned char creation;
+ unsigned int creation;
} Erl_Port;
typedef struct {
@@ -226,7 +226,7 @@ typedef struct {
Erl_Atom_data node;
int len;
unsigned int n[3];
- unsigned char creation;
+ unsigned int creation;
} Erl_Ref;
typedef struct {
diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c
index 7b1b2810bb..f2531de5bd 100644
--- a/lib/erl_interface/src/connect/ei_connect.c
+++ b/lib/erl_interface/src/connect/ei_connect.c
@@ -1342,7 +1342,8 @@ static int send_name_or_challenge(int fd, char *nodename,
| DFLAG_NEW_FLOATS
| DFLAG_SMALL_ATOM_TAGS
| DFLAG_UTF8_ATOMS
- | DFLAG_MAP_TAG));
+ | DFLAG_MAP_TAG
+ | DFLAG_BIG_CREATION));
if (f_chall)
put32be(s, challenge);
memcpy(s, nodename, strlen(nodename));
diff --git a/lib/erl_interface/src/connect/ei_connect_int.h b/lib/erl_interface/src/connect/ei_connect_int.h
index efb6719a1d..12e089f60e 100644
--- a/lib/erl_interface/src/connect/ei_connect_int.h
+++ b/lib/erl_interface/src/connect/ei_connect_int.h
@@ -106,6 +106,7 @@ extern int h_errno;
#define DFLAG_SMALL_ATOM_TAGS 0x4000
#define DFLAG_UTF8_ATOMS 0x10000
#define DFLAG_MAP_TAG 0x20000
+#define DFLAG_BIG_CREATION 0x40000
ei_cnode *ei_fd_to_cnode(int fd);
int ei_distversion(int fd);
diff --git a/lib/erl_interface/src/decode/decode_pid.c b/lib/erl_interface/src/decode/decode_pid.c
index 7fbb818b31..e5750caba6 100644
--- a/lib/erl_interface/src/decode/decode_pid.c
+++ b/lib/erl_interface/src/decode/decode_pid.c
@@ -27,18 +27,22 @@ int ei_decode_pid(const char *buf, int *index, erlang_pid *p)
{
const char *s = buf + *index;
const char *s0 = s;
+ const char tag = get8(s);
- if (get8(s) != ERL_PID_EXT) return -1;
+ if (tag != ERL_PID_EXT && tag != ERL_NEW_PID_EXT) return -1;
if (p) {
if (get_atom(&s, p->node, NULL) < 0) return -1;
p->num = get32be(s) & 0x7fff; /* 15 bits */
p->serial = get32be(s) & 0x1fff; /* 13 bits */
- p->creation = get8(s) & 0x03; /* 2 bits */
+ if (tag == ERL_PID_EXT)
+ p->creation = get8(s) & 0x03; /* 2 bits */
+ else
+ p->creation = get32be(s); /* 32 bits */
}
else {
if (get_atom(&s, NULL, NULL) < 0) return -1;
- s+= 9;
+ s+= (tag == ERL_PID_EXT ? 9 : 12);
}
*index += s-s0;
diff --git a/lib/erl_interface/src/decode/decode_port.c b/lib/erl_interface/src/decode/decode_port.c
index e039b5b845..7b61f254ff 100644
--- a/lib/erl_interface/src/decode/decode_port.c
+++ b/lib/erl_interface/src/decode/decode_port.c
@@ -26,17 +26,21 @@ int ei_decode_port(const char *buf, int *index, erlang_port *p)
{
const char *s = buf + *index;
const char *s0 = s;
+ const char tag = get8(s);
- if (get8(s) != ERL_PORT_EXT) return -1;
+ if (tag != ERL_PORT_EXT && tag != ERL_NEW_PORT_EXT) return -1;
if (p) {
if (get_atom(&s, p->node, NULL) < 0) return -1;
p->id = get32be(s) & 0x0fffffff /* 28 bits */;
- p->creation = get8(s) & 0x03;
+ if (tag == ERL_PORT_EXT)
+ p->creation = get8(s) & 0x03;
+ else
+ p->creation = get32be(s);
}
else {
if (get_atom(&s, NULL, NULL) < 0) return -1;
- s += 5;
+ s += (tag == ERL_PORT_EXT ? 5 : 8);
}
*index += s-s0;
diff --git a/lib/erl_interface/src/decode/decode_ref.c b/lib/erl_interface/src/decode/decode_ref.c
index a6b87e5a21..b8e1ebfedd 100644
--- a/lib/erl_interface/src/decode/decode_ref.c
+++ b/lib/erl_interface/src/decode/decode_ref.c
@@ -28,8 +28,9 @@ int ei_decode_ref(const char *buf, int *index, erlang_ref *p)
const char *s = buf + *index;
const char *s0 = s;
int count, i;
+ const char tag = get8(s);
- switch (get8(s)) {
+ switch (tag) {
case ERL_REFERENCE_EXT:
if (p) {
if (get_atom(&s, p->node, NULL) < 0) return -1;
@@ -47,18 +48,23 @@ int ei_decode_ref(const char *buf, int *index, erlang_ref *p)
return 0;
break;
- case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
+
/* first the integer count */
count = get16be(s);
if (p) {
p->len = count;
if (get_atom(&s, p->node, NULL) < 0) return -1;
- p->creation = get8(s) & 0x03;
+ if (tag == ERL_NEW_REFERENCE_EXT)
+ p->creation = get8(s) & 0x03;
+ else
+ p->creation = get32be(s);
}
else {
if (get_atom(&s, NULL, NULL) < 0) return -1;
- s += 1;
+ s += (tag == ERL_NEW_REFERENCE_EXT ? 1 : 4);
}
/* finally the id integers */
diff --git a/lib/erl_interface/src/decode/decode_skip.c b/lib/erl_interface/src/decode/decode_skip.c
index d49ae0007f..4ba94a658a 100644
--- a/lib/erl_interface/src/decode/decode_skip.c
+++ b/lib/erl_interface/src/decode/decode_skip.c
@@ -35,12 +35,15 @@ int ei_skip_term(const char* buf, int* index)
NULL, NULL) < 0) return -1;
break;
case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT:
if (ei_decode_pid(buf, index, NULL) < 0) return -1;
break;
case ERL_PORT_EXT:
+ case ERL_NEW_PORT_EXT:
if (ei_decode_port(buf, index, NULL) < 0) return -1;
break;
case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
case ERL_REFERENCE_EXT:
if (ei_decode_ref(buf, index, NULL) < 0) return -1;
break;
diff --git a/lib/erl_interface/src/encode/encode_pid.c b/lib/erl_interface/src/encode/encode_pid.c
index 7b01b7045f..3eabbdcc02 100644
--- a/lib/erl_interface/src/encode/encode_pid.c
+++ b/lib/erl_interface/src/encode/encode_pid.c
@@ -24,7 +24,8 @@
int ei_encode_pid(char *buf, int *index, const erlang_pid *p)
{
- char *s = buf + *index;
+ char* s = buf + *index;
+ const char tag = (p->creation > 3) ? ERL_NEW_PID_EXT : ERL_PID_EXT;
++(*index); /* skip ERL_PID_EXT */
if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node),
@@ -32,17 +33,21 @@ int ei_encode_pid(char *buf, int *index, const erlang_pid *p)
return -1;
if (buf) {
- put8(s,ERL_PID_EXT);
+ put8(s, tag);
s = buf + *index;
/* now the integers */
put32be(s,p->num & 0x7fff); /* 15 bits */
put32be(s,p->serial & 0x1fff); /* 13 bits */
- put8(s,(p->creation & 0x03)); /* 2 bits */
+ if (tag == ERL_PID_EXT) {
+ put8(s,(p->creation & 0x03)); /* 2 bits */
+ } else {
+ put32be(s, p->creation); /* 32 bits */
+ }
}
- *index += 4 + 4 + 1;
+ *index += 4 + 4 + (tag == ERL_PID_EXT ? 1 : 4);
return 0;
}
diff --git a/lib/erl_interface/src/encode/encode_port.c b/lib/erl_interface/src/encode/encode_port.c
index a7468e5917..a6e7d3541a 100644
--- a/lib/erl_interface/src/encode/encode_port.c
+++ b/lib/erl_interface/src/encode/encode_port.c
@@ -25,6 +25,7 @@
int ei_encode_port(char *buf, int *index, const erlang_port *p)
{
char *s = buf + *index;
+ const char tag = p->creation > 3 ? ERL_NEW_PORT_EXT : ERL_PORT_EXT;
++(*index); /* skip ERL_PORT_EXT */
if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node), ERLANG_UTF8,
@@ -32,16 +33,19 @@ int ei_encode_port(char *buf, int *index, const erlang_port *p)
return -1;
}
if (buf) {
- put8(s,ERL_PORT_EXT);
+ put8(s, tag);
s = buf + *index;
/* now the integers */
put32be(s,p->id & 0x0fffffff /* 28 bits */);
- put8(s,(p->creation & 0x03));
+ if (tag == ERL_PORT_EXT) {
+ put8(s,(p->creation & 0x03));
+ } else {
+ put32be(s, p->creation);
+ }
}
-
- *index += 4 + 1;
+ *index += 4 + (tag == ERL_PORT_EXT ? 1 : 4);
return 0;
}
diff --git a/lib/erl_interface/src/encode/encode_ref.c b/lib/erl_interface/src/encode/encode_ref.c
index 0f27a086f0..956a9a7e16 100644
--- a/lib/erl_interface/src/encode/encode_ref.c
+++ b/lib/erl_interface/src/encode/encode_ref.c
@@ -24,6 +24,7 @@
int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
{
+ const char tag = (p->creation > 3) ? ERL_NEWER_REFERENCE_EXT : ERL_NEW_REFERENCE_EXT;
char *s = buf + *index;
int i;
@@ -36,7 +37,7 @@ int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
/* Always encode as an extended reference; all participating parties
are now expected to be able to decode extended references. */
if (buf) {
- put8(s,ERL_NEW_REFERENCE_EXT);
+ put8(s, tag);
/* first, number of integers */
put16be(s, p->len);
@@ -45,12 +46,15 @@ int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
s = buf + *index;
/* now the integers */
- put8(s,(p->creation & 0x03));
+ if (tag == ERL_NEW_REFERENCE_EXT)
+ put8(s,(p->creation & 0x03));
+ else
+ put32be(s, p->creation);
for (i = 0; i < p->len; i++)
put32be(s,p->n[i]);
}
- *index += p->len*4 + 1;
+ *index += p->len*4 + (tag == ERL_NEW_REFERENCE_EXT ? 1 : 4);
return 0;
}
diff --git a/lib/erl_interface/src/legacy/erl_eterm.c b/lib/erl_interface/src/legacy/erl_eterm.c
index f2f35ab693..8fcb39b91d 100644
--- a/lib/erl_interface/src/legacy/erl_eterm.c
+++ b/lib/erl_interface/src/legacy/erl_eterm.c
@@ -285,12 +285,12 @@ ETERM *erl_mk_pid(const char *node,
erl_errno = ENOMEM;
return NULL;
}
- erl_mk_pid_helper(ep, number, serial, creation);
+ erl_mk_pid_helper(ep, number, serial, creation & 0x03);
return ep;
}
void erl_mk_pid_helper(ETERM *ep, unsigned int number,
- unsigned int serial, unsigned char creation)
+ unsigned int serial, unsigned int creation)
{
ERL_PID_NUMBER(ep) = number & 0x7fff; /* 15 bits */
if (ei_internal_use_r9_pids_ports()) {
@@ -299,7 +299,7 @@ void erl_mk_pid_helper(ETERM *ep, unsigned int number,
else {
ERL_PID_SERIAL(ep) = serial & 0x1fff; /* 13 bits */
}
- ERL_PID_CREATION(ep) = creation & 0x03; /* 2 bits */
+ ERL_PID_CREATION(ep) = creation; /* 32 bits */
}
/*
@@ -326,7 +326,7 @@ ETERM *erl_mk_port(const char *node,
return ep;
}
-void erl_mk_port_helper(ETERM* ep, unsigned number, unsigned char creation)
+void erl_mk_port_helper(ETERM* ep, unsigned number, unsigned int creation)
{
if (ei_internal_use_r9_pids_ports()) {
ERL_PORT_NUMBER(ep) = number & 0x3ffff; /* 18 bits */
@@ -334,7 +334,7 @@ void erl_mk_port_helper(ETERM* ep, unsigned number, unsigned char creation)
else {
ERL_PORT_NUMBER(ep) = number & 0x0fffffff; /* 18 bits */
}
- ERL_PORT_CREATION(ep) = creation & 0x03; /* 2 bits */
+ ERL_PORT_CREATION(ep) = creation; /* 32 bits */
}
/*
@@ -344,7 +344,7 @@ ETERM *__erl_mk_reference (ETERM* t,
const char *node,
size_t len,
unsigned int n[],
- unsigned char creation)
+ unsigned int creation)
{
if (t == NULL) {
if (node == NULL) return NULL;
@@ -363,7 +363,7 @@ ETERM *__erl_mk_reference (ETERM* t,
ERL_REF_NUMBERS(t)[0] = n[0] & 0x3ffff; /* 18 bits */
ERL_REF_NUMBERS(t)[1] = n[1];
ERL_REF_NUMBERS(t)[2] = n[2];
- ERL_REF_CREATION(t) = creation & 0x03; /* 2 bits */
+ ERL_REF_CREATION(t) = creation; /* 32 bits */
return t;
}
diff --git a/lib/erl_interface/src/legacy/erl_eterm.h b/lib/erl_interface/src/legacy/erl_eterm.h
index d9a26b2541..1b3f20f25c 100644
--- a/lib/erl_interface/src/legacy/erl_eterm.h
+++ b/lib/erl_interface/src/legacy/erl_eterm.h
@@ -56,9 +56,9 @@ typedef struct _heapmark {
} Erl_HeapMark;
-void erl_mk_port_helper(ETERM* ep, unsigned number, unsigned char creation);
-void erl_mk_pid_helper(ETERM*, unsigned,unsigned, unsigned char);
-ETERM * __erl_mk_reference(ETERM*, const char *, size_t, unsigned int n[], unsigned char);
+void erl_mk_port_helper(ETERM* ep, unsigned number, unsigned int creation);
+void erl_mk_pid_helper(ETERM*, unsigned,unsigned, unsigned int);
+ETERM * __erl_mk_reference(ETERM*, const char *, size_t, unsigned int n[], unsigned int);
int erl_current_fix_desc(void);
#endif /* _ERL_ETERM_H */
diff --git a/lib/erl_interface/src/legacy/erl_marshal.c b/lib/erl_interface/src/legacy/erl_marshal.c
index a4216c9541..ebb6b78540 100644
--- a/lib/erl_interface/src/legacy/erl_marshal.c
+++ b/lib/erl_interface/src/legacy/erl_marshal.c
@@ -120,10 +120,13 @@ void erl_init_marshal(void)
cmp_array[ERL_SMALL_ATOM_UTF8_EXT] = ERL_ATOM_CMP;
cmp_array[ERL_REFERENCE_EXT] = ERL_REF_CMP;
cmp_array[ERL_NEW_REFERENCE_EXT] = ERL_REF_CMP;
+ cmp_array[ERL_NEWER_REFERENCE_EXT]=ERL_REF_CMP;
cmp_array[ERL_FUN_EXT] = ERL_FUN_CMP;
cmp_array[ERL_NEW_FUN_EXT] = ERL_FUN_CMP;
cmp_array[ERL_PORT_EXT] = ERL_PORT_CMP;
+ cmp_array[ERL_NEW_PORT_EXT] = ERL_PORT_CMP;
cmp_array[ERL_PID_EXT] = ERL_PID_CMP;
+ cmp_array[ERL_NEW_PID_EXT] = ERL_PID_CMP;
cmp_array[ERL_SMALL_TUPLE_EXT] = ERL_TUPLE_CMP;
cmp_array[ERL_LARGE_TUPLE_EXT] = ERL_TUPLE_CMP;
cmp_array[ERL_NIL_EXT] = ERL_NIL_CMP;
@@ -304,8 +307,8 @@ int erl_encode_it(ETERM *ep, unsigned char **ext, int dist)
*(*ext)++ = ul & 0xff;
return 0;
- case ERL_PID:
- *(*ext)++ = ERL_PID_EXT;
+ case ERL_PID: {
+ unsigned char* tagp = (*ext)++;
/* First poke in node as an atom */
encode_atom(&ep->uval.pidval.node, ext);
/* And then fill in the integer fields */
@@ -319,17 +322,29 @@ int erl_encode_it(ETERM *ep, unsigned char **ext, int dist)
*(*ext)++ = (i >> 16) &0xff;
*(*ext)++ = (i >> 8) &0xff;
*(*ext)++ = i &0xff;
- *(*ext)++ = ERL_PID_CREATION(ep);
+
+ i = ERL_PID_CREATION(ep);
+ if ((unsigned int)i <= 3) {
+ *tagp = ERL_PID_EXT;
+ *(*ext)++ = i;
+ } else {
+ *tagp = ERL_NEW_PID_EXT;
+ *(*ext)++ = (i >> 24) &0xff;
+ *(*ext)++ = (i >> 16) &0xff;
+ *(*ext)++ = (i >> 8) &0xff;
+ *(*ext)++ = i &0xff;
+ }
return 0;
+ }
case ERL_REF: {
+ unsigned char* tagp = (*ext)++;
+
int len, j;
/* Always encode as an extended reference; all
participating parties are now expected to be
able to decode extended references. */
- *(*ext)++ = ERL_NEW_REFERENCE_EXT;
-
i = strlen((char *)ERL_REF_NODE(ep));
len = ERL_REF_LEN(ep);
*(*ext)++ = (len >> 8) &0xff;
@@ -337,7 +352,18 @@ int erl_encode_it(ETERM *ep, unsigned char **ext, int dist)
encode_atom(&ep->uval.refval.node, ext);
- *(*ext)++ = ERL_REF_CREATION(ep);
+ i = ERL_REF_CREATION(ep);
+ if ((unsigned int)i <= 3) {
+ *tagp = ERL_NEW_REFERENCE_EXT;
+ *(*ext)++ = i;
+ } else {
+ *tagp = ERL_NEWER_REFERENCE_EXT;
+ *(*ext)++ = (i >> 24) &0xff;
+ *(*ext)++ = (i >> 16) &0xff;
+ *(*ext)++ = (i >> 8) &0xff;
+ *(*ext)++ = i &0xff;
+ }
+
/* Then the integer fields */
for (j = 0; j < ERL_REF_LEN(ep); j++) {
i = ERL_REF_NUMBERS(ep)[j];
@@ -348,8 +374,8 @@ int erl_encode_it(ETERM *ep, unsigned char **ext, int dist)
}
}
return 0;
- case ERL_PORT:
- *(*ext)++ = ERL_PORT_EXT;
+ case ERL_PORT: {
+ unsigned char* tagp = (*ext)++;
/* First poke in node as an atom */
encode_atom(&ep->uval.portval.node, ext);
/* Then the integer fields */
@@ -358,8 +384,20 @@ int erl_encode_it(ETERM *ep, unsigned char **ext, int dist)
*(*ext)++ = (i >> 16) &0xff;
*(*ext)++ = (i >> 8) &0xff;
*(*ext)++ = i &0xff;
- *(*ext)++ = ERL_PORT_CREATION(ep);
+
+ i = ERL_PORT_CREATION(ep);
+ if ((unsigned int)i <= 3) {
+ *tagp = ERL_PORT_EXT;
+ *(*ext)++ = i;
+ } else {
+ *tagp = ERL_NEW_PORT_EXT;
+ *(*ext)++ = (i >> 24) &0xff;
+ *(*ext)++ = (i >> 16) &0xff;
+ *(*ext)++ = (i >> 8) &0xff;
+ *(*ext)++ = i &0xff;
+ }
return 0;
+ }
case ERL_EMPTY_LIST:
*(*ext)++ = ERL_NIL_EXT;
break;
@@ -698,12 +736,14 @@ static ETERM *erl_decode_it(unsigned char **ext)
unsigned int u,sign;
int i,j,arity;
double ff;
+ unsigned char tag;
/* Assume we are going to decode an integer */
ep = erl_alloc_eterm(ERL_INTEGER);
ERL_COUNT(ep) = 1;
- switch (*(*ext)++)
+ tag = *(*ext)++;
+ switch (tag)
{
case ERL_INTEGER_EXT:
i = (int) (**ext << 24) | ((*ext)[1] << 16) |
@@ -801,9 +841,10 @@ static ETERM *erl_decode_it(unsigned char **ext)
return ep;
case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT:
{
unsigned int number, serial;
- unsigned char creation;
+ unsigned int creation;
ERL_TYPE(ep) = ERL_PID;
if (read_atom(ext, &ep->uval.pidval.node) < 0) return NULL;
@@ -815,7 +856,13 @@ static ETERM *erl_decode_it(unsigned char **ext)
serial = ((*ext)[0] << 24) | ((*ext)[1]) << 16 |
((*ext)[2]) << 8 | ((*ext)[3]);
*ext += 4;
- creation = *(*ext)++;
+ if (tag == ERL_PID_EXT)
+ creation = *(*ext)++;
+ else {
+ creation = ((*ext)[0] << 24) | ((*ext)[1]) << 16 |
+ ((*ext)[2]) << 8 | ((*ext)[3]);
+ *ext += 4;
+ }
erl_mk_pid_helper(ep, number, serial, creation);
return ep;
}
@@ -836,11 +883,12 @@ static ETERM *erl_decode_it(unsigned char **ext)
return ep;
}
- case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
{
size_t cnt, i;
unsigned int n[3];
- unsigned char creation;
+ unsigned int creation;
ERL_TYPE(ep) = ERL_REF;
cnt = ((*ext)[0] << 8) | (*ext)[1];
@@ -849,7 +897,13 @@ static ETERM *erl_decode_it(unsigned char **ext)
if (read_atom(ext, &ep->uval.refval.node) < 0) return NULL;
/* get the integers */
- creation = *(*ext)++;
+ if (tag == ERL_NEW_REFERENCE_EXT)
+ creation = *(*ext)++;
+ else {
+ creation = ((*ext)[0] << 24) | ((*ext)[1]) << 16 |
+ ((*ext)[2]) << 8 | ((*ext)[3]);
+ *ext += 4;
+ }
for(i = 0; i < cnt; i++)
{
n[i] = ((*ext)[0] << 24) | ((*ext)[1]) << 16 |
@@ -861,9 +915,10 @@ static ETERM *erl_decode_it(unsigned char **ext)
}
case ERL_PORT_EXT:
+ case ERL_NEW_PORT_EXT:
{
unsigned int number;
- unsigned char creation;
+ unsigned int creation;
ERL_TYPE(ep) = ERL_PORT;
if (read_atom(ext, &ep->uval.portval.node) < 0) return NULL;
@@ -872,7 +927,13 @@ static ETERM *erl_decode_it(unsigned char **ext)
number = ((*ext)[0] << 24) | ((*ext)[1]) << 16 |
((*ext)[2]) << 8 | ((*ext)[3]);
*ext += 4;
- creation = *(*ext)++;
+ if (tag == ERL_PORT_EXT)
+ creation = *(*ext)++;
+ else {
+ creation = (((*ext)[0] << 24) | ((*ext)[1]) << 16 |
+ ((*ext)[2]) << 8 | ((*ext)[3]));
+ *ext += 4;
+ }
erl_mk_port_helper(ep, number, creation);
return ep;
}
@@ -1114,11 +1175,14 @@ unsigned char erl_ext_type(unsigned char *ext)
case ERL_SMALL_ATOM_UTF8_EXT:
return ERL_ATOM;
case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT:
return ERL_PID;
case ERL_PORT_EXT:
+ case ERL_NEW_PORT_EXT:
return ERL_PORT;
case ERL_REFERENCE_EXT:
case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
return ERL_REF;
case ERL_NIL_EXT:
return ERL_EMPTY_LIST;
@@ -1167,9 +1231,12 @@ int erl_ext_size(unsigned char *t)
case ERL_SMALL_ATOM_EXT:
case ERL_SMALL_ATOM_UTF8_EXT:
case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT:
case ERL_PORT_EXT:
+ case ERL_NEW_PORT_EXT:
case ERL_REFERENCE_EXT:
case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
case ERL_NIL_EXT:
case ERL_BINARY_EXT:
case ERL_STRING_EXT:
@@ -1240,8 +1307,9 @@ static int jump(unsigned char **ext)
{
int j,k,i=0;
int n;
+ const int tag = *(*ext)++;
- switch (*(*ext)++) {
+ switch (tag) {
case ERL_VERSION_MAGIC:
return jump(ext);
case ERL_INTEGER_EXT:
@@ -1257,22 +1325,29 @@ static int jump(unsigned char **ext)
jump_atom(ext);
break;
case ERL_PID_EXT:
- /* eat first atom */
if (!jump_atom(ext)) return 0;
- *ext += 9; /* Two int's and the creation field */
+ *ext += 4 + 4 + 1;
break;
+ case ERL_NEW_PID_EXT:
+ if (!jump_atom(ext)) return 0;
+ *ext += 4 + 4 + 4;
+ break;
case ERL_REFERENCE_EXT:
case ERL_PORT_EXT:
- /* first field is an atom */
if (!jump_atom(ext)) return 0;
- *ext += 5; /* One int and the creation field */
+ *ext += 4 + 1;
break;
+ case ERL_NEW_PORT_EXT:
+ if (!jump_atom(ext)) return 0;
+ *ext += 4 + 4;
+ break;
case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
n = (**ext << 8) | (*ext)[1];
*ext += 2;
/* first field is an atom */
if (!jump_atom(ext)) return 0;
- *ext += 4*n+1;
+ *ext += 4*n + (tag == ERL_NEW_REFERENCE_EXT ? 1 : 4);
break;
case ERL_NIL_EXT:
/* We just passed it... */
@@ -1605,7 +1680,6 @@ static int cmp_exe2(unsigned char **e1, unsigned char **e2)
{
int min, ret,i,j,k;
double ff1, ff2;
- unsigned char *tmp1, *tmp2;
unsigned char tag1, tag2;
if ( ((*e1)[0] == ERL_STRING_EXT) && ((*e2)[0] == ERL_LIST_EXT) ) {
@@ -1649,47 +1723,68 @@ static int cmp_exe2(unsigned char **e1, unsigned char **e2)
*e1 += i;
*e2 += j;
return ret;
- case ERL_PID_EXT: {
- unsigned char *n1 = *e1;
- unsigned char *n2 = *e2;
- CMP_EXT_SKIP_ATOM(*e1); CMP_EXT_SKIP_ATOM(*e2);
- *e1 += 9; *e2 += 9;
+ case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT: {
+ erlang_pid pid1, pid2;
+ unsigned char* buf1 = *e1 - 1;
+ unsigned char* buf2 = *e2 - 1;
+ int ix1 = 0, ix2 = 0;
+
+ if (ei_decode_pid((char*)buf1, &ix1, &pid1) ||
+ ei_decode_pid((char*)buf2, &ix2, &pid2))
+ return CMP_EXT_ERROR_CODE;
+
+ *e1 = buf1 + ix1;
+ *e2 = buf2 + ix2;
/* First compare serials ... */
- tmp1 = *e1 - 5; tmp2 = *e2 - 5;
- CMP_EXT_INT32_BE(tmp1, tmp2);
+ if (pid1.serial < pid2.serial) return -1;
+ else if (pid1.serial > pid2.serial) return 1;
/* ... then ids ... */
- tmp1 -= 4; tmp2 -= 4;
- CMP_EXT_INT32_BE(tmp1, tmp2);
+ if (pid1.num < pid2.num) return -1;
+ else if (pid1.num > pid2.num) return 1;
/* ... then node names ... */
- ret = cmp_exe2(&n1, &n2);
- if (ret != 0)
- return ret;
+ j = strcmp(pid1.node, pid2.node);
+ if (j < 0) return -1;
+ else if (j > 0) return 1;
/* ... and then finaly creations. */
- tmp1 += 8; tmp2 += 8;
- if (*tmp1 != *tmp2)
- return *tmp1 < *tmp2 ? -1 : 1;
+ if (pid1.creation < pid2.creation) return -1;
+ else if (pid1.creation > pid2.creation) return 1;
+
return 0;
}
case ERL_PORT_EXT:
- /* First compare node names ... */
- if (!IS_ERL_ATOM(**e1) || !IS_ERL_ATOM(**e2))
- return CMP_EXT_ERROR_CODE;
- ret = cmp_exe2(e1, e2);
- *e1 += 5; *e2 += 5;
- if (ret != 0)
- return ret;
+ case ERL_NEW_PORT_EXT: {
+ erlang_port port1, port2;
+ unsigned char* buf1 = *e1 - 1;
+ unsigned char* buf2 = *e2 - 1;
+ int ix1 = 0, ix2 = 0;
+
+ if (ei_decode_port((char*)buf1, &ix1, &port1) ||
+ ei_decode_port((char*)buf2, &ix2, &port2))
+ return CMP_EXT_ERROR_CODE;
+
+ *e1 = buf1 + ix1;
+ *e2 = buf2 + ix2;
+
+ /* First compare node names ... */
+ j = strcmp(port1.node, port2.node);
+ if (j < 0) return -1;
+ else if (j > 0) return 1;
+
/* ... then creations ... */
- tmp1 = *e1 - 1; tmp2 = *e2 - 1;
- if (*tmp1 != *tmp2)
- return *tmp1 < *tmp2 ? -1 : 1;
+ if (port1.creation < port2.creation) return -1;
+ else if (port1.creation > port2.creation) return 1;
+
/* ... and then finaly ids. */
- tmp1 -= 4; tmp2 -= 4;
- CMP_EXT_INT32_BE(tmp1, tmp2);
- return 0;
+ if (port1.id < port2.id) return -1;
+ else if (port1.id > port2.id) return 1;
+
+ return 0;
+ }
case ERL_NIL_EXT: return 0;
case ERL_LIST_EXT:
i = (**e1 << 24) | ((*e1)[1] << 16) |((*e1)[2] << 8) | (*e1)[3];
diff --git a/lib/erl_interface/src/misc/ei_decode_term.c b/lib/erl_interface/src/misc/ei_decode_term.c
index 0ec67dde09..37375b4e8e 100644
--- a/lib/erl_interface/src/misc/ei_decode_term.c
+++ b/lib/erl_interface/src/misc/ei_decode_term.c
@@ -33,7 +33,7 @@
int ei_decode_ei_term(const char* buf, int* index, ei_term* term)
{
const char* s = buf + *index, * s0 = s;
- int i, n, sign;
+ int n, sign;
char c;
if (term == NULL) return -1;
@@ -47,47 +47,27 @@ int ei_decode_ei_term(const char* buf, int* index, ei_term* term)
break;
case ERL_FLOAT_EXT:
case NEW_FLOAT_EXT:
- return ei_decode_double(buf, index, &term->value.d_val);
+ return (ei_decode_double(buf, index, &term->value.d_val) < 0
+ ? -1 : 1);
case ERL_ATOM_EXT:
case ERL_ATOM_UTF8_EXT:
case ERL_SMALL_ATOM_EXT:
case ERL_SMALL_ATOM_UTF8_EXT:
- return ei_decode_atom(buf, index, term->value.atom_name);
+ return (ei_decode_atom(buf, index, term->value.atom_name) < 0
+ ? -1 : 1);
case ERL_REFERENCE_EXT:
- /* first the nodename */
- if (get_atom(&s, term->value.ref.node, NULL) < 0) return -1;
- /* now the numbers: num (4), creation (1) */
- term->value.ref.n[0] = get32be(s);
- term->value.ref.len = 1;
- term->value.ref.creation = get8(s) & 0x03;
- break;
case ERL_NEW_REFERENCE_EXT:
- /* first the integer count */
- term->value.ref.len = get16be(s);
- /* then the nodename */
- if (get_atom(&s, term->value.ref.node, NULL) < 0) return -1;
- /* creation */
- term->value.ref.creation = get8(s) & 0x03;
- /* finally the id integers */
- for (i = 0; (i<term->value.ref.len) && (i<3); i++) {
- term->value.ref.n[i] = get32be(s);
- }
- if (term->value.ref.len > 3) {
- s += 4 * (term->value.ref.len - 3);
- }
- break;
+ case ERL_NEWER_REFERENCE_EXT:
+ return (ei_decode_ref(buf, index, &term->value.ref) < 0
+ ? -1 : 1);
case ERL_PORT_EXT:
- if (get_atom(&s, term->value.port.node, NULL) < 0) return -1;
- term->value.port.id = get32be(s) & 0x0fffffff; /* 28 bits */;
- term->value.port.creation = get8(s) & 0x03;
- break;
+ case ERL_NEW_PORT_EXT:
+ return (ei_decode_port(buf, index, &term->value.port) < 0
+ ? -1 : 1);
case ERL_PID_EXT:
- if (get_atom(&s, term->value.pid.node, NULL) < 0) return -1;
- /* now the numbers: num (4), serial (4), creation (1) */
- term->value.pid.num = get32be(s) & 0x7fff; /* 15 bits */
- term->value.pid.serial = get32be(s) & 0x1fff; /* 13 bits */
- term->value.pid.creation = get8(s) & 0x03; /* 2 bits */
- break;
+ case ERL_NEW_PID_EXT:
+ return (ei_decode_pid(buf, index, &term->value.pid) < 0
+ ? -1 : 1);
case ERL_SMALL_TUPLE_EXT:
term->arity = get8(s);
break;
diff --git a/lib/erl_interface/src/misc/ei_printterm.c b/lib/erl_interface/src/misc/ei_printterm.c
index 702ee9566d..8b216b2b96 100644
--- a/lib/erl_interface/src/misc/ei_printterm.c
+++ b/lib/erl_interface/src/misc/ei_printterm.c
@@ -151,15 +151,18 @@ static int print_term(FILE* fp, ei_x_buff* x,
}
break;
case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT:
if (ei_decode_pid(buf, index, &pid) < 0) goto err;
ch_written += xprintf(fp, x, "<%s.%d.%d>", pid.node,
pid.num, pid.serial);
break;
case ERL_PORT_EXT:
+ case ERL_NEW_PORT_EXT:
if (ei_decode_port(buf, index, &port) < 0) goto err;
ch_written += xprintf(fp, x, "#Port<%d.%d>", port.id, port.creation);
break;
case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
case ERL_REFERENCE_EXT:
if (ei_decode_ref(buf, index, &ref) < 0) goto err;
ch_written += xprintf(fp, x, "#Ref<");
diff --git a/lib/erl_interface/src/misc/get_type.c b/lib/erl_interface/src/misc/get_type.c
index 6b95c1f470..62eac4a30e 100644
--- a/lib/erl_interface/src/misc/get_type.c
+++ b/lib/erl_interface/src/misc/get_type.c
@@ -76,6 +76,15 @@ int ei_get_type_internal(const char *buf, const int *index,
*len = get32be(s); /* #digit_bytes */
break;
+ case ERL_NEW_PID_EXT:
+ *type = ERL_PID_EXT;
+ break;
+ case ERL_NEW_PORT_EXT:
+ *type = ERL_PORT_EXT;
+ break;
+ case ERL_NEWER_REFERENCE_EXT:
+ *type = ERL_NEW_REFERENCE_EXT;
+ break;
default:
*len = 0;
break;
diff --git a/lib/erl_interface/src/misc/show_msg.c b/lib/erl_interface/src/misc/show_msg.c
index b08b17aea4..3b9f934c62 100644
--- a/lib/erl_interface/src/misc/show_msg.c
+++ b/lib/erl_interface/src/misc/show_msg.c
@@ -398,6 +398,7 @@ static void show_term(const char *termbuf, int *index, FILE *stream)
break;
case ERL_PID_EXT:
+ case ERL_NEW_PID_EXT:
ei_decode_pid(termbuf,index,&pid);
show_pid(stream,&pid);
break;
@@ -432,6 +433,7 @@ static void show_term(const char *termbuf, int *index, FILE *stream)
case ERL_REFERENCE_EXT:
case ERL_NEW_REFERENCE_EXT:
+ case ERL_NEWER_REFERENCE_EXT:
ei_decode_ref(termbuf,index,&ref);
fprintf(stream,"#Ref<%s",ref.node);
for (i = 0; i < ref.len; i++) {
@@ -441,6 +443,7 @@ static void show_term(const char *termbuf, int *index, FILE *stream)
break;
case ERL_PORT_EXT:
+ case ERL_NEW_PORT_EXT:
ei_decode_port(termbuf,index,&port);
fprintf(stream,"#Port<%s.%u.%u>",port.node,port.id,port.creation);
break;
diff --git a/lib/erl_interface/test/all_SUITE_data/ei_runner.c b/lib/erl_interface/test/all_SUITE_data/ei_runner.c
index 2b0d6c856a..e9b4b2de57 100644
--- a/lib/erl_interface/test/all_SUITE_data/ei_runner.c
+++ b/lib/erl_interface/test/all_SUITE_data/ei_runner.c
@@ -255,12 +255,17 @@ do_report(file, line, ok)
* Erlang side.
*/
-void do_fail(char* file, int line, char* reason)
+void do_fail(const char* file, int line, const char* reason, ...)
{
+ va_list ap;
char sbuf[2048];
+ char* sp = sbuf;
- sbuf[0] = 'f';
- sprintf(sbuf+1, "%s, line %d: %s", file, line, reason);
+ *sp++ = 'f';
+ sp += sprintf(sp, "%s, line %d: ", file, line);
+ va_start(ap, reason);
+ sp += vsprintf(sp, reason, ap);
+ va_end(ap);
reply(sbuf, 1+strlen(sbuf+1));
}
diff --git a/lib/erl_interface/test/all_SUITE_data/ei_runner.h b/lib/erl_interface/test/all_SUITE_data/ei_runner.h
index 62997d00a0..ca01a1d3ed 100644
--- a/lib/erl_interface/test/all_SUITE_data/ei_runner.h
+++ b/lib/erl_interface/test/all_SUITE_data/ei_runner.h
@@ -52,10 +52,11 @@ void free_packet(char*);
*/
#define fail(reason) do_fail(__FILE__, __LINE__, reason)
+#define fail1(reason, a1) do_fail(__FILE__, __LINE__, reason, a1)
#define report(ok) do_report(__FILE__, __LINE__, ok)
void do_report(char* file, int line, int ok);
-void do_fail(char* file, int line, char* reason);
+void do_fail(const char* file, int line, const char* reason, ...);
void send_buffer(char* buf, int size);
void message(char* format, ...);
diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE.erl b/lib/erl_interface/test/ei_decode_encode_SUITE.erl
index a3d0ca0576..14aee76500 100644
--- a/lib/erl_interface/test/ei_decode_encode_SUITE.erl
+++ b/lib/erl_interface/test/ei_decode_encode_SUITE.erl
@@ -89,17 +89,16 @@ test_ei_decode_encode(Config) when is_list(Config) ->
TXPort = mk_port(ThisNode, 268435455),
TXRef = mk_ref(ThisNode, [262143, 4294967295, 4294967295]),
- OtherNode = {gurka@sallad, 2},
- OXPid = mk_pid(OtherNode, 32767, 8191),
- OXPort = mk_port(OtherNode, 268435455),
- OXRef = mk_ref(OtherNode, [262143, 4294967295, 4294967295]),
-
send_rec(P, TXPid),
send_rec(P, TXPort),
send_rec(P, TXRef),
- send_rec(P, OXPid),
- send_rec(P, OXPort),
- send_rec(P, OXRef),
+
+ [begin OtherNode = {gurka@sallad, Creation},
+ send_rec(P, mk_pid(OtherNode, 32767, 8191)),
+ send_rec(P, mk_port(OtherNode, 268435455)),
+ send_rec(P, mk_ref(OtherNode, [262143, 4294967295, 4294967295])),
+ void
+ end || Creation <- [1, 2, 3, 4, 16#adec0ded]],
%% Unicode atoms
[begin send_rec(P, Atom),
@@ -176,6 +175,9 @@ get_binary(P) ->
-define(PORT_EXT, 102).
-define(PID_EXT, 103).
-define(NEW_REFERENCE_EXT, 114).
+-define(NEW_PID_EXT, $X).
+-define(NEW_PORT_EXT, $Y).
+-define(NEWER_REFERENCE_EXT, $Z).
uint32_be(Uint) when is_integer(Uint), 0 =< Uint, Uint < 1 bsl 32 ->
[(Uint bsr 24) band 16#ff,
@@ -197,51 +199,62 @@ uint8(Uint) when is_integer(Uint), 0 =< Uint, Uint < 1 bsl 8 ->
uint8(Uint) ->
exit({badarg, uint8, [Uint]}).
+pid_tag(Creation) when Creation =< 3 -> ?PID_EXT;
+pid_tag(_Creation) -> ?NEW_PID_EXT.
+enc_creation(Creation) when Creation =< 3 -> uint8(Creation);
+enc_creation(Creation) -> uint32_be(Creation).
mk_pid({NodeName, Creation}, Number, Serial) when is_atom(NodeName) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_pid({NodeNameExt, Creation}, Number, Serial);
mk_pid({NodeNameExt, Creation}, Number, Serial) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PID_EXT,
- NodeNameExt,
- uint32_be(Number),
- uint32_be(Serial),
- uint8(Creation)])) of
- Pid when is_pid(Pid) ->
- Pid;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_pid, [{NodeNameExt, Creation}, Number, Serial]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ pid_tag(Creation),
+ NodeNameExt,
+ uint32_be(Number),
+ uint32_be(Serial),
+ enc_creation(Creation)])) of
+ Pid when is_pid(Pid) ->
+ Pid;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_pid, [{NodeNameExt, Creation}, Number, Serial]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end.
+port_tag(Creation) when Creation =< 3 -> ?PORT_EXT;
+port_tag(_Creation) -> ?NEW_PORT_EXT.
+
mk_port({NodeName, Creation}, Number) when is_atom(NodeName) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_port({NodeNameExt, Creation}, Number);
mk_port({NodeNameExt, Creation}, Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PORT_EXT,
- NodeNameExt,
- uint32_be(Number),
- uint8(Creation)])) of
- Port when is_port(Port) ->
- Port;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_port, [{NodeNameExt, Creation}, Number]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ port_tag(Creation),
+ NodeNameExt,
+ uint32_be(Number),
+ enc_creation(Creation)])) of
+ Port when is_port(Port) ->
+ Port;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_port, [{NodeNameExt, Creation}, Number]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end.
+ref_tag(Creation) when Creation =< 3 -> ?NEW_REFERENCE_EXT;
+ref_tag(_Creation) -> ?NEWER_REFERENCE_EXT.
+
mk_ref({NodeName, Creation}, Numbers) when is_atom(NodeName),
is_integer(Creation),
is_list(Numbers) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_ref({NodeNameExt, Creation}, Numbers);
mk_ref({NodeNameExt, Creation}, [Number]) when is_binary(NodeNameExt),
- is_integer(Creation),
- is_integer(Number) ->
+ is_integer(Creation),
+ Creation =< 3,
+ is_integer(Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
?REFERENCE_EXT,
NodeNameExt,
@@ -258,20 +271,20 @@ mk_ref({NodeNameExt, Creation}, Numbers) when is_binary(NodeNameExt),
is_integer(Creation),
is_list(Numbers) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?NEW_REFERENCE_EXT,
- uint16_be(length(Numbers)),
- NodeNameExt,
- uint8(Creation),
- lists:map(fun (N) ->
- uint32_be(N)
- end,
- Numbers)])) of
- Ref when is_reference(Ref) ->
- Ref;
- {'EXIT', {badarg, _}} ->
- exit({badarg, mk_ref, [{NodeNameExt, Creation}, Numbers]});
- Other ->
- exit({unexpected_binary_to_term_result, Other})
+ ref_tag(Creation),
+ uint16_be(length(Numbers)),
+ NodeNameExt,
+ enc_creation(Creation),
+ lists:map(fun (N) ->
+ uint32_be(N)
+ end,
+ Numbers)])) of
+ Ref when is_reference(Ref) ->
+ Ref;
+ {'EXIT', {badarg, _}} ->
+ exit({badarg, mk_ref, [{NodeNameExt, Creation}, Numbers]});
+ Other ->
+ exit({unexpected_binary_to_term_result, Other})
end.
diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c
index 4b0201ca0b..58b2dc1671 100644
--- a/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c
+++ b/lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c
@@ -240,7 +240,7 @@ void decode_encode(struct Type** tv, int nobj)
if (err != -1) {
fail("decode returned non zero but not -1");
} else {
- fail("decode returned non zero");
+ fail1("decode '%s' returned non zero", t->name);
}
return;
}
@@ -491,12 +491,11 @@ TESTCASE(test_ei_decode_encode)
decode_encode_big(&big_type);
/* Test large node containers... */
- decode_encode_one(&pid_type);
- decode_encode_one(&port_type);
- decode_encode_one(&ref_type);
- decode_encode_one(&pid_type);
- decode_encode_one(&port_type);
- decode_encode_one(&ref_type);
+ for (i=0; i<6; i++) {
+ decode_encode_one(&pid_type);
+ decode_encode_one(&port_type);
+ decode_encode_one(&ref_type);
+ }
/* Unicode atoms */
for (i=0; i<24; i++) {
diff --git a/lib/erl_interface/test/ei_tmo_SUITE.erl b/lib/erl_interface/test/ei_tmo_SUITE.erl
index 4cd4202116..aaa0992fb4 100644
--- a/lib/erl_interface/test/ei_tmo_SUITE.erl
+++ b/lib/erl_interface/test/ei_tmo_SUITE.erl
@@ -25,11 +25,10 @@
-include_lib("kernel/include/inet.hrl").
-include("ei_tmo_SUITE_data/ei_tmo_test_cases.hrl").
--define(dummy_host,test01).
-
-export([all/0, suite/0,
init_per_testcase/2, end_per_testcase/2,
framework_check/1, ei_accept_tmo/1, ei_connect_tmo/1, ei_send_tmo/1,
+ ei_connect_tmo/0,
ei_recv_tmo/1]).
suite() ->
@@ -165,12 +164,12 @@ do_one_send_failure(Config,From,FakeName,CName,VxSim) ->
{term, X} = runner:get_term(P3, 10000),
true = is_integer(X),
Message = [112,term_to_binary({6,self(),'',test}),
- term_to_binary({From,10000,
+ term_to_binary({From,50000,
{app,["lapp",{sa,["att",du,{slapp,
sitta}]}]}})],
gen_tcp:send(SocketB,Message),
- %% At this point the test program starts sending messages (max 10000). Since
+ %% At this point the test program starts sending messages (max 50000). Since
%% we're not receiving, eventually the send buffer fills up. Then no more
%% sending is possible and select() times out. The number of messages sent
%% before this happens is returned in Iters. The timeout value for get_term/2
@@ -196,6 +195,8 @@ do_one_send_failure(Config,From,FakeName,CName,VxSim) ->
%% Check accept with timeouts.
+ei_connect_tmo() -> [{require, test_host_not_reachable}].
+
ei_connect_tmo(Config) when is_list(Config) ->
%dbg:tracer(),
%dbg:p(self()),
@@ -311,12 +312,13 @@ make_node(X) ->
make_and_check_dummy() ->
% First check that the host has an ip and is *not* reachable
- case gen_tcp:connect(?dummy_host,23,[{active,false}],5000) of
+ HostNotReachable = ct:get_config(test_host_not_reachable),
+ case gen_tcp:connect(HostNotReachable, 23, [{active,false}],5000) of
{error,timeout} -> ok;
{error,ehostunreach} -> ok
end,
- list_to_atom("dummy@"++atom_to_list(?dummy_host)).
+ list_to_atom("dummy@"++HostNotReachable).
%%
%% Stolen from the erl_distribution_wb_test in kernel
diff --git a/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c b/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c
index 1104f642a2..78dc9c5b8a 100644
--- a/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c
+++ b/lib/erl_interface/test/ei_tmo_SUITE_data/ei_tmo_test.c
@@ -512,18 +512,21 @@ TESTCASE(send_tmo)
for (i=0;i < iterations; ++i) {
res = ei_send_tmo(com_sock, &pid, send_buffer.buff,
send_buffer.index, 5000);
- DEBUGF(("Sent bindata (%d):\n",res));
+ if (res < 0) {
+ DEBUGF(("Sent bindata failed (%d) after %d iterations:\n", res, i));
+ break;
+ }
#ifdef DEBUG
+ if (i < 10 || (i % 100 == 0)) /* don't flood the log */
{
int ndx = 0;
int v;
+ DEBUGF(("%d: Sent bindata (%d): ", i, res));
ei_decode_version(send_buffer.buff,&ndx,&v);
ei_print_term(debugfile, send_buffer.buff, &ndx);
+ DEBUGF(("\n"));
}
#endif
- DEBUGF(("\n"));
- if (res < 0)
- break;
}
if (res < 0) {
DEBUGF(("ei_send_tmo failure at line %d\n",__LINE__));
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/AbstractNode.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/AbstractNode.java
index d7ba88288f..0072c5939a 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/AbstractNode.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/AbstractNode.java
@@ -95,6 +95,7 @@ public class AbstractNode implements OtpTransportFactory {
static final int dFlagUnicodeIo = 0x1000;
static final int dFlagUtf8Atoms = 0x10000;
static final int dFlagMapTag = 0x20000;
+ static final int dFlagBigCreation = 0x40000;
int ntype = NTYPE_R6;
int proto = 0; // tcp/ip
@@ -103,7 +104,8 @@ public class AbstractNode implements OtpTransportFactory {
int creation = 0;
int flags = dFlagExtendedReferences | dFlagExtendedPidsPorts
| dFlagBitBinaries | dFlagNewFloats | dFlagFunTags
- | dflagNewFunTags | dFlagUtf8Atoms | dFlagMapTag;
+ | dflagNewFunTags | dFlagUtf8Atoms | dFlagMapTag
+ | dFlagBigCreation;
/* initialize hostname and default cookie */
static {
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPid.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPid.java
index 20b7ff6a7f..66b4475a9e 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPid.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPid.java
@@ -27,6 +27,7 @@ public class OtpErlangPid extends OtpErlangObject implements Comparable<Object>
// don't change this!
private static final long serialVersionUID = 1664394142301803659L;
+ private final int tag;
private final String node;
private final int id;
private final int serial;
@@ -44,6 +45,7 @@ public class OtpErlangPid extends OtpErlangObject implements Comparable<Object>
public OtpErlangPid(final OtpLocalNode self) {
final OtpErlangPid p = self.createPid();
+ tag = p.tag;
id = p.id;
serial = p.serial;
creation = p.creation;
@@ -65,6 +67,7 @@ public class OtpErlangPid extends OtpErlangObject implements Comparable<Object>
throws OtpErlangDecodeException {
final OtpErlangPid p = buf.read_pid();
+ tag = p.tag;
node = p.node();
id = p.id();
serial = p.serial();
@@ -85,15 +88,52 @@ public class OtpErlangPid extends OtpErlangObject implements Comparable<Object>
* used.
*
* @param creation
- * yet another arbitrary number. Only the low order 2 bits will
+ * yet another arbitrary number. Ony the low order 2 bits will
* be used.
*/
public OtpErlangPid(final String node, final int id, final int serial,
- final int creation) {
- this.node = node;
- this.id = id & 0x7fff; // 15 bits
- this.serial = serial & 0x1fff; // 13 bits
- this.creation = creation & 0x03; // 2 bits
+ final int creation) {
+ this(OtpExternal.pidTag, node, id, serial, creation);
+ }
+
+ /**
+ * Create an Erlang pid from its components.
+ *
+ * @param tag
+ * the external format to be compliant with
+ * OtpExternal.pidTag where only a subset of the bits are significant (see other constructor).
+ * OtpExternal.newPidTag where all 32 bits of id,serial and creation are significant.
+ * newPidTag can only be decoded by OTP-19 and newer.
+ * @param node
+ * the nodename.
+ *
+ * @param id
+ * an arbitrary number.
+ *
+ * @param serial
+ * another arbitrary number.
+ *
+ * @param creation
+ * yet another arbitrary number.
+ */
+ protected OtpErlangPid(final int tag, final String node, final int id,
+ final int serial, final int creation) {
+ this.tag = tag;
+ this.node = node;
+ if (tag == OtpExternal.pidTag) {
+ this.id = id & 0x7fff; // 15 bits
+ this.serial = serial & 0x1fff; // 13 bits
+ this.creation = creation & 0x03; // 2 bits
+ }
+ else { // allow all 32 bits for newPidTag
+ this.id = id;
+ this.serial = serial;
+ this.creation = creation;
+ }
+ }
+
+ protected int tag() {
+ return tag;
}
/**
@@ -151,7 +191,7 @@ public class OtpErlangPid extends OtpErlangObject implements Comparable<Object>
*/
@Override
public void encode(final OtpOutputStream buf) {
- buf.write_pid(node, id, serial, creation);
+ buf.write_pid(this);
}
/**
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPort.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPort.java
index a6198d56cc..16c8d2ed85 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPort.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangPort.java
@@ -26,6 +26,7 @@ public class OtpErlangPort extends OtpErlangObject {
// don't change this!
private static final long serialVersionUID = 4037115468007644704L;
+ private final int tag;
private final String node;
private final int id;
private final int creation;
@@ -42,6 +43,7 @@ public class OtpErlangPort extends OtpErlangObject {
private OtpErlangPort(final OtpSelf self) {
final OtpErlangPort p = self.createPort();
+ tag = p.tag;
id = p.id;
creation = p.creation;
node = p.node;
@@ -62,6 +64,7 @@ public class OtpErlangPort extends OtpErlangObject {
throws OtpErlangDecodeException {
final OtpErlangPort p = buf.read_port();
+ tag = p.tag;
node = p.node();
id = p.id();
creation = p.creation();
@@ -77,13 +80,45 @@ public class OtpErlangPort extends OtpErlangObject {
* an arbitrary number. Only the low order 28 bits will be used.
*
* @param creation
- * another arbitrary number. Only the low order 2 bits will be
- * used.
+ * another arbitrary number. Only the low order 2 bits will be used.
*/
public OtpErlangPort(final String node, final int id, final int creation) {
- this.node = node;
- this.id = id & 0xfffffff; // 28 bits
- this.creation = creation & 0x03; // 2 bits
+ this(OtpExternal.portTag, node, id, creation);
+ }
+
+ /**
+ * Create an Erlang port from its components.
+ *
+ * @param tag
+ * the external format to be compliant with.
+ * OtpExternal.portTag where only a subset of the bits are used (see other constructor)
+ * OtpExternal.newPortTag where all 32 bits of id and creation are significant.
+ * newPortTag can only be decoded by OTP-19 and newer.
+ * @param node
+ * the nodename.
+ *
+ * @param id
+ * an arbitrary number. Only the low order 28 bits will be used.
+ *
+ * @param creation
+ * another arbitrary number.
+ */
+ public OtpErlangPort(final int tag, final String node, final int id,
+ final int creation) {
+ this.tag = tag;
+ this.node = node;
+ if (tag == OtpExternal.portTag) {
+ this.id = id & 0xfffffff; // 28 bits
+ this.creation = creation & 0x3; // 2 bits
+ }
+ else {
+ this.id = id;
+ this.creation = creation;
+ }
+ }
+
+ protected int tag() {
+ return tag;
}
/**
@@ -132,7 +167,7 @@ public class OtpErlangPort extends OtpErlangObject {
*/
@Override
public void encode(final OtpOutputStream buf) {
- buf.write_port(node, id, creation);
+ buf.write_port(this);
}
/**
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangRef.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangRef.java
index 8b57e7265b..c0a3a4061d 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangRef.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpErlangRef.java
@@ -28,11 +28,13 @@ public class OtpErlangRef extends OtpErlangObject {
// don't change this!
private static final long serialVersionUID = -7022666480768586521L;
+ private final int tag;
private final String node;
private final int creation;
// old style refs have one 18-bit id
// r6 "new" refs have array of ids, first one is only 18 bits however
+ // 19 "newer" refs have full 32-bits for creation and for ids[0]
private int ids[] = null;
/**
@@ -47,6 +49,7 @@ public class OtpErlangRef extends OtpErlangObject {
public OtpErlangRef(final OtpLocalNode self) {
final OtpErlangRef r = self.createRef();
+ tag = r.tag;
ids = r.ids;
creation = r.creation;
node = r.node;
@@ -67,6 +70,7 @@ public class OtpErlangRef extends OtpErlangObject {
throws OtpErlangDecodeException {
final OtpErlangRef r = buf.read_ref();
+ tag = r.tag;
node = r.node();
creation = r.creation();
@@ -83,10 +87,10 @@ public class OtpErlangRef extends OtpErlangObject {
* an arbitrary number. Only the low order 18 bits will be used.
*
* @param creation
- * another arbitrary number. Only the low order 2 bits will be
- * used.
+ * another arbitrary number.
*/
public OtpErlangRef(final String node, final int id, final int creation) {
+ this.tag = OtpExternal.newRefTag;
this.node = node;
ids = new int[1];
ids[0] = id & 0x3ffff; // 18 bits
@@ -110,10 +114,34 @@ public class OtpErlangRef extends OtpErlangObject {
* used.
*/
public OtpErlangRef(final String node, final int[] ids, final int creation) {
+ this(OtpExternal.newRefTag, node, ids, creation);
+ }
+
+ /**
+ * Create a new(er) style Erlang ref from its components.
+ *
+ * @param tag
+ * the external format to be compliant with.
+ * OtpExternal.newRefTag where only a subset of the bits are used (see other constructor)
+ * OtpExternal.newerRefTag where all bits of ids and creation are used.
+ * newerPortTag can only be decoded by OTP-19 and newer.
+ *
+ * @param node
+ * the nodename.
+ *
+ * @param ids
+ * an array of arbitrary numbers. At most three numbers
+ * will be read from the array.
+ *
+ * @param creation
+ * another arbitrary number.
+ */
+ public OtpErlangRef(final int tag, final String node, final int[] ids,
+ final int creation) {
+ this.tag = tag;
this.node = node;
- this.creation = creation & 0x03; // 2 bits
- // use at most 82 bits (18 + 32 + 32)
+ // use at most 3 words
int len = ids.length;
this.ids = new int[3];
this.ids[0] = 0;
@@ -124,7 +152,17 @@ public class OtpErlangRef extends OtpErlangObject {
len = 3;
}
System.arraycopy(ids, 0, this.ids, 0, len);
- this.ids[0] &= 0x3ffff; // only 18 significant bits in first number
+ if (tag == OtpExternal.newRefTag) {
+ this.creation = creation & 0x3;
+ this.ids[0] &= 0x3ffff; // only 18 significant bits in first number
+ }
+ else {
+ this.creation = creation;
+ }
+ }
+
+ protected int tag() {
+ return tag;
}
/**
@@ -202,7 +240,7 @@ public class OtpErlangRef extends OtpErlangObject {
*/
@Override
public void encode(final OtpOutputStream buf) {
- buf.write_ref(node, ids, creation);
+ buf.write_ref(this);
}
/**
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpExternal.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpExternal.java
index 4645f25590..e19e7304b7 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpExternal.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpExternal.java
@@ -46,9 +46,11 @@ public class OtpExternal {
/** The tag used for ports */
public static final int portTag = 102;
+ public static final int newPortTag = 89;
/** The tag used for PIDs */
public static final int pidTag = 103;
+ public static final int newPidTag = 88;
/** The tag used for small tuples */
public static final int smallTupleTag = 104;
@@ -85,6 +87,7 @@ public class OtpExternal {
/** The tag used for new style references */
public static final int newRefTag = 114;
+ public static final int newerRefTag = 90;
/** The tag used for maps */
public static final int mapTag = 116;
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java
index fa0815fbf0..50d825fb80 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpInputStream.java
@@ -954,18 +954,23 @@ public class OtpInputStream extends ByteArrayInputStream {
tag = read1skip_version();
- if (tag != OtpExternal.pidTag) {
+ if (tag != OtpExternal.pidTag &&
+ tag != OtpExternal.newPidTag) {
throw new OtpErlangDecodeException(
"Wrong tag encountered, expected " + OtpExternal.pidTag
+ + " or " + OtpExternal.newPidTag
+ ", got " + tag);
}
node = read_atom();
- id = read4BE() & 0x7fff; // 15 bits
- serial = read4BE() & 0x1fff; // 13 bits
- creation = read1() & 0x03; // 2 bits
-
- return new OtpErlangPid(node, id, serial, creation);
+ id = read4BE();
+ serial = read4BE();
+ if (tag == OtpExternal.pidTag)
+ creation = read1();
+ else
+ creation = read4BE();
+
+ return new OtpErlangPid(tag, node, id, serial, creation);
}
/**
@@ -984,17 +989,22 @@ public class OtpInputStream extends ByteArrayInputStream {
tag = read1skip_version();
- if (tag != OtpExternal.portTag) {
+ if (tag != OtpExternal.portTag &&
+ tag != OtpExternal.newPortTag) {
throw new OtpErlangDecodeException(
"Wrong tag encountered, expected " + OtpExternal.portTag
+ + " or " + OtpExternal.newPortTag
+ ", got " + tag);
}
node = read_atom();
- id = read4BE() & 0xfffffff; // 28 bits
- creation = read1() & 0x03; // 2 bits
+ id = read4BE();
+ if (tag == OtpExternal.portTag)
+ creation = read1();
+ else
+ creation = read4BE();
- return new OtpErlangPort(node, id, creation);
+ return new OtpErlangPort(tag, node, id, creation);
}
/**
@@ -1021,16 +1031,23 @@ public class OtpInputStream extends ByteArrayInputStream {
return new OtpErlangRef(node, id, creation);
case OtpExternal.newRefTag:
+ case OtpExternal.newerRefTag:
final int arity = read2BE();
+ if (arity > 3) {
+ throw new OtpErlangDecodeException(
+ "Ref arity " + arity + " too large ");
+ }
node = read_atom();
- creation = read1() & 0x03; // 2 bits
+ if (tag == OtpExternal.newRefTag)
+ creation = read1();
+ else
+ creation = read4BE();
final int[] ids = new int[arity];
for (int i = 0; i < arity; i++) {
ids[i] = read4BE();
}
- ids[0] &= 0x3ffff; // first id gets truncated to 18 bits
- return new OtpErlangRef(node, ids, creation);
+ return new OtpErlangRef(tag, node, ids, creation);
default:
throw new OtpErlangDecodeException(
@@ -1200,15 +1217,18 @@ public class OtpInputStream extends ByteArrayInputStream {
case OtpExternal.refTag:
case OtpExternal.newRefTag:
+ case OtpExternal.newerRefTag:
return new OtpErlangRef(this);
case OtpExternal.mapTag:
return new OtpErlangMap(this);
case OtpExternal.portTag:
+ case OtpExternal.newPortTag:
return new OtpErlangPort(this);
case OtpExternal.pidTag:
+ case OtpExternal.newPidTag:
return new OtpErlangPid(this);
case OtpExternal.stringTag:
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java
index 4faae2a157..10e48ffc43 100644
--- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java
+++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java
@@ -728,14 +728,38 @@ public class OtpOutputStream extends ByteArrayOutputStream {
*/
public void write_pid(final String node, final int id, final int serial,
final int creation) {
- write1(OtpExternal.pidTag);
- write_atom(node);
- write4BE(id & 0x7fff); // 15 bits
- write4BE(serial & 0x1fff); // 13 bits
- write1(creation & 0x3); // 2 bits
+ write1(OtpExternal.pidTag);
+ write_atom(node);
+ write4BE(id & 0x7fff); // 15 bits
+ write4BE(serial & 0x1fff); // 13 bits
+ write1(creation & 0x3); // 2 bits
}
/**
+ * Write an Erlang PID to the stream.
+ *
+ * @param pid
+ * the pid
+ */
+ public void write_pid(OtpErlangPid pid) {
+ write1(pid.tag());
+ write_atom(pid.node());
+ write4BE(pid.id());
+ write4BE(pid.serial());
+ switch (pid.tag()) {
+ case OtpExternal.pidTag:
+ write1(pid.creation());
+ break;
+ case OtpExternal.newPidTag:
+ write4BE(pid.creation());
+ break;
+ default:
+ throw new AssertionError("Invalid pid tag " + pid.tag());
+ }
+ }
+
+
+ /**
* Write an Erlang port to the stream.
*
* @param node
@@ -745,15 +769,36 @@ public class OtpOutputStream extends ByteArrayOutputStream {
* an arbitrary number. Only the low order 28 bits will be used.
*
* @param creation
- * another arbitrary number. Only the low order 2 bits will be
- * used.
- *
+ * another arbitrary number. Only the low order 2 bits will
+ * be used.
*/
public void write_port(final String node, final int id, final int creation) {
- write1(OtpExternal.portTag);
- write_atom(node);
- write4BE(id & 0xfffffff); // 28 bits
- write1(creation & 0x3); // 2 bits
+ write1(OtpExternal.portTag);
+ write_atom(node);
+ write4BE(id & 0xfffffff); // 28 bits
+ write1(creation & 0x3); // 2 bits
+ }
+
+ /**
+ * Write an Erlang port to the stream.
+ *
+ * @param port
+ * the port.
+ */
+ public void write_port(OtpErlangPort port) {
+ write1(port.tag());
+ write_atom(port.node());
+ write4BE(port.id());
+ switch (port.tag()) {
+ case OtpExternal.portTag:
+ write1(port.creation());
+ break;
+ case OtpExternal.newPortTag:
+ write4BE(port.creation());
+ break;
+ default:
+ throw new AssertionError("Invalid port tag " + port.tag());
+ }
}
/**
@@ -766,32 +811,31 @@ public class OtpOutputStream extends ByteArrayOutputStream {
* an arbitrary number. Only the low order 18 bits will be used.
*
* @param creation
- * another arbitrary number. Only the low order 2 bits will be
- * used.
+ * another arbitrary number.
*
*/
public void write_ref(final String node, final int id, final int creation) {
- write1(OtpExternal.refTag);
- write_atom(node);
- write4BE(id & 0x3ffff); // 18 bits
- write1(creation & 0x3); // 2 bits
+ /* Always encode as an extended reference; all
+ participating parties are now expected to be
+ able to decode extended references. */
+ int ids[] = new int[1];
+ ids[0] = id;
+ write_ref(node, ids, creation);
}
/**
- * Write a new style (R6 and later) Erlang ref to the stream.
+ * Write an Erlang ref to the stream.
*
* @param node
* the nodename.
*
* @param ids
* an array of arbitrary numbers. Only the low order 18 bits of
- * the first number will be used. If the array contains only one
- * number, an old style ref will be written instead. At most
- * three numbers will be read from the array.
+ * the first number will be used. At most three numbers
+ * will be read from the array.
*
* @param creation
- * another arbitrary number. Only the low order 2 bits will be
- * used.
+ * another arbitrary number. Only the low order 2 bits will be used.
*
*/
public void write_ref(final String node, final int[] ids, final int creation) {
@@ -800,29 +844,54 @@ public class OtpOutputStream extends ByteArrayOutputStream {
arity = 3; // max 3 words in ref
}
- if (arity == 1) {
- // use old method
- this.write_ref(node, ids[0], creation);
- } else {
- // r6 ref
- write1(OtpExternal.newRefTag);
+ write1(OtpExternal.newRefTag);
- // how many id values
- write2BE(arity);
+ // how many id values
+ write2BE(arity);
- write_atom(node);
+ write_atom(node);
- // note: creation BEFORE id in r6 ref
- write1(creation & 0x3); // 2 bits
+ write1(creation & 0x3); // 2 bits
- // first int gets truncated to 18 bits
- write4BE(ids[0] & 0x3ffff);
+ // first int gets truncated to 18 bits
+ write4BE(ids[0] & 0x3ffff);
- // remaining ones are left as is
- for (int i = 1; i < arity; i++) {
- write4BE(ids[i]);
- }
- }
+ // remaining ones are left as is
+ for (int i = 1; i < arity; i++) {
+ write4BE(ids[i]);
+ }
+ }
+
+ /**
+ * Write an Erlang ref to the stream.
+ *
+ * @param ref
+ * the reference
+ */
+ public void write_ref(OtpErlangRef ref) {
+ int[] ids = ref.ids();
+ int arity = ids.length;
+
+ write1(ref.tag());
+ write2BE(arity);
+ write_atom(ref.node());
+
+ switch (ref.tag()) {
+ case OtpExternal.newRefTag:
+ write1(ref.creation());
+ write4BE(ids[0] & 0x3ffff); // first word gets truncated to 18 bits
+ break;
+ case OtpExternal.newerRefTag:
+ write4BE(ref.creation());
+ write4BE(ids[0]); // full first word
+ break;
+ default:
+ throw new AssertionError("Invalid ref tag " + ref.tag());
+ }
+
+ for (int i = 1; i < arity; i++) {
+ write4BE(ids[i]);
+ }
}
/**
diff --git a/lib/jinterface/test/nc_SUITE.erl b/lib/jinterface/test/nc_SUITE.erl
index 9910334749..3022eb1635 100644
--- a/lib/jinterface/test/nc_SUITE.erl
+++ b/lib/jinterface/test/nc_SUITE.erl
@@ -31,6 +31,10 @@
-define(NEW_REFERENCE_EXT, 114).
-define(ATOM_UTF8_EXT, 118).
-define(SMALL_ATOM_UTF8_EXT, 119).
+-define(NEW_PID_EXT, $X).
+-define(NEW_PORT_EXT, $Y).
+-define(NEWER_REFERENCE_EXT, $Z).
+
-export([all/0, suite/0,groups/0,init_per_group/2,end_per_group/2,
init_per_suite/1,
@@ -123,12 +127,13 @@ pid_roundtrip(doc) -> [];
pid_roundtrip(suite) -> [];
pid_roundtrip(Config) when is_list(Config)->
ThisNode = {node(), erlang:system_info(creation)},
- RemNode = {gurka@sallad, 2},
+ RemPids = [mk_pid({gurka@sallad, Cr}, Num, Ser)
+ || Cr <- [1,2,3,4,16#adec0ded],
+ {Num, Ser} <- [{4711,4711},{32767, 8191}]],
do_echo([self(),
mk_pid(ThisNode, 4711, 4711),
- mk_pid(ThisNode, 32767, 8191),
- mk_pid(RemNode, 4711, 4711),
- mk_pid(RemNode, 32767, 8191)],
+ mk_pid(ThisNode, 32767, 8191)
+ | RemPids],
Config).
fun_roundtrip(doc) -> [];
@@ -144,26 +149,29 @@ port_roundtrip(doc) -> [];
port_roundtrip(suite) -> [];
port_roundtrip(Config) when is_list(Config)->
ThisNode = {node(), erlang:system_info(creation)},
- RemNode = {gurka@sallad, 2},
+ RemPorts = [mk_port({gurka@sallad, Cr}, Num)
+ || Cr <- [1,2,3,4,16#adec0ded],
+ Num <- [4711, 268435455]],
do_echo([hd(erlang:ports()),
mk_port(ThisNode, 4711),
- mk_port(ThisNode, 268435455),
- mk_port(RemNode, 4711),
- mk_port(RemNode, 268435455)],
+ mk_port(ThisNode, 268435455)
+ | RemPorts],
Config).
ref_roundtrip(doc) -> [];
ref_roundtrip(suite) -> [];
ref_roundtrip(Config) when is_list(Config)->
ThisNode = {node(), erlang:system_info(creation)},
- RemNode = {gurka@sallad, 2},
+ RemRefs = [mk_ref({gurka@sallad, Cr}, Words)
+ || Cr <- [1,2,3,4,16#adec0ded],
+ Words <- [[4711],
+ [4711, 4711, 4711],
+ [262143, 4294967295, 4294967295]]],
do_echo([make_ref(),
mk_ref(ThisNode, [4711]),
mk_ref(ThisNode, [4711, 4711, 4711]),
- mk_ref(ThisNode, [262143, 4294967295, 4294967295]),
- mk_ref(RemNode, [4711]),
- mk_ref(RemNode, [4711, 4711, 4711]),
- mk_ref(RemNode, [262143, 4294967295, 4294967295])],
+ mk_ref(ThisNode, [262143, 4294967295, 4294967295])
+ | RemRefs],
Config).
new_float(doc) -> [];
@@ -759,17 +767,22 @@ uint8(Uint) ->
exit({badarg, uint8, [Uint]}).
+pid_tag(Creation) when Creation =< 3 -> ?PID_EXT;
+pid_tag(_Creation) -> ?NEW_PID_EXT.
+
+enc_creation(Creation) when Creation =< 3 -> uint8(Creation);
+enc_creation(Creation) -> uint32_be(Creation).
mk_pid({NodeName, Creation}, Number, Serial) when is_atom(NodeName) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_pid({NodeNameExt, Creation}, Number, Serial);
mk_pid({NodeNameExt, Creation}, Number, Serial) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PID_EXT,
+ pid_tag(Creation),
NodeNameExt,
uint32_be(Number),
uint32_be(Serial),
- uint8(Creation)])) of
+ enc_creation(Creation)])) of
Pid when is_pid(Pid) ->
Pid;
{'EXIT', {badarg, _}} ->
@@ -778,15 +791,18 @@ mk_pid({NodeNameExt, Creation}, Number, Serial) ->
exit({unexpected_binary_to_term_result, Other})
end.
+port_tag(Creation) when Creation =< 3 -> ?PORT_EXT;
+port_tag(_Creation) -> ?NEW_PORT_EXT.
+
mk_port({NodeName, Creation}, Number) when is_atom(NodeName) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_port({NodeNameExt, Creation}, Number);
mk_port({NodeNameExt, Creation}, Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?PORT_EXT,
+ port_tag(Creation),
NodeNameExt,
uint32_be(Number),
- uint8(Creation)])) of
+ enc_creation(Creation)])) of
Port when is_port(Port) ->
Port;
{'EXIT', {badarg, _}} ->
@@ -795,12 +811,16 @@ mk_port({NodeNameExt, Creation}, Number) ->
exit({unexpected_binary_to_term_result, Other})
end.
+ref_tag(Creation) when Creation =< 3 -> ?NEW_REFERENCE_EXT;
+ref_tag(_Creation) -> ?NEWER_REFERENCE_EXT.
+
mk_ref({NodeName, Creation}, [Number] = NL) when is_atom(NodeName),
is_integer(Creation),
is_integer(Number) ->
<<?VERSION_MAGIC, NodeNameExt/binary>> = term_to_binary(NodeName),
mk_ref({NodeNameExt, Creation}, NL);
mk_ref({NodeNameExt, Creation}, [Number]) when is_integer(Creation),
+ Creation =< 3,
is_integer(Number) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
?REFERENCE_EXT,
@@ -822,10 +842,10 @@ mk_ref({NodeName, Creation}, Numbers) when is_atom(NodeName),
mk_ref({NodeNameExt, Creation}, Numbers) when is_integer(Creation),
is_list(Numbers) ->
case catch binary_to_term(list_to_binary([?VERSION_MAGIC,
- ?NEW_REFERENCE_EXT,
+ ref_tag(Creation),
uint16_be(length(Numbers)),
NodeNameExt,
- uint8(Creation),
+ enc_creation(Creation),
lists:map(fun (N) ->
uint32_be(N)
end,
diff --git a/lib/kernel/include/dist.hrl b/lib/kernel/include/dist.hrl
index 47d9459a19..412ea58e65 100644
--- a/lib/kernel/include/dist.hrl
+++ b/lib/kernel/include/dist.hrl
@@ -39,3 +39,4 @@
-define(DFLAG_SMALL_ATOM_TAGS, 16#4000).
-define(DFLAG_UTF8_ATOMS, 16#10000).
-define(DFLAG_MAP_TAG, 16#20000).
+-define(DFLAG_BIG_CREATION, 16#40000).
diff --git a/lib/kernel/src/dist_util.erl b/lib/kernel/src/dist_util.erl
index e3817fcce5..36b9a22493 100644
--- a/lib/kernel/src/dist_util.erl
+++ b/lib/kernel/src/dist_util.erl
@@ -118,7 +118,8 @@ make_this_flags(RequestType, OtherNode) ->
?DFLAG_DIST_HDR_ATOM_CACHE bor
?DFLAG_SMALL_ATOM_TAGS bor
?DFLAG_UTF8_ATOMS bor
- ?DFLAG_MAP_TAG).
+ ?DFLAG_MAP_TAG bor
+ ?DFLAG_BIG_CREATION).
handshake_other_started(#hs_data{request_type=ReqType}=HSData0) ->
{PreOtherFlags,Node,Version} = recv_name(HSData0),