diff options
Diffstat (limited to 'lib/erl_interface')
47 files changed, 773 insertions, 181 deletions
diff --git a/lib/erl_interface/aclocal.m4 b/lib/erl_interface/aclocal.m4 index 918e30a886..25f40944e7 100644 --- a/lib/erl_interface/aclocal.m4 +++ b/lib/erl_interface/aclocal.m4 @@ -1,7 +1,7 @@ dnl dnl %CopyrightBegin% dnl -dnl Copyright Ericsson AB 1998-2012. All Rights Reserved. +dnl Copyright Ericsson AB 1998-2013. All Rights Reserved. dnl dnl The contents of this file are subject to the Erlang Public License, dnl Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/doc/src/ei.xml b/lib/erl_interface/doc/src/ei.xml index 117c787da6..dfe181bd1d 100644 --- a/lib/erl_interface/doc/src/ei.xml +++ b/lib/erl_interface/doc/src/ei.xml @@ -4,7 +4,7 @@ <cref> <header> <copyright> - <year>2001</year><year>2011</year> + <year>2001</year><year>2013</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -86,18 +86,21 @@ <title>DATA TYPES</title> <taglist> - <tag><marker id="erlang_char_encoding"/>enum erlang_char_encoding</tag> + <tag><marker id="erlang_char_encoding"/>erlang_char_encoding</tag> <item> <p/> <code type="none"> -enum erlang_char_encoding { - ERLANG_ASCII, ERLANG_LATIN1, ERLANG_UTF8 -}; +typedef enum { + ERLANG_ASCII = 1, + ERLANG_LATIN1 = 2, + ERLANG_UTF8 = 4 +}erlang_char_encoding; </code> - <p>The character encoding used for atoms. <c>ERLANG_ASCII</c> represents 7-bit ASCII. + <p>The character encodings used for atoms. <c>ERLANG_ASCII</c> represents 7-bit ASCII. Latin1 and UTF8 are different extensions of 7-bit ASCII. All 7-bit ASCII characters are valid Latin1 and UTF8 characters. ASCII and Latin1 both represent each character - by one byte. A UTF8 character can consist of one to four bytes.</p> + by one byte. A UTF8 character can consist of one to four bytes. Note that these + constants are bit-flags and can be combined with bitwise-or.</p> </item> </taglist> </section> @@ -250,10 +253,10 @@ enum erlang_char_encoding { </desc> </func> <func> - <name><ret>int</ret><nametext>ei_encode_atom_as(char *buf, int *index, const char *p, enum erlang_char_encoding from_enc, enum erlang_char_encoding to_enc)</nametext></name> - <name><ret>int</ret><nametext>ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, enum erlang_char_encoding from_enc, enum erlang_char_encoding to_enc)</nametext></name> - <name><ret>int</ret><nametext>ei_x_encode_atom_as(ei_x_buff* x, const char *p, enum erlang_char_encoding from_enc, enum erlang_char_encoding to_enc)</nametext></name> - <name><ret>int</ret><nametext>ei_x_encode_atom_len_as(ei_x_buff* x, const char *p, int len, enum erlang_char_encoding from_enc, enum erlang_char_encoding to_enc)</nametext></name> + <name><ret>int</ret><nametext>ei_encode_atom_as(char *buf, int *index, const char *p, erlang_char_encoding from_enc, erlang_char_encoding to_enc)</nametext></name> + <name><ret>int</ret><nametext>ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, erlang_char_encoding from_enc, erlang_char_encoding to_enc)</nametext></name> + <name><ret>int</ret><nametext>ei_x_encode_atom_as(ei_x_buff* x, const char *p, erlang_char_encoding from_enc, erlang_char_encoding to_enc)</nametext></name> + <name><ret>int</ret><nametext>ei_x_encode_atom_len_as(ei_x_buff* x, const char *p, int len, erlang_char_encoding from_enc, erlang_char_encoding to_enc)</nametext></name> <fsummary>Encode an atom</fsummary> <desc> <p>Encodes an atom in the binary format with character encoding @@ -534,7 +537,7 @@ ei_x_encode_empty_list(&x); </desc> </func> <func> - <name><ret>int</ret><nametext>ei_decode_atom_as(const char *buf, int *index, char *p, int plen, enum erlang_char_encoding want, enum erlang_char_encoding* was, enum erlang_char_encoding* result)</nametext></name> + <name><ret>int</ret><nametext>ei_decode_atom_as(const char *buf, int *index, char *p, int plen, erlang_char_encoding want, erlang_char_encoding* was, erlang_char_encoding* result)</nametext></name> <fsummary>Decode an atom</fsummary> <desc> <p>This function decodes an atom from the binary format. The diff --git a/lib/erl_interface/doc/src/erl_eterm.xml b/lib/erl_interface/doc/src/erl_eterm.xml index c7840d7813..a7921ea9d2 100644 --- a/lib/erl_interface/doc/src/erl_eterm.xml +++ b/lib/erl_interface/doc/src/erl_eterm.xml @@ -4,7 +4,7 @@ <cref> <header> <copyright> - <year>1996</year><year>2009</year> + <year>1996</year><year>2013</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> diff --git a/lib/erl_interface/doc/src/notes.xml b/lib/erl_interface/doc/src/notes.xml index f0a9b336ff..7cf3d46d88 100644 --- a/lib/erl_interface/doc/src/notes.xml +++ b/lib/erl_interface/doc/src/notes.xml @@ -30,6 +30,33 @@ </header> <p>This document describes the changes made to the Erl_interface application.</p> +<section><title>Erl_Interface 3.7.10</title> + + <section><title>Improvements and New Features</title> + <list> + <item> + <p>Where necessary a comment stating encoding has been + added to Erlang files. The comment is meant to be removed + in Erlang/OTP R17B when UTF-8 becomes the default + encoding. </p> + <p> + Own Id: OTP-10630</p> + </item> + <item> + <p> + Limited support for unicode atoms in the external format + and in the internal representation of the vm. This is a + preparative feature in order to support communication + with future releases of Erlang/OTP that may create + unicode atoms.</p> + <p> + Own Id: OTP-10753</p> + </item> + </list> + </section> + +</section> + <section><title>Erl_Interface 3.7.9</title> <section><title>Improvements and New Features</title> diff --git a/lib/erl_interface/include/ei.h b/lib/erl_interface/include/ei.h index 2278a28adb..66dc64a69d 100644 --- a/lib/erl_interface/include/ei.h +++ b/lib/erl_interface/include/ei.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2010. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -190,17 +190,16 @@ extern volatile int __erl_errno; #define MAXATOMLEN_UTF8 (255*4 + 1) #define MAXNODELEN EI_MAXALIVELEN+1+EI_MAXHOSTNAMELEN -enum erlang_char_encoding { +typedef enum { ERLANG_ASCII = 1, ERLANG_LATIN1 = 2, ERLANG_UTF8 = 4, - ERLANG_ANY = ERLANG_ASCII|ERLANG_LATIN1|ERLANG_UTF8 -}; +}erlang_char_encoding; /* a pid */ typedef struct { char node[MAXATOMLEN_UTF8]; - enum erlang_char_encoding node_org_enc; + erlang_char_encoding node_org_enc; unsigned int num; unsigned int serial; unsigned int creation; @@ -209,7 +208,7 @@ typedef struct { /* a port */ typedef struct { char node[MAXATOMLEN_UTF8]; - enum erlang_char_encoding node_org_enc; + erlang_char_encoding node_org_enc; unsigned int id; unsigned int creation; } erlang_port; @@ -217,7 +216,7 @@ typedef struct { /* a ref */ typedef struct { char node[MAXATOMLEN_UTF8]; - enum erlang_char_encoding node_org_enc; + erlang_char_encoding node_org_enc; int len; unsigned int n[3]; unsigned int creation; @@ -246,7 +245,7 @@ typedef struct { typedef struct { long arity; char module[MAXATOMLEN_UTF8]; - enum erlang_char_encoding module_org_enc; + erlang_char_encoding module_org_enc; char md5[16]; long index; long old_index; @@ -441,16 +440,16 @@ int ei_x_encode_string(ei_x_buff* x, const char* s); int ei_x_encode_string_len(ei_x_buff* x, const char* s, int len); int ei_encode_atom(char *buf, int *index, const char *p); int ei_encode_atom_as(char *buf, int *index, const char *p, - enum erlang_char_encoding from, enum erlang_char_encoding to); + erlang_char_encoding from, erlang_char_encoding to); int ei_encode_atom_len(char *buf, int *index, const char *p, int len); int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, - enum erlang_char_encoding from, enum erlang_char_encoding to); + erlang_char_encoding from, erlang_char_encoding to); int ei_x_encode_atom(ei_x_buff* x, const char* s); int ei_x_encode_atom_as(ei_x_buff* x, const char* s, - enum erlang_char_encoding from, enum erlang_char_encoding to); + erlang_char_encoding from, erlang_char_encoding to); int ei_x_encode_atom_len(ei_x_buff* x, const char* s, int len); int ei_x_encode_atom_len_as(ei_x_buff* x, const char* s, int len, - enum erlang_char_encoding from, enum erlang_char_encoding to); + erlang_char_encoding from, erlang_char_encoding to); int ei_encode_binary(char *buf, int *index, const void *p, long len); int ei_x_encode_binary(ei_x_buff* x, const void* s, int len); int ei_encode_pid(char *buf, int *index, const erlang_pid *p); @@ -500,7 +499,7 @@ int ei_decode_boolean(const char *buf, int *index, int *p); int ei_decode_char(const char *buf, int *index, char *p); int ei_decode_string(const char *buf, int *index, char *p); int ei_decode_atom(const char *buf, int *index, char *p); -int ei_decode_atom_as(const char *buf, int *index, char *p, int destlen, enum erlang_char_encoding want, enum erlang_char_encoding* was, enum erlang_char_encoding* result); +int ei_decode_atom_as(const char *buf, int *index, char *p, int destlen, erlang_char_encoding want, erlang_char_encoding* was, erlang_char_encoding* result); int ei_decode_binary(const char *buf, int *index, void *p, long *len); int ei_decode_fun(const char* buf, int* index, erlang_fun* p); void free_fun(erlang_fun* f); diff --git a/lib/erl_interface/include/erl_interface.h b/lib/erl_interface/include/erl_interface.h index 98acc0d71d..7f44cb83bd 100644 --- a/lib/erl_interface/include/erl_interface.h +++ b/lib/erl_interface/include/erl_interface.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/Makefile b/lib/erl_interface/src/Makefile index 03e2ce14f0..a069aa07ab 100644 --- a/lib/erl_interface/src/Makefile +++ b/lib/erl_interface/src/Makefile @@ -1,7 +1,7 @@ # # %CopyrightBegin% # -# Copyright Ericsson AB 1996-2009. All Rights Reserved. +# Copyright Ericsson AB 1996-2013. All Rights Reserved. # # The contents of this file are subject to the Erlang Public License, # Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c index 4421bbb7fe..c1361e169e 100644 --- a/lib/erl_interface/src/connect/ei_connect.c +++ b/lib/erl_interface/src/connect/ei_connect.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2000-2011. All Rights Reserved. + * Copyright Ericsson AB 2000-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/connect/ei_connect_int.h b/lib/erl_interface/src/connect/ei_connect_int.h index 81c384e38d..42ab9b58d7 100644 --- a/lib/erl_interface/src/connect/ei_connect_int.h +++ b/lib/erl_interface/src/connect/ei_connect_int.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2010. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/connect/ei_resolve.c b/lib/erl_interface/src/connect/ei_resolve.c index 79d259b92d..2545c5f3de 100644 --- a/lib/erl_interface/src/connect/ei_resolve.c +++ b/lib/erl_interface/src/connect/ei_resolve.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1997-2011. All Rights Reserved. + * Copyright Ericsson AB 1997-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/connect/eirecv.c b/lib/erl_interface/src/connect/eirecv.c index 075f78e3d2..1821de3844 100644 --- a/lib/erl_interface/src/connect/eirecv.c +++ b/lib/erl_interface/src/connect/eirecv.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2010. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/decode/decode_atom.c b/lib/erl_interface/src/decode/decode_atom.c index 9779ad3f35..44fd4df12c 100644 --- a/lib/erl_interface/src/decode/decode_atom.c +++ b/lib/erl_interface/src/decode/decode_atom.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2011. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -28,14 +28,14 @@ int ei_decode_atom(const char *buf, int *index, char *p) } int ei_decode_atom_as(const char *buf, int *index, char* p, int destlen, - enum erlang_char_encoding want_enc, - enum erlang_char_encoding* was_encp, - enum erlang_char_encoding* res_encp) + erlang_char_encoding want_enc, + erlang_char_encoding* was_encp, + erlang_char_encoding* res_encp) { const char *s = buf + *index; const char *s0 = s; int len; - enum erlang_char_encoding got_enc; + erlang_char_encoding got_enc; switch (get8(s)) { case ERL_ATOM_EXT: @@ -92,7 +92,7 @@ int ei_decode_atom_as(const char *buf, int *index, char* p, int destlen, int utf8_to_latin1(char* dst, const char* src, int slen, int destlen, - enum erlang_char_encoding* res_encp) + erlang_char_encoding* res_encp) { const char* const dst_start = dst; const char* const dst_end = dst + destlen; @@ -128,7 +128,7 @@ int utf8_to_latin1(char* dst, const char* src, int slen, int destlen, } int latin1_to_utf8(char* dst, const char* src, int slen, int destlen, - enum erlang_char_encoding* res_encp) + erlang_char_encoding* res_encp) { const char* const src_end = src + slen; const char* const dst_start = dst; @@ -163,7 +163,7 @@ int latin1_to_utf8(char* dst, const char* src, int slen, int destlen, int ei_internal_get_atom(const char** bufp, char* p, - enum erlang_char_encoding* was_encp) + erlang_char_encoding* was_encp) { int ix = 0; if (ei_decode_atom_as(*bufp, &ix, p, MAXATOMLEN_UTF8, ERLANG_UTF8, was_encp, NULL) < 0) diff --git a/lib/erl_interface/src/decode/decode_boolean.c b/lib/erl_interface/src/decode/decode_boolean.c index f20690249b..8c44a1ccfc 100644 --- a/lib/erl_interface/src/decode/decode_boolean.c +++ b/lib/erl_interface/src/decode/decode_boolean.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/decode/decode_fun.c b/lib/erl_interface/src/decode/decode_fun.c index 7bbef5db44..2adaedb825 100644 --- a/lib/erl_interface/src/decode/decode_fun.c +++ b/lib/erl_interface/src/decode/decode_fun.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2009. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -30,6 +30,25 @@ int ei_decode_fun(const char *buf, int *index, erlang_fun *p) const char *s = buf + *index; const char *s0 = s; int i, ix, ix0, n; + erlang_pid* p_pid; + char* p_module; + enum erlang_char_encoding* p_module_org_enc; + long* p_index; + long* p_uniq; + long* p_old_index; + + if (p != NULL) { + p_pid = &p->pid; + p_module = &p->module[0]; + p_module_org_enc = &p->module_org_enc; + p_index = &p->index; + p_uniq = &p->uniq; + p_old_index = &p->old_index; + } + else { + p_pid = NULL; p_module = NULL; p_module_org_enc = NULL; + p_index = NULL; p_uniq = NULL; p_old_index = NULL; + } switch (get8(s)) { case ERL_FUN_EXT: @@ -39,17 +58,17 @@ int ei_decode_fun(const char *buf, int *index, erlang_fun *p) n = get32be(s); /* then the pid */ ix = 0; - if (ei_decode_pid(s, &ix, (p == NULL ? (erlang_pid*)NULL : &p->pid)) < 0) + if (ei_decode_pid(s, &ix, p_pid) < 0) return -1; /* then the module (atom) */ - if (ei_decode_atom_as(s, &ix, (p == NULL ? (char*)NULL : p->module), - MAXATOMLEN_UTF8, ERLANG_UTF8, &p->module_org_enc, NULL) < 0) + if (ei_decode_atom_as(s, &ix, p_module, MAXATOMLEN_UTF8, ERLANG_UTF8, + p_module_org_enc, NULL) < 0) return -1; /* then the index */ - if (ei_decode_long(s, &ix, (p == NULL ? (long*)NULL : &p->index)) < 0) + if (ei_decode_long(s, &ix, p_index) < 0) return -1; /* then the uniq */ - if (ei_decode_long(s, &ix, (p == NULL ? (long*)NULL : &p->uniq)) < 0) + if (ei_decode_long(s, &ix, p_uniq) < 0) return -1; /* finally the free vars */ ix0 = ix; @@ -85,17 +104,17 @@ int ei_decode_fun(const char *buf, int *index, erlang_fun *p) if (p != NULL) p->n_free_vars = i; /* then the module (atom) */ ix = 0; - if (ei_decode_atom_as(s, &ix, (p == NULL ? (char*)NULL : p->module), - MAXATOMLEN_UTF8, ERLANG_UTF8, &p->module_org_enc, NULL) < 0) + if (ei_decode_atom_as(s, &ix, p_module, MAXATOMLEN_UTF8, ERLANG_UTF8, + p_module_org_enc, NULL) < 0) return -1; /* then the old_index */ - if (ei_decode_long(s, &ix, (p == NULL ? (long*)NULL : &p->old_index)) < 0) + if (ei_decode_long(s, &ix, p_old_index) < 0) return -1; /* then the old_uniq */ - if (ei_decode_long(s, &ix, (p == NULL ? (long*)NULL : &p->uniq)) < 0) + if (ei_decode_long(s, &ix, p_uniq) < 0) return -1; /* the the pid */ - if (ei_decode_pid(s, &ix, (p == NULL ? (erlang_pid*)NULL : &p->pid)) < 0) + if (ei_decode_pid(s, &ix, p_pid) < 0) return -1; /* finally the free vars */ s += ix; diff --git a/lib/erl_interface/src/decode/decode_pid.c b/lib/erl_interface/src/decode/decode_pid.c index e79952195d..d429fb2fd8 100644 --- a/lib/erl_interface/src/decode/decode_pid.c +++ b/lib/erl_interface/src/decode/decode_pid.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2011. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -29,16 +29,16 @@ int ei_decode_pid(const char *buf, int *index, erlang_pid *p) if (get8(s) != ERL_PID_EXT) return -1; - /* first the nodename */ - if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; - - /* now the numbers: num (4), serial (4), creation (1) */ if (p) { + if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; p->num = get32be(s) & 0x7fff; /* 15 bits */ p->serial = get32be(s) & 0x1fff; /* 13 bits */ p->creation = get8(s) & 0x03; /* 2 bits */ } - else s+= 9; + else { + if (get_atom(&s, NULL, NULL) < 0) return -1; + s+= 9; + } *index += s-s0; diff --git a/lib/erl_interface/src/decode/decode_port.c b/lib/erl_interface/src/decode/decode_port.c index 5fd96b51a4..7a691f0be6 100644 --- a/lib/erl_interface/src/decode/decode_port.c +++ b/lib/erl_interface/src/decode/decode_port.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2011. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -28,15 +28,15 @@ int ei_decode_port(const char *buf, int *index, erlang_port *p) if (get8(s) != ERL_PORT_EXT) return -1; - /* first the nodename */ - if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; - - /* now the numbers: num (4), creation (1) */ if (p) { + if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; p->id = get32be(s) & 0x0fffffff /* 28 bits */; p->creation = get8(s) & 0x03; } - else s += 5; + else { + if (get_atom(&s, NULL, NULL) < 0) return -1; + s += 5; + } *index += s-s0; diff --git a/lib/erl_interface/src/decode/decode_ref.c b/lib/erl_interface/src/decode/decode_ref.c index 7294e5d239..01e3061cb4 100644 --- a/lib/erl_interface/src/decode/decode_ref.c +++ b/lib/erl_interface/src/decode/decode_ref.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2011. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -30,17 +30,16 @@ int ei_decode_ref(const char *buf, int *index, erlang_ref *p) switch (get8(s)) { case ERL_REFERENCE_EXT: - - /* nodename */ - if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; - - /* now the numbers: num (4), creation (1) */ if (p) { + if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; p->n[0] = get32be(s); p->len = 1; p->creation = get8(s) & 0x03; } - else s += 5; + else { + if (get_atom(&s, NULL, NULL) < 0) return -1; + s += 5; + } *index += s-s0; @@ -50,16 +49,16 @@ int ei_decode_ref(const char *buf, int *index, erlang_ref *p) case ERL_NEW_REFERENCE_EXT: /* first the integer count */ count = get16be(s); - if (p) p->len = count; - /* then the nodename */ - if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; - - /* creation */ if (p) { + p->len = count; + if (get_atom(&s, p->node, &p->node_org_enc) < 0) return -1; p->creation = get8(s) & 0x03; } - else s += 1; + else { + if (get_atom(&s, NULL, NULL) < 0) return -1; + s += 1; + } /* finally the id integers */ if (p) { diff --git a/lib/erl_interface/src/decode/decode_skip.c b/lib/erl_interface/src/decode/decode_skip.c index f6c5d861ab..e2bfe1f802 100644 --- a/lib/erl_interface/src/decode/decode_skip.c +++ b/lib/erl_interface/src/decode/decode_skip.c @@ -30,7 +30,8 @@ int ei_skip_term(const char* buf, int* index) switch (ty) { case ERL_ATOM_EXT: /* FIXME: what if some weird locale is in use? */ - if (ei_decode_atom(buf, index, NULL) < 0) return -1; + if (ei_decode_atom_as(buf, index, NULL, MAXATOMLEN_UTF8, (ERLANG_LATIN1|ERLANG_UTF8), + NULL, NULL) < 0) return -1; break; case ERL_PID_EXT: if (ei_decode_pid(buf, index, NULL) < 0) return -1; diff --git a/lib/erl_interface/src/decode/decode_trace.c b/lib/erl_interface/src/decode/decode_trace.c index ebaa78e29e..88fb3451ec 100644 --- a/lib/erl_interface/src/decode/decode_trace.c +++ b/lib/erl_interface/src/decode/decode_trace.c @@ -22,18 +22,30 @@ int ei_decode_trace(const char *buf, int *index, erlang_trace *p) { int arity = 0; - int tindex = *index; - - /* use a temporary index if any function should fail */ + int tindex = *index; /* use a temporary index if any function should fail */ + long *p_flags, *p_label, *p_serial, *p_prev; + erlang_pid *p_from; + + if (p != NULL) { + p_flags = &p->flags; + p_label = &p->label; + p_serial = &p->serial; + p_prev = &p->prev; + p_from = &p->from; + } + else { + p_flags = p_label = p_serial = p_prev = NULL; + p_from = NULL; + } /* { Flags, Label, Serial, FromPid, Prev } */ if (ei_decode_tuple_header(buf, &tindex, &arity) || (arity != 5) - || ei_decode_long(buf, &tindex, &p->flags) - || ei_decode_long(buf, &tindex, &p->label) - || ei_decode_long(buf, &tindex, &p->serial) - || ei_decode_pid( buf, &tindex, &p->from) - || ei_decode_long(buf, &tindex, &p->prev)) return -1; + || ei_decode_long(buf, &tindex, p_flags) + || ei_decode_long(buf, &tindex, p_label) + || ei_decode_long(buf, &tindex, p_serial) + || ei_decode_pid( buf, &tindex, p_from) + || ei_decode_long(buf, &tindex, p_prev)) return -1; /* index is updated by the functions we called */ diff --git a/lib/erl_interface/src/encode/encode_atom.c b/lib/erl_interface/src/encode/encode_atom.c index 044f17cb60..df4b0af5db 100644 --- a/lib/erl_interface/src/encode/encode_atom.c +++ b/lib/erl_interface/src/encode/encode_atom.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2011. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -23,8 +23,8 @@ #include "putget.h" -static int copy_ascii_atom(char* dst, const char* src, int slen); -static int copy_utf8_atom(char* dst, const char* src, int slen); +static int verify_ascii_atom(const char* src, int slen); +static int verify_utf8_atom(const char* src, int slen); int ei_encode_atom(char *buf, int *index, const char *p) @@ -45,15 +45,15 @@ int ei_encode_atom_len(char *buf, int *index, const char *p, int len) } int ei_encode_atom_as(char *buf, int *index, const char *p, - enum erlang_char_encoding from_enc, - enum erlang_char_encoding to_enc) + erlang_char_encoding from_enc, + erlang_char_encoding to_enc) { return ei_encode_atom_len_as(buf, index, p, strlen(p), from_enc, to_enc); } int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, - enum erlang_char_encoding from_enc, - enum erlang_char_encoding to_enc) + erlang_char_encoding from_enc, + erlang_char_encoding to_enc) { char *s = buf + *index; char *s0 = s; @@ -73,7 +73,8 @@ int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, if (len < 0) return -1; break; case ERLANG_ASCII: - if (copy_ascii_atom(s+2, p, len) < 0) return -1; + if (verify_ascii_atom(p, len) < 0) return -1; + memcpy(s+2, p, len); break; case ERLANG_LATIN1: memcpy(s+2, p, len); @@ -88,7 +89,8 @@ int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, if (from_enc == ERLANG_UTF8) { len = utf8_to_latin1(NULL, p, len, MAXATOMLEN-1, NULL); if (len < 0) return -1; - } + } else if (from_enc == ERLANG_ASCII) + if (verify_ascii_atom(p, len) < 0) return -1; } break; @@ -100,11 +102,13 @@ int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, len = latin1_to_utf8((buf ? s+offs : NULL), p, len, MAXATOMLEN_UTF8-1, NULL); break; case ERLANG_ASCII: - if (buf && copy_ascii_atom(s+offs, p, len) < 0) return -1; + if (verify_ascii_atom(p, len) < 0) return -1; + if (buf) memcpy(s+offs,p,len); break; case ERLANG_UTF8: if (len >= 256) offs++; - if (buf && copy_utf8_atom(s+offs, p, len) < 0) return -1; + if (verify_utf8_atom(p, len) < 0) return -1; + if (buf) memcpy(s+offs,p,len); break; default: return -1; @@ -134,7 +138,7 @@ int ei_encode_atom_len_as(char *buf, int *index, const char *p, int len, int ei_internal_put_atom(char** bufp, const char* p, int slen, - enum erlang_char_encoding to_enc) + erlang_char_encoding to_enc) { int ix = 0; if (ei_encode_atom_len_as(*bufp, &ix, p, slen, ERLANG_UTF8, to_enc) < 0) @@ -144,17 +148,17 @@ ei_internal_put_atom(char** bufp, const char* p, int slen, } -int copy_ascii_atom(char* dst, const char* src, int slen) +int verify_ascii_atom(const char* src, int slen) { while (slen > 0) { if ((src[0] & 0x80) != 0) return -1; - *dst++ = *src++; + src++; slen--; } return 0; } -int copy_utf8_atom(char* dst, const char* src, int slen) +int verify_utf8_atom(const char* src, int slen) { int num_chars = 0; @@ -163,25 +167,22 @@ int copy_utf8_atom(char* dst, const char* src, int slen) if ((src[0] & 0x80) != 0) { if ((src[0] & 0xE0) == 0xC0) { if (slen < 2 || (src[1] & 0xC0) != 0x80) return -1; - *dst++ = *src++; + src++; slen--; } else if ((src[0] & 0xF0) == 0xE0) { if (slen < 3 || (src[1] & 0xC0) != 0x80 || (src[2] & 0xC0) != 0x80) return -1; - *dst++ = *src++; - *dst++ = *src++; + src += 2; slen -= 2; } else if ((src[0] & 0xF8) == 0xF0) { if (slen < 4 || (src[1] & 0xC0) != 0x80 || (src[2] & 0xC0) != 0x80 || (src[3] & 0xC0) != 0x80) return -1; - *dst++ = *src++; - *dst++ = *src++; - *dst++ = *src++; + src += 3; slen -= 3; } else return -1; } - *dst++ = *src++; + src++; slen--; } return 0; diff --git a/lib/erl_interface/src/encode/encode_fun.c b/lib/erl_interface/src/encode/encode_fun.c index 4daee32648..455d8a5a94 100644 --- a/lib/erl_interface/src/encode/encode_fun.c +++ b/lib/erl_interface/src/encode/encode_fun.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2009. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/encode/encode_pid.c b/lib/erl_interface/src/encode/encode_pid.c index 0cf3ef4efb..903c9cce00 100644 --- a/lib/erl_interface/src/encode/encode_pid.c +++ b/lib/erl_interface/src/encode/encode_pid.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/encode/encode_port.c b/lib/erl_interface/src/encode/encode_port.c index 2bf9e26d78..c729aeb4eb 100644 --- a/lib/erl_interface/src/encode/encode_port.c +++ b/lib/erl_interface/src/encode/encode_port.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/encode/encode_ref.c b/lib/erl_interface/src/encode/encode_ref.c index e8b3173315..3511366bef 100644 --- a/lib/erl_interface/src/encode/encode_ref.c +++ b/lib/erl_interface/src/encode/encode_ref.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/legacy/erl_connect.c b/lib/erl_interface/src/legacy/erl_connect.c index f82704ea8b..eca16497dc 100644 --- a/lib/erl_interface/src/legacy/erl_connect.c +++ b/lib/erl_interface/src/legacy/erl_connect.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2011. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/legacy/erl_eterm.c b/lib/erl_interface/src/legacy/erl_eterm.c index aa0fd5ddcf..7ca4f430de 100644 --- a/lib/erl_interface/src/legacy/erl_eterm.c +++ b/lib/erl_interface/src/legacy/erl_eterm.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2010. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -154,7 +154,7 @@ ETERM *erl_mk_atom (const char *s) char* erl_atom_ptr_latin1(Erl_Atom_data* a) { if (a->latin1 == NULL) { - enum erlang_char_encoding enc; + erlang_char_encoding enc; a->lenL = utf8_to_latin1(NULL, a->utf8, a->lenU, a->lenU, &enc); if (a->lenL < 0) { a->lenL = 0; diff --git a/lib/erl_interface/src/legacy/erl_eterm.h b/lib/erl_interface/src/legacy/erl_eterm.h index 2e8129d9cd..ca4ec7925a 100644 --- a/lib/erl_interface/src/legacy/erl_eterm.h +++ b/lib/erl_interface/src/legacy/erl_eterm.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/legacy/erl_format.c b/lib/erl_interface/src/legacy/erl_format.c index 533241e396..fda05cbdb8 100644 --- a/lib/erl_interface/src/legacy/erl_format.c +++ b/lib/erl_interface/src/legacy/erl_format.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2011. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/legacy/erl_malloc.c b/lib/erl_interface/src/legacy/erl_malloc.c index d09239e02d..c320a00bfe 100644 --- a/lib/erl_interface/src/legacy/erl_malloc.c +++ b/lib/erl_interface/src/legacy/erl_malloc.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2009. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/legacy/erl_marshal.c b/lib/erl_interface/src/legacy/erl_marshal.c index 4c45cebb02..e207b5f0f1 100644 --- a/lib/erl_interface/src/legacy/erl_marshal.c +++ b/lib/erl_interface/src/legacy/erl_marshal.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1996-2011. All Rights Reserved. + * Copyright Ericsson AB 1996-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -660,7 +660,7 @@ static int read_atom(unsigned char** ext, Erl_Atom_data* a) { char buf[MAXATOMLEN_UTF8]; int offs = 0; - enum erlang_char_encoding enc; + erlang_char_encoding enc; int ret = ei_decode_atom_as((char*)*ext, &offs, buf, MAXATOMLEN_UTF8, ERLANG_LATIN1|ERLANG_UTF8, NULL, &enc); *ext += offs; @@ -1423,8 +1423,8 @@ static int cmpbytes(unsigned char* s1,int l1,unsigned char* s2,int l2) static int cmpatoms(unsigned char* s1, int l1, unsigned char tag1, unsigned char* s2, int l2, unsigned char tag2) { - enum erlang_char_encoding enc1 = tag2enc(tag1); - enum erlang_char_encoding enc2 = tag2enc(tag2); + erlang_char_encoding enc1 = tag2enc(tag1); + erlang_char_encoding enc2 = tag2enc(tag2); if (enc1 == enc2) { return cmpbytes(s1, l1,s2,l2); diff --git a/lib/erl_interface/src/legacy/global_whereis.c b/lib/erl_interface/src/legacy/global_whereis.c index e6c556d907..589c9d17de 100644 --- a/lib/erl_interface/src/legacy/global_whereis.c +++ b/lib/erl_interface/src/legacy/global_whereis.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2009. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/misc/ei_decode_term.c b/lib/erl_interface/src/misc/ei_decode_term.c index 65afee89cc..1423ec7ed7 100644 --- a/lib/erl_interface/src/misc/ei_decode_term.c +++ b/lib/erl_interface/src/misc/ei_decode_term.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2011. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/misc/ei_format.c b/lib/erl_interface/src/misc/ei_format.c index b5f11e618e..07499213cd 100644 --- a/lib/erl_interface/src/misc/ei_format.c +++ b/lib/erl_interface/src/misc/ei_format.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2012. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/misc/ei_printterm.c b/lib/erl_interface/src/misc/ei_printterm.c index f3003a6172..95369db15a 100644 --- a/lib/erl_interface/src/misc/ei_printterm.c +++ b/lib/erl_interface/src/misc/ei_printterm.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2010. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/misc/ei_x_encode.c b/lib/erl_interface/src/misc/ei_x_encode.c index 44dcff7664..14d0b56b8f 100644 --- a/lib/erl_interface/src/misc/ei_x_encode.c +++ b/lib/erl_interface/src/misc/ei_x_encode.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2001-2009. All Rights Reserved. + * Copyright Ericsson AB 2001-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -99,7 +99,8 @@ int ei_x_encode_string(ei_x_buff* x, const char* s) int ei_x_encode_string_len(ei_x_buff* x, const char* s, int len) { int i = x->index; - ei_encode_string_len(NULL, &i, s, len); + if (ei_encode_string_len(NULL, &i, s, len) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_string_len(x->buff, &x->index, s, len); @@ -108,7 +109,8 @@ int ei_x_encode_string_len(ei_x_buff* x, const char* s, int len) int ei_x_encode_binary(ei_x_buff* x, const void* p, int len) { int i = x->index; - ei_encode_binary(NULL, &i, p, len); + if (ei_encode_binary(NULL, &i, p, len) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_binary(x->buff, &x->index, p, len); @@ -117,7 +119,8 @@ int ei_x_encode_binary(ei_x_buff* x, const void* p, int len) int ei_x_encode_long(ei_x_buff* x, long n) { int i = x->index; - ei_encode_long(NULL, &i, n); + if (ei_encode_long(NULL, &i, n) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_long(x->buff, &x->index, n); @@ -126,7 +129,8 @@ int ei_x_encode_long(ei_x_buff* x, long n) int ei_x_encode_ulong(ei_x_buff* x, unsigned long n) { int i = x->index; - ei_encode_ulong(NULL, &i, n); + if (ei_encode_ulong(NULL, &i, n) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_ulong(x->buff, &x->index, n); @@ -135,7 +139,8 @@ int ei_x_encode_ulong(ei_x_buff* x, unsigned long n) int ei_x_encode_char(ei_x_buff* x, char p) { int i = x->index; - ei_encode_char(NULL, &i, p); + if (ei_encode_char(NULL, &i, p) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_char(x->buff, &x->index, p); @@ -144,7 +149,8 @@ int ei_x_encode_char(ei_x_buff* x, char p) int ei_x_encode_boolean(ei_x_buff* x, int p) { int i = x->index; - ei_encode_boolean(NULL, &i, p); + if (ei_encode_boolean(NULL, &i, p) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_boolean(x->buff, &x->index, p); @@ -153,7 +159,8 @@ int ei_x_encode_boolean(ei_x_buff* x, int p) int ei_x_encode_double(ei_x_buff* x, double dbl) { int i = x->index; - ei_encode_double(NULL, &i, dbl); + if (ei_encode_double(NULL, &i, dbl) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_double(x->buff, &x->index, dbl); @@ -162,7 +169,8 @@ int ei_x_encode_double(ei_x_buff* x, double dbl) int ei_x_encode_list_header(ei_x_buff* x, long n) { int i = x->index; - ei_encode_list_header(NULL, &i, n); + if (ei_encode_list_header(NULL, &i, n) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_list_header(x->buff, &x->index, n); @@ -171,7 +179,8 @@ int ei_x_encode_list_header(ei_x_buff* x, long n) int ei_x_encode_empty_list(ei_x_buff* x) { int i = x->index; - ei_encode_empty_list(NULL, &i); + if (ei_encode_empty_list(NULL, &i) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_empty_list(x->buff, &x->index); @@ -180,7 +189,8 @@ int ei_x_encode_empty_list(ei_x_buff* x) int ei_x_encode_version(ei_x_buff* x) { int i = x->index; - ei_encode_version(NULL, &i); + if (ei_encode_version(NULL, &i) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_version(x->buff, &x->index); @@ -189,7 +199,8 @@ int ei_x_encode_version(ei_x_buff* x) int ei_x_encode_tuple_header(ei_x_buff* x, long n) { int i = x->index; - ei_encode_tuple_header(NULL, &i, n); + if (ei_encode_tuple_header(NULL, &i, n) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_tuple_header(x->buff, &x->index, n); @@ -206,18 +217,19 @@ int ei_x_encode_atom_len(ei_x_buff* x, const char* s, int len) } int ei_x_encode_atom_as(ei_x_buff* x, const char* s, - enum erlang_char_encoding from_enc, - enum erlang_char_encoding to_enc) + erlang_char_encoding from_enc, + erlang_char_encoding to_enc) { return ei_x_encode_atom_len_as(x, s, strlen(s), from_enc, to_enc); } int ei_x_encode_atom_len_as(ei_x_buff* x, const char* s, int len, - enum erlang_char_encoding from_enc, - enum erlang_char_encoding to_enc) + erlang_char_encoding from_enc, + erlang_char_encoding to_enc) { int i = x->index; - ei_encode_atom_len_as(NULL, &i, s, len, from_enc, to_enc); + if (ei_encode_atom_len_as(NULL, &i, s, len, from_enc, to_enc) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_atom_len_as(x->buff, &x->index, s, len, from_enc, to_enc); @@ -227,7 +239,8 @@ int ei_x_encode_atom_len_as(ei_x_buff* x, const char* s, int len, int ei_x_encode_pid(ei_x_buff* x, const erlang_pid* pid) { int i = x->index; - ei_encode_pid(NULL, &i, pid); + if (ei_encode_pid(NULL, &i, pid) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_pid(x->buff, &x->index, pid); @@ -236,7 +249,8 @@ int ei_x_encode_pid(ei_x_buff* x, const erlang_pid* pid) int ei_x_encode_fun(ei_x_buff* x, const erlang_fun* fun) { int i = x->index; - ei_encode_fun(NULL, &i, fun); + if (ei_encode_fun(NULL, &i, fun) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_fun(x->buff, &x->index, fun); @@ -245,7 +259,8 @@ int ei_x_encode_fun(ei_x_buff* x, const erlang_fun* fun) int ei_x_encode_ref(ei_x_buff* x, const erlang_ref* ref) { int i = x->index; - ei_encode_ref(NULL, &i, ref); + if (ei_encode_ref(NULL, &i, ref) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_ref(x->buff, &x->index, ref); @@ -254,7 +269,8 @@ int ei_x_encode_ref(ei_x_buff* x, const erlang_ref* ref) int ei_x_encode_port(ei_x_buff* x, const erlang_port* port) { int i = x->index; - ei_encode_port(NULL, &i, port); + if (ei_encode_port(NULL, &i, port) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_port(x->buff, &x->index, port); @@ -263,7 +279,8 @@ int ei_x_encode_port(ei_x_buff* x, const erlang_port* port) int ei_x_encode_trace(ei_x_buff* x, const erlang_trace* trace) { int i = x->index; - ei_encode_trace(NULL, &i, trace); + if (ei_encode_trace(NULL, &i, trace) == -1) + return -1; if (!x_fix_buff(x, i)) return -1; return ei_encode_trace(x->buff, &x->index, trace); diff --git a/lib/erl_interface/src/misc/get_type.c b/lib/erl_interface/src/misc/get_type.c index 54465196b0..2bd992bd56 100644 --- a/lib/erl_interface/src/misc/get_type.c +++ b/lib/erl_interface/src/misc/get_type.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2010. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/misc/putget.h b/lib/erl_interface/src/misc/putget.h index 77ae168f8c..c751e03093 100644 --- a/lib/erl_interface/src/misc/putget.h +++ b/lib/erl_interface/src/misc/putget.h @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2010. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -105,10 +105,10 @@ ((EI_ULONGLONG)((unsigned char *)(s))[-2] << 8) | \ (EI_ULONGLONG)((unsigned char *)(s))[-1])) -int utf8_to_latin1(char* dst, const char* src, int slen, int destlen, enum erlang_char_encoding* res_encp); -int latin1_to_utf8(char* dst, const char* src, int slen, int destlen, enum erlang_char_encoding* res_encp); -int ei_internal_get_atom(const char** bufp, char* p, enum erlang_char_encoding*); -int ei_internal_put_atom(char** bufp, const char* p, int slen, enum erlang_char_encoding); +int utf8_to_latin1(char* dst, const char* src, int slen, int destlen, erlang_char_encoding* res_encp); +int latin1_to_utf8(char* dst, const char* src, int slen, int destlen, erlang_char_encoding* res_encp); +int ei_internal_get_atom(const char** bufp, char* p, erlang_char_encoding*); +int ei_internal_put_atom(char** bufp, const char* p, int slen, erlang_char_encoding); #define get_atom ei_internal_get_atom #define put_atom ei_internal_put_atom diff --git a/lib/erl_interface/src/misc/show_msg.c b/lib/erl_interface/src/misc/show_msg.c index 33b09643ca..935a9a3287 100644 --- a/lib/erl_interface/src/misc/show_msg.c +++ b/lib/erl_interface/src/misc/show_msg.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 1998-2010. All Rights Reserved. + * Copyright Ericsson AB 1998-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in diff --git a/lib/erl_interface/src/prog/ei_fake_prog.c b/lib/erl_interface/src/prog/ei_fake_prog.c index 34101a2851..56d4eb7db4 100644 --- a/lib/erl_interface/src/prog/ei_fake_prog.c +++ b/lib/erl_interface/src/prog/ei_fake_prog.c @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2002-2009. All Rights Reserved. + * Copyright Ericsson AB 2002-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -96,7 +96,7 @@ int main(void) EI_ULONGLONG *ulonglongp = (EI_ULONGLONG*)NULL; EI_ULONGLONG ulonglongx = 0; #endif - enum erlang_char_encoding enc; + erlang_char_encoding enc; intx = erl_errno; diff --git a/lib/erl_interface/test/all_SUITE_data/init_tc.erl b/lib/erl_interface/test/all_SUITE_data/init_tc.erl index 7e370c566a..0f2ac215f9 100644 --- a/lib/erl_interface/test/all_SUITE_data/init_tc.erl +++ b/lib/erl_interface/test/all_SUITE_data/init_tc.erl @@ -40,7 +40,7 @@ run([]) -> run1(Name) -> CFile = Name ++ ".c", {ok, Bin} = file:read_file(CFile), - RE = "\nTESTCASE\\(([_a-zA-Z]*)\\)", + RE = "\nTESTCASE\\(([_a-zA-Z0-9]*)\\)", {match, Cases0} = re:run(Bin, RE, [{capture,all_but_first,list},global]), Cases = lists:concat(Cases0), generate(Name, Cases). diff --git a/lib/erl_interface/test/ei_decode_SUITE.erl b/lib/erl_interface/test/ei_decode_SUITE.erl index 2c4b6e5541..5a94994912 100644 --- a/lib/erl_interface/test/ei_decode_SUITE.erl +++ b/lib/erl_interface/test/ei_decode_SUITE.erl @@ -27,14 +27,16 @@ -export( [ all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, - init_per_group/2,end_per_group/2, + init_per_group/2,end_per_group/2, init_per_testcase/2, + end_per_testcase/2, test_ei_decode_long/1, test_ei_decode_ulong/1, test_ei_decode_longlong/1, test_ei_decode_ulonglong/1, test_ei_decode_char/1, test_ei_decode_nonoptimal/1, - test_ei_decode_misc/1 + test_ei_decode_misc/1, + test_ei_decode_utf8_atom/1 ]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -43,7 +45,7 @@ all() -> [test_ei_decode_long, test_ei_decode_ulong, test_ei_decode_longlong, test_ei_decode_ulonglong, test_ei_decode_char, test_ei_decode_nonoptimal, - test_ei_decode_misc]. + test_ei_decode_misc, test_ei_decode_utf8_atom]. groups() -> []. @@ -60,6 +62,11 @@ init_per_group(_GroupName, Config) -> end_per_group(_GroupName, Config) -> Config. +init_per_testcase(_TC, Config) -> + Config. + +end_per_testcase(_RC, Config) -> + Config. %% --------------------------------------------------------------------------- @@ -221,6 +228,29 @@ test_ei_decode_misc(Config) when is_list(Config) -> ?line runner:recv_eot(P), ok. +%% ######################################################################## %% + +test_ei_decode_utf8_atom(Config) -> + ?line P = runner:start(?test_ei_decode_utf8_atom), + + send_utf8_atom_as_binary(P,"å"), + send_utf8_atom_as_binary(P,"ä"), + send_term_as_binary(P,'ö'), + send_term_as_binary(P,'õ'), + + ?line send_utf8_atom_as_binary(P,[1758]), + ?line send_utf8_atom_as_binary(P,[1758,1758]), + ?line send_utf8_atom_as_binary(P,[1758,1758,1758]), + ?line send_utf8_atom_as_binary(P,[1758,1758,1758,1758]), + + send_utf8_atom_as_binary(P,"a"), + send_utf8_atom_as_binary(P,"b"), + send_term_as_binary(P,'c'), + send_term_as_binary(P,'d'), + + ?line runner:recv_eot(P), + ok. + %% ######################################################################## %% @@ -230,6 +260,8 @@ send_term_as_binary(Port, Term) when is_port(Port) -> send_raw(Port, Bin) when is_port(Port) -> Port ! {self(), {command, Bin}}. +send_utf8_atom_as_binary(Port, String) -> + Port ! {self(), {command, term_to_binary(uc_atup(String))}}. send_integers(P) -> ?line send_term_as_binary(P,0), % SMALL_INTEGER_EXT smallest @@ -304,3 +336,43 @@ send_integers2(P) -> ?line send_term_as_binary(P, 16#ffffffffffffffff), % largest u64 ?line send_term_as_binary(P, []), % illegal type ok. + +uc_atup(ATxt) -> + string_to_atom(ATxt). + +string_to_atom(String) -> + Utf8List = string_to_utf8_list(String), + Len = length(Utf8List), + TagLen = case Len < 256 of + true -> [119, Len]; + false -> [118, Len bsr 8, Len band 16#ff] + end, + binary_to_term(list_to_binary([131, TagLen, Utf8List])). + +string_to_utf8_list([]) -> + []; +string_to_utf8_list([CP|CPs]) when is_integer(CP), + 0 =< CP, + CP =< 16#7F -> + [CP | string_to_utf8_list(CPs)]; +string_to_utf8_list([CP|CPs]) when is_integer(CP), + 16#80 =< CP, + CP =< 16#7FF -> + [16#C0 bor (CP bsr 6), + 16#80 bor (16#3F band CP) + | string_to_utf8_list(CPs)]; +string_to_utf8_list([CP|CPs]) when is_integer(CP), + 16#800 =< CP, + CP =< 16#FFFF -> + [16#E0 bor (CP bsr 12), + 16#80 bor (16#3F band (CP bsr 6)), + 16#80 bor (16#3F band CP) + | string_to_utf8_list(CPs)]; +string_to_utf8_list([CP|CPs]) when is_integer(CP), + 16#10000 =< CP, + CP =< 16#10FFFF -> + [16#F0 bor (CP bsr 18), + 16#80 bor (16#3F band (CP bsr 12)), + 16#80 bor (16#3F band (CP bsr 6)), + 16#80 bor (16#3F band CP) + | string_to_utf8_list(CPs)]. diff --git a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c index b349138ae9..f5c8c4fa7d 100644 --- a/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c +++ b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c @@ -17,6 +17,8 @@ * %CopyrightEnd% */ +#include <string.h> + #ifdef VXWORKS #include "reclaim.h" #endif @@ -38,6 +40,24 @@ err, size1, SIZE, (EI_LONGLONG)p); #endif +#define ERLANG_ANY (ERLANG_ASCII|ERLANG_LATIN1|ERLANG_UTF8) + +struct my_atom { + erlang_char_encoding from; + erlang_char_encoding was_check; + erlang_char_encoding result_check; +}; + +/* Allow arrays constants to be part of macro arguments */ +#define P99(...) __VA_ARGS__ + +int ei_decode_my_atom_as(const char *buf, int *index, char *to, + struct my_atom *atom); +int ei_decode_my_atom(const char *buf, int *index, char *to, + struct my_atom *atom); +int ei_decode_my_string(const char *buf, int *index, char *to, + struct my_atom *atom); + #define EI_DECODE_2(FUNC,SIZE,TYPE,VAL) \ { \ TYPE p; \ @@ -129,17 +149,26 @@ } \ } \ -#define EI_DECODE_STRING(FUNC,SIZE,VAL) \ +#define dump(arr, num) { \ + int i; \ + message("Dumping " #arr ": "); \ + for (i = 0; i < num; i++) message("%u, ",(unsigned char)arr[i]); \ + message("\n"); \ + } + +#define EI_DECODE_STRING_4(FUNC,SIZE,VAL,ATOM) \ { \ char p[1024]; \ char *buf; \ + unsigned char val[] = VAL; \ int size1 = 0; \ int size2 = 0; \ int err; \ - message("ei_" #FUNC " should be " #VAL); \ + struct my_atom atom = ATOM; \ + message("ei_" #FUNC " should be " #VAL "\n"); \ buf = read_packet(NULL); \ \ - err = ei_ ## FUNC(buf+1, &size1, NULL); \ + err = ei_ ## FUNC(buf+1, &size1, NULL, &atom); \ message("err = %d, size = %d, expected size = %d\n",err,size1,SIZE); \ if (err != 0) { \ if (err != -1) { \ @@ -150,7 +179,7 @@ return; \ } \ \ - err = ei_ ## FUNC(buf+1, &size2, p); \ + err = ei_ ## FUNC(buf+1, &size2, p, &atom); \ message("err = %d, size = %d, expected size = %d\n",err,size2,SIZE); \ if (err != 0) { \ if (err != -1) { \ @@ -161,7 +190,7 @@ return; \ } \ \ - if (strcmp(p,VAL) != 0) { \ + if (strcmp(p,val) != 0) { \ fail("value is not correct"); \ return; \ } \ @@ -177,6 +206,51 @@ } \ } \ +#define EI_DECODE_STRING(FUNC,SIZE,VAL) \ + EI_DECODE_STRING_4(FUNC,SIZE,VAL, \ + P99({ERLANG_ANY,ERLANG_ANY,ERLANG_ANY})) + +#define EI_DECODE_STRING_FAIL(FUNC,ATOM) \ + { \ + char p[1024]; \ + char *buf; \ + int size1 = 0; \ + int size2 = 0; \ + int err; \ + struct my_atom atom = ATOM;\ + message("ei_" #FUNC " should fail\n"); \ + p[0] = 0; \ + message("p[0] is %d\n",p[0]); \ + buf = read_packet(NULL); \ +\ + err = ei_ ## FUNC(buf+1, &size1, NULL, &atom); \ + if (err != -1) { \ + fail("should return -1 if NULL pointer"); \ + return; \ + } \ +\ + err = ei_ ## FUNC(buf+1, &size2, p, &atom); \ + if (err != -1) { \ + fail("should return -1"); \ + return; \ + } \ + if (p[0] != 0) { \ + message("p[0] argument was modified to %u\n",(unsigned char)p[0]); \ + } \ +\ + if (size1 != 0) { \ + fail("size of encoded data should be 0 if NULL"); \ + return; \ + } \ +\ + if (size2 != 0) { \ + fail("size of encoded data should be 0"); \ + return; \ + } \ + } \ + +//#define EI_DECODE_UTF8_STRING(FUNC,SIZE,VAL) + #define EI_DECODE_BIN(FUNC,SIZE,VAL,LEN) \ { \ char p[1024]; \ @@ -536,13 +610,13 @@ TESTCASE(test_ei_decode_misc) EI_DECODE_2(decode_boolean, 8, int, 0); EI_DECODE_2(decode_boolean, 7, int, 1); - EI_DECODE_STRING(decode_atom, 6, "foo"); - EI_DECODE_STRING(decode_atom, 3, ""); - EI_DECODE_STRING(decode_atom, 9, "������"); + EI_DECODE_STRING(decode_my_atom, 6, "foo"); + EI_DECODE_STRING(decode_my_atom, 3, ""); + EI_DECODE_STRING(decode_my_atom, 9, "������"); - EI_DECODE_STRING(decode_string, 6, "foo"); - EI_DECODE_STRING(decode_string, 1, ""); - EI_DECODE_STRING(decode_string, 9, "������"); + EI_DECODE_STRING(decode_my_string, 6, "foo"); + EI_DECODE_STRING(decode_my_string, 1, ""); + EI_DECODE_STRING(decode_my_string, 9, "������"); EI_DECODE_BIN(decode_binary, 8, "foo", 3); EI_DECODE_BIN(decode_binary, 5, "", 0); @@ -559,3 +633,63 @@ TESTCASE(test_ei_decode_misc) /* ******************************************************************** */ +TESTCASE(test_ei_decode_utf8_atom) +{ + + EI_DECODE_STRING_4(decode_my_atom_as, 4, P99({229,0}), /* LATIN1 "�" */ + P99({ERLANG_ANY,ERLANG_LATIN1,ERLANG_LATIN1})); + EI_DECODE_STRING_4(decode_my_atom_as, 4, P99({195,164,0}), /* UTF8 "�" */ + P99({ERLANG_UTF8,ERLANG_LATIN1,ERLANG_UTF8})); + EI_DECODE_STRING_4(decode_my_atom_as, 4, P99({246,0}), /* LATIN1 "�" */ + P99({ERLANG_LATIN1,ERLANG_LATIN1,ERLANG_LATIN1})); + EI_DECODE_STRING_FAIL(decode_my_atom_as, + P99({ERLANG_ASCII,ERLANG_ANY,ERLANG_ANY})); + + EI_DECODE_STRING_4(decode_my_atom_as, 4, P99({219,158,0}), + P99({ERLANG_ANY,ERLANG_UTF8,ERLANG_UTF8})); + EI_DECODE_STRING_4(decode_my_atom_as, 6, P99({219,158,219,158,0}), + P99({ERLANG_UTF8,ERLANG_UTF8,ERLANG_UTF8})); + EI_DECODE_STRING_FAIL(decode_my_atom_as, + P99({ERLANG_LATIN1,ERLANG_ANY,ERLANG_ANY})); + EI_DECODE_STRING_FAIL(decode_my_atom_as, + P99({ERLANG_ASCII,ERLANG_ANY,ERLANG_ANY})); + + EI_DECODE_STRING_4(decode_my_atom_as, 4, "a", + P99({ERLANG_ANY,ERLANG_LATIN1,ERLANG_ASCII})); + EI_DECODE_STRING_4(decode_my_atom_as, 4, "b", + P99({ERLANG_UTF8,ERLANG_LATIN1,ERLANG_ASCII})); + EI_DECODE_STRING_4(decode_my_atom_as, 4, "c", + P99({ERLANG_LATIN1,ERLANG_LATIN1,ERLANG_ASCII})); + EI_DECODE_STRING_4(decode_my_atom_as, 4, "d", + P99({ERLANG_ASCII,ERLANG_LATIN1,ERLANG_ASCII})); + + report(1); +} + +/* ******************************************************************** */ + +int ei_decode_my_atom_as(const char *buf, int *index, char *to, + struct my_atom *atom) { + erlang_char_encoding was,result; + int res = ei_decode_atom_as(buf,index,to,1024,atom->from,&was,&result); + if (res != 0) + return res; + if (!(was & atom->was_check)) { + message("Original encoding was %d not %d\n",was,atom->was_check); + return -1; + } else if (!(result & atom->result_check)) { + message("Result encoding was %d not %d\n",result,atom->result_check); + return -1; + } + return res; +} + +int ei_decode_my_atom(const char *buf, int *index, char *to, + struct my_atom *atom) { + return ei_decode_atom(buf, index, to); +} + +int ei_decode_my_string(const char *buf, int *index, char *to, + struct my_atom *atom) { + return ei_decode_string(buf, index, to); +} diff --git a/lib/erl_interface/test/ei_decode_encode_SUITE.erl b/lib/erl_interface/test/ei_decode_encode_SUITE.erl index 0c98b494ec..2271278291 100644 --- a/lib/erl_interface/test/ei_decode_encode_SUITE.erl +++ b/lib/erl_interface/test/ei_decode_encode_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2004-2011. All Rights Reserved. +%% Copyright Ericsson AB 2004-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in 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 e57663f984..317e5edecd 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 @@ -1,7 +1,7 @@ /* * %CopyrightBegin% * - * Copyright Ericsson AB 2004-2009. All Rights Reserved. + * Copyright Ericsson AB 2004-2013. All Rights Reserved. * * The contents of this file are subject to the Erlang Public License, * Version 1.1, (the "License"); you may not use this file except in @@ -47,12 +47,13 @@ struct Type { typedef struct { char name[MAXATOMLEN_UTF8]; - enum erlang_char_encoding enc; + erlang_char_encoding enc; }my_atom; int ei_decode_my_atom(const char *buf, int *index, my_atom* a) { - return ei_decode_atom_as(buf, index, a->name, sizeof(a->name), ERLANG_UTF8, &a->enc, NULL); + return ei_decode_atom_as(buf, index, (a ? a->name : NULL), sizeof(a->name), + ERLANG_UTF8, (a ? &a->enc : NULL), NULL); } int ei_encode_my_atom(char *buf, int *index, my_atom* a) { @@ -77,7 +78,7 @@ void decode_encode(struct Type* t, void* obj) MESSAGE("ei_decode_%s, arg is type %s", t->name, t->type); buf = read_packet(NULL); - err = t->ei_decode_fp(buf+1, &size1, obj); + err = t->ei_decode_fp(buf+1, &size1, NULL); if (err != 0) { if (err != -1) { fail("decode returned non zero but not -1"); @@ -96,7 +97,35 @@ void decode_encode(struct Type* t, void* obj) return; } + err = t->ei_decode_fp(buf+1, &size2, obj); + if (err != 0) { + if (err != -1) { + fail("decode returned non zero but not -1"); + } else { + fail("decode returned non zero"); + } + return; + } + if (size1 != size2) { + MESSAGE("size1 = %d, size2 = %d\n",size1,size2); + fail("decode sizes differs"); + return; + } + + size2 = 0; + err = ei_skip_term(buf+1, &size2); + if (err != 0) { + fail("ei_skip_term returned non zero"); + return; + } + if (size1 != size2) { + MESSAGE("size1 = %d, size2 = %d\n",size1,size2); + fail("skip size differs"); + return; + } + MESSAGE("ei_encode_%s buf is NULL, arg is type %s", t->name, t->type); + size2 = 0; err = t->ei_encode_fp(NULL, &size2, obj); if (err != 0) { if (err != -1) { diff --git a/lib/erl_interface/test/ei_encode_SUITE.erl b/lib/erl_interface/test/ei_encode_SUITE.erl index 537e9cb01c..e0ac4c0637 100644 --- a/lib/erl_interface/test/ei_encode_SUITE.erl +++ b/lib/erl_interface/test/ei_encode_SUITE.erl @@ -34,7 +34,9 @@ test_ei_encode_ulonglong/1, test_ei_encode_char/1, test_ei_encode_misc/1, - test_ei_encode_fails/1 + test_ei_encode_fails/1, + test_ei_encode_utf8_atom/1, + test_ei_encode_utf8_atom_len/1 ]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -43,7 +45,8 @@ all() -> [test_ei_encode_long, test_ei_encode_ulong, test_ei_encode_longlong, test_ei_encode_ulonglong, test_ei_encode_char, test_ei_encode_misc, - test_ei_encode_fails]. + test_ei_encode_fails, test_ei_encode_utf8_atom, + test_ei_encode_utf8_atom_len]. groups() -> []. @@ -257,6 +260,38 @@ test_ei_encode_fails(Config) when is_list(Config) -> %% ######################################################################## %% +test_ei_encode_utf8_atom(Config) -> + ?line P = runner:start(?test_ei_encode_utf8_atom), + + ?line {<<119,2,195,133>>,'Å'} = get_buf_and_term(P), + ?line {<<100,0,1,197>>,'Å'} = get_buf_and_term(P), + ?line {<<100,0,1,197>>,'Å'} = get_buf_and_term(P), + ?line {<<119,2,195,133>>,'Å'} = get_buf_and_term(P), + + ?line {<<119,1,$A>>,'A'} = get_buf_and_term(P), + ?line {<<100,0,1,$A>>,'A'} = get_buf_and_term(P), + + ?line runner:recv_eot(P), + ok. + +%% ######################################################################## %% +test_ei_encode_utf8_atom_len(Config) -> + ?line P = runner:start(?test_ei_encode_utf8_atom_len), + + ?line {<<119,2,195,133>>,'Å'} = get_buf_and_term(P), + ?line {<<100,0,2,197,196>>,'ÅÄ'} = get_buf_and_term(P), + ?line {<<100,0,1,197>>,'Å'} = get_buf_and_term(P), + ?line {<<119,4,195,133,195,132>>,'ÅÄ'} = get_buf_and_term(P), + + ?line {<<119,1,$A>>,'A'} = get_buf_and_term(P), + ?line {<<100,0,2,$A,$B>>,'AB'} = get_buf_and_term(P), + ?line {<<100,0,255,_:(255*8)>>,_} = get_buf_and_term(P), + + ?line runner:recv_eot(P), + ok. + +%% ######################################################################## %% + % We read two packets for each test, the ei_encode and ei_x_encode version.... get_buf_and_term(P) -> diff --git a/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c b/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c index c373658152..e904375e9e 100644 --- a/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c +++ b/lib/erl_interface/test/ei_encode_SUITE_data/ei_encode_test.c @@ -208,6 +208,196 @@ ei_x_free(&arg); \ } +#define EI_ENCODE_3(FUNC,ARG1,ARG2,ARG3) \ + { \ + char buf[1024]; \ + int size1 = 0; \ + int size2 = 0; \ + int err; \ + message("ei_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " encoded as "); \ + err = ei_ ## FUNC(NULL, &size1, ARG1, ARG2, ARG3); \ + if (err != 0) { \ + if (err != -1) { \ + fail("size calculation returned non zero but not -1"); \ + return; \ + } else { \ + fail("size calculation returned non zero"); \ + return; \ + } \ + } \ + err = ei_ ## FUNC(buf, &size2, ARG1, ARG2, ARG3); \ + if (err != 0) { \ + if (err != -1) { \ + fail("returned non zero but not -1"); \ + } else { \ + fail("returned non zero"); \ + } \ + return; \ + } \ + if (size1 != size2) { \ + fail("size differs when arg is NULL or buf"); \ + return; \ + } \ + if (size1 < 1) { \ + fail("size is < 1"); \ + return; \ + } \ + send_buffer(buf, size1); \ + } \ + { \ + ei_x_buff arg; \ + int err; \ + message("ei_x_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " encoded as "); \ + ei_x_new(&arg); \ + err = ei_x_ ## FUNC(&arg, ARG1, ARG2, ARG3); \ + if (err != 0) { \ + if (err != -1) { \ + fail("returned non zero but not -1"); \ + } else { \ + fail("returned non zero"); \ + } \ + ei_x_free(&arg); \ + return; \ + } \ + if (arg.index < 1) { \ + fail("size is < 1"); \ + ei_x_free(&arg); \ + return; \ + } \ + send_buffer(arg.buff, arg.index); \ + ei_x_free(&arg); \ + } + +#define EI_ENCODE_3_FAIL(FUNC,ARG1,ARG2,ARG3) \ + { \ + char buf[1024]; \ + int size1 = 0; \ + int size2 = 0; \ + int err; \ + message("ei_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " encoded as "); \ + err = ei_ ## FUNC(NULL, &size1, ARG1, ARG2, ARG3); \ + if (err != -1) { \ + fail("size calculation returned non -1"); \ + return; \ + } \ + err = ei_ ## FUNC(buf, &size2, ARG1, ARG2, ARG3); \ + if (err != -1) { \ + fail("returned non -1"); \ + } \ + if (size1 != size2) { \ + fail("size differs when arg is NULL or buf"); \ + return; \ + } \ + } \ + { \ + ei_x_buff arg; \ + int err; \ + message("ei_x_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " encoded as "); \ + ei_x_new(&arg); \ + err = ei_x_ ## FUNC(&arg, ARG1, ARG2, ARG3); \ + if (err != -1) { \ + fail("returned non -1"); \ + ei_x_free(&arg); \ + return; \ + } \ + ei_x_free(&arg); \ + } + +#define EI_ENCODE_4(FUNC,ARG1,ARG2,ARG3,ARG4) \ + { \ + char buf[1024]; \ + int size1 = 0; \ + int size2 = 0; \ + int err; \ + message("ei_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " " #ARG4 " encoded as "); \ + err = ei_ ## FUNC(NULL, &size1, ARG1, ARG2, ARG3, ARG4); \ + if (err != 0) { \ + if (err != -1) { \ + fail("size calculation returned non zero but not -1"); \ + return; \ + } else { \ + fail("size calculation returned non zero"); \ + return; \ + } \ + } \ + err = ei_ ## FUNC(buf, &size2, ARG1, ARG2, ARG3, ARG4); \ + if (err != 0) { \ + if (err != -1) { \ + fail("returned non zero but not -1"); \ + } else { \ + fail("returned non zero"); \ + } \ + return; \ + } \ + if (size1 != size2) { \ + fail("size differs when arg is NULL or buf"); \ + return; \ + } \ + if (size1 < 1) { \ + fail("size is < 1"); \ + return; \ + } \ + send_buffer(buf, size1); \ + } \ + { \ + ei_x_buff arg; \ + int err; \ + message("ei_x_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " " #ARG4 " encoded as "); \ + ei_x_new(&arg); \ + err = ei_x_ ## FUNC(&arg, ARG1, ARG2, ARG3, ARG4); \ + if (err != 0) { \ + if (err != -1) { \ + fail("returned non zero but not -1"); \ + } else { \ + fail("returned non zero"); \ + } \ + ei_x_free(&arg); \ + return; \ + } \ + if (arg.index < 1) { \ + fail("size is < 1"); \ + ei_x_free(&arg); \ + return; \ + } \ + send_buffer(arg.buff, arg.index); \ + ei_x_free(&arg); \ + } + +#define EI_ENCODE_4_FAIL(FUNC,ARG1,ARG2,ARG3,ARG4) \ + { \ + char buf[1024]; \ + int size1 = 0; \ + int size2 = 0; \ + int err; \ + message("ei_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " " #ARG4 " encoded as "); \ + err = ei_ ## FUNC(NULL, &size1, ARG1, ARG2, ARG3, ARG4); \ + if (err != -1) { \ + fail("size calculation returned non -1"); \ + return; \ + } \ + err = ei_ ## FUNC(buf, &size2, ARG1, ARG2, ARG3, ARG4); \ + if (err != -1) { \ + fail("returned non -1"); \ + } \ + if (size1 != size2) { \ + fail("size differs when arg is NULL or buf"); \ + return; \ + } \ + } \ + { \ + ei_x_buff arg; \ + int err; \ + message("ei_x_" #FUNC " " #ARG1 " " #ARG2 " " #ARG3 " " #ARG4 " encoded as "); \ + ei_x_new(&arg); \ + err = ei_x_ ## FUNC(&arg, ARG1, ARG2, ARG3, ARG4); \ + if (err != -1) { \ + fail("returned non -1"); \ + ei_x_free(&arg); \ + return; \ + } \ + ei_x_free(&arg); \ + } + /* ******************************************************************** */ TESTCASE(test_ei_encode_long) @@ -464,3 +654,57 @@ TESTCASE(test_ei_encode_fails) report(1); } + +/* ******************************************************************** */ + +TESTCASE(test_ei_encode_utf8_atom) +{ + + EI_ENCODE_3(encode_atom_as, "�", ERLANG_LATIN1, ERLANG_UTF8); + EI_ENCODE_3(encode_atom_as, "�", ERLANG_LATIN1, ERLANG_LATIN1); + EI_ENCODE_3(encode_atom_as, "\303\205", + ERLANG_UTF8, ERLANG_LATIN1); + EI_ENCODE_3(encode_atom_as, "\303\205", + ERLANG_UTF8, ERLANG_UTF8); + + EI_ENCODE_3(encode_atom_as, "A", ERLANG_ASCII, ERLANG_UTF8); + EI_ENCODE_3(encode_atom_as, "A", ERLANG_ASCII, ERLANG_LATIN1); + + EI_ENCODE_3_FAIL(encode_atom_as, "�", ERLANG_UTF8, ERLANG_UTF8); + EI_ENCODE_3_FAIL(encode_atom_as, "�", ERLANG_UTF8, ERLANG_LATIN1); + EI_ENCODE_3_FAIL(encode_atom_as, "�", ERLANG_ASCII, ERLANG_UTF8); + EI_ENCODE_3_FAIL(encode_atom_as, "�", ERLANG_ASCII, ERLANG_LATIN1); + + EI_ENCODE_3_FAIL(encode_atom_as, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", ERLANG_ASCII, ERLANG_LATIN1); + EI_ENCODE_3_FAIL(encode_atom_as, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", ERLANG_LATIN1, ERLANG_LATIN1); + + EI_ENCODE_3_FAIL(encode_atom_as, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", ERLANG_UTF8, ERLANG_LATIN1); + + report(1); +} + +TESTCASE(test_ei_encode_utf8_atom_len) +{ + + EI_ENCODE_4(encode_atom_len_as, "���", 1, ERLANG_LATIN1, ERLANG_UTF8); + EI_ENCODE_4(encode_atom_len_as, "���", 2, ERLANG_LATIN1, ERLANG_LATIN1); + EI_ENCODE_4(encode_atom_len_as, "\303\205\303\204\303\226", 2, + ERLANG_UTF8, ERLANG_LATIN1); + EI_ENCODE_4(encode_atom_len_as, "\303\205\303\204\303\226", 4, + ERLANG_UTF8, ERLANG_UTF8); + + EI_ENCODE_4(encode_atom_len_as, "ABC", 1, ERLANG_ASCII, ERLANG_UTF8); + EI_ENCODE_4(encode_atom_len_as, "ABC", 2, ERLANG_ASCII, ERLANG_LATIN1); + + EI_ENCODE_4_FAIL(encode_atom_len_as, "���", 1, ERLANG_UTF8, ERLANG_UTF8); + EI_ENCODE_4_FAIL(encode_atom_len_as, "���", 2, ERLANG_UTF8, ERLANG_LATIN1); + EI_ENCODE_4_FAIL(encode_atom_len_as, "���", 3, ERLANG_ASCII, ERLANG_UTF8); + EI_ENCODE_4_FAIL(encode_atom_len_as, "���", 4, ERLANG_ASCII, ERLANG_LATIN1); + + EI_ENCODE_4(encode_atom_len_as, "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", 255, ERLANG_ASCII, ERLANG_LATIN1); + + EI_ENCODE_4_FAIL(encode_atom_len_as, "\303\205\303\204\303\226", 1, + ERLANG_UTF8, ERLANG_LATIN1); + + report(1); +} diff --git a/lib/erl_interface/vsn.mk b/lib/erl_interface/vsn.mk index 1718f38069..2a3843bda6 100644 --- a/lib/erl_interface/vsn.mk +++ b/lib/erl_interface/vsn.mk @@ -1 +1 @@ -EI_VSN = 3.7.9 +EI_VSN = 3.7.10 |