~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to erts/doc/src/erl_nif.xml

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
<cref>
5
5
  <header>
6
6
    <copyright>
7
 
      <year>2001</year><year>2009</year>
 
7
      <year>2001</year><year>2011</year>
8
8
      <holder>Ericsson AB. All Rights Reserved.</holder>
9
9
    </copyright>
10
10
    <legalnotice>
34
34
  <lib>erl_nif</lib>
35
35
  <libsummary>API functions for an Erlang NIF library</libsummary>
36
36
  <description>
37
 
     <warning><p>The NIF concept is introduced in R13B03 as an
38
 
        EXPERIMENTAL feature. The interfaces may be changed in any way
39
 
        in coming releases. The API introduced in this release is very
40
 
        sparse and contains only the most basic functions to read and
41
 
        write Erlang terms.
42
 
        </p></warning>
 
37
     <note><p>The NIF concept is officially supported from R14B. NIF source code
 
38
     written for earlier experimental versions might need adaption to run on R14B.</p>
 
39
    <p>No incompatible changes between <em>R14B</em> and R14A.</p>
 
40
    <p>Incompatible changes between <em>R14A</em> and R13B04:</p>
 
41
  <list>
 
42
    <item>Environment argument removed for <c>enif_alloc</c>,
 
43
    <c>enif_realloc</c>, <c>enif_free</c>, <c>enif_alloc_binary</c>,
 
44
    <c>enif_realloc_binary</c>, <c>enif_release_binary</c>,
 
45
    <c>enif_alloc_resource</c>, <c>enif_release_resource</c>,
 
46
    <c>enif_is_identical</c> and <c>enif_compare</c>.</item>
 
47
    <item>Character encoding argument added to <c>enif_get_atom</c>
 
48
    and <c>enif_make_existing_atom</c>.</item>
 
49
    <item>Module argument added to <c>enif_open_resource_type</c>
 
50
      while changing name spaces of resource types from global to module local.</item>
 
51
  </list>
 
52
  <p>Incompatible changes between <em>R13B04</em> and R13B03:</p>
 
53
  <list>
 
54
    <item>The function prototypes of the NIFs have  changed to expect <c>argc</c> and <c>argv</c>
 
55
          arguments. The arity of a NIF is by that no longer limited to 3.</item>
 
56
    <item><c>enif_get_data</c> renamed as <c>enif_priv_data</c>.</item>
 
57
    <item><c>enif_make_string</c> got a third argument for character encoding.</item>
 
58
  </list>
 
59
  </note>
43
60
 
44
61
    <p>A NIF library contains native implementation of some functions
45
 
    of an erlang module. The native implemented functions (NIFs) are
 
62
    of an Erlang module. The native implemented functions (NIFs) are
46
63
    called like any other functions without any difference to the
47
64
    caller. Each NIF must also have an implementation in Erlang that
48
65
    will be invoked if the function is called before the NIF library
49
66
    has been successfully loaded. A typical such stub implementation
50
67
    is to throw an exception. But it can also be used as a fallback
51
68
    implementation if the NIF library is not implemented for some
52
 
    architecture.</p> 
 
69
    architecture.</p>     
53
70
    <p>A minimal example of a NIF library can look like this:</p>
54
71
      <p/>
55
72
      <code type="none">
56
73
/* niftest.c */
57
74
#include "erl_nif.h"
58
75
 
59
 
static ERL_NIF_TERM hello(ErlNifEnv* env)
 
76
static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
60
77
{
61
 
    return enif_make_string(env, "Hello world!");
 
78
    return enif_make_string(env, "Hello world!", ERL_NIF_LATIN1);
62
79
}
63
80
 
64
81
static ErlNifFunc nif_funcs[] =
69
86
ERL_NIF_INIT(niftest,nif_funcs,NULL,NULL,NULL,NULL)
70
87
</code>
71
88
 
72
 
    <p>and the erlang module would have to look something like
 
89
    <p>and the Erlang module would have to look something like
73
90
    this:</p>
74
91
      <p/>
75
92
      <code type="none">
100
117
</code>
101
118
 
102
119
     <p>A better solution for a real module is to take advantage of
103
 
     the new attribute <c>on_load</c> to automatically load the NIF
104
 
     library when the module is loaded.</p>
 
120
     the new directive <seealso
 
121
     marker="doc/reference_manual:code_loading#on_load">on_load</seealso> to automatically
 
122
     load the NIF library when the module is loaded.</p>
 
123
     <note><p>A NIF does not have to be exported, it can be local to the module.
 
124
     Note however that unused local stub functions will be optimized
 
125
     away by the compiler causing loading of the NIF library to fail.</p>
 
126
    </note>
105
127
     <p>A loaded NIF library is tied to the Erlang module code version
106
128
     that loaded it. If the module is upgraded with a new version, the
107
 
     new code will have to load its own NIF library (or maybe choose not
 
129
     new Erlang code will have to load its own NIF library (or maybe choose not
108
130
     to). The new code version can however choose to load the exact
109
131
     same NIF library as the old code if it wants to. Sharing the same
110
132
     dynamic library will mean that static data defined by the library
111
133
     will be shared as well. To avoid unintentionally shared static
112
134
     data, each Erlang module code can keep its own private data. This
113
 
     global private data can be set when the NIF library is loaded and
114
 
     then retrieved by calling <seealso marker="erl_nif#enif_get_data">enif_get_data()</seealso>.</p>
115
 
    <p>There is currently no way to explicitly unload a NIF
116
 
     library. A library will be automatically unloaded when the module
117
 
     code that it belongs to is purged by the code server. A NIF
118
 
     library will can also be unloaded by replacing it with another
119
 
     version of the library by a second call to
 
135
     private data can be set when the NIF library is loaded and
 
136
     then retrieved by calling <seealso marker="#enif_priv_data">enif_priv_data</seealso>.</p>
 
137
    <p>There is no way to explicitly unload a NIF library. A library will be
 
138
     automatically unloaded when the module code that it belongs to is purged
 
139
     by the code server. A NIF library will also be unloaded if it is replaced
 
140
     by another version of the library by a second call to
120
141
     <c>erlang:load_nif/2</c> from the same module code.</p> 
121
142
  </description>
122
 
 
 
143
  <section>
 
144
  <title>FUNCTIONALITY</title>
 
145
  <p>All functions that a NIF library needs to do with Erlang are
 
146
      performed through the NIF API functions. There are functions
 
147
      for the following functionality:</p>
 
148
    <taglist>
 
149
      <tag>Read and write Erlang terms</tag>
 
150
      <item><p>Any Erlang terms can be passed to a NIF as function arguments and
 
151
      be returned as function return values. The terms are of C-type
 
152
      <seealso marker="#ERL_NIF_TERM">ERL_NIF_TERM</seealso>
 
153
      and can only be read or written using API functions. Most functions to read
 
154
      the content of a term are prefixed <c>enif_get_</c> and usually return
 
155
      true (or false) if the term was of the expected type (or not).    
 
156
      The functions to write terms are all prefixed <c>enif_make_</c> and usually
 
157
      return the created <c>ERL_NIF_TERM</c>. There are also some functions
 
158
      to query terms, like <c>enif_is_atom</c>, <c>enif_is_identical</c> and
 
159
      <c>enif_compare</c>.</p>
 
160
      <p>All terms of type <c>ERL_NIF_TERM</c> belong to an environment of type
 
161
      <seealso marker="#ErlNifEnv">ErlNifEnv</seealso>. The lifetime of a term is
 
162
      controlled by the lifetime of its environment object. All API functions that read
 
163
      or write terms has the environment, that the term belongs to, as the first
 
164
      function argument.</p></item>
 
165
      <tag>Binaries</tag>
 
166
      <item><p>Terms of type binary are accessed with the help of the struct type
 
167
      <seealso marker="#ErlNifBinary">ErlNifBinary</seealso>    
 
168
      that contains a pointer (<c>data</c>) to the raw binary data and the length
 
169
      (<c>size</c>) of the data in bytes. Both <c>data</c> and <c>size</c> are
 
170
      read-only and should only be written using calls to API functions.
 
171
      Instances of <c>ErlNifBinary</c> are however always allocated by the user
 
172
      (usually as local variables).</p>
 
173
      <p>The raw data pointed to by <c>data</c> is only mutable after a call to
 
174
      <seealso marker="#enif_alloc_binary">enif_alloc_binary</seealso> or
 
175
      <seealso marker="#enif_realloc_binary">enif_realloc_binary</seealso>.
 
176
      All other functions that operates on a binary will leave the data as read-only.
 
177
      A mutable binary must in the end either be freed with
 
178
      <seealso marker="#enif_release_binary">enif_release_binary</seealso>
 
179
      or made read-only by transferring it to an Erlang term with
 
180
      <seealso marker="#enif_make_binary">enif_make_binary</seealso>.
 
181
      But it does not have to happen in the same NIF call. Read-only binaries
 
182
      do not have to be released.</p>
 
183
      <p><seealso marker="#enif_make_new_binary">enif_make_new_binary</seealso>
 
184
      can be used as a shortcut to allocate and return a binary in the same NIF call.</p>
 
185
      <p>Binaries are sequences of whole bytes. Bitstrings with an arbitrary
 
186
      bit length have no support yet.</p>
 
187
       </item>
 
188
      <tag>Resource objects</tag>
 
189
      <item><p>The use of resource objects is a way to return pointers to
 
190
      native data structures from a NIF in a safe way. A resource object is
 
191
      just a block of memory allocated with
 
192
      <seealso marker="#enif_alloc_resource">enif_alloc_resource</seealso>.
 
193
      A handle ("safe pointer") to this memory block can then be returned to Erlang by the use of
 
194
      <seealso marker="#enif_make_resource">enif_make_resource</seealso>.
 
195
      The term returned by <c>enif_make_resource</c>
 
196
      is totally opaque in nature. It can be stored and passed between processes
 
197
      on the same node, but the only real end usage is to pass it back as an argument to a NIF.
 
198
      The NIF can then call <seealso marker="#enif_get_resource">enif_get_resource</seealso>
 
199
      and get back a pointer to the memory block that is guaranteed to still be
 
200
      valid. A resource object will not be deallocated until the last handle term
 
201
      has been garbage collected by the VM and the resource has been
 
202
      released with <seealso marker="#enif_release_resource">enif_release_resource</seealso>
 
203
      (not necessarily in that order).</p>      
 
204
      <p>All resource objects are created as instances of some <em>resource type</em>.
 
205
      This makes resources from different modules to be distinguishable. 
 
206
      A resource type is created by calling
 
207
      <seealso marker="#enif_open_resource_type">enif_open_resource_type</seealso>
 
208
      when a library is loaded. Objects of that resource type can then later be allocated
 
209
      and <c>enif_get_resource</c> verifies that the resource is of the expected type.
 
210
      A resource type can have a user supplied destructor function that is
 
211
      automatically called when resources of that type are released (by either
 
212
      the garbage collector or <c>enif_release_resource</c>). Resource types
 
213
      are uniquely identified by a supplied name string and the name of the
 
214
      implementing module.</p>
 
215
      <marker id="enif_resource_example"/><p>Here is a template example of how to create and return a resource object.</p>
 
216
      <p/>
 
217
      <code type="none">
 
218
    ERL_NIF_TERM term;
 
219
    MyStruct* ptr = enif_alloc_resource(my_resource_type, sizeof(MyStruct));
 
220
 
 
221
    /* initialize struct ... */
 
222
 
 
223
    term = enif_make_resource(env, ptr);
 
224
 
 
225
    if (keep_a_reference_of_our_own) {
 
226
        /* store 'ptr' in static variable, private data or other resource object */
 
227
    }
 
228
    else {
 
229
        enif_release_resource(obj);
 
230
        /* resource now only owned by "Erlang" */
 
231
    }
 
232
    return term;
 
233
    </code>
 
234
      <p>Note that once <c>enif_make_resource</c> creates the term to
 
235
      return to Erlang, the code can choose to either keep its own
 
236
      native pointer to the allocated struct and release it later, or
 
237
      release it immediately and rely solely on the garbage collector
 
238
      to eventually deallocate the resource object when it collects
 
239
      the term.</p> 
 
240
      <p>Another usage of resource objects is to create binary terms with
 
241
      user defined memory management.
 
242
      <seealso marker="#enif_make_resource_binary">enif_make_resource_binary</seealso>
 
243
      will create a binary term that is connected to a resource object. The
 
244
      destructor of the resource will be called when the binary is garbage
 
245
      collected, at which time the binary data can be released. An example of
 
246
      this can be a binary term consisting of data from a <c>mmap</c>'ed file.
 
247
      The destructor can then do <c>munmap</c> to release the memory
 
248
      region.</p>
 
249
      <p>Resource types support upgrade in runtime by allowing a loaded NIF
 
250
      library to takeover an already existing resource type and thereby
 
251
      "inherit" all existing objects of that type. The destructor of the new
 
252
      library will thereafter be called for the inherited objects and the
 
253
      library with the old destructor function can be safely unloaded. Existing
 
254
      resource objects, of a module that is upgraded, must either be deleted
 
255
      or taken over by the new NIF library. The unloading of a library will be
 
256
      postponed as long as there exist resource objects with a destructor
 
257
      function in the library.
 
258
      </p>
 
259
      </item>
 
260
      <tag>Threads and concurrency</tag>
 
261
      <item><p>A NIF is thread-safe without any explicit synchronization as
 
262
      long as it acts as a pure function and only reads the supplied
 
263
      arguments. As soon as you write towards a shared state either through
 
264
      static variables or <seealso marker="#enif_priv_data">enif_priv_data</seealso>
 
265
      you need to supply your own explicit synchronization. This includes terms
 
266
      in process independent environments that are shared between threads.
 
267
      Resource objects will also require synchronization if you treat them as
 
268
      mutable.</p>
 
269
      <p>The library initialization callbacks <c>load</c>, <c>reload</c> and
 
270
      <c>upgrade</c> are all thread-safe even for shared state data.</p>
 
271
      <p>Avoid doing lengthy work in NIF calls as that may degrade the
 
272
      responsiveness of the VM. NIFs are called directly by the same scheduler
 
273
      thread that executed the calling Erlang code. The calling scheduler will thus
 
274
      be blocked from doing any other work until the NIF returns.</p>
 
275
      </item>
 
276
    </taglist>
 
277
  </section>
123
278
  <section>
124
279
    <title>INITIALIZATION</title>
125
280
    <taglist>
142
297
       <item><p><c>load</c> is called when the NIF library is loaded
143
298
        and there is no previously loaded library for this module.</p>
144
299
        <p><c>*priv_data</c> can be set to point to some private data
145
 
           that the library needs in able to keep a state between NIF 
146
 
           calls. <c>enif_get_data()</c> will return this pointer.</p> 
 
300
           that the library needs in order to keep a state between NIF
 
301
           calls. <c>enif_priv_data</c> will return this pointer.
 
302
           <c>*priv_data</c> will be initialized to NULL when <c>load</c> is
 
303
           called.</p> 
147
304
        <p><c>load_info</c> is the second argument to <seealso
148
 
           marker="erlang#erlang:load_nif-2">erlang:load_nif/2</seealso>.</p>
 
305
           marker="erlang#load_nif-2">erlang:load_nif/2</seealso>.</p>
149
306
        <p>The library will fail to load if <c>load</c> returns
150
307
           anything other than 0. <c>load</c> can be NULL in case no
151
308
           initialization is needed.</p> 
165
322
      <tag><marker id="upgrade"/>int (*upgrade)(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM load_info)</tag>
166
323
       <item><p><c>upgrade</c> is called when the NIF library is loaded
167
324
        and there is no previously loaded library for this module
168
 
        code, BUT there is old code of this module with a
169
 
        loaded NIF library.</p>
 
325
        code, BUT there is old code of this module with a loaded NIF library.</p>
170
326
        <p>Works the same as <c>load</c>. The only difference is that
171
327
        <c>*old_priv_data</c> already contains the value set by the
172
328
         last call to <c>load</c> or <c>reload</c> for the old module
173
 
         code. It is allowed to write to both *priv_data and
174
 
         *old_priv_data.</p> 
 
329
         code. <c>*priv_data</c> will be initialized to NULL when <c>upgrade</c>
 
330
         is called. It is allowed to write to both *priv_data and *old_priv_data.</p> 
175
331
        <p>The library will fail to load if <c>upgrade</c> returns
176
332
           anything other than 0 or if <c>upgrade</c> is NULL.</p>
177
333
      </item>
179
335
      <tag><marker id="unload"/>void (*unload)(ErlNifEnv* env, void* priv_data)</tag>
180
336
       <item><p><c>unload</c> is called when the module code that
181
337
       the NIF library belongs to is purged as old. New code
182
 
       of the same module may or may not exist.</p>
 
338
       of the same module may or may not exist. Note that <c>unload</c> is not
 
339
       called for a replaced library as a consequence of <c>reload</c>.</p>
183
340
      </item>
184
341
 
185
 
 
186
342
    </taglist>
187
343
  </section>
188
344
 
190
346
    <title>DATA TYPES</title>
191
347
 
192
348
    <taglist>
193
 
     <tag><marker id="ErlDrvEnv"/>ErlDrvEnv</tag>
 
349
      <tag><marker id="ERL_NIF_TERM"/>ERL_NIF_TERM</tag>
 
350
       <item>
 
351
        <p>Variables of type <c>ERL_NIF_TERM</c> can refer to any Erlang term.
 
352
        This is an opaque type and values of it can only by used either as
 
353
        arguments to API functions or as return values from NIFs. All
 
354
        <c>ERL_NIF_TERM</c>'s belong to an environment
 
355
        (<seealso marker="#ErlNifEnv">ErlNifEnv</seealso>). A term can not be
 
356
        destructed individually, it is valid until its environment is destructed.</p>
 
357
      </item>
 
358
     <tag><marker id="ErlNifEnv"/>ErlNifEnv</tag>
194
359
      <item>
195
 
        <p><c>ErlNifEnv</c> contains information about the context in
196
 
          which a NIF call is made. This pointer should not be
197
 
          dereferenced in any way, but only passed on to API
198
 
          functions. An <c>ErlNifEnv</c> pointer is only valid until
199
 
          the function, where is what supplied as argument,
200
 
          returns. There is thus useless and dangerous to store <c>ErlNifEnv</c>
201
 
          pointers in between NIF calls.</p>
 
360
        <p><c>ErlNifEnv</c> represents an environment that can host Erlang terms.
 
361
        All terms in an environment are valid as long as the environment is valid.
 
362
        <c>ErlNifEnv</c> is an opaque type and pointers to it can only be passed
 
363
        on to API functions. There are two types of environments; process
 
364
        bound and process independent.</p>
 
365
        <p>A <em>process bound environment</em> is passed as the first argument to all NIFs.
 
366
        All function arguments passed to a NIF will belong to that environment.
 
367
        The return value from a NIF must also be a term belonging to the same
 
368
        environment.
 
369
        In addition a process bound environment contains transient information
 
370
        about the calling Erlang process. The environment is only valid in the 
 
371
        thread where it was supplied as argument until the NIF returns. It is
 
372
        thus useless and dangerous to store pointers to process bound
 
373
        environments between NIF calls. </p>
 
374
        <p>A <em>process independent environment</em> is created by calling
 
375
        <seealso marker="#enif_alloc_env">enif_alloc_env</seealso>. It can be
 
376
        used to store terms between NIF calls and to send terms with
 
377
        <seealso marker="#enif_send">enif_send</seealso>. A process
 
378
        independent environment with all its terms is valid until you explicitly
 
379
        invalidates it with <seealso marker="#enif_free_env">enif_free_env</seealso>
 
380
        or <c>enif_send</c>.</p>
 
381
        <p>All elements of a list/tuple must belong to the same environment as the
 
382
        list/tuple itself. Terms can be copied between environments with
 
383
        <seealso marker="#enif_make_copy">enif_make_copy</seealso>.</p>
202
384
      </item>
203
385
    <tag><marker id="ErlNifFunc"/>ErlNifFunc</tag>
204
386
     <item>
205
387
      <p/>
206
388
      <code type="none">
207
389
typedef struct {
208
 
    const char* name;
209
 
    unsigned arity;
210
 
    ERL_NIF_TERM (*fptr)(ErlNifEnv* env, ...);
 
390
    const char* <em>name</em>;
 
391
    unsigned <em>arity</em>;
 
392
    ERL_NIF_TERM (*<em>fptr</em>)(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
211
393
} ErlNifFunc;
212
394
</code>
213
395
        <p>Describes a NIF by its name, arity and implementation.
214
396
        <c>fptr</c> is a pointer to the function that implements the
215
 
        NIF. The number of arguments must match the arity. A NIF of
216
 
        arity 2 will thus look like:</p> 
217
 
      <p/>
218
 
      <code type="none">
219
 
ERL_NIF_TERM my_nif(ErlNifEnv* env, ERL_NIF_TERM arg1, ERL_NIF_TERM arg2)
220
 
{
221
 
    /* ... */
222
 
}
223
 
</code>
224
 
        <p>The maximum allowed arity for a NIF is 3 in current implementation.</p>
 
397
        NIF. The argument <c>argv</c> of a NIF will contain the
 
398
        function arguments passed to the NIF and <c>argc</c> is the
 
399
        length of the array, i.e. the function arity. <c>argv[N-1]</c>
 
400
        will thus denote the Nth argument to the NIF. Note that the
 
401
        <c>argc</c> argument allows for the same C function to
 
402
        implement several Erlang functions with different arity (but
 
403
        same name probably).</p>
225
404
      </item>
226
405
    <tag><marker id="ErlNifBinary"/>ErlNifBinary</tag>
227
406
     <item>
228
407
      <p/>
229
408
      <code type="none">
230
409
typedef struct {
231
 
    unsigned size;
232
 
    unsigned char* data;
 
410
    unsigned <em>size</em>;
 
411
    unsigned char* <em>data</em>;
233
412
} ErlNifBinary;
234
413
</code>
235
414
        <p><c>ErlNifBinary</c> contains transient information about an
236
415
          inspected binary term. <c>data</c> is a pointer to a buffer
237
416
          of <c>size</c> bytes with the raw content of the binary.</p>
238
 
      </item>
239
 
      <tag><marker id="ERL_NIF_TERM"/>ERL_NIF_TERM</tag>
240
 
       <item>
241
 
        <p>Variables of type <c>ERL_NIF_TERM</c> can refere to any
242
 
        Erlang term. This is an opaque type and values of it can only
243
 
        by used either as arguments to API functions or as return
244
 
        values from NIFs. A variable of type <c>ERL_NIF_TERM</c> is
245
 
        only valid until the NIF call, where it was obtained,
246
 
        returns.</p>
247
 
      </item>
 
417
          <p>Note that <c>ErlNifBinary</c> is a semi-opaque type and you are
 
418
          only allowed to read fields <c>size</c> and <c>data</c>.</p>
 
419
      </item>
 
420
      <tag><marker id="ErlNifPid"/>ErlNifPid</tag>
 
421
       <item>
 
422
          <p><c>ErlNifPid</c> is a process identifier (pid). In contrast to
 
423
          pid terms (instances of <c>ERL_NIF_TERM</c>), <c>ErlNifPid</c>'s are self
 
424
          contained and not bound to any
 
425
          <seealso marker="#ErlNifEnv">environment</seealso>. <c>ErlNifPid</c>
 
426
          is an opaque type.</p>
 
427
        </item>
 
428
 
 
429
      <tag><marker id="ErlNifResourceType"/>ErlNifResourceType</tag>
 
430
       <item>
 
431
          <p>Each instance of <c>ErlNifResourceType</c> represent a class of
 
432
          memory managed resource objects that can be garbage collected.
 
433
          Each resource type has a unique name and a destructor function that
 
434
          is called when objects of its type are released.</p>
 
435
        </item>
 
436
        <tag><marker id="ErlNifResourceDtor"/>ErlNifResourceDtor</tag>
 
437
         <item>
 
438
           <p/>
 
439
           <code type="none">
 
440
typedef void ErlNifResourceDtor(ErlNifEnv* env, void* obj);
 
441
</code>
 
442
            <p>The function prototype of a resource destructor function.
 
443
            A destructor function is not allowed to call any term-making functions.</p>
 
444
          </item>
 
445
          <tag><marker id="ErlNifCharEncoding"/>ErlNifCharEncoding</tag>
 
446
           <item>
 
447
             <p/>
 
448
             <code type="none">
 
449
typedef enum {
 
450
    ERL_NIF_LATIN1
 
451
}ErlNifCharEncoding;
 
452
</code>
 
453
              <p>The character encoding used in strings and atoms. The only
 
454
              supported encoding is currently <c>ERL_NIF_LATIN1</c> for
 
455
              iso-latin-1 (8-bit ascii).</p>
 
456
            </item>
 
457
            <tag><marker id="ErlNifSysInfo"/>ErlNifSysInfo</tag>
 
458
             <item>
 
459
                <p>Used by <seealso marker="#enif_system_info">enif_system_info</seealso>
 
460
                to return information about the runtime system. Contains currently
 
461
                the exact same content as <seealso marker="erl_driver#ErlDrvSysInfo">ErlDrvSysInfo</seealso>.</p>
 
462
              </item>
 
463
              <tag><marker id="ErlNifSInt64"/>ErlNifSInt64</tag>
 
464
               <item><p>A native signed 64-bit integer type.</p></item>
 
465
              <tag><marker id="ErlNifUInt64"/>ErlNifUInt64</tag>
 
466
               <item><p>A native unsigned 64-bit integer type.</p></item>
 
467
 
248
468
    </taglist>
249
469
  </section>
250
470
 
251
471
  <funcs>
252
 
    <func><name><ret>void*</ret><nametext>enif_get_data(ErlNifEnv* env)</nametext></name>
253
 
      <fsummary>Get the private data of a NIF library</fsummary>
254
 
      <desc><p>Returns the pointer to the private data that was set by <c>load</c>, <c>reload</c> or <c>upgrade</c>.</p></desc>
255
 
    </func>
256
 
    <func><name><ret>void*</ret><nametext>enif_alloc(ErlNifEnv* env, size_t size)</nametext></name>
 
472
    <func><name><ret>void*</ret><nametext>enif_alloc(size_t size)</nametext></name>
257
473
      <fsummary>Allocate dynamic memory.</fsummary>
258
 
      <desc><p>Allocate memory of <c>size</c> bytes.</p></desc>
259
 
    </func>
260
 
    <func><name><ret>void</ret><nametext>enif_free(ErlNifEnv* env, void* ptr)</nametext></name>
 
474
      <desc><p>Allocate memory of <c>size</c> bytes. Return NULL if allocation failed.</p></desc>
 
475
    </func>
 
476
    <func><name><ret>int</ret><nametext>enif_alloc_binary(size_t size, ErlNifBinary* bin)</nametext></name>
 
477
      <fsummary>Create a new binary.</fsummary>
 
478
      <desc><p>Allocate a new binary of size <c>size</c>
 
479
      bytes. Initialize the structure pointed to by <c>bin</c> to
 
480
      refer to the allocated binary. The binary must either be released by 
 
481
      <seealso marker="#enif_release_binary">enif_release_binary</seealso> 
 
482
      or ownership transferred to an Erlang term with 
 
483
      <seealso marker="#enif_make_binary">enif_make_binary</seealso>. 
 
484
      An allocated (and owned) <c>ErlNifBinary</c> can be kept between NIF
 
485
      calls.</p>
 
486
        <p>Return true on success or false if allocation failed.</p>
 
487
      </desc>
 
488
    </func>
 
489
    <func><name><ret>ErlNifEnv*</ret><nametext>enif_alloc_env()</nametext></name>
 
490
      <fsummary>Create a new environment</fsummary>
 
491
      <desc><p>Allocate a new process independent environment. The environment can
 
492
      be used to hold terms that is not bound to any process. Such terms can
 
493
      later be copied to a process environment with
 
494
      <seealso marker="#enif_make_copy">enif_make_copy</seealso>
 
495
      or be sent to a process as a message with <seealso marker="#enif_send">enif_send</seealso>.</p>
 
496
      <p>Return pointer to the new environment.</p>
 
497
      </desc>
 
498
    </func>
 
499
    <func><name><ret>void*</ret><nametext>enif_alloc_resource(ErlNifResourceType* type, unsigned size)</nametext></name>
 
500
      <fsummary>Allocate a memory managed resource object</fsummary>
 
501
      <desc><p>Allocate a memory managed resource object of type <c>type</c> and size <c>size</c> bytes.</p></desc>
 
502
    </func>
 
503
    <func><name><ret>void</ret><nametext>enif_clear_env(ErlNifEnv* env)</nametext></name>
 
504
      <fsummary>Clear an environment for reuse.</fsummary>
 
505
      <desc><p>Free all terms in an environment and clear it for reuse. The environment must
 
506
      have been allocated with <seealso marker="#enif_alloc_env">enif_alloc_env</seealso>.
 
507
      </p></desc>
 
508
    </func>
 
509
    <func><name><ret>int</ret><nametext>enif_compare(ERL_NIF_TERM lhs, ERL_NIF_TERM rhs)</nametext></name>
 
510
      <fsummary>Compare two terms</fsummary>
 
511
      <desc><p>Return an integer less than, equal to, or greater than
 
512
      zero if <c>lhs</c> is found, respectively, to be less than,
 
513
      equal, or greater than <c>rhs</c>. Corresponds to the Erlang
 
514
      operators <c>==</c>, <c>/=</c>, <c>=&lt;</c>, <c>&lt;</c>,
 
515
      <c>&gt;=</c> and <c>&gt;</c> (but <em>not</em> <c>=:=</c> or <c>=/=</c>).</p></desc>
 
516
    </func>
 
517
    <func><name><ret>void</ret><nametext>enif_cond_broadcast(ErlNifCond *cnd)</nametext></name>
 
518
    <fsummary></fsummary>
 
519
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_broadcast">erl_drv_cond_broadcast</seealso>.
 
520
          </p></desc>
 
521
    </func>
 
522
    <func><name><ret>ErlNifCond*</ret><nametext>enif_cond_create(char *name)</nametext></name>
 
523
    <fsummary></fsummary>
 
524
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_create">erl_drv_cond_create</seealso>.
 
525
          </p></desc>
 
526
    </func>
 
527
    <func><name><ret>void</ret><nametext>enif_cond_destroy(ErlNifCond *cnd)</nametext></name>
 
528
    <fsummary></fsummary>
 
529
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_destroy">erl_drv_cond_destroy</seealso>.
 
530
          </p></desc>
 
531
    </func>
 
532
    <func><name><ret>void</ret><nametext>enif_cond_signal(ErlNifCond *cnd)</nametext></name>
 
533
    <fsummary></fsummary>
 
534
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_signal">erl_drv_cond_signal</seealso>.
 
535
          </p></desc>
 
536
    </func>
 
537
    <func><name><ret>void</ret><nametext>enif_cond_wait(ErlNifCond *cnd, ErlNifMutex *mtx)</nametext></name>
 
538
    <fsummary></fsummary>
 
539
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_cond_wait">erl_drv_cond_wait</seealso>.
 
540
          </p></desc>
 
541
    </func>
 
542
    <func><name><ret>int</ret><nametext>enif_equal_tids(ErlNifTid tid1, ErlNifTid tid2)</nametext></name>
 
543
    <fsummary></fsummary>
 
544
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_equal_tids">erl_drv_equal_tids</seealso>.
 
545
          </p></desc>
 
546
    </func>
 
547
    <func><name><ret>void</ret><nametext>enif_free(void* ptr)</nametext></name>
261
548
      <fsummary>Free dynamic memory</fsummary>
262
549
      <desc><p>Free memory allocated by <c>enif_alloc</c>.</p></desc>
263
550
    </func>
264
 
    <func><name><ret>int</ret><nametext>enif_is_binary(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
265
 
      <fsummary>Determine if a term is a binary</fsummary>
266
 
      <desc><p>Return true if <c>term</c> is a binary</p></desc>
267
 
    </func>
268
 
    <func><name><ret>int</ret><nametext>enif_inspect_binary(ErlNifEnv* env, ERL_NIF_TERM bin_term, ErlNifBinary* bin)</nametext></name>
269
 
      <fsummary>Inspect the content of a binary</fsummary>
270
 
      <desc><p>Initialize the structure pointed to by <c>bin</c> with
271
 
      transient information about the binary term
272
 
      <c>bin_term</c>. Return false if <c>bin_term</c> is not a binary.</p></desc> 
273
 
    </func>
274
 
    <func><name><ret>int</ret><nametext>enif_alloc_binary(ErlNifEnv* env, unsigned size, ErlNifBinary* bin)</nametext></name>
275
 
      <fsummary>Create a new binary.</fsummary>
276
 
      <desc><p>Allocate a new binary of size of <c>size</c>
277
 
      bytes. Initialize the structure pointed to by <c>bin</c> to
278
 
      refer to the allocated binary.</p></desc>
279
 
    </func>
280
 
    <func><name><ret>void</ret><nametext>enif_release_binary(ErlNifEnv* env, ErlNifBinary* bin)</nametext></name>
281
 
      <fsummary>Release a binary.</fsummary>
282
 
      <desc><p>Release a binary obtained from <c>enif_alloc_binary</c> or <c>enif_inspect_binary</c>.</p></desc>
 
551
    <func><name><ret>void</ret><nametext>enif_free_env(ErlNifEnv* env)</nametext></name>
 
552
      <fsummary>Free an environment allocated with enif_alloc_env</fsummary>
 
553
      <desc><p>Free an environment allocated with <seealso marker="#enif_alloc_env">enif_alloc_env</seealso>.
 
554
      All terms created in the environment will be freed as well.</p></desc>
 
555
    </func>
 
556
    <func><name><ret>int</ret><nametext>enif_get_atom(ErlNifEnv* env, ERL_NIF_TERM term, char* buf, unsigned size, ErlNifCharEncoding encode)</nametext></name>
 
557
      <fsummary>Get the text representation of an atom term</fsummary>
 
558
      <desc><p>Write a null-terminated string, in the buffer pointed to by
 
559
              <c>buf</c> of size <c>size</c>, consisting of the string 
 
560
              representation of the atom <c>term</c> with encoding
 
561
              <seealso marker="#ErlNifCharEncoding">encode</seealso>. Return
 
562
              the number of bytes written (including terminating null character) or 0 if
 
563
              <c>term</c> is not an atom with maximum length of 
 
564
              <c>size-1</c>.</p></desc>
 
565
    </func>
 
566
    <func><name><ret>int</ret><nametext>enif_get_atom_length(ErlNifEnv* env, ERL_NIF_TERM term, unsigned* len, ErlNifCharEncoding encode)</nametext></name>
 
567
      <fsummary>Get the length of atom <c>term</c>.</fsummary>
 
568
      <desc><p>Set <c>*len</c> to the length (number of bytes excluding
 
569
      terminating null character) of the atom <c>term</c> with encoding
 
570
      <c>encode</c>. Return true on success or false if <c>term</c> is not an
 
571
      atom.</p></desc>
 
572
    </func>
 
573
    <func><name><ret>int</ret><nametext>enif_get_double(ErlNifEnv* env, ERL_NIF_TERM term, double* dp)</nametext></name>
 
574
      <fsummary>Read a floating-point number term.</fsummary>
 
575
      <desc><p>Set <c>*dp</c> to the floating point value of
 
576
      <c>term</c>. Return true on success or false if <c>term</c> is not a float.</p></desc>
283
577
    </func>
284
578
    <func><name><ret>int</ret><nametext>enif_get_int(ErlNifEnv* env, ERL_NIF_TERM term, int* ip)</nametext></name>
285
 
      <fsummary>Read an integer term.</fsummary>
286
 
      <desc><p>Set <c>*ip</c> to the integer value of
287
 
      <c>term</c> or return false if <c>term</c> is not an integer or is
288
 
      outside the bounds of type <c>int</c></p></desc>
289
 
    </func>
290
 
    <func><name><ret>int</ret><nametext>enif_get_ulong(ErlNifEnv* env, ERL_NIF_TERM term, unsigned long* ip)</nametext></name>
291
 
      <fsummary>Read an unsigned long integer</fsummary>
292
 
      <desc><p>Set <c>*ip</c> to the unsigned long integer value of
293
 
      <c>term</c> or return false if <c>term</c> is not an unsigned
294
 
      integer or is outside the bounds of type <c>unsigned long</c></p></desc>
 
579
      <fsummary>Read an integer term</fsummary>
 
580
      <desc><p>Set <c>*ip</c> to the integer value of
 
581
      <c>term</c>. Return true on success or false if <c>term</c> is not an
 
582
      integer or is outside the bounds of type <c>int</c>.</p></desc>
 
583
    </func>
 
584
    <func><name><ret>int</ret><nametext>enif_get_int64(ErlNifEnv* env, ERL_NIF_TERM term, ErlNifSInt64* ip)</nametext></name>
 
585
      <fsummary>Read a 64-bit integer term</fsummary>
 
586
      <desc><p>Set <c>*ip</c> to the integer value of
 
587
      <c>term</c>. Return true on success or false if <c>term</c> is not an
 
588
      integer or is outside the bounds of a signed 64-bit integer.</p></desc>
 
589
    </func>
 
590
    <func><name><ret>int</ret><nametext>enif_get_local_pid(ErlNifEnv* env, ERL_NIF_TERM term, ErlNifPid* pid)</nametext></name>
 
591
    <fsummary>Read an local pid term</fsummary>
 
592
    <desc><p>If <c>term</c> is the pid of a node local process, initialize the
 
593
    pid variable <c>*pid</c> from it and return true. Otherwise return false.
 
594
    No check if the process is alive is done.</p></desc>
295
595
    </func>
296
596
    <func><name><ret>int</ret><nametext>enif_get_list_cell(ErlNifEnv* env, ERL_NIF_TERM list, ERL_NIF_TERM* head, ERL_NIF_TERM* tail)</nametext></name>
297
597
      <fsummary>Get head and tail from a list</fsummary>
298
598
      <desc><p>Set <c>*head</c> and <c>*tail</c> from
299
 
      <c>list</c> or return false if <c>list</c> is not a non-empty
300
 
      list.</p></desc>
301
 
    </func>
302
 
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_binary(ErlNifEnv* env, ErlNifBinary* bin)</nametext></name>
303
 
      <fsummary>Make a binary term.</fsummary>
304
 
      <desc><p>Make a binary term from <c>bin</c>. Will also release
305
 
      the binary.</p></desc>
 
599
      <c>list</c> and return true, or return false if <c>list</c> is not a
 
600
      non-empty list.</p></desc>
 
601
    </func>
 
602
    <func><name><ret>int</ret><nametext>enif_get_list_length(ErlNifEnv* env, ERL_NIF_TERM term, unsigned* len)</nametext></name>
 
603
      <fsummary>Get the length of list <c>term</c>.</fsummary>
 
604
      <desc><p>Set <c>*len</c> to the length of list <c>term</c> and return true,
 
605
      or return false if <c>term</c> is not a list.</p></desc>
 
606
    </func>
 
607
    <func><name><ret>int</ret><nametext>enif_get_long(ErlNifEnv* env, ERL_NIF_TERM term, long int* ip)</nametext></name>
 
608
      <fsummary>Read an long integer term.</fsummary>
 
609
      <desc><p>Set <c>*ip</c> to the long integer value of <c>term</c> and
 
610
      return true, or return false if <c>term</c> is not an integer or is
 
611
      outside the bounds of type <c>long int</c>.</p></desc>
 
612
    </func>
 
613
    <func><name><ret>int</ret><nametext>enif_get_resource(ErlNifEnv* env, ERL_NIF_TERM term, ErlNifResourceType* type, void** objp)</nametext></name>
 
614
      <fsummary>Get the pointer to a resource object</fsummary>
 
615
      <desc><p>Set <c>*objp</c> to point to the resource object referred to by <c>term</c>.</p>
 
616
      <p>Return true on success or false if <c>term</c> is not a handle to a resource object
 
617
      of type <c>type</c>.</p></desc>
 
618
    </func>
 
619
    <func><name><ret>int</ret><nametext>enif_get_string(ErlNifEnv* env, 
 
620
                                ERL_NIF_TERM list, char* buf, unsigned size,
 
621
                                ErlNifCharEncoding encode)</nametext></name>
 
622
      <fsummary>Get a C-string from a list.</fsummary>
 
623
      <desc><p>Write a null-terminated string, in the buffer pointed to by
 
624
              <c>buf</c> with size <c>size</c>, consisting of the characters
 
625
              in the string <c>list</c>. The characters are written using encoding
 
626
              <seealso marker="#ErlNifCharEncoding">encode</seealso>.
 
627
              Return the number of bytes written (including terminating null
 
628
              character), or <c>-size</c> if the string was truncated due to
 
629
              buffer space, or 0 if <c>list</c> is not a string that can be
 
630
              encoded with <c>encode</c> or if <c>size</c> was less than 1.              
 
631
              The written string is always null-terminated unless buffer
 
632
              <c>size</c> is less than 1.</p></desc>
 
633
    </func>
 
634
    <func><name><ret>int</ret><nametext>enif_get_tuple(ErlNifEnv* env, ERL_NIF_TERM term, int* arity, const ERL_NIF_TERM** array)</nametext></name>
 
635
      <fsummary>Inspect the elements of a tuple.</fsummary>
 
636
      <desc><p>If <c>term</c> is a tuple, set <c>*array</c> to point
 
637
      to an array containing the elements of the tuple and set
 
638
      <c>*arity</c> to the number of elements. Note that the array
 
639
      is read-only and <c>(*array)[N-1]</c> will be the Nth element of
 
640
      the tuple. <c>*array</c> is undefined if the arity of the tuple
 
641
      is zero.</p><p>Return true on success or false if <c>term</c> is not a
 
642
      tuple.</p></desc>
 
643
    </func>
 
644
    <func><name><ret>int</ret><nametext>enif_get_uint(ErlNifEnv* env, ERL_NIF_TERM term, unsigned int* ip)</nametext></name>
 
645
      <fsummary>Read an unsigned integer term.</fsummary>
 
646
      <desc><p>Set <c>*ip</c> to the unsigned integer value of <c>term</c> and
 
647
      return true, or return false if <c>term</c> is not an unsigned integer or
 
648
      is outside the bounds of type <c>unsigned int</c>.</p></desc>
 
649
    </func>
 
650
    <func><name><ret>int</ret><nametext>enif_get_uint64(ErlNifEnv* env, ERL_NIF_TERM term, ErlNifUInt64* ip)</nametext></name>
 
651
      <fsummary>Read an unsigned 64-bit integer term.</fsummary>
 
652
      <desc><p>Set <c>*ip</c> to the unsigned integer value of <c>term</c> and
 
653
      return true, or return false if <c>term</c> is not an unsigned integer or
 
654
      is outside the bounds of an unsigned 64-bit integer.</p></desc>
 
655
    </func>
 
656
    <func><name><ret>int</ret><nametext>enif_get_ulong(ErlNifEnv* env, ERL_NIF_TERM term, unsigned long* ip)</nametext></name>
 
657
      <fsummary>Read an unsigned integer term.</fsummary>
 
658
      <desc><p>Set <c>*ip</c> to the unsigned long integer value of <c>term</c>
 
659
      and return true, or return false if <c>term</c> is not an unsigned integer or is
 
660
      outside the bounds of type <c>unsigned long</c>.</p></desc>
 
661
    </func>
 
662
    <func><name><ret>int</ret><nametext>enif_inspect_binary(ErlNifEnv* env, ERL_NIF_TERM bin_term, ErlNifBinary* bin)</nametext></name>
 
663
      <fsummary>Inspect the content of a binary</fsummary>
 
664
      <desc><p>Initialize the structure pointed to by <c>bin</c> with 
 
665
              information about the binary term
 
666
      <c>bin_term</c>. Return true on success or false if <c>bin_term</c> is not a binary.</p></desc> 
 
667
    </func>
 
668
    <func><name><ret>int</ret><nametext>enif_inspect_iolist_as_binary(ErlNifEnv* 
 
669
                                env, ERL_NIF_TERM term, ErlNifBinary* bin)
 
670
                              </nametext></name>
 
671
      <fsummary>Inspect the content of an iolist</fsummary>
 
672
      <desc><p>Initialize the structure pointed to by <c>bin</c> with one
 
673
      continuous buffer with the same byte content as <c>iolist</c>. As with 
 
674
      inspect_binary, the data pointed to by <c>bin</c> is transient and does 
 
675
      not need to be released. Return true on success or false if <c>iolist</c> is not an
 
676
      iolist.</p>
 
677
      </desc> 
 
678
    </func>
 
679
    <func><name><ret>int</ret><nametext>enif_is_atom(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
680
      <fsummary>Determine if a term is an atom</fsummary>
 
681
      <desc><p>Return true if <c>term</c> is an atom.</p></desc>
 
682
    </func>
 
683
    <func><name><ret>int</ret><nametext>enif_is_binary(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
684
      <fsummary>Determine if a term is a binary</fsummary>
 
685
      <desc><p>Return true if <c>term</c> is a binary</p></desc>
 
686
    </func>
 
687
    <func><name><ret>int</ret><nametext>enif_is_empty_list(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
688
      <fsummary>Determine if a term is an empty list</fsummary>
 
689
      <desc><p>Return true if <c>term</c> is an empty list.</p></desc>
 
690
    </func>
 
691
    <func><name><ret>int</ret><nametext>enif_is_fun(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
692
      <fsummary>Determine if a term is a fun</fsummary>
 
693
      <desc><p>Return true if <c>term</c> is a fun.</p></desc>
 
694
    </func>
 
695
    <func><name><ret>int</ret><nametext>enif_is_identical(ERL_NIF_TERM lhs, ERL_NIF_TERM rhs)</nametext></name>
 
696
      <fsummary>Erlang operator =:=</fsummary>
 
697
      <desc><p>Return true if the two terms are identical. Corresponds to the
 
698
      Erlang operators <c>=:=</c> and
 
699
      <c>=/=</c>.</p></desc> 
 
700
    </func>
 
701
    <func><name><ret>int</ret><nametext>enif_is_pid(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
702
      <fsummary>Determine if a term is a pid</fsummary>
 
703
      <desc><p>Return true if <c>term</c> is a pid.</p></desc>
 
704
    </func>
 
705
    <func><name><ret>int</ret><nametext>enif_is_port(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
706
      <fsummary>Determine if a term is a port</fsummary>
 
707
      <desc><p>Return true if <c>term</c> is a port.</p></desc>
 
708
    </func>
 
709
    <func><name><ret>int</ret><nametext>enif_is_ref(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
710
      <fsummary>Determine if a term is a reference</fsummary>
 
711
      <desc><p>Return true if <c>term</c> is a reference.</p></desc>
 
712
    </func>
 
713
    <func><name><ret>int</ret><nametext>enif_is_tuple(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
714
      <fsummary>Determine if a term is a tuple</fsummary>
 
715
      <desc><p>Return true if <c>term</c> is a tuple.</p></desc>
 
716
    </func>
 
717
    <func><name><ret>int</ret><nametext>enif_is_list(ErlNifEnv* env, ERL_NIF_TERM term)</nametext></name>
 
718
      <fsummary>Determine if a term is a list</fsummary>
 
719
      <desc><p>Return true if <c>term</c> is a list.</p></desc>
 
720
    </func>
 
721
    <func><name><ret>int</ret><nametext>enif_keep_resource(void* obj)</nametext></name>
 
722
      <fsummary>Add a reference to a resource object</fsummary>
 
723
      <desc><p>Add a reference to resource object <c>obj</c> obtained from
 
724
      <seealso marker="#enif_alloc_resource">enif_alloc_resource</seealso>.
 
725
      Each call to <c>enif_keep_resource</c> for an object must be balanced by
 
726
      a call to <seealso marker="#enif_release_resource">enif_release_resource</seealso>
 
727
      before the object will be destructed.</p></desc>
 
728
    </func>
 
729
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_atom(ErlNifEnv* env, const char* name)</nametext></name>
 
730
      <fsummary>Create an atom term</fsummary>
 
731
      <desc><p>Create an atom term from the null-terminated C-string <c>name</c>
 
732
      with iso-latin-1 encoding.</p></desc>
 
733
    </func>
 
734
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_atom_len(ErlNifEnv* env, const char* name, size_t len)</nametext></name>
 
735
      <fsummary>Create an atom term</fsummary>
 
736
      <desc><p>Create an atom term from the string <c>name</c> with length <c>len</c>.
 
737
      Null-characters are treated as any other characters.</p></desc>
306
738
    </func>
307
739
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_badarg(ErlNifEnv* env)</nametext></name>
308
740
      <fsummary>Make a badarg exception.</fsummary>
309
741
      <desc><p>Make a badarg exception to be returned from a NIF.</p></desc>
310
742
    </func>
 
743
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_binary(ErlNifEnv* env, ErlNifBinary* bin)</nametext></name>
 
744
      <fsummary>Make a binary term.</fsummary>
 
745
      <desc><p>Make a binary term from <c>bin</c>. Any ownership of 
 
746
              the binary data will be transferred to the created term and
 
747
              <c>bin</c> should be considered read-only for the rest of the NIF
 
748
              call and then as released.</p></desc>
 
749
    </func>
 
750
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_copy(ErlNifEnv* dst_env, ERL_NIF_TERM src_term)</nametext></name>
 
751
      <fsummary>Make a copy of a term.</fsummary>
 
752
      <desc><p>Make a copy of term <c>src_term</c>. The copy will be created in
 
753
      environment <c>dst_env</c>. The source term may be located in any
 
754
      environment.</p></desc>        
 
755
    </func>
 
756
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_double(ErlNifEnv* env, double d)</nametext></name>
 
757
      <fsummary>Create a floating-point term</fsummary>
 
758
      <desc><p>Create a floating-point term from a <c>double</c>.</p></desc>
 
759
    </func>
 
760
    <func><name><ret>int</ret><nametext>enif_make_existing_atom(ErlNifEnv* env, const char* name, ERL_NIF_TERM* atom, ErlNifCharEncoding encode)</nametext></name>
 
761
      <fsummary>Create an existing atom term</fsummary>
 
762
      <desc><p>Try to create the term of an already existing atom from
 
763
      the null-terminated C-string <c>name</c> with encoding
 
764
      <seealso marker="#ErlNifCharEncoding">encode</seealso>. If the atom
 
765
      already exists store the term in <c>*atom</c> and return true, otherwise
 
766
      return false.</p></desc>
 
767
    </func>
 
768
    <func><name><ret>int</ret><nametext>enif_make_existing_atom_len(ErlNifEnv* env, const char* name, size_t len, ERL_NIF_TERM* atom, ErlNifCharEncoding encoding)</nametext></name>
 
769
      <fsummary>Create an existing atom term</fsummary>
 
770
      <desc><p>Try to create the term of an already existing atom from the
 
771
      string <c>name</c> with length <c>len</c> and encoding
 
772
      <seealso marker="#ErlNifCharEncoding">encode</seealso>. Null-characters
 
773
      are treated as any other characters. If the atom already exists store the term
 
774
      in <c>*atom</c> and return true, otherwise return false.</p></desc>
 
775
    </func>
311
776
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_int(ErlNifEnv* env, int i)</nametext></name>
312
777
      <fsummary>Create an integer term</fsummary>
313
778
      <desc><p>Create an integer term.</p></desc>
314
779
    </func>
315
 
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_ulong(ErlNifEnv* env, unsigned long i)</nametext></name>
316
 
      <fsummary>Create an integer term from an unsigned long int</fsummary>
317
 
      <desc><p>Create an integer term from an <c>unsigned long int</c>.</p></desc>
318
 
    </func>
319
 
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_atom(ErlNifEnv* env, const char* name)</nametext></name>
320
 
      <fsummary>Create an atom term</fsummary>
321
 
      <desc><p>Create an atom term from the C-string <c>name</c>. Atom
322
 
      terms may be saved and used between NIF calls.</p></desc>
323
 
    </func>
324
 
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple(ErlNifEnv* env, unsigned cnt, ...)</nametext></name>
325
 
      <fsummary>Create a tuple term.</fsummary>
326
 
      <desc><p>Create a tuple term of arity <c>cnt</c>. Expects
327
 
      <c>cnt</c> number of arguments (after <c>cnt</c>) of type ERL_NIF_TERM as the
328
 
      elements of the tuple.</p></desc>
 
780
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_int64(ErlNifEnv* env, ErlNifSInt64 i)</nametext></name>
 
781
      <fsummary>Create an integer term</fsummary>
 
782
      <desc><p>Create an integer term from a signed 64-bit integer.</p></desc>
329
783
    </func>
330
784
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list(ErlNifEnv* env, unsigned cnt, ...)</nametext></name>
331
785
      <fsummary>Create a list term.</fsummary>
333
787
      <c>cnt</c> number of arguments (after <c>cnt</c>) of type ERL_NIF_TERM as the
334
788
      elements of the list. An empty list is returned if <c>cnt</c> is 0.</p></desc>
335
789
    </func>
 
790
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list1(ErlNifEnv* env, ERL_NIF_TERM e1)</nametext></name>
 
791
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list2(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2)</nametext></name>
 
792
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list3(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2, ERL_NIF_TERM e3)</nametext></name>
 
793
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list4(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e4)</nametext></name>
 
794
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list5(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e5)</nametext></name>
 
795
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list6(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e6)</nametext></name>
 
796
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list7(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e7)</nametext></name>
 
797
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list8(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e8)</nametext></name>
 
798
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list9(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e9)</nametext></name>
 
799
      <fsummary>Create a list term.</fsummary>
 
800
      <desc><p>Create an ordinary list term with length indicated by the
 
801
      function name. Prefer these functions (macros) over the variadic
 
802
      <c>enif_make_list</c>  to get a compile time error if the number of
 
803
      arguments does not match.</p></desc>
 
804
    </func>
336
805
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list_cell(ErlNifEnv* env, ERL_NIF_TERM head, ERL_NIF_TERM tail)</nametext></name>
337
806
      <fsummary>Create a list cell.</fsummary>
338
807
      <desc><p>Create a list cell <c>[head | tail]</c>.</p></desc>
339
808
    </func>
340
 
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_string(ErlNifEnv* env, const char* string)</nametext></name>
341
 
      <fsummary>Create a string.</fsummary>
342
 
      <desc><p>Creates a list containing the characters of the
343
 
      C-string <c>string</c>.</p></desc>
 
809
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_list_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], unsigned cnt)</nametext></name>
 
810
      <fsummary>Create a list term from an array.</fsummary>
 
811
      <desc><p>Create an ordinary list containing the elements of array <c>arr</c>
 
812
      of length <c>cnt</c>. An empty list is returned if <c>cnt</c> is 0.</p></desc>
 
813
    </func>
 
814
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_long(ErlNifEnv* env, long int i)</nametext></name>
 
815
      <fsummary>Create an integer term from a long int</fsummary>
 
816
      <desc><p>Create an integer term from a <c>long int</c>.</p></desc>
 
817
    </func>
 
818
    <func><name><ret>unsigned char*</ret><nametext>enif_make_new_binary(ErlNifEnv* env, size_t size, ERL_NIF_TERM* termp)</nametext></name>
 
819
      <fsummary>Allocate and create a new binary term</fsummary>
 
820
      <desc><p>Allocate a binary of size <c>size</c> bytes and create an owning
 
821
      term. The binary data is mutable until the calling NIF returns. This is a
 
822
      quick way to create a new binary without having to use
 
823
      <seealso marker="#ErlNifBinary">ErlNifBinary</seealso>. The drawbacks are
 
824
      that the binary can not be kept between NIF calls and it can not be
 
825
      reallocated.</p><p>Return a pointer to the raw binary data and set
 
826
      <c>*termp</c> to the binary term.</p></desc>
 
827
    </func>
 
828
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_pid(ErlNifEnv* env, const ErlNifPid* pid)</nametext></name>
 
829
      <fsummary>Make a pid term</fsummary>
 
830
      <desc><p>Make a pid term from <c>*pid</c>.</p></desc>
 
831
    </func>
 
832
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_ref(ErlNifEnv* env)</nametext></name>
 
833
      <fsummary>Create a reference.</fsummary>
 
834
      <desc><p>Create a reference like <seealso marker="erlang#make_ref-0">erlang:make_ref/0</seealso>.</p></desc>
 
835
    </func>
 
836
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_resource(ErlNifEnv* env, void* obj)</nametext></name>
 
837
      <fsummary>Create an opaque handle to a resource object</fsummary>
 
838
      <desc><p>Create an opaque handle to a memory managed resource object
 
839
      obtained by <seealso marker="#enif_alloc_resource">enif_alloc_resource</seealso>.
 
840
      No ownership transfer is done, as the resource object still needs to be released by
 
841
      <seealso marker="#enif_release_resource">enif_release_resource</seealso>,
 
842
      but note that the call to <c>enif_release_resource</c> can occur
 
843
      immediately after obtaining the term from <c>enif_make_resource</c>,
 
844
      in which case the resource object will be deallocated when the
 
845
      term is garbage collected. See the
 
846
      <seealso marker="#enif_resource_example">example of creating and
 
847
      returning a resource object</seealso> for more details.</p> 
 
848
      <p>Note that the only defined behaviour of using a resource term in
 
849
      an Erlang program is to store it and send it between processes on the
 
850
      same node. Other operations such as matching or <c>term_to_binary</c>
 
851
      will have unpredictable (but harmless) results.</p></desc>
 
852
    </func>
 
853
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_resource_binary(ErlNifEnv* env, void* obj, const void* data, size_t size)</nametext></name>
 
854
      <fsummary>Create a custom binary term</fsummary>
 
855
      <desc><p>Create a binary term that is memory managed by a resource object
 
856
      <c>obj</c> obtained by <seealso marker="#enif_alloc_resource">enif_alloc_resource</seealso>.
 
857
      The returned binary term will consist of <c>size</c> bytes pointed to
 
858
      by <c>data</c>. This raw binary data must be kept readable and unchanged
 
859
      until the destructor of the resource is called. The binary data may be
 
860
      stored external to the resource object in which case it is the responsibility
 
861
      of the destructor to release the data.</p>
 
862
      <p>Several binary terms may be managed by the same resource object. The
 
863
      destructor will not be called until the last binary is garbage collected.
 
864
      This can be useful as a way to return different parts of a larger binary
 
865
      buffer.</p>
 
866
      <p>As with <seealso marker="#enif_make_resource">enif_make_resource</seealso>,
 
867
      no ownership transfer is done. The resource still needs to be released with
 
868
      <seealso marker="#enif_release_resource">enif_release_resource</seealso>.</p>
 
869
      </desc>
 
870
    </func>
 
871
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_string(ErlNifEnv* env, const char* string, ErlNifCharEncoding encoding)</nametext></name>
 
872
      <fsummary>Create a string.</fsummary>
 
873
      <desc><p>Create a list containing the characters of the
 
874
      null-terminated string <c>string</c> with encoding <seealso marker="#ErlNifCharEncoding">encoding</seealso>.</p></desc>
 
875
    </func>
 
876
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_string_len(ErlNifEnv* env, const char* string, size_t len, ErlNifCharEncoding encoding)</nametext></name>
 
877
      <fsummary>Create a string.</fsummary>
 
878
      <desc><p>Create a list containing the characters of the string <c>string</c> with
 
879
      length <c>len</c> and encoding <seealso marker="#ErlNifCharEncoding">encoding</seealso>.
 
880
      Null-characters are treated as any other characters.</p></desc>
 
881
    </func>
 
882
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_sub_binary(ErlNifEnv* 
 
883
      env, ERL_NIF_TERM bin_term, size_t pos, size_t size)</nametext></name>
 
884
      <fsummary>Make a subbinary term.</fsummary>
 
885
      <desc><p>Make a subbinary of binary <c>bin_term</c>, starting at 
 
886
              zero-based position <c>pos</c> with a length of <c>size</c> bytes. 
 
887
              <c>bin_term</c> must be a binary or bitstring and
 
888
              <c>pos+size</c> must be less or equal to the number of whole
 
889
              bytes in <c>bin_term</c>.</p></desc>
 
890
    </func>
 
891
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple(ErlNifEnv* env, unsigned cnt, ...)</nametext></name>
 
892
      <fsummary>Create a tuple term.</fsummary>
 
893
      <desc><p>Create a tuple term of arity <c>cnt</c>. Expects
 
894
      <c>cnt</c> number of arguments (after <c>cnt</c>) of type ERL_NIF_TERM as the
 
895
      elements of the tuple.</p></desc>
 
896
    </func>
 
897
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple1(ErlNifEnv* env, ERL_NIF_TERM e1)</nametext></name>
 
898
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple2(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2)</nametext></name>
 
899
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple3(ErlNifEnv* env, ERL_NIF_TERM e1, ERL_NIF_TERM e2, ERL_NIF_TERM e3)</nametext></name>
 
900
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple4(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e4)</nametext></name>
 
901
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple5(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e5)</nametext></name>
 
902
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple6(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e6)</nametext></name>
 
903
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple7(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e7)</nametext></name>
 
904
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple8(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e8)</nametext></name>
 
905
    <name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple9(ErlNifEnv* env, ERL_NIF_TERM e1, ..., ERL_NIF_TERM e9)</nametext></name>
 
906
      <fsummary>Create a tuple term.</fsummary>
 
907
      <desc><p>Create a tuple term with length indicated by the
 
908
      function name. Prefer these functions (macros) over the variadic
 
909
      <c>enif_make_tuple</c>  to get a compile time error if the number of
 
910
      arguments does not match.</p></desc>
 
911
    </func>
 
912
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_tuple_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[], unsigned cnt)</nametext></name>
 
913
      <fsummary>Create a tuple term from an array.</fsummary>
 
914
      <desc><p>Create a tuple containing the elements of array <c>arr</c>
 
915
      of length <c>cnt</c>.</p></desc>
 
916
    </func>
 
917
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_uint(ErlNifEnv* env, unsigned int i)</nametext></name>
 
918
      <fsummary>Create an unsigned integer term</fsummary>
 
919
      <desc><p>Create an integer term from an <c>unsigned int</c>.</p></desc>
 
920
    </func>
 
921
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_uint64(ErlNifEnv* env, ErlNifUInt64 i)</nametext></name>
 
922
      <fsummary>Create an unsigned integer term</fsummary>
 
923
      <desc><p>Create an integer term from an unsigned 64-bit integer.</p></desc>
 
924
    </func>
 
925
    <func><name><ret>ERL_NIF_TERM</ret><nametext>enif_make_ulong(ErlNifEnv* env, unsigned long i)</nametext></name>
 
926
      <fsummary>Create an integer term from an unsigned long int</fsummary>
 
927
      <desc><p>Create an integer term from an <c>unsigned long int</c>.</p></desc>
 
928
    </func>
 
929
    <func><name><ret>ErlNifMutex*</ret><nametext>enif_mutex_create(char *name)</nametext></name>
 
930
    <fsummary></fsummary>
 
931
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_create">erl_drv_mutex_create</seealso>.
 
932
    </p></desc>
 
933
    </func>
 
934
    <func><name><ret>void</ret><nametext>enif_mutex_destroy(ErlNifMutex *mtx)</nametext></name>
 
935
    <fsummary></fsummary>
 
936
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_destroy">erl_drv_mutex_destroy</seealso>.
 
937
          </p></desc>
 
938
    </func>
 
939
    <func><name><ret>void</ret><nametext>enif_mutex_lock(ErlNifMutex *mtx)</nametext></name>
 
940
    <fsummary></fsummary>
 
941
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_lock">erl_drv_mutex_lock</seealso>.
 
942
          </p></desc>
 
943
    </func>
 
944
    <func><name><ret>int</ret><nametext>enif_mutex_trylock(ErlNifMutex *mtx)</nametext></name>
 
945
    <fsummary></fsummary>
 
946
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_trylock">erl_drv_mutex_trylock</seealso>.
 
947
          </p></desc>
 
948
    </func>
 
949
    <func><name><ret>void</ret><nametext>enif_mutex_unlock(ErlNifMutex *mtx)</nametext></name>
 
950
    <fsummary></fsummary>
 
951
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_mutex_unlock">erl_drv_mutex_unlock</seealso>.
 
952
          </p></desc>
 
953
    </func>
 
954
    <func><name><ret>ErlNifResourceType*</ret><nametext>enif_open_resource_type(ErlNifEnv* env,
 
955
                             const char* module_str, const char* name,
 
956
                             ErlNifResourceDtor* dtor, ErlNifResourceFlags flags, ErlNifResourceFlags* tried)</nametext></name>
 
957
      <fsummary>Create or takeover a resource type</fsummary>
 
958
      <desc><p>Create or takeover a resource type identified by the string
 
959
      <c>name</c> and give it the destructor function pointed to by <seealso marker="#ErlNifResourceDtor">dtor</seealso>.
 
960
      Argument <c>flags</c> can have the following values:</p>
 
961
      <taglist>
 
962
        <tag><c>ERL_NIF_RT_CREATE</c></tag>
 
963
              <item>Create a new resource type that does not already exist.</item>
 
964
        <tag><c>ERL_NIF_RT_TAKEOVER</c></tag>
 
965
              <item>Open an existing resource type and take over ownership of all its instances.
 
966
               The supplied destructor <c>dtor</c> will be called both for existing instances
 
967
               as well as new instances not yet created by the calling NIF library.</item>            
 
968
      </taglist>
 
969
      <p>The two flag values can be combined with bitwise-or. The name of the
 
970
      resource type is local to the calling module. Argument <c>module_str</c>
 
971
      is not (yet) used and must be NULL. The <c>dtor</c> may  be <c>NULL</c>
 
972
      in case no destructor is needed.</p>
 
973
      <p>On success, return a pointer to the resource type and <c>*tried</c>
 
974
      will be set to either <c>ERL_NIF_RT_CREATE</c> or
 
975
      <c>ERL_NIF_RT_TAKEOVER</c> to indicate what was actually done.
 
976
       On failure, return <c>NULL</c> and set <c>*tried</c> to <c>flags</c>.
 
977
       It is allowed to set <c>tried</c> to <c>NULL</c>.</p>
 
978
       <p>Note that <c>enif_open_resource_type</c> is only allowed to be called in the three callbacks
 
979
       <seealso marker="#load">load</seealso>, <seealso marker="#reload">reload</seealso>
 
980
       and <seealso marker="#upgrade">upgrade</seealso>.</p>
 
981
      </desc>
 
982
    </func>
 
983
    <func><name><ret>void*</ret><nametext>enif_priv_data(ErlNifEnv* env)</nametext></name>
 
984
      <fsummary>Get the private data of a NIF library</fsummary>
 
985
      <desc><p>Return the pointer to the private data that was set by <c>load</c>,
 
986
      <c>reload</c> or <c>upgrade</c>.</p>
 
987
      <p>Was previously named <c>enif_get_data</c>.</p></desc>
 
988
    </func>
 
989
    <func><name><ret>int</ret><nametext>enif_realloc_binary(ErlNifBinary* bin, size_t size)</nametext></name>
 
990
      <fsummary>Change the size of a binary.</fsummary>
 
991
      <desc><p>Change the size of a binary <c>bin</c>. The source binary
 
992
      may be read-only, in which case it will be left untouched and
 
993
      a mutable copy is allocated and assigned to <c>*bin</c>. Return true on success,
 
994
      false if memory allocation failed.</p></desc>
 
995
    </func>
 
996
    <func><name><ret>void</ret><nametext>enif_release_binary(ErlNifBinary* bin)</nametext></name>
 
997
      <fsummary>Release a binary.</fsummary>
 
998
      <desc><p>Release a binary obtained from <c>enif_alloc_binary</c>.</p></desc>
 
999
    </func>
 
1000
    <func><name><ret>void</ret><nametext>enif_release_resource(void* obj)</nametext></name>
 
1001
      <fsummary>Release a resource object.</fsummary>
 
1002
      <desc><p>Remove a reference to resource object <c>obj</c>obtained from
 
1003
      <seealso marker="#enif_alloc_resource">enif_alloc_resource</seealso>.
 
1004
      The resource object will be destructed when the last reference is removed.
 
1005
      Each call to <c>enif_release_resource</c> must correspond to a previous
 
1006
      call to <c>enif_alloc_resource</c> or
 
1007
      <seealso marker="#enif_keep_resource">enif_keep_resource</seealso>.
 
1008
      References made by <seealso marker="#enif_make_resource">enif_make_resource</seealso>
 
1009
      can only be removed by the garbage collector.</p></desc>
 
1010
    </func>
 
1011
    <func><name><ret>ErlNifRWLock*</ret><nametext>enif_rwlock_create(char *name)</nametext></name>
 
1012
    <fsummary></fsummary>
 
1013
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_create">erl_drv_rwlock_create</seealso>.
 
1014
          </p></desc>
 
1015
    </func>
 
1016
    <func><name><ret>void</ret><nametext>enif_rwlock_destroy(ErlNifRWLock *rwlck)</nametext></name>
 
1017
    <fsummary></fsummary>
 
1018
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_destroy">erl_drv_rwlock_destroy</seealso>.
 
1019
          </p></desc>
 
1020
    </func>
 
1021
    <func><name><ret>void</ret><nametext>enif_rwlock_rlock(ErlNifRWLock *rwlck)</nametext></name>
 
1022
    <fsummary></fsummary>
 
1023
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_rlock">erl_drv_rwlock_rlock</seealso>.
 
1024
          </p></desc>
 
1025
    </func>
 
1026
    <func><name><ret>void</ret><nametext>enif_rwlock_runlock(ErlNifRWLock *rwlck)</nametext></name>
 
1027
    <fsummary></fsummary>
 
1028
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_runlock">erl_drv_rwlock_runlock</seealso>.
 
1029
          </p></desc>
 
1030
    </func>
 
1031
    <func><name><ret>void</ret><nametext>enif_rwlock_rwlock(ErlNifRWLock *rwlck)</nametext></name>
 
1032
    <fsummary></fsummary>
 
1033
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_rwlock">erl_drv_rwlock_rwlock</seealso>.
 
1034
          </p></desc>
 
1035
    </func>
 
1036
    <func><name><ret>void</ret><nametext>enif_rwlock_rwunlock(ErlNifRWLock *rwlck)</nametext></name>
 
1037
    <fsummary></fsummary>
 
1038
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_rwunlock">erl_drv_rwlock_rwunlock</seealso>.
 
1039
          </p></desc>
 
1040
    </func>
 
1041
    <func><name><ret>int</ret><nametext>enif_rwlock_tryrlock(ErlNifRWLock *rwlck)</nametext></name>
 
1042
    <fsummary></fsummary>
 
1043
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_tryrlock">erl_drv_rwlock_tryrlock</seealso>.
 
1044
          </p></desc>
 
1045
    </func>
 
1046
    <func><name><ret>int</ret><nametext>enif_rwlock_tryrwlock(ErlNifRWLock *rwlck)</nametext></name>
 
1047
    <fsummary></fsummary>
 
1048
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_rwlock_tryrwlock">erl_drv_rwlock_tryrwlock</seealso>.
 
1049
          </p></desc>
 
1050
    </func>
 
1051
    <func><name><ret>ErlNifPid*</ret><nametext>enif_self(ErlNifEnv* caller_env, ErlNifPid* pid)</nametext></name>
 
1052
      <fsummary>Get the pid of the calling process.</fsummary>
 
1053
      <desc><p>Initialize the pid variable <c>*pid</c> to represent the
 
1054
      calling process. Return <c>pid</c>.</p></desc>
 
1055
    </func>
 
1056
    <func><name><ret>int</ret><nametext>enif_send(ErlNifEnv* env, ErlNifPid* to_pid, ErlNifEnv* msg_env, ERL_NIF_TERM msg)</nametext></name>
 
1057
      <fsummary>Send a message to a process.</fsummary>
 
1058
      <desc><p>Send a message to a process.</p>
 
1059
      <taglist>
 
1060
        <tag><c>env</c></tag>
 
1061
              <item>The environment of the calling process. Must be NULL if and
 
1062
              only if calling from a created thread.</item>
 
1063
        <tag><c>*to_pid</c></tag>
 
1064
              <item>The pid of the receiving process. The pid should refer to a process on the local node.</item>
 
1065
        <tag><c>msg_env</c></tag>
 
1066
              <item>The environment of the message term. Must be a process
 
1067
              independent environment allocated with
 
1068
               <seealso marker="#enif_alloc_env">enif_alloc_env</seealso>.</item>
 
1069
        <tag><c>msg</c></tag>
 
1070
              <item>The message term to send.</item>
 
1071
      </taglist>
 
1072
      <p>Return true on success, or false if <c>*to_pid</c> does not refer to an alive local process.</p>
 
1073
      <p>The message environment <c>msg_env</c> with all its terms (including
 
1074
      <c>msg</c>) will be invalidated by a successful call to <c>enif_send</c>. The environment
 
1075
      should either be freed with <seealso marker="#enif_free_env">enif_free_env</seealso>
 
1076
      of cleared for reuse with <seealso marker="#enif_clear_env">enif_clear_env</seealso>.</p>
 
1077
      <p>This function is only thread-safe when the emulator with SMP support is used.
 
1078
      It can only be used in a non-SMP emulator from a NIF-calling thread.</p>
 
1079
      </desc>
 
1080
    </func>
 
1081
    <func><name><ret>unsigned</ret><nametext>enif_sizeof_resource(void* obj)</nametext></name>
 
1082
      <fsummary>Get the byte size of a resource object</fsummary>
 
1083
      <desc><p>Get the byte size of a resource object <c>obj</c> obtained by
 
1084
      <seealso marker="#enif_alloc_resource">enif_alloc_resource</seealso>.</p></desc>
 
1085
    </func>
 
1086
    <func>
 
1087
      <name><ret>void</ret><nametext>enif_system_info(ErlNifSysInfo *sys_info_ptr, size_t size)</nametext></name>
 
1088
      <fsummary>Get information about the Erlang runtime system</fsummary>
 
1089
      <desc><p>Same as <seealso marker="erl_driver#driver_system_info">driver_system_info</seealso>.
 
1090
            </p></desc>
 
1091
    </func>
 
1092
    <func><name><ret>int</ret><nametext>enif_thread_create(char *name,ErlNifTid *tid,void * (*func)(void *),void *args,ErlNifThreadOpts *opts)</nametext></name>
 
1093
    <fsummary></fsummary>
 
1094
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_create">erl_drv_thread_create</seealso>.
 
1095
          </p></desc>
 
1096
    </func>
 
1097
    <func><name><ret>void</ret><nametext>enif_thread_exit(void *resp)</nametext></name>
 
1098
    <fsummary></fsummary>
 
1099
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_exit">erl_drv_thread_exit</seealso>.
 
1100
          </p></desc>
 
1101
    </func>
 
1102
    <func><name><ret>int</ret><nametext>enif_thread_join(ErlNifTid, void **respp)</nametext></name>
 
1103
    <fsummary></fsummary>
 
1104
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_join">erl_drv_thread_join </seealso>.
 
1105
          </p></desc>
 
1106
    </func>
 
1107
    <func><name><ret>ErlNifThreadOpts*</ret><nametext>enif_thread_opts_create(char *name)</nametext></name>
 
1108
    <fsummary></fsummary>
 
1109
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_opts_create">erl_drv_thread_opts_create</seealso>.
 
1110
          </p></desc>
 
1111
    </func>
 
1112
    <func><name><ret>void</ret><nametext>enif_thread_opts_destroy(ErlNifThreadOpts *opts)</nametext></name>
 
1113
    <fsummary></fsummary>
 
1114
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_opts_destroy">erl_drv_thread_opts_destroy</seealso>.
 
1115
          </p></desc>
 
1116
    </func>
 
1117
    <func><name><ret>ErlNifTid</ret><nametext>enif_thread_self(void)</nametext></name>
 
1118
    <fsummary></fsummary>
 
1119
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_thread_self">erl_drv_thread_self</seealso>.
 
1120
          </p></desc>
 
1121
    </func>
 
1122
    <func><name><ret>int</ret><nametext>enif_tsd_key_create(char *name, ErlNifTSDKey *key)</nametext></name>
 
1123
    <fsummary></fsummary>
 
1124
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_key_create">erl_drv_tsd_key_create</seealso>.
 
1125
          </p></desc>
 
1126
    </func>
 
1127
    <func><name><ret>void</ret><nametext>enif_tsd_key_destroy(ErlNifTSDKey key)</nametext></name>
 
1128
    <fsummary></fsummary>
 
1129
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_key_destroy">erl_drv_tsd_key_destroy</seealso>.
 
1130
          </p></desc>
 
1131
    </func>
 
1132
    <func><name><ret>void*</ret><nametext>enif_tsd_get(ErlNifTSDKey key)</nametext></name>
 
1133
    <fsummary></fsummary>
 
1134
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_get">erl_drv_tsd_get</seealso>.
 
1135
          </p></desc>
 
1136
    </func>
 
1137
    <func><name><ret>void</ret><nametext>enif_tsd_set(ErlNifTSDKey key, void *data)</nametext></name>
 
1138
    <fsummary></fsummary>
 
1139
    <desc><p>Same as <seealso marker="erl_driver#erl_drv_tsd_set">erl_drv_tsd_set</seealso>.
 
1140
          </p></desc>
344
1141
    </func>
345
1142
  </funcs>
346
1143
  <section>
347
1144
    <title>SEE ALSO</title>
348
 
    <p><seealso marker="erlang#erlang:load_nif-2">load_nif(3)</seealso></p>
 
1145
    <p><seealso marker="erlang#load_nif-2">erlang:load_nif/2</seealso></p>
349
1146
  </section>
350
1147
</cref>
351
1148