aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface/src/README
blob: 7591615f781c3c4d94e9ef7df074523f9f7ca889 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
Erl_interface README July 2, 1997.
Bjorn Gustavsson
----------------------------------

About the erl_interface library
-------------------------------

The pre-release version of erl_interface provided in this package
is compiled for use of DNS and with symbol information.
Also, assertions are enabled, meaning that the code will be a
little bit slower.  In the final release, there will be two
alternative libraries shipped, with and without assertions.

If an assertion triggers, there will be a printout similar to this
one:

	Assertion failed: ep != NULL in erl_eterm.c, line 694
	Abort (core dumped)

The cause of an assertion can be either errors in the application
program (for instance, passing NULL pointers to any function that
expects an ETERM pointer) or in erl_interface itself.

If you encounter any assertion failures which think you originate in
erl_interface, I'll need the following information to track it down:

1a) The printout from the assertion, especially filename and line number.

1b) A dump of the stack, obtained by running a debugger.

 - OR -

2) The source for a small test program which triggers the assertion.

Changes in this version
-----------------------

There is now *one* representation for an empty list, not two as is used
to be.  An empty list is represented by the Erl_EmptyList structure.
There are new macros, ERL_IS_EMPTY_LIST(ep), to test for an empty list,
and ERL_IS_CONS(ep) to test for a cons cell (more on that below).

None of the type checking macros (ERL_IS_LIST(ep), ERL_IS_TUPLE(ep), etc),
accept NULL pointers any longer.  Make sure to only pass valid ETERM
pointers.

erl_cons(head, tail) now requires tail to be a non-NULL pointer.
To represent the end of a list, use the return value from
erl_mk_empty_list().

erl_length() now only works for a proper list; i.e. for the
the term [a|b], erl_length() returns -1.

erl_tl(), erl_hd() is now silent if given a bad list
(but still returns NULL).

The string data type has been removed, including the macro ERL_IS_STRING().
The functions erl_mk_string() and erl_mk_estring() still exists, but builds
lists instead of strings.

There are two new functions to convert I/O lists (= deep lists of
byte-sized integers and binaries):

	char* erl_iolist_to_string(ETERM* term);
	ETERM* erl_iolist_to_binary(ETERM* term);

The erl_iolist_to_string() function converts an I/O list to a
'\0' terminated string.

Known bugs
----------

The term erl_mk_small_int(-0x10000000) will be incorrectly represented
if decoded and sent to the Erlang side.

Calling erl_mk_int() on an integer whose value is represented
in more than 28 bits, will result in an ETERM which is not an integer
(i.e. ERL_IS_INTEGER() will fail).

Planned future changes
----------------------

Support for heap allocation of Erlang terms will be dropped.
It will be assumed that malloc()/free() functions are available.

There will be one header file, erl_interface.h, not one for each
"module".

The type checking macros for lists
----------------------------------

In this version of erl_interface, there are three macros for testing
types of lists:

ERL_IS_LIST(term)
ERL_IS_CONS(term)
ERL_IS_EMPTY_LIST(term)

They behave as follows:

ERL_IS_LIST(term) is used like a list/1 guard function in Erlang:

function(List) when list(List) ->
	....

It is true if its argument is a list, even an empty list.

ERL_IS_EMPTY(term) is true only for an empty list; thus it can be
used like the following function head:

function([]) ->
	....

ERL_IS_CONS(term) only if the list is not empty; it is similar to the
following function head:

function([H|T] ->
	....

Documentation for new functions
-------------------------------

/***********************************************************************
 * I o l i s t   f u n c t i o n s
 *
 * The following functions handles I/O lists.
 *
 * Informally, an I/O list is a deep list of characters and binaries,
 * which can be sent to an Erlang port.
 *
 * Formally, in BNF, an I/O list is defined as:
 *
 * iolist ::= []
 *        |   Binary
 *        |   [iohead | iolist]
 *        ;
 *
 * iohead ::= Binary
 *        |   Byte (integer in the range [0..255])
 *        |   iolist
 *        ;
 *
 * Note that versions of Erlang/OTP prior to R2 had a slightly more
 * restricted definition of I/O lists, in that the tail of a an I/O list
 * was not allowed to be a binary.  The erl_interface functions
 * for I/O lists follows the more liberal rules described by the BNF
 * description above.
 ***********************************************************************/

/*
 * This function converts an I/O list to a '\0' terminated C string.
 * The I/O list must not contain any occurrences of the integer 0.
 *
 * The string will be in memory allocated by erl_malloc().  It is the
 * responsibility of the caller to eventually call erl_free() to free
 * the memory.
 *
 * Returns: NULL if the list was not an I/O list or contained
 * the integer 0, otherwise a pointer to '\0' terminated string.
 */

char*
erl_iolist_to_string(term)
    ETERM* term;		/* Term to convert to a string. */

/*
 * This function converts an I/O list to a binary term.
 *
 * Returns: NULL if the list was not an I/O list, otherwise
 * an ETERM pointer pointing to a binary term.
 */

ETERM*
erl_iolist_to_binary(term)
    ETERM* term;		/* Term to convert to a binary. */

/*
 * Returns the length of an I/O list.
 *
 * Returns: -1 if the term if the given term is not a I/O list,
 * or the length otherwise.
 */

int
erl_iolist_length(term)
    ETERM* term;