|
A foreign function interface (or FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written in another. The term comes from the specification for Common Lisp, which explicitly refers to the language features for inter-language calls as such; the term is also used officially by the Haskell programming language. Other languages use other terminology (the Java programming language refers to its FFI as the Java Native Interface, or JNI). Foreign function interface has become generic terminology for mechaisms which provide such services. Computer code (HTML with JavaScript) in a tool that uses syntax highlighting (colors) to help the developer see the purpose of each piece of code. ...
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, standardised by ANSI X3. ...
Haskell is a standardized pure functional programming language with non-strict semantics named after the logician Haskell Curry. ...
Java is an object-oriented programming language developed by James Gosling and colleagues at Sun Microsystems in the early 1990s. ...
The Java Native Interface (JNI) is a programming framework that allows Java code running in the Java virtual machine (VM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C, C++ and assembly. ...
It should be noted that despite the name, FFIs are not necessarily restricted to function calls; many FFIs permit method calls on objects; and some even permit migration of non-trivial datatypes and/or objects across the language boundary. In computer science, a subroutine (function, procedure, or subprogram) is a sequence of code which performs a specific task, as part of a larger program, and is grouped as one or more statement blocks; such code is sometimes collected into software libraries. ...
The term foreign function interface is generally not used to describe multi-lingual runtimes such as the Microsoft Common Language Runtime, where a common "substrate" is provided which enables any CLR-compliant language to use services defined in any other. In addition, many distributed computing architectures such as the Java Remote Method Invokation (RMI), RPC, CORBA, and SOAP permit different services to be written in different languages; such architectures are generally not considered FFIs. Microsoft Corporation (NASDAQ: MSFT, SEHK: 4338) is an international computer technology corporation with 2005 global annual sales of close to $40 billion USD and about 64,000 employees in 85 countries and regions which develops, manufactures, licenses, and supports a wide range of software products for computing devices. ...
In computing, Common Language Runtime (CLR) is the name chosen by Microsoft for the virtual machine plus runtime library underlying their . ...
RMI is a TLA that can refer to: The Remote Method Invocation in the Java programming language. ...
RPC can refer to: Remote procedure call, a protocol that allows a computer program running on one host to cause code to be executed on another host Revolutionary Policy Committee, a faction within the Independent Labour Party, a United Kingdom political party during the 1930s Rail Passengers Council, a network...
In computing, Common Object Request Broker Architecture (CORBA) is a standard for software componentry, created and controlled by the Object Management Group (OMG). ...
Soap most commonly appears in bar form. ...
In most cases, a FFI is defined by a "higher-level" language, so that it may employ services defined and implemented in a lower level language, typically a systems language like C or C++. This is typically done to either access OS services in the language in which the OS' API is defined, or for performance considerations. Many FFIs also provide the means for the called language to invoke services in the host language as well.
Operation of a FFI
The primary function of a FFI is to mate the semantics and calling conventions of one programming language (the host language, or the language which defines the FFI), with the semantics and conventions of another (the guest language). This process must also take into consideration the runtime environments and/or application binary interfaces of both. This can be done in several ways: Computer programming (often simply programming) is the craft of implementing one or more interrelated abstract algorithms using a particular programming language to produce a concrete computer program. ...
In computer software, an application binary interface (ABI) describes the low-level interface between an application program and the operating system, between an application and its libraries, or between component parts of the application. ...
- Requiring that guest-language functions which are to be host-language callable be specified or implemented in a particular way; often using a compatibility library of some sort.
- Use of a tool to automatically "wrap" guest-language functions with appropriate glue code, which performs any necessary translation.
- Restricting the set of host language capabilities which can be used cross-language. For example, C functions called from C++ may not (in general) include reference parameters or throw exceptions.
FFIs may be complicated by the following considerations: - If one language supports garbage collection and the other does not; care must be taken that the non-GC language code doesn't do something to cause the GC to fail. In JNI, for example, C code which "holds on to" object references passed from Java must "register" this fact with the Java runtime; otherwise the referred-to objects may be garbage-collected if no more valid references to the object(s) exist within the Java environment. (The C code must likewise release such references manually when the corresponding object is no longer needed).
- Complicated or non-trivial objects or datatype may be difficult to map from one environment to another.
- It may not be possible for both languages to maintain references to the same instance of a mutable object, due to the mapping issue above.
- One or both languages may be running on a virtual machine (including different VMs).
- Cross language inheritance or other forms of type or object composition may be especially difficult.
Garbage collection can refer to two different things: Garbage collection (computer science): an automatic way of reclaiming unused storage; Civic garbage collection: waste management. ...
In general terms, a virtual machine in computer science is software that creates an environment between the computer platform and the end user in which the end user can operate software. ...
This article is about inheritance in object-oriented programming. ...
Examples Examples of FFIs include: - C++ has a trivial FFI with C, as the languages share a significant common subset. The primary effect of the extern "C" declaration in C++ is to disable name mangling.
- JNI, which provides an interface between Java and C/C++, the preferred systems language on most systems where Java is deployed
- The FFIs of Common Lisp and Haskell
- The major "scripting" languages, such as Python, Perl, and Ruby, all provide easy access to native code written in C/C++ (or any other language obeying C/C++ calling conventions).
In addition, many FFIs can be generated automatically: for example, SWIG. It has been suggested that Name decoration be merged into this article or section. ...
The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a standardized imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...
C++ (generally pronounced see plus plus, IPA: ) is a general-purpose computer programming language. ...
Common Lisp, commonly abbreviated CL, is a dialect of the Lisp programming language, standardised by ANSI X3. ...
Haskell is a standardized pure functional programming language with non-strict semantics named after the logician Haskell Curry. ...
Python is an interpreted programming language created by Guido van Rossum in 1990. ...
Programming Republic of Perl logo Perl, also Practical Extraction and Report Language (a backronym, see below), is a programming language released by Larry Wall on December 18, 1987 that borrows features from C, sed, awk, shell scripting (sh), and (to a lesser extent) from many other programming languages. ...
Ruby is a reflective, object-oriented programming language. ...
SWIG (Simplified Wrapper and Interface Generator) is a free computer software tool used to connect programs written in C/C++ with scripting languages such as Tcl, Perl, Python, Ruby, Guile, PHP and other languages like Java, C#, and Ocaml. ...
External links |