diff options
Diffstat (limited to 'lib/erl_interface')
-rw-r--r-- | lib/erl_interface/doc/src/ei.xml | 25 | ||||
-rw-r--r-- | lib/erl_interface/include/ei.h | 23 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_atom.c | 14 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_fun.c | 39 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_pid.c | 10 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_port.c | 10 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_ref.c | 23 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_skip.c | 3 | ||||
-rw-r--r-- | lib/erl_interface/src/decode/decode_trace.c | 28 | ||||
-rw-r--r-- | lib/erl_interface/src/encode/encode_atom.c | 10 | ||||
-rw-r--r-- | lib/erl_interface/src/legacy/erl_eterm.c | 2 | ||||
-rw-r--r-- | lib/erl_interface/src/legacy/erl_marshal.c | 6 | ||||
-rw-r--r-- | lib/erl_interface/src/misc/ei_x_encode.c | 8 | ||||
-rw-r--r-- | lib/erl_interface/src/misc/putget.h | 8 | ||||
-rw-r--r-- | lib/erl_interface/src/prog/ei_fake_prog.c | 2 | ||||
-rw-r--r-- | lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c | 10 | ||||
-rw-r--r-- | lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c | 35 |
17 files changed, 160 insertions, 96 deletions
diff --git a/lib/erl_interface/doc/src/ei.xml b/lib/erl_interface/doc/src/ei.xml index 03eea49224..dfe181bd1d 100644 --- a/lib/erl_interface/doc/src/ei.xml +++ b/lib/erl_interface/doc/src/ei.xml @@ -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/include/ei.h b/lib/erl_interface/include/ei.h index 29d53ab3a2..66dc64a69d 100644 --- a/lib/erl_interface/include/ei.h +++ b/lib/erl_interface/include/ei.h @@ -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/src/decode/decode_atom.c b/lib/erl_interface/src/decode/decode_atom.c index af4fc114d1..44fd4df12c 100644 --- a/lib/erl_interface/src/decode/decode_atom.c +++ b/lib/erl_interface/src/decode/decode_atom.c @@ -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_fun.c b/lib/erl_interface/src/decode/decode_fun.c index c4667822e5..2adaedb825 100644 --- a/lib/erl_interface/src/decode/decode_fun.c +++ b/lib/erl_interface/src/decode/decode_fun.c @@ -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 67ce7e05f9..d429fb2fd8 100644 --- a/lib/erl_interface/src/decode/decode_pid.c +++ b/lib/erl_interface/src/decode/decode_pid.c @@ -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 2d1b46e705..7a691f0be6 100644 --- a/lib/erl_interface/src/decode/decode_port.c +++ b/lib/erl_interface/src/decode/decode_port.c @@ -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 579371ed7d..01e3061cb4 100644 --- a/lib/erl_interface/src/decode/decode_ref.c +++ b/lib/erl_interface/src/decode/decode_ref.c @@ -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 32f5ae2af1..df4b0af5db 100644 --- a/lib/erl_interface/src/encode/encode_atom.c +++ b/lib/erl_interface/src/encode/encode_atom.c @@ -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; @@ -138,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) diff --git a/lib/erl_interface/src/legacy/erl_eterm.c b/lib/erl_interface/src/legacy/erl_eterm.c index 9e778a299e..7ca4f430de 100644 --- a/lib/erl_interface/src/legacy/erl_eterm.c +++ b/lib/erl_interface/src/legacy/erl_eterm.c @@ -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_marshal.c b/lib/erl_interface/src/legacy/erl_marshal.c index c051c3a597..e207b5f0f1 100644 --- a/lib/erl_interface/src/legacy/erl_marshal.c +++ b/lib/erl_interface/src/legacy/erl_marshal.c @@ -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/misc/ei_x_encode.c b/lib/erl_interface/src/misc/ei_x_encode.c index 4e6f4a1d36..14d0b56b8f 100644 --- a/lib/erl_interface/src/misc/ei_x_encode.c +++ b/lib/erl_interface/src/misc/ei_x_encode.c @@ -217,15 +217,15 @@ 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; if (ei_encode_atom_len_as(NULL, &i, s, len, from_enc, to_enc) == -1) diff --git a/lib/erl_interface/src/misc/putget.h b/lib/erl_interface/src/misc/putget.h index 587bf1a0f8..c751e03093 100644 --- a/lib/erl_interface/src/misc/putget.h +++ b/lib/erl_interface/src/misc/putget.h @@ -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/prog/ei_fake_prog.c b/lib/erl_interface/src/prog/ei_fake_prog.c index 52a46fc341..56d4eb7db4 100644 --- a/lib/erl_interface/src/prog/ei_fake_prog.c +++ b/lib/erl_interface/src/prog/ei_fake_prog.c @@ -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/ei_decode_SUITE_data/ei_decode_test.c b/lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c index 6db04aa676..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 @@ -40,10 +40,12 @@ err, size1, SIZE, (EI_LONGLONG)p); #endif +#define ERLANG_ANY (ERLANG_ASCII|ERLANG_LATIN1|ERLANG_UTF8) + struct my_atom { - enum erlang_char_encoding from; - enum erlang_char_encoding was_check; - enum erlang_char_encoding result_check; + erlang_char_encoding from; + erlang_char_encoding was_check; + erlang_char_encoding result_check; }; /* Allow arrays constants to be part of macro arguments */ @@ -668,7 +670,7 @@ TESTCASE(test_ei_decode_utf8_atom) int ei_decode_my_atom_as(const char *buf, int *index, char *to, struct my_atom *atom) { - enum erlang_char_encoding was,result; + erlang_char_encoding was,result; int res = ei_decode_atom_as(buf,index,to,1024,atom->from,&was,&result); if (res != 0) return res; 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 996d923ffc..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 @@ -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) { |