Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Generic Erlang Port [Driver]: Automatically generate an Erlang port driver or Erlang port for C/C++ bindings using a single self-contained file, and easily switch between either.
C++ Erlang C
branch: master
Failed to load latest commit information.
CMake/erlang
.gitignore Add cmake build system
CMakeLists.txt Add cmake build system
LICENSE.txt Generic Erlang Port [Driver] (GEP[D]), Version 0.7
README.markdown
erlang_functions_hrl.h Generic Erlang Port [Driver] (GEP[D]), Version 0.9
main.cpp
make.sh
pchar_len_t.h Update documentation.
port.cpp Generic Erlang Port [Driver] (GEP[D]), Version 0.9
port.hpp
port_driver.cpp Fix deprecated driver_output_term.
realloc_ptr.hpp
test_bindings.erl Add binary return values from functions with the type "pchar_len_t". …
test_bindings.h Generic Erlang Port [Driver] (GEP[D]), Version 0.9
test_functions.c Add binary return values from functions with the type "pchar_len_t". …
test_functions.h Add binary return values from functions with the type "pchar_len_t". …

README.markdown

GENERIC ERLANG PORT [DRIVER] (GEP[D]), VERSION 0.9 (Jan 25 2012)

PURPOSE

To automatically generate an Erlang port driver or Erlang port for C/C++ bindings using a single self-contained file.

Files:

  • test_bindings.h contains the ONLY configuration to support the C functions (in test_functions.h and test_functions.c)
  • test_bindings.erl provides the gen_server to manage the port or port driver
  • erlang_functions_hrl.h creates the erlang function interface
  • port_driver.cpp provides the Erlang port driver implementation
  • port.cpp and port.hpp provide the Erlang port implementation

Whether PORT_DRIVER_NAME_PREFIX or PORT_NAME_PREFIX is defined determines if a port driver or port is built, respectively (in test_bindings.h). If both are defined, both are built and the port driver is used within test_bindings.erl (undefine ERL_PORT_DRIVER_NAME if you want to use the port).

Features:

  • a function binding with only a single line tuple
  • efficient passing of function types with no intermediate character buffer
  • functionality like the Erlang Driver Tool Kit (EDTK) (no fd handling though)
  • macro expansion to avoid code duplication errors
  • floating point type handling
  • stdout/stderr handling in the generated port code

Caveat:

(This is no longer true for Erlang >= R15) The generated port driver code can not be used for hot code updating if it performs an asynchronous call because erts will lock the driver (making it "permanent") with driver_lock_driver() (http://erlang.org/doc/man/erl_driver.html#driver_lock_driver). With the driver locked, there is no possibility that an async operation would create instability after a hot code update.

BUILDING

Some of the features in port_driver.cpp requires erts >= 5.6.1 (Erlang >= R12B01). Boost is required for the preprocessor macro expansion code (http://www.boost.org/).

To build with cmake:

mkdir build
cd build
cmake ..
make

To build with the make script:

./make.sh

RUNNING

The test_bindings code should generate output similar to:

$ erl +A 16
Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:8:8] [async-threads:16] [kernel-poll:false]

Eshell V5.10.1  (abort with ^G)
1> test_bindings:start().
using port driver
{ok,<0.35.0>}
2> test_bindings:test().
sync sleep
async sleep
...
stdout writing before 2 second sleep
                                    ok
3> stdout writing after 2 second sleep
                                      stderr
                                            line
                                                break(s)
                                                        missasync function call returned: {ok,ok}
3> 

LICENSE

BSD license

CONTACT

Michael Truog

THANKS

  • Matt Stancliff (GEPD CMake integration)
  • Scott Lystig Fritchie (EDTK, i.e., Erlang Driver Tool Kit)
Something went wrong with that request. Please try again.