Git Product home page Git Product logo

okeuday / gepd Goto Github PK

View Code? Open in Web Editor NEW
82.0 14.0 11.0 125 KB

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.

License: MIT License

C 5.04% C++ 62.47% Shell 0.80% Erlang 8.33% CMake 4.75% Makefile 0.96% M4 17.65%
erlang erlang-encoding erlang-port erlang-port-driver

gepd's Introduction

GENERIC ERLANG PORT [DRIVER] (GEP[D])

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

Erlang/OTP >= R14A is required. Boost is required for the preprocessor macro expansion code (http://www.boost.org/).

To build, use:

./autogen.sh
./configure
make
make install

RUNNING

The test_bindings code should generate output similar to:

$ erl +A 16
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

MIT License

CONTACT

Michael Truog

THANKS

  • Matt Stancliff (GEPD CMake integration)
  • Scott Lystig Fritchie (EDTK, i.e., Erlang Driver Tool Kit)

gepd's People

Contributors

mattsta avatar okeuday avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gepd's Issues

Returning tuples?

I've been playing with this project a little bit, it seems pretty nice so far.

I have a C function from which I need to return more than just a single value - take something that would be a struct in my C code and represent it as a tuple in Erlang.

It looks like my best bet may be to use the ei/eterm functions to build and encode a tuple in my C code which I return through a pchar_len_t and then use binary_to_term to decode into an Erlang tuple - does that sound about right? I'm rather new at all this so thought I'd ask in case there is maybe an easier answer with this framework.

Thanks!

Variables not being populated on Mac

These variables are not populated on Mac
Erlang installed with brew

ERLANG_EI_PATH
ERLANG_ERTS_PATH
ERLANG_EI_INCLUDE_PATH
ERLANG_EI_LIBRARY_PATH
ERLANG_ERTS_INCLUDE_PATH
ERLANG_ERTS_LIBRARY_PATH

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.