skip to main content
10.1145/2975969.2975970acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

The Nifty way to call hell from heaven

Published: 23 September 2016 Publication History

Abstract

Often Erlang programmers want or need to use existing C libraries. Also, occasionally they have good reasons to implement parts of their applications directly in C. To cater for such situations, the Erlang/OTP system comes with various mechanisms to call C from Erlang. The most modern of them allows to call C functions from Erlang as natively implemented functions (NIFs). Unfortunately, the use of a NIF library currently requires writing by hand a fair amount of code that to a large extent is boilerplate. To ease the lives of Erlang programmers and simplify the task of using existing C code bases from Erlang, we have created Nifty, a tool that automates the process of creating NIF libraries from C header files containing declarations of types and functions that the library supplies. This paper describes the functionality and implementation of Nifty, its current limitations and our experiences with it so far.

References

[1]
Interoperability tutorial user’s guide. http://www.erlang.org/doc/ tutorial/users_guide.html, Apr. 2016.
[2]
API functions for an Erlang NIF library. http://erlang.org/doc/ man/erl_nif.html, Apr. 2016.
[3]
Erlang Tutorial - NIFs. http://www.erlang.org/doc/tutorial/ nif.html, Apr. 2016.
[4]
An Erlang NIF wrapper for Google’s snappy compressor/decompressor. https://github.com/fdmanana/snappy-erlang-nif, May 2016.
[5]
Clang documentation - choosing the right interface for your application. http://clang.llvm.org/doxygen/group__CINDEX.html, Apr. 2016.
[6]
ErlyDTL homepage. https://github.com/erlydtl/erlydtl/ wiki, Apr. 2016.
[7]
Haskell: Foreign Function Interface. https://wiki.haskell.org/ Foreign_Function_Interface, May 2016.
[8]
libclang. http://clang.llvm.org/doxygen/group__CINDEX. html, Apr. 2016.
[9]
libffi: A portable foreign function interface library. http:// sourceware.org/libffi/, May 2016.
[10]
Nifty - NIF Interface Generator. http://parapluu.github.io/ nifty/, May 2016.
[11]
rebar homepage. https://github.com/rebar/rebar/wiki, May 2016.
[12]
D. M. Beazley. SWIG: An easy to use tool for integrating scripting languages with C and C++. In Proceedings of the 4th USENIX Tcl/Tk Workshop, pages 129–139, Berkeley, CA, USA, July 1996. USENIX.
[13]
A. D. Birrell and B. J. Nelson. Implementing remote procedure calls. ACM Trans. Comput. Syst., 2(1):39–59, Feb. 1984. ISSN 0734-2071.
[15]
M. Blume. No-longer-foreign: Teaching an ML compiler to speak C “natively”. Electronic Notes in Theoretical Computer Science, 59(1): 36–52, 2001. ISSN 1571-0661.
[16]
Cesanta. Mongoose embedded webserver library. https://www. cesanta.com/products/mongoose, May 2016.
[17]
Django Software Foundation. Django template language. https: //docs.djangoproject.com/en/1.9/topics/templates/, Apr. 2016.
[18]
A. Dunkels, B. Grönvall, and T. Voigt. Contiki—a lightweight and flexible operating system for tiny networked sensors. In Proceedings of the 29th Annual IEEE International Conference on Local Computer Networks, pages 455–462. IEEE, 2004.
[19]
Ericsson Utvecklings AB. The interface generator (IG). http://www1.erlang.org/documentation/doc-4.8.2/lib/ ig-1.8/doc/index.html, May 2016.
[20]
Google. snappy - a fast compressor/decompressor. http://google. github.io/snappy/, Apr. 2016.
[21]
iMatix Corporation. 0mq code connected. http://zeromq.org/, May 2016.
[22]
G. K. Kloss. Automatic C library wrapping Ctypes from the trenches. The Python Papers, 3(3):5, 2008.
[23]
A. Löscher, K. Sagonas, and T. Voigt. Property-based testing of sensor networks. In Sensing, Communication, and Networking (SECON), 2015 12th Annual IEEE International Conference on, pages 100–108. IEEE, June 2015.
[25]
M. Papadakis and K. Sagonas. A PropEr integration of types and function specifications with property-based testing. In Proceedings of the 10th ACM SIGPLAN Workshop on Erlang, Erlang ’11, pages 39–50, New York, NY, USA, 2011. ACM. ISBN 978-1-4503-0859-5.
[26]
QuviQ AB. Demo of Erlang QuickCheck testing C code. https: //vimeo.com/104007760, May 2016.
[27]
S. Vinoski. Tackling Dirty Jobs with Erlang’s Schedulers. Code Mesh 2014 London, Nov. 2014.

Cited By

View all
  • (2019)Functional Federated Learning in Erlang (ffl-erl)Functional and Constraint Logic Programming10.1007/978-3-030-16202-3_10(162-178)Online publication date: 16-Mar-2019

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
Erlang 2016: Proceedings of the 15th International Workshop on Erlang
September 2016
61 pages
ISBN:9781450344319
DOI:10.1145/2975969
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 23 September 2016

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. foreign language interface
  2. language interoperability

Qualifiers

  • Research-article

Conference

ICFP'16
Sponsor:

Acceptance Rates

Overall Acceptance Rate 51 of 68 submissions, 75%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 02 Mar 2025

Other Metrics

Citations

Cited By

View all
  • (2019)Functional Federated Learning in Erlang (ffl-erl)Functional and Constraint Logic Programming10.1007/978-3-030-16202-3_10(162-178)Online publication date: 16-Mar-2019

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media