aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src
diff options
context:
space:
mode:
Diffstat (limited to 'lib/erl_interface/src')
-rw-r--r--lib/erl_interface/src/connect/ei_connect.c1
-rw-r--r--lib/erl_interface/src/decode/decode_pid.c2
-rw-r--r--lib/erl_interface/src/decode/decode_port.c2
-rw-r--r--lib/erl_interface/src/decode/decode_ref.c4
-rw-r--r--lib/erl_interface/src/encode/encode_atom.c24
-rw-r--r--lib/erl_interface/src/encode/encode_pid.c3
-rw-r--r--lib/erl_interface/src/encode/encode_port.c2
-rw-r--r--lib/erl_interface/src/encode/encode_ref.c2
-rw-r--r--lib/erl_interface/src/legacy/erl_connect.c2
-rw-r--r--lib/erl_interface/src/misc/ei_decode_term.c8
10 files changed, 33 insertions, 17 deletions
diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c
index c1361e169e..3ab86bb340 100644
--- a/lib/erl_interface/src/connect/ei_connect.c
+++ b/lib/erl_interface/src/connect/ei_connect.c
@@ -459,7 +459,6 @@ int ei_connect_xinit(ei_cnode* ec, const char *thishostname,
/* memmove(&ec->this_ipaddr, thisipaddr, sizeof(ec->this_ipaddr)); */
strcpy(ec->self.node,thisnodename);
- ec->self.node_org_enc = ERLANG_LATIN1;
ec->self.num = 0;
ec->self.serial = 0;
ec->self.creation = creation;
diff --git a/lib/erl_interface/src/decode/decode_pid.c b/lib/erl_interface/src/decode/decode_pid.c
index d429fb2fd8..cd5ae2ab20 100644
--- a/lib/erl_interface/src/decode/decode_pid.c
+++ b/lib/erl_interface/src/decode/decode_pid.c
@@ -30,7 +30,7 @@ int ei_decode_pid(const char *buf, int *index, erlang_pid *p)
if (get8(s) != ERL_PID_EXT) return -1;
if (p) {
- if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;
+ 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 */
diff --git a/lib/erl_interface/src/decode/decode_port.c b/lib/erl_interface/src/decode/decode_port.c
index 7a691f0be6..8fbdc5f3d3 100644
--- a/lib/erl_interface/src/decode/decode_port.c
+++ b/lib/erl_interface/src/decode/decode_port.c
@@ -29,7 +29,7 @@ int ei_decode_port(const char *buf, int *index, erlang_port *p)
if (get8(s) != ERL_PORT_EXT) return -1;
if (p) {
- if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;
+ if (get_atom(&s, p->node, NULL) < 0) return -1;
p->id = get32be(s) & 0x0fffffff /* 28 bits */;
p->creation = get8(s) & 0x03;
}
diff --git a/lib/erl_interface/src/decode/decode_ref.c b/lib/erl_interface/src/decode/decode_ref.c
index 01e3061cb4..78db118172 100644
--- a/lib/erl_interface/src/decode/decode_ref.c
+++ b/lib/erl_interface/src/decode/decode_ref.c
@@ -31,7 +31,7 @@ int ei_decode_ref(const char *buf, int *index, erlang_ref *p)
switch (get8(s)) {
case ERL_REFERENCE_EXT:
if (p) {
- if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;
+ if (get_atom(&s, p->node, NULL) < 0) return -1;
p->n[0] = get32be(s);
p->len = 1;
p->creation = get8(s) & 0x03;
@@ -52,7 +52,7 @@ int ei_decode_ref(const char *buf, int *index, erlang_ref *p)
if (p) {
p->len = count;
- if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1;
+ if (get_atom(&s, p->node, NULL) < 0) return -1;
p->creation = get8(s) & 0x03;
}
else {
diff --git a/lib/erl_interface/src/encode/encode_atom.c b/lib/erl_interface/src/encode/encode_atom.c
index df4b0af5db..46d34c3bf0 100644
--- a/lib/erl_interface/src/encode/encode_atom.c
+++ b/lib/erl_interface/src/encode/encode_atom.c
@@ -25,7 +25,7 @@
static int verify_ascii_atom(const char* src, int slen);
static int verify_utf8_atom(const char* src, int slen);
-
+static int is_latin1_as_utf8(const char *p, int len);
int ei_encode_atom(char *buf, int *index, const char *p)
{
@@ -63,6 +63,14 @@ int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len,
return -1;
}
+ if (to_enc == (ERLANG_LATIN1 | ERLANG_UTF8)) {
+ if (from_enc == ERLANG_UTF8) {
+ to_enc = is_latin1_as_utf8(p, len) ? ERLANG_LATIN1 : ERLANG_UTF8;
+ }
+ else {
+ to_enc = from_enc;
+ }
+ }
switch(to_enc) {
case ERLANG_LATIN1:
if (buf) {
@@ -148,7 +156,7 @@ ei_internal_put_atom(char** bufp, const char* p, int slen,
}
-int verify_ascii_atom(const char* src, int slen)
+static int verify_ascii_atom(const char* src, int slen)
{
while (slen > 0) {
if ((src[0] & 0x80) != 0) return -1;
@@ -158,7 +166,7 @@ int verify_ascii_atom(const char* src, int slen)
return 0;
}
-int verify_utf8_atom(const char* src, int slen)
+static int verify_utf8_atom(const char* src, int slen)
{
int num_chars = 0;
@@ -188,3 +196,13 @@ int verify_utf8_atom(const char* src, int slen)
return 0;
}
+/* Only latin1 code points in utf8 string?
+ */
+static int is_latin1_as_utf8(const char *p, int len)
+{
+ int i;
+ for (i=0; i<len; i++) {
+ if ((unsigned char)p[i] > 0xC3) return 0;
+ }
+ return 1;
+}
diff --git a/lib/erl_interface/src/encode/encode_pid.c b/lib/erl_interface/src/encode/encode_pid.c
index 903c9cce00..86d0f393e5 100644
--- a/lib/erl_interface/src/encode/encode_pid.c
+++ b/lib/erl_interface/src/encode/encode_pid.c
@@ -26,7 +26,8 @@ int ei_encode_pid(char *buf, int *index, const erlang_pid *p)
char *s = buf + *index;
++(*index); /* skip ERL_PID_EXT */
- if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node), ERLANG_UTF8, p->node_org_enc) < 0)
+ if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node),
+ ERLANG_UTF8, ERLANG_LATIN1|ERLANG_UTF8) < 0)
return -1;
if (buf) {
diff --git a/lib/erl_interface/src/encode/encode_port.c b/lib/erl_interface/src/encode/encode_port.c
index c729aeb4eb..a206de56c7 100644
--- a/lib/erl_interface/src/encode/encode_port.c
+++ b/lib/erl_interface/src/encode/encode_port.c
@@ -27,7 +27,7 @@ int ei_encode_port(char *buf, int *index, const erlang_port *p)
++(*index); /* skip ERL_PORT_EXT */
if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node), ERLANG_UTF8,
- p->node_org_enc) < 0) {
+ ERLANG_LATIN1|ERLANG_UTF8) < 0) {
return -1;
}
if (buf) {
diff --git a/lib/erl_interface/src/encode/encode_ref.c b/lib/erl_interface/src/encode/encode_ref.c
index 3511366bef..9855231848 100644
--- a/lib/erl_interface/src/encode/encode_ref.c
+++ b/lib/erl_interface/src/encode/encode_ref.c
@@ -28,7 +28,7 @@ int ei_encode_ref(char *buf, int *index, const erlang_ref *p)
(*index) += 1 + 2; /* skip to node atom */
if (ei_encode_atom_len_as(buf, index, p->node, strlen(p->node), ERLANG_UTF8,
- p->node_org_enc) < 0) {
+ ERLANG_LATIN1|ERLANG_UTF8) < 0) {
return -1;
}
diff --git a/lib/erl_interface/src/legacy/erl_connect.c b/lib/erl_interface/src/legacy/erl_connect.c
index eca16497dc..ae0265a388 100644
--- a/lib/erl_interface/src/legacy/erl_connect.c
+++ b/lib/erl_interface/src/legacy/erl_connect.c
@@ -250,11 +250,9 @@ int erl_send(int fd, ETERM *to ,ETERM *msg)
if (to->uval.pidval.node.latin1) {
strcpy(topid.node, to->uval.pidval.node.latin1);
- topid.node_org_enc = ERLANG_LATIN1;
}
else {
strcpy(topid.node, to->uval.pidval.node.utf8);
- topid.node_org_enc = ERLANG_UTF8;
}
topid.num = ERL_PID_NUMBER(to);
topid.serial = ERL_PID_SERIAL(to);
diff --git a/lib/erl_interface/src/misc/ei_decode_term.c b/lib/erl_interface/src/misc/ei_decode_term.c
index 1423ec7ed7..ce5ae5b19d 100644
--- a/lib/erl_interface/src/misc/ei_decode_term.c
+++ b/lib/erl_interface/src/misc/ei_decode_term.c
@@ -54,7 +54,7 @@ int ei_decode_ei_term(const char* buf, int* index, ei_term* term)
return ei_decode_atom(buf, index, term->value.atom_name);
case ERL_REFERENCE_EXT:
/* first the nodename */
- if (get_atom(&s, term->value.ref.node, &term->value.ref.node_org_enc) < 0) return -1;
+ 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;
@@ -64,7 +64,7 @@ int ei_decode_ei_term(const char* buf, int* index, ei_term* term)
/* first the integer count */
term->value.ref.len = get16be(s);
/* then the nodename */
- if (get_atom(&s, term->value.ref.node, &term->value.ref.node_org_enc) < 0) return -1;
+ if (get_atom(&s, term->value.ref.node, NULL) < 0) return -1;
/* creation */
term->value.ref.creation = get8(s) & 0x03;
/* finally the id integers */
@@ -76,12 +76,12 @@ int ei_decode_ei_term(const char* buf, int* index, ei_term* term)
}
break;
case ERL_PORT_EXT:
- if (get_atom(&s, term->value.port.node, &term->value.port.node_org_enc) < 0) return -1;
+ 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_PID_EXT:
- if (get_atom(&s, term->value.pid.node, &term->value.port.node_org_enc) < 0) return -1;
+ 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 */