Foundationপ্রথম নীতি থেকে
LEVEL 5 · Programming Languages

FFI

এক ভাষার code অন্য ভাষার function call করার ব্যবস্থা — মূলত দুই runtime/ABI-র সীমানায় দোভাষীর কাজ।

also: Foreign Function Interface, foreign function interface

Python-এর C call-এ যা যা মেলাতে হয়:

libc = ctypes.CDLL("libc.so.6")
libc.printf(b"%d years\n", 42)      # C ABI: char*, int, varargs
  • Calling convention match: argument register/stack order, return register, caller/callee-saved
  • Data representation: int width, struct layout/alignment, string encoding — ভুল হলে silent corruption
  • Memory ownership: কে allocate করল কে free করবে — দুই allocator-এর সীমানায় double-free-র ঝুঁকি
  • Managed runtime-এ বাড়তি: GC object-কে C-র হাতে ধরে রাখা বোঝানো (pinning/anchor), exception crossing boundary
  • Tools: ctypes/cffi, Java JNI, Rust extern "C", cgo — সবগুলোই একই সমস্যার ভিন্ন packaging