From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: FFI in Emacs Date: Tue, 12 Mar 2013 23:50:46 +0200 Message-ID: <83d2v4jnih.fsf@gnu.org> References: Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE X-Trace: ger.gmane.org 1363125195 6017 80.91.229.3 (12 Mar 2013 21:53:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 12 Mar 2013 21:53:15 +0000 (UTC) Cc: joakim@verona.se, emacs-devel@gnu.org To: =?utf-8?Q?Aur=C3=A9lien?= Aptel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 12 22:53:40 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UFX8d-0007CN-Dt for ged-emacs-devel@m.gmane.org; Tue, 12 Mar 2013 22:53:39 +0100 Original-Received: from localhost ([::1]:53719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFX8H-0005pT-5S for ged-emacs-devel@m.gmane.org; Tue, 12 Mar 2013 17:53:17 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:56825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFX7A-0002nd-VK for emacs-devel@gnu.org; Tue, 12 Mar 2013 17:53:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFX64-0007fl-6H for emacs-devel@gnu.org; Tue, 12 Mar 2013 17:52:06 -0400 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:56798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFX63-0007fI-Tx for emacs-devel@gnu.org; Tue, 12 Mar 2013 17:51:00 -0400 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0MJK00A00HSF2000@a-mtaout22.012.net.il> for emacs-devel@gnu.org; Tue, 12 Mar 2013 23:50:50 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0MJK009MJI0QX360@a-mtaout22.012.net.il>; Tue, 12 Mar 2013 23:50:50 +0200 (IST) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: Solaris 10 X-Received-From: 80.179.55.172 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:157800 Archived-At: > Date: Tue, 12 Mar 2013 20:16:42 +0100 > From: Aur=C3=A9lien Aptel > Cc: emacs-devel@gnu.org >=20 > a) load the shared library dynamically > b) get the address of any symbol in it (be it a global var or a fun= ction). >=20 > Then, to call a function: > c) load the argument according to user-provided type and ABI > d) make the call > e) retrieve eventual return value (also depends on ABI) >=20 > Steps a and b can be done portably using libltdl [1]; c,d and e wit= h > libffi [2] or libffcall [3]. Do we really need these libraries? If the Posix hosts can do with dlopen, dlsym, dlclose, and dlerror, then it's very easy to emulate that on platforms that don't have these in the system libraries. Wha= t else is needed, and why? > a) a function can allocate memory that has to be freed At least on Windows, this cannot be done safely, so please don't design the interface based on the assumption this is doable. If a shared object allocates memory, it should be responsible for freeing it, or provide an API for telling it to free it. Likewise with file descriptors -- they cannot be safely shared across the interface, because the shared library could have used a different runtime for opening files.