aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2013-02-07 14:46:19 +0100
committerSverker Eriksson <[email protected]>2013-02-07 14:46:19 +0100
commitb0693061137de237c38965c556c7d6ded8977394 (patch)
tree18bb5289d54c522fd39d5893d48a4783b4909a54
parent68b804f34d4ec420d86953e3f519179a40fbee8f (diff)
downloadotp-b0693061137de237c38965c556c7d6ded8977394.tar.gz
otp-b0693061137de237c38965c556c7d6ded8977394.tar.bz2
otp-b0693061137de237c38965c556c7d6ded8977394.zip
erl_interface: Change enum erlang_char_encoding to a typedef
to make the API independent of the actual type of erlang_char_encoding
-rw-r--r--lib/erl_interface/doc/src/ei.xml25
-rw-r--r--lib/erl_interface/include/ei.h23
-rw-r--r--lib/erl_interface/src/decode/decode_atom.c14
-rw-r--r--lib/erl_interface/src/encode/encode_atom.c10
-rw-r--r--lib/erl_interface/src/legacy/erl_eterm.c2
-rw-r--r--lib/erl_interface/src/legacy/erl_marshal.c6
-rw-r--r--lib/erl_interface/src/misc/ei_x_encode.c8
-rw-r--r--lib/erl_interface/src/misc/putget.h8
-rw-r--r--lib/erl_interface/src/prog/ei_fake_prog.c2
-rw-r--r--lib/erl_interface/test/ei_decode_SUITE_data/ei_decode_test.c10
-rw-r--r--lib/erl_interface/test/ei_decode_encode_SUITE_data/ei_decode_encode_test.c2
11 files changed, 57 insertions, 53 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(&amp;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/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..b3f0807765 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,7 +47,7 @@ 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)