肝结节是什么意思| 宝宝缺钙吃什么补得快| 眼睛蒙蒙的是什么原因| 咳嗽吃什么药| 忘忧草是什么意思| 捡到狗狗代表什么预兆| 小儿鼻炎用什么药好| 去化是什么意思| 经常上火口腔溃疡是什么原因| 三岁宝宝喝什么奶粉比较好| 手掌小鱼际发红是什么原因| 属猴是什么命| 右耳朵耳鸣是什么原因| 脖子爱出汗是什么原因| 碎石后要注意些什么| 春节的习俗是什么| 什么是性冷淡| 神经痛吃什么药效果好| 湖水蓝是什么颜色| 手抖看什么科| 金今念什么| 桦树茸有什么功效| 光棍一条是什么生肖| 山见念什么| 血液由什么和什么组成| 1998年什么命| 对峙是什么意思| 后脑勺发麻是什么原因| prf是什么意思| 副局长什么级别| 64年属什么生肖| 怀孕查雌二醇什么作用| 什么时候闰十二月| 有什么奇怪| 大量出汗是什么原因引起的| 下面有炎症用什么药| 什么风呼啸| 增强抵抗力吃什么| 普罗帕酮又叫什么| 为什么前壁容易生男孩| 蛋白粉什么时间喝最好| 口什么心什么| 醒酒喝什么饮料| 白细胞低吃什么药| aso是什么意思| 蓝色妖姬是什么意思| 屁股上长痘痘是什么情况| vaude是什么品牌| 羊猄皮是什么皮| 拾掇是什么意思| 颈椎病吃什么药好| 九秩是什么意思| 无名指是什么经络| 喊麦什么意思| 不怀孕需要做什么检查项目| 海参几头是什么意思| 什么的叹气| 什么是盆腔炎| 副脾对身体有什么影响| 雷同是什么意思| 为什么啊| 肠胃不好吃什么药| 陌路人是什么意思| 肺栓塞是什么意思| 9月16日是什么星座| 喉咙里的小肉球叫什么| 幼儿急疹吃什么药| 吃猪腰子有什么好处和坏处| 来字五行属什么| 内科是看什么病的| 毛肚是什么东西| 白兰地是属于什么酒| 枸杞和红枣泡水喝有什么好处| 黄五行属什么| 一般细菌涂片检查是查什么| 头晕出虚汗是什么原因引起的| ep什么意思| 什么叫血糖| 郁郁寡欢什么意思| 鸽子拉绿稀便是什么病| hugo是什么意思| 纤维蛋白原是什么意思| pc肌是什么| 女生什么时候最容易怀孕| 用热毛巾敷眼睛有什么好处| 铁观音属于什么茶类| 老流鼻血是什么原因| 五常是什么| 现在的节气是什么| 10月12号是什么星座| 邪祟是什么意思| 外感风寒吃什么药| 寄生虫感染吃什么药| 卵圆孔未闭是什么病| 尿胆红素高是什么原因| sp是什么意思啊| 真维斯属于什么档次| 成人改名字需要什么手续| 怀孕会出现什么状况| 神经外科治疗什么病| 造孽是什么意思| 吃火龙果对身体有什么好处| 乜贴是什么意思| 什么是静脉| 肺气肿吃什么药| 棺材用什么木材做最好| 什么是直径| asmr是什么| 马牛羊鸡犬豕中的豕指的是什么| 家有一老如有一宝是什么意思| 爱哭的人是什么性格| 武夷岩茶属于什么茶| cl是什么元素| 女性腋臭什么年龄消失| 湿疹长什么样图片| 最近有什么病毒感染| 1月22日是什么星座| 地包天是什么意思| 精子对女性有什么好处| 脚背麻木是什么原因| 2月25日是什么星座| 化气行水是什么意思| 男人吃鸽子有什么好处| 2段和3段奶粉有什么区别| 指示是什么意思| 沙中土是什么生肖| 内分泌失调是什么| 感觉抑郁了去医院挂什么科| 放的偏旁是什么| 睡眠不好去医院挂什么科| 时乖命蹇是什么意思| 什么叫蛋白质| 莯字五行属什么| 优点是什么意思| 猴子是什么动物| 心肌缺血吃什么药| 磁共振是做什么的| 骨皮质断裂是什么意思| 身上发抖是什么原因| 螺蛳粉为什么臭| 尿道口红肿用什么药| 客厅挂画有什么讲究| 薛字五行属什么| 什么是代孕| 为什么要做包皮手术| love是什么词性| 三焦经在什么位置| 老蒯是什么意思| 尿道口为什么叫马眼| 这个季节适合种什么蔬菜| 勾践属什么生肖| ufo是什么| 呆板是什么意思| 银耳和什么一起煮最好| 掉头发是什么原因导致的| 中央党校校长是什么级别| 梦见双头蛇是什么征兆| 槐花什么时候开花| 吴优为什么叫大胸姐| 搞破鞋什么意思| 草字头的字有什么| tfcc是什么| 脑脊液白细胞高是什么原因| 黑眼圈是什么原因造成的| 手肿胀是什么原因| 房性早搏吃什么药| 肺气阴两虚吃什么中成药| 天厨贵人是什么意思| 抑郁症去医院挂什么科| 急性牙髓炎吃什么药| 杭州什么宽带好又便宜| 糟卤可以做什么菜| 居住证签注是什么意思| 抗美援朝是什么时候| 门字五行属什么| 梦见情人是什么意思啊| 孕妇吃什么会流产| 马陆吃什么| 印度尼西亚是什么人种| asia是什么意思| 黑色的鸟是什么鸟| 怕痒的男人意味着什么| 银行卡销户是什么意思| 蚂蝗怕什么| ggdb是什么牌子| 余情未了什么意思| 嘴皮发白是什么原因| 2017是什么年| 头疼想吐是什么原因引起的| 神经递质是什么意思| 冰箱发热是什么原因| 94年属什么的| 男性吃什么增强性功能| 满字是什么结构| 过敏可以吃什么| 同房后出血什么原因| 元老是什么意思| 人为什么要火化| 什么水果通便效果最好| 月经腰疼是什么原因引起的| cea检查是什么意思| 汉武帝属什么生肖| 人生的尽头是什么| 九五至尊是什么生肖| 临床医学学什么| 弟是什么结构的字| 为什么虾煮熟了会变红| 什么时候喝牛奶最好| 蝉的鸣叫声像什么| 头发五行属什么| 晚上睡觉腿酸难受是什么原因| 梦见捡到钱是什么意思| 捞女什么意思| 子宫内膜为什么会增厚| 蜘蛛属于什么| 肝胆湿热吃什么中成药最好| 金蟾折桂什么意思| 低热是什么症状| 牙疼吃什么药止疼最快| 倒斗是什么意思| 蟑螂吃什么东西| 一岁宝宝能吃什么水果| 吃什么能增强性功能| 已售罄是什么意思| 卧室放什么花最好健康| 月经血量少是什么原因| 1月27号是什么星座| 梦见抽血是什么预兆| 儿童拉稀吃什么药| 一个山一个脊念什么| 不劳而获是什么意思| 李逵的绰号是什么| 欲女是什么意思| 被蝎子蛰了用什么药| ahc是韩国什么档次| porridge什么意思| 癌症晚期吃什么食物好| 制动是什么意思| 钠低是什么原因| 为什么同房会痛| 六子是什么意思| 口腔经常溃疡是什么原因| 左脸颊长痘是什么原因| 自然堂适合什么年龄| 胃窦肠化是什么意思| 蚕吃什么| 甲状腺是什么症状表现| 蚊虫叮咬过敏用什么药| 悬雍垂发炎吃什么药| 闲云野鹤是什么意思| 减肥为什么不让吃茄子| canon什么牌子| 老干局是干什么的| 男人肾虚吃什么好| 新生儿黄疸高有什么危害| 水洗棉是什么| 射手男和什么座最配对| 全麻对身体有什么影响| 傍晚是什么时候| im什么意思| 滋阴润燥是什么意思| t代表什么| 遥字五行属什么| 梦见洗头发是什么意思| 百度Jump to content

灵武:“打牢做实”精准扶贫 让水利扶贫开出幸福花

From Wikipedia, the free encyclopedia
(Redirected from Foreign Function Interface)
百度 =  新闻盘点  看看他们都给情妇承诺了啥  记者盘点近几年给情妇写“承诺书”的官员发现,他们都与情妇保持关系多年,因金钱纠纷或权利纠纷而决裂。

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into a binary dynamic-link library.

Naming

[edit]

The term comes from the specification for Common Lisp, which explicitly refers to the programming language feature enabling for inter-language calls as such;[citation needed] the term is also often used officially by the interpreter and compiler documentation for Haskell,[1] Rust,[2] PHP,[3] Python, and LuaJIT (Lua)[4][5]:?35?.[6] Other languages use other terminology: Ada has language bindings, while Java has Java Native Interface (JNI), Java Native Access (JNA), or since Java 22, Foreign Function and Memory API. Foreign function interface has become generic terminology for mechanisms which provide such services.

Operation

[edit]

The primary function of a foreign function interface 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 application binary interfaces of both. This can be done in several ways:

  • 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.
  • Use of a wrapper library
  • Restricting the set of host language abilities 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 (GC) and the other does not; care must be taken that the non-GC language code does nothing to cause GC in the other to fail. In JNI, for example, C code which "holds on to" object references that it receives from Java must communicate this information successfully to the Java virtual machine or Java Runtime Environment (JRE), otherwise, Java may delete objects before C finishes with them. (The C code must also explicitly release its link to any such object once C has no further need of that object.)
  • Complicated or non-trivial objects or datatypes 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 (VM); moreover, if both are, these are often different VMs.
  • Cross-language inheritance and other differences, such as between type systems or between object composition models, may be especially difficult.

UML ffi.svg

Examples of FFIs include:

  • Ada language bindings, allowing not only to call foreign functions but also to export its functions and methods to be called from non-Ada code.[7]
  • 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 C++ name mangling. With other languages, separate utils or middleware are used, examples include:
  • Clean provides a bidirectional FFI with all languages following C or the stdcall calling convention.[8][9]
  • Common Lisp
  • Compiled Native Interface (CNI), alternative to JNI used in the GNU compiler environment.
  • One of the bases of the Component Object Model is a common interface format, which natively uses the same types as Visual Basic for strings and arrays.
  • D does it the same way as C++ does, with extern "C" through extern (C++)
  • Dart includes dart:ffi[10] library to call native C code for mobile, command-line, and server applications
  • Dynamic programming languages, such as Python, Perl, Tcl, and Ruby, all provide easy access to native code written in C, C++, or any other language obeying C/C++ calling conventions.
  • Factor has FFIs for C, Fortran, Objective-C, and Windows COM; all of these enable importing and calling arbitrary shared libraries dynamically.
  • Fortran 2003 has a module ISO_C_BINDING which provides interoperable data types (both intrinsic types and POD structs), interoperable pointers, interoperable global data stores, and mechanisms for calling C from Fortran and for calling Fortran from C.[11] It has been improved in the Fortran 2018 standard.
  • Go can call C code directly via the "C" pseudo-package.[12]
  • Google Web Toolkit (GWT), in which Java is compiled to JavaScript, has an FFI named JSNI which allows Java source code to call arbitrary JavaScript functions, and for JavaScript to call back into Java.
  • Haskell
  • Java Native Interface (JNI), which provides an interface between Java and C/C++, the preferred systems languages on most systems where Java is deployed. Java Native Access (JNA) provides an interface with native libraries without having to write glue code. In Java 22, the Foreign Function and Memory API was added which is a modern replacement for JNI.
  • LuaJIT, a just-in-time implementation of Lua, has an FFI that allows "calling external C functions and using C data structures from pure Lua code".[4][5]:?35?
  • .NET have FFI through its LibraryImport attribute.
  • Nim has an FFI which enables it to use source from C, C++, and Objective-C. It can also interface with JavaScript.
  • JavaScript usually runs inside web browser runtimes that don't provide direct access to system libraries or commands to run, but there are few exceptions:
    • Node.js provides functions to open precompiled .node modules that in turn may provide access to non-builtin resources.
    • Deno, provides kind of FFI interface via dlopen(...) functions.[13]
    • Bun provides a built-in module, bun:ffi, to efficiently call native libraries directly from JavaScript.[14]
  • Julia has ccall keyword to call C (and other languages, e.g., Fortran);[15] while packages, providing similar no-boilerplate support, are available for some languages e.g., for Python[16] (to e.g. provide OO support and GC support), Java (and supports other JDK-languages, such as Scala) and R. Interactive use with C++ is also possible with Cxx.jl package.
  • PhoneGap (was named Apache Callback, but is now Apache Cordova) is a platform for building native mobile applications using HTML, CSS and JavaScript. Also, it has FFIs via JavaScript callback functions for access to methods and properties of mobile phone's native features including accelerometer, camera (also PhotoLibrary and SavedPhotoAlbum), compass, storage (SQL database and localStorage), notification, media and capture (playing and recording or audio and video), file, contacts (address book), events, device, and connection information.[1],[2].
  • PHP provides FFI to C.[17]
  • Pony supports integration with C via its FFI.[18]
  • Python provides the ctypes and cffi modules. For example, the ctypes module can load C functions from a shared library, or dynamic-link library (DLL) on-the-fly and translate simple data types automatically between Python and C semantics as follows:
    import ctypes
    libc = ctypes.CDLL("/lib/libc.so.6")  # Under Linux/Unix
    t = libc.time(None)                   # Equivalent C code: t = time(NULL)
    print(t)
    
  • P/Invoke, which provides an interface between the Microsoft Common Language Runtime and native code.
  • Racket has a native FFI based heavily on macros that enables importing arbitrary shared libraries dynamically.[19][20]
  • Raku can call Ruby, Python, Perl, Brainfuck, Lua, C, C++, Go, Scheme (Guile, Gambit), and Rust[21][22]
  • Ruby provides FFI either through the ffi gem, or through the standard library fiddle.
    require 'fiddle'
    
    libm = Fiddle.dlopen('/lib/libm.so.6')
    
    # Equivalent to: double floor(double x);
    floor = Fiddle::Function.new(
      libm.sym('floor'),     # ptr is a referenced function(, or symbol), of a Fiddle::Handle.
      [Fiddle::TYPE_DOUBLE], # args is an Array of arguments, passed to the ptr function.
      Fiddle::TYPE_DOUBLE    # ret_type is the return type of the function
    )
    
    # Equivalent to: floor(3.14159);
    floor.call(3.14159) #=> 3.0
    
  • Rust defines a foreign function interface to functions with various standard application binary interface (ABIs) in namespace std::ffi for calling C code.[23] There is also a library called CXX for interfacing with C++, as well as for Elixir, Rustler.
  • V (Vlang) can include and supports the use of C source code and libraries.[24]
  • Visual Basic has a declarative syntax that allows it to call non-Unicode C functions.
  • Wolfram Language provides a technology named Wolfram Symbolic Transfer Protocol (WSTP) which enables bidirectional calling of code between other languages with bindings for C++, Java, .NET. and other languages.
  • Zig provides FFI to C using the builtin cImport function.[25]

In addition, many FFIs can be generated automatically: for example, SWIG. However, in the case of an extension language a semantic inversion of the relationship of guest and host can occur, when a smaller body of extension language is the guest invoking services in the larger body of host language, such as writing a small plugin[26] for GIMP.[27]

Some FFIs are restricted to free standing functions, while others also allow calls of functions embedded in an object or class (often called method calls); some even permit migration of complex datatypes or objects across the language boundary.

In most cases, an FFI is defined by a higher-level language, so that it may employ services defined and implemented in a lower-level language, typically a system programming language like C or C++. This is typically done to either access operating system (OS) services in the language in which the OS API is defined, or for performance goals.

Many FFIs also provide the means for the called language to invoke services in the host language also.

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. (However, in this case the CLR does include an FFI, P/Invoke, to call outside the runtime.) In addition, many distributed computing architectures such as the Java remote method invocation (RMI), RPC, CORBA, SOAP and D-Bus permit different services to be written in different languages; such architectures are generally not considered FFIs.

Special cases

[edit]

There are some special cases, in which the languages compile into the same bytecode VM, like Clojure and Java, as well as Elixir and Erlang. Since there is no interface, it is not an FFI, strictly speaking, while it offers the same functions to the user.

See also

[edit]

References

[edit]
  1. ^ "FFI Introduction". HaskellWiki. Retrieved 19 June 2015. Haskell's FFI is used to call functions from other languages (basically C at this point), and for C to call Haskell functions.
  2. ^ "std::ffi". Rust-lang.org. Retrieved 1 April 2021. This module provides utilities to handle data across non-Rust interfaces, like other programming languages and the underlying operating system. It is mainly of use for FFI (Foreign Function Interface) bindings and code that needs to exchange C-like strings with other languages.
  3. ^ "PHP FFI Manual". PHP Manual. Retrieved 31 August 2023. Defined C variables are made available as properties of the FFI instance.
  4. ^ a b Mike Pall. "FFI Library". Luajit.org. Retrieved 2025-08-06.
  5. ^ a b Heintz, Joachim; Hofmann, Alex; McCurdy, Iain (2013). Ways Ahead: Proceedings of the First International Csound Conference. Newcastle upon Tyne: Cambridge Scholars Publishing. ISBN 978-1-4438-5122-0. OCLC 855505215.
  6. ^ "CFFI documentation". Retrieved 19 June 2015. C Foreign Function Interface for Python. The goal is to provide a convenient and reliable way to call compiled C code from Python using interface declarations written in C.
  7. ^ "Interface to Other Languages". Adaic.org. Retrieved 2025-08-06.
  8. ^ "Foreign Export". Retrieved 2025-08-06.
  9. ^ "Calling C From Clean". Retrieved 2025-08-06.
  10. ^ "dart:ffi library". Retrieved 2025-08-06.
  11. ^ "'fortran-iso-c-binding' tag wiki". Stack Overflow.
  12. ^ "cgo". Go Programming Language. Retrieved 2025-08-06.
  13. ^ "Foreign Function Interface | Manual". Deno. Retrieved 2025-08-06.
  14. ^ "FFI API". Bun Docs.
  15. ^ "Calling C and Fortran Code". JuliaLang.org. Retrieved 2025-08-06.
  16. ^ PyCall.jl: Package to call Python functions from the Julia language, JuliaPy, 2025-08-06, retrieved 2025-08-06
  17. ^ "PHP: FFI - Manual". The PHP Group. Retrieved 13 June 2019.
  18. ^ "Pony C-FFI Overview". Retrieved 9 April 2025.
  19. ^ Eli Barzilay. "The Racket Foreign Interface". Docs.racket-lang.org. Retrieved 2025-08-06.
  20. ^ "TR600.pdf" (PDF). Archived from the original (PDF) on 2025-08-06. Retrieved 2025-08-06.
  21. ^ "Inline implementations". Retrieved 2025-08-06.
  22. ^ "Native Call". Retrieved 2025-08-06.
  23. ^ "Using extern Functions to Call External Code". Retrieved 2025-08-06.
  24. ^ "Including C code". Vlang. Retrieved 2025-08-06.
  25. ^ "Import from C Header File". Zig Software Foundation. Retrieved 2025-08-06.
  26. ^ "4. A sample script". Gimp.org. 2025-08-06. Retrieved 2025-08-06.
  27. ^ "Script-Fu and plug-ins for The GIMP". Gimp.org. Retrieved 2025-08-06.
[edit]


用苦良心是什么意思 什么是云母 睡醒嘴巴苦是什么原因 cho是什么 棕色皮鞋配什么颜色裤子
八面玲珑指什么生肖 阑尾炎手术后可以吃什么水果 今年的属相是什么生肖 妯娌是什么意思 县级干部是什么级别
故事是什么意思 蓝莓什么时候吃最好 微笑是什么 长时间手淫有什么危害 慢性结肠炎吃什么药好
戒指上的s925是什么意思 7月13日是什么日子 一月二十五号是什么星座 为什么一个月来两次月经 什么炒菜好吃
secret是什么意思bfb118.com 深圳少年宫有什么好玩的hcv9jop5ns7r.cn 韶关有什么特产chuanglingweilai.com 外交是什么意思aiwuzhiyu.com 吃什么瘦肚子脂肪最快hcv9jop8ns0r.cn
做孕检都检查什么项目hcv8jop7ns3r.cn 凌晨两点是什么时辰hcv7jop4ns5r.cn 头经常晕是什么原因hcv9jop8ns2r.cn 恐龙是什么时候灭绝的hcv8jop0ns0r.cn 跑步对身体有什么好处hcv9jop0ns6r.cn
血小板有什么作用luyiluode.com 白细胞偏低吃什么药imcecn.com 盐酸氟桂利嗪胶囊治什么病hcv9jop7ns3r.cn 喝什么茶可以降血脂hcv8jop3ns2r.cn 西游记是一部什么小说hcv8jop7ns5r.cn
茶歇是什么意思hcv8jop1ns9r.cn 99年属什么cl108k.com 低血钾是什么病hcv8jop3ns1r.cn 马云父母是做什么的hcv9jop4ns0r.cn 农历六月十七是什么日子hcv9jop3ns5r.cn
百度