aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src/encode/encode_atom.c
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2013-02-18 15:09:00 +0100
committerSverker Eriksson <[email protected]>2013-02-18 15:20:47 +0100
commit9a35c01873fb56316136e1314ad6adffe97b9fa5 (patch)
treea67f86b77f1e08049b51e766468fb63a139d666e /lib/erl_interface/src/encode/encode_atom.c
parent499eef0cd693b2f96ec19148d2f6666c3df7d834 (diff)
downloadotp-9a35c01873fb56316136e1314ad6adffe97b9fa5.tar.gz
otp-9a35c01873fb56316136e1314ad6adffe97b9fa5.tar.bz2
otp-9a35c01873fb56316136e1314ad6adffe97b9fa5.zip
erl_interface,ic: Remove node_org_enc from erlang_{pid,port,ref}
in order to be backward compatible with user code that accesses the members of erlang_pid and friend. The documentation does not mention the content of these structs, but we have example code that does. So the safe way it the revert the node_org_enc field (added in R16A) and instead determine in runtime which atom encoding to use depending on if the node atom contains unicode (>255) characters or not.
Diffstat (limited to 'lib/erl_interface/src/encode/encode_atom.c')
-rw-r--r--lib/erl_interface/src/encode/encode_atom.c24
1 files changed, 21 insertions, 3 deletions
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;
+}