From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: inotify ffi Date: Tue, 11 Nov 2014 14:10:35 -0500 Message-ID: <87d28timdw.fsf@yeeloong.lan> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1415733138 29473 80.91.229.3 (11 Nov 2014 19:12:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 11 Nov 2014 19:12:18 +0000 (UTC) Cc: guile-devel@gnu.org To: Chaos Eternal Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Nov 11 20:12:13 2014 Return-path: Envelope-to: guile-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 1XoGrM-0000ik-On for guile-devel@m.gmane.org; Tue, 11 Nov 2014 20:12:13 +0100 Original-Received: from localhost ([::1]:50283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoGrM-0003P5-BY for guile-devel@m.gmane.org; Tue, 11 Nov 2014 14:12:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoGrD-0003OW-PJ for guile-devel@gnu.org; Tue, 11 Nov 2014 14:12:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XoGr6-0004LG-AZ for guile-devel@gnu.org; Tue, 11 Nov 2014 14:12:03 -0500 Original-Received: from world.peace.net ([96.39.62.75]:43156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoGr6-0004L6-6p for guile-devel@gnu.org; Tue, 11 Nov 2014 14:11:56 -0500 Original-Received: from c-24-62-95-23.hsd1.ma.comcast.net ([24.62.95.23] helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1XoGqy-00027d-JR; Tue, 11 Nov 2014 14:11:48 -0500 In-Reply-To: (Chaos Eternal's message of "Wed, 12 Nov 2014 01:59:13 +0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17601 Archived-At: Chaos Eternal writes: > i wrote a FFI to inotify system call. > > https://github.com/ChaosEternal/guile-inotify2 > > procedures: > * inotify-init > * inotify-init1 > * inotify-add-watch > * inotify-rm-watch > * inotify-read-port > > the errno handle is unreliable, use with caution. > > License: LGPL v3 and later, he wrote: > and it is not very portable. Thanks for working on this, but as you pointed out, the method you use to check 'errno' is extremely unportable and also quite fragile. It makes assumptions about internal details of the C library and Guile, and is likely to break in future versions of glibc and/or Guile. It might not even work properly with current versions. There are many things that could happen between the call to the C function and checking 'errno' that might disturb the value of 'errno'. Unfortunately, there's currently no proper way to check 'errno' using the Dynamic FFI. For now, the only proper solution is to write a C extension as described in: http://www.gnu.org/software/guile/manual/html_node/C-Extensions.html Your C wrapper should call the relevant C function and then immediately read the value of 'errno' if the return value indicates an error. You should not make any calls to libguile before reading 'errno'. Hopefully, Guile 2.0.12 will include a way to check 'errno' after calls to the Dynamic FFI. Most likely, this will involve adding a keyword argument to 'pointer->procedure' that causes the generated wrapper to check 'errno' immediately after the C function returns. The ticket for this issue is here: http://bugs.gnu.org/18592 Regards, Mark