aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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
35 files changed, 663 insertions, 282 deletions
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),