From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 30 16:20:11 2014 Received: (at submit) by debbugs.gnu.org; 30 Sep 2014 20:20:11 +0000 Received: from localhost ([127.0.0.1]:56691 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XZ3u6-0006DF-17 for submit@debbugs.gnu.org; Tue, 30 Sep 2014 16:20:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:42986) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XZ3u3-0006D6-7v for submit@debbugs.gnu.org; Tue, 30 Sep 2014 16:20:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZ3tt-00028K-7R for submit@debbugs.gnu.org; Tue, 30 Sep 2014 16:20:06 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:52630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ3tt-00028D-3u for submit@debbugs.gnu.org; Tue, 30 Sep 2014 16:19:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ3tl-0006Hi-Fj for bug-guile@gnu.org; Tue, 30 Sep 2014 16:19:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZ3te-00026M-0g for bug-guile@gnu.org; Tue, 30 Sep 2014 16:19:49 -0400 Received: from smtprelay04.ispgateway.de ([80.67.31.42]:49036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ3td-00026B-QD for bug-guile@gnu.org; Tue, 30 Sep 2014 16:19:41 -0400 Received: from [46.183.96.49] (helo=jim.voodoo.lan) by smtprelay04.ispgateway.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84) (envelope-from ) id 1XZ3tc-00038Z-4D for bug-guile@gnu.org; Tue, 30 Sep 2014 22:19:40 +0200 Received: by jim.voodoo.lan (Postfix, from userid 1000) id B9D4297698; Tue, 30 Sep 2014 22:17:04 +0200 (CEST) From: Frank Terbeck To: bug-guile@gnu.org Subject: FFI should have portable access to =?utf-8?B?4oCYZXJybm/igJk=?= User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.93 (gnu/linux) Date: Tue, 30 Sep 2014 22:17:04 +0200 Message-ID: <87fvf8oocf.fsf@ft.bewatermyfriend.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Df-Sender: NDMwNDQ0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hello Guile Maintainers! When accessing POSIX functions from a system's libc via Guile's dynamic FFI, you commonly want to access the =E2=80=98errno=E2=80=99 variable to be= able to produce useful diagnostic messages. Currently there's no such access built-in. Mark Weaver on IRC thought it would be a good idea to add portable access to the contents of =E2=80=98errno=E2=80=99 (however it's actually im= plemented) to Guile's FFI. And now the idea has entered the bug tracker. :) Regards, Frank --=20 In protocol design, perfection has been reached not when there is nothing left to add, but when there is nothing left to take away. -- RFC 1925 From debbugs-submit-bounces@debbugs.gnu.org Wed Oct 01 01:27:21 2014 Received: (at control) by debbugs.gnu.org; 1 Oct 2014 05:27:21 +0000 Received: from localhost ([127.0.0.1]:56806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XZCRd-0003QG-6R for submit@debbugs.gnu.org; Wed, 01 Oct 2014 01:27:21 -0400 Received: from world.peace.net ([96.39.62.75]:34904) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XZCRb-0003Q8-3K for control@debbugs.gnu.org; Wed, 01 Oct 2014 01:27:19 -0400 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 1XZCRV-00007l-FR; Wed, 01 Oct 2014 01:27:13 -0400 From: Mark H Weaver To: control@debbugs.gnu.org Date: Wed, 01 Oct 2014 01:27:02 -0400 Message-ID: <87tx3o8imx.fsf@yeeloong.lan> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: severity 18592 wishlist thanks [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: severity 18592 wishlist thanks [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject severity 18592 wishlist thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 11 10:04:47 2014 Received: (at 18592) by debbugs.gnu.org; 11 Nov 2014 15:04:48 +0000 Received: from localhost ([127.0.0.1]:57474 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XoCzv-0002p4-El for submit@debbugs.gnu.org; Tue, 11 Nov 2014 10:04:47 -0500 Received: from world.peace.net ([96.39.62.75]:45328) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XoCzs-0002ov-HU for 18592@debbugs.gnu.org; Tue, 11 Nov 2014 10:04:45 -0500 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 1XoCzl-0001L2-Dp; Tue, 11 Nov 2014 10:04:37 -0500 From: Mark H Weaver To: Frank Terbeck Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> Date: Tue, 11 Nov 2014 10:03:23 -0500 In-Reply-To: <87fvf8oocf.fsf@ft.bewatermyfriend.org> (Frank Terbeck's message of "Tue, 30 Sep 2014 22:17:04 +0200") Message-ID: <87wq71ixtw.fsf@yeeloong.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Frank Terbeck writes: > When accessing POSIX functions from a system's libc via Guile's dynamic > FFI, you commonly want to access the =E2=80=98errno=E2=80=99 variable to = be able to > produce useful diagnostic messages. > > Currently there's no such access built-in. > > Mark Weaver on IRC thought it would be a good idea to add portable > access to the contents of =E2=80=98errno=E2=80=99 (however it's actually = implemented) to > Guile's FFI. And now the idea has entered the bug tracker. :) Indeed, thanks for filing this ticket. I see a problem with this idea: something (e.g. a system async) might change 'errno' before the Scheme code fetches the 'errno' value. Mark From debbugs-submit-bounces@debbugs.gnu.org Tue Nov 11 15:04:42 2014 Received: (at 18592) by debbugs.gnu.org; 11 Nov 2014 20:04:42 +0000 Received: from localhost ([127.0.0.1]:57643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XoHgA-0004Rj-5g for submit@debbugs.gnu.org; Tue, 11 Nov 2014 15:04:42 -0500 Received: from smtprelay01.ispgateway.de ([80.67.31.24]:59126) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XoHg7-0004Ra-VE for 18592@debbugs.gnu.org; Tue, 11 Nov 2014 15:04:40 -0500 Received: from [46.183.98.176] (helo=jim.voodoo.lan) by smtprelay01.ispgateway.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84) (envelope-from ) id 1XoHg6-0005QQ-L8; Tue, 11 Nov 2014 21:04:38 +0100 Received: by jim.voodoo.lan (Postfix, from userid 1000) id 2B2C7989B1; Tue, 11 Nov 2014 21:02:21 +0100 (CET) From: Frank Terbeck To: Mark H Weaver Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= In-Reply-To: <87wq71ixtw.fsf@yeeloong.lan> (Mark H. Weaver's message of "Tue, 11 Nov 2014 10:03:23 -0500") References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87wq71ixtw.fsf@yeeloong.lan> User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.4.51 (gnu/linux) Date: Tue, 11 Nov 2014 21:02:20 +0100 Message-ID: <87k331v73n.fsf@ft.bewatermyfriend.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Df-Sender: NDMwNDQ0 X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Mark H. Weaver wrote: > Frank Terbeck writes: [...] >> Mark Weaver on IRC thought it would be a good idea to add portable >> access to the contents of =E2=80=98errno=E2=80=99 (however it's actually= implemented) to >> Guile's FFI. And now the idea has entered the bug tracker. :) > > Indeed, thanks for filing this ticket. > > I see a problem with this idea: something (e.g. a system async) might > change 'errno' before the Scheme code fetches the 'errno' value. Yes. Ludovic hinted at the use of =E2=80=98call-with-blocked-asyncs=E2=80= =99 to avoid this. To deal with that, I wrote a macro for guile-termios=C2=B9: (define-syntax-rule (call-with-errno (errno exp) fail0 fail1 ...) (let-values (((failed? errno) (call-with-blocked-asyncs (lambda () (let* ((f? (termios-failure? exp)) (err (if f? (get-errno) 0))) (values f? err)))))) (if failed? (begin fail0 fail1 ...) #t))) That seems to work fine, unless I'm missing something. Regards, Frank =C2=B9 https://github.com/ft/guile-termios From debbugs-submit-bounces@debbugs.gnu.org Thu Nov 13 12:13:55 2014 Received: (at 18592) by debbugs.gnu.org; 13 Nov 2014 17:13:55 +0000 Received: from localhost ([127.0.0.1]:59616 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xoxxz-0002TM-3o for submit@debbugs.gnu.org; Thu, 13 Nov 2014 12:13:55 -0500 Received: from world.peace.net ([96.39.62.75]:47814) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xoxxx-0002TC-7b for 18592@debbugs.gnu.org; Thu, 13 Nov 2014 12:13:53 -0500 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 1Xoxxq-0002OC-98; Thu, 13 Nov 2014 12:13:46 -0500 From: Mark H Weaver To: Frank Terbeck Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87wq71ixtw.fsf@yeeloong.lan> <87k331v73n.fsf@ft.bewatermyfriend.org> Date: Thu, 13 Nov 2014 12:12:32 -0500 In-Reply-To: <87k331v73n.fsf@ft.bewatermyfriend.org> (Frank Terbeck's message of "Tue, 11 Nov 2014 21:02:20 +0100") Message-ID: <87ioijf2in.fsf@yeeloong.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Frank Terbeck writes: > Mark H. Weaver wrote: >> Frank Terbeck writes: > [...] >>> Mark Weaver on IRC thought it would be a good idea to add portable >>> access to the contents of =E2=80=98errno=E2=80=99 (however it's actuall= y implemented) to >>> Guile's FFI. And now the idea has entered the bug tracker. :) >> >> Indeed, thanks for filing this ticket. >> >> I see a problem with this idea: something (e.g. a system async) might >> change 'errno' before the Scheme code fetches the 'errno' value. > > Yes. Ludovic hinted at the use of =E2=80=98call-with-blocked-asyncs=E2=80= =99 to avoid > this. To deal with that, I wrote a macro for guile-termios=C2=B9: > > (define-syntax-rule (call-with-errno (errno exp) fail0 fail1 ...) > (let-values (((failed? errno) (call-with-blocked-asyncs > (lambda () > (let* ((f? (termios-failure? exp)) > (err (if f? (get-errno) 0))) > (values f? err)))))) > (if failed? > (begin fail0 fail1 ...) > #t))) > > That seems to work fine, unless I'm missing something. I looked at guile-termios, and I can see that you've done about as good a job as could be expected from pure Guile Scheme code today, but even so, it's neither portable nor future-proof, and might not even work reliably today. One potential problem is that memory allocation might modify 'errno', and in Guile 2.2 even calling a Scheme procedure can cause memory allocation if the stack needs to be expanded. With current versions of Guile, I see no good way to check 'errno' using the Dynamic FFI. I think the only proper solution today is to write a C extension that wraps each library function that might set 'errno', and to have those wrappers check 'errno' immediately after the wrapped function returns, without using any libguile functions in between. I intend to have a better solution for this in Guile 2.0.12. Regards, Mark From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 22 12:53:40 2014 Received: (at 18592) by debbugs.gnu.org; 22 Nov 2014 17:53:40 +0000 Received: from localhost ([127.0.0.1]:41945 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XsEsN-00012K-NE for submit@debbugs.gnu.org; Sat, 22 Nov 2014 12:53:40 -0500 Received: from mail-ie0-f181.google.com ([209.85.223.181]:36077) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XsEsK-00012B-Li for 18592@debbugs.gnu.org; Sat, 22 Nov 2014 12:53:37 -0500 Received: by mail-ie0-f181.google.com with SMTP id tp5so6763697ieb.12 for <18592@debbugs.gnu.org>; Sat, 22 Nov 2014 09:53:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=mEbUbvpAYpvLY9gZzjx3kPkPPKojdnm/LD6rahPH3tM=; b=m59SUPtBbtdbsNWA16mibDtCZZHxn8zyiyWixsNy+GKryKMqQ3JXmM8h+ZrcmiUA8p Le1lxUJ/eJBDsu246ywUWdaL94jC083DVhlr4sYrNXUy26yYib/5bvGtVJ3p2DUrUUUO k0KRYGwf+F7mIIw3oJ8esEbnqcvTznItkL49gRD/MqY4p9RcoecHYKabG/fWsULVvTCd gwh1Ko3j/ksnc4QhiVKwVv31IsrKvIFOeXvX/egewm1bpVNxCK+pfxRSehK0dBQMUrNf +oVkM4IbzcJT0XKEdCLCBYascpLQFfUfpVMgQwDrZtYitpQwRHbgVn4QhehPpN32YRrq kmpQ== X-Gm-Message-State: ALoCoQkW8DHYHK9423mtzHcEu7zcKxzL+Xug81jTjaw3Yfy6uKfHDc6z0dYTCMtNjO+4YbfAb8ul MIME-Version: 1.0 X-Received: by 10.43.157.202 with SMTP id lr10mr7660732icc.78.1416678815849; Sat, 22 Nov 2014 09:53:35 -0800 (PST) Received: by 10.64.102.40 with HTTP; Sat, 22 Nov 2014 09:53:35 -0800 (PST) Date: Sun, 23 Nov 2014 01:53:35 +0800 Message-ID: Subject: =?UTF-8?Q?Re=3A_bug=2318592=3A_FFI_should_have_portable_access_to_?= =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Chaos Eternal To: 18592@debbugs.gnu.org Content-Type: text/plain; charset=UTF-8 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Proposals to solve this bug: Proposal 1. Adding a keyword argument to pointer->procedure, if set to true, the generated wrapper will check 'errno' immediately after ffi_call and return the errno as second value. the proposed pointer->procedure maybe like this: pointer->procedure return_type func_ptr arg_types #:return-errno Proposal 2. let pointer->procedure check return_type, if it is a list: (func_return_type, 'errno) then return multiple values, as errno be second value. Proposal 3. introduce another procedure "pointers->procedure", which will pack multiple function pointer into one procedure, in this procedure, the packed functions will be called in sequence, and their return value will be returned as multiple values. the interface would be like this: pointers->procedure (list-of-return-type) (list-of-pointers) (list-of arg-defs) also, we need a simple c-function deref-pointer-to-int, which will de-reference a pointer and return it's int value. using above tools, a proper system call with errno be returned could be like this: ((pointers->procedure (list int int) (list pointer-of-inotify-add-watch pointer-of-deref-pointer-to-int) (list (list int '* int) (list '*))) (list inotify-fd "path-to-watch" watch-flag) (list pointer-of-errno)) using this proposal, many "errno" like mechanisms can be handled, for example, the h_errno of libc, etc. further more, this proposal can be used to solve a sort of requirements like make several calls atomic. -- regards From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 19 15:22:16 2015 Received: (at 18592) by debbugs.gnu.org; 19 Jan 2015 20:22:16 +0000 Received: from localhost ([127.0.0.1]:49883 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YDIpz-0004gg-P0 for submit@debbugs.gnu.org; Mon, 19 Jan 2015 15:22:16 -0500 Received: from hera.aquilenet.fr ([141.255.128.1]:54698) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YDIpx-0004gV-0X for 18592@debbugs.gnu.org; Mon, 19 Jan 2015 15:22:13 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 1821C454F; Mon, 19 Jan 2015 21:22:12 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qPNLM5leBg84; Mon, 19 Jan 2015 21:22:12 +0100 (CET) Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by hera.aquilenet.fr (Postfix) with ESMTPSA id AACC019D7; Mon, 19 Jan 2015 21:22:11 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Chaos Eternal Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 30 =?utf-8?Q?Niv=C3=B4se?= an 223 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu Date: Mon, 19 Jan 2015 21:22:11 +0100 In-Reply-To: (Chaos Eternal's message of "Sun, 23 Nov 2014 01:53:35 +0800") Message-ID: <87h9vmy0zw.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hi, Sorry for the long delay. Chaos Eternal skribis: > Proposals to solve this bug: > > Proposal 1. > > Adding a keyword argument to pointer->procedure, if set to true, the > generated wrapper will check 'errno' immediately after ffi_call and > return the errno as second value. > > the proposed pointer->procedure maybe like this: > pointer->procedure return_type func_ptr arg_types #:return-errno > > Proposal 2. > > let pointer->procedure check return_type, if it is a list: > (func_return_type, 'errno) > then return multiple values, as errno be second value. That=E2=80=99s my favorite because it=E2=80=99s both pragmatic and extensib= le (we can also add support for h_errno, etc.) > Proposal 3. > > introduce another procedure "pointers->procedure", which will pack > multiple function pointer into one procedure, in this procedure, the > packed functions will be called in sequence, and their return value > will be returned as multiple values. > > the interface would be like this: > pointers->procedure (list-of-return-type) (list-of-pointers) (list-of arg= -defs) > > also, we need a simple c-function deref-pointer-to-int, which will > de-reference a pointer and return it's int value. > > using above tools, a proper system call with errno be returned could > be like this: > > ((pointers->procedure > (list int int) > (list pointer-of-inotify-add-watch pointer-of-deref-pointer-to-int) > (list (list int '* int) (list '*))) > (list inotify-fd "path-to-watch" watch-flag) (list pointer-of-errno)) The problem is that POINTER-OF-ERRNO does not necessarily exist and cannot be obtained portably. Also, I find the interface a bit clumsy. So my support goes to #2. Would you like to give it a try? Thanks for your input! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 24 03:11:14 2015 Received: (at 18592) by debbugs.gnu.org; 24 Jan 2015 08:11:14 +0000 Received: from localhost ([127.0.0.1]:54768 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YEvoH-00072j-Qx for submit@debbugs.gnu.org; Sat, 24 Jan 2015 03:11:14 -0500 Received: from world.peace.net ([50.252.239.5]:50222 ident=hope1) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YEvoE-00072X-9W for 18592@debbugs.gnu.org; Sat, 24 Jan 2015 03:11:11 -0500 Received: from [10.1.10.10] (helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1YEvo7-0002G3-9z; Sat, 24 Jan 2015 03:11:03 -0500 From: Mark H Weaver To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> Date: Sat, 24 Jan 2015 03:08:23 -0500 In-Reply-To: <87h9vmy0zw.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Mon, 19 Jan 2015 21:22:11 +0100") Message-ID: <87twzgeh3c.fsf@yeeloong.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: Chaos Eternal , 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Chaos Eternal skribis: > >> Proposals to solve this bug: >> >> Proposal 1. >> >> Adding a keyword argument to pointer->procedure, if set to true, the >> generated wrapper will check 'errno' immediately after ffi_call and >> return the errno as second value. >> >> the proposed pointer->procedure maybe like this: >> pointer->procedure return_type func_ptr arg_types #:return-errno >> >> Proposal 2. >> >> let pointer->procedure check return_type, if it is a list: >> (func_return_type, 'errno) >> then return multiple values, as errno be second value. > > That=E2=80=99s my favorite because it=E2=80=99s both pragmatic and extens= ible (we can > also add support for h_errno, etc.) We can't do this, because although it's not documented in our manual, a list passed as a foreign type already has a meaning: it means a struct. See 'parse_ffi_type' in foreign.c. I mentioned this fact on guile-user: https://lists.gnu.org/archive/html/guile-user/2012-05/msg00037.html Of the proposals given here, I would support #1, but maybe there's a better option. Thanks, Mark From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 24 03:25:08 2015 Received: (at 18592) by debbugs.gnu.org; 24 Jan 2015 08:25:08 +0000 Received: from localhost ([127.0.0.1]:54776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YEw1j-0007N5-UQ for submit@debbugs.gnu.org; Sat, 24 Jan 2015 03:25:08 -0500 Received: from world.peace.net ([50.252.239.5]:50250 ident=hope1) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YEw1i-0007Mx-63 for 18592@debbugs.gnu.org; Sat, 24 Jan 2015 03:25:06 -0500 Received: from [10.1.10.10] (helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1YEw1b-0002Hi-TW; Sat, 24 Jan 2015 03:24:59 -0500 From: Mark H Weaver To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> Date: Sat, 24 Jan 2015 03:22:15 -0500 In-Reply-To: <87twzgeh3c.fsf@yeeloong.lan> (Mark H. Weaver's message of "Sat, 24 Jan 2015 03:08:23 -0500") Message-ID: <87ppa4egg8.fsf@yeeloong.lan> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: Chaos Eternal , 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Mark H Weaver writes: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Chaos Eternal skribis: >> >>> Proposal 2. >>> >>> let pointer->procedure check return_type, if it is a list: >>> (func_return_type, 'errno) >>> then return multiple values, as errno be second value. >> >> That=E2=80=99s my favorite because it=E2=80=99s both pragmatic and exten= sible (we can >> also add support for h_errno, etc.) > > We can't do this, because although it's not documented in our manual, a > list passed as a foreign type already has a meaning: it means a struct. > See 'parse_ffi_type' in foreign.c. Also see 'fill_ffi_type' in the same file. Mark From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 24 05:33:47 2015 Received: (at 18592) by debbugs.gnu.org; 24 Jan 2015 10:33:47 +0000 Received: from localhost ([127.0.0.1]:54825 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YEy2F-00024W-4m for submit@debbugs.gnu.org; Sat, 24 Jan 2015 05:33:47 -0500 Received: from fencepost.gnu.org ([208.118.235.10]:33282 ident=Debian-exim) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YEy2D-00024P-Ev for 18592@debbugs.gnu.org; Sat, 24 Jan 2015 05:33:45 -0500 Received: from reverse-83.fdn.fr ([80.67.176.83]:49749 helo=pluto) by fencepost.gnu.org with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1YEy2C-0005kJ-L4; Sat, 24 Jan 2015 05:33:45 -0500 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Mark H Weaver Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 5 =?utf-8?Q?Pluvi=C3=B4se?= an 223 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu Date: Sat, 24 Jan 2015 11:33:42 +0100 In-Reply-To: <87twzgeh3c.fsf@yeeloong.lan> (Mark H. Weaver's message of "Sat, 24 Jan 2015 03:08:23 -0500") Message-ID: <87r3uko4c9.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 18592 Cc: Chaos Eternal , 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Chaos Eternal skribis: >> >>> Proposals to solve this bug: >>> >>> Proposal 1. >>> >>> Adding a keyword argument to pointer->procedure, if set to true, the >>> generated wrapper will check 'errno' immediately after ffi_call and >>> return the errno as second value. >>> >>> the proposed pointer->procedure maybe like this: >>> pointer->procedure return_type func_ptr arg_types #:return-errno >>> >>> Proposal 2. >>> >>> let pointer->procedure check return_type, if it is a list: >>> (func_return_type, 'errno) >>> then return multiple values, as errno be second value. >> >> That=E2=80=99s my favorite because it=E2=80=99s both pragmatic and exten= sible (we can >> also add support for h_errno, etc.) > > We can't do this, because although it's not documented in our manual, a > list passed as a foreign type already has a meaning: it means a struct. > See 'parse_ffi_type' in foreign.c. I mentioned this fact on guile-user: > > https://lists.gnu.org/archive/html/guile-user/2012-05/msg00037.html Indeed, I had forgotten that. > Of the proposals given here, I would support #1, but maybe there's a > better option. I agree #1 is now the best option so far. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 25 20:06:41 2015 Received: (at 18592) by debbugs.gnu.org; 26 Jan 2015 01:06:41 +0000 Received: from localhost ([127.0.0.1]:56376 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YFY8W-0006h7-Da for submit@debbugs.gnu.org; Sun, 25 Jan 2015 20:06:41 -0500 Received: from app.discard.email ([37.120.161.148]:37283) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YFUHN-0000BT-W5 for 18592@debbugs.gnu.org; Sun, 25 Jan 2015 15:59:34 -0500 Received: by app.discard.email (Postfix, from userid 33) id AEF6DE1A3D; Sun, 25 Jan 2015 21:59:32 +0100 (CET) To: 18592@debbugs.gnu.org Subject: =?UTF-8?Q?Re:_FFI_should_have_portable_access_to_=E2=80=98errno=E2=80=99?= X-PHP-Originating-Script: 0:PHPMailer.class.php Date: Sun, 25 Jan 2015 21:59:32 +0100 From: "guile@discard.email" Message-ID: <486f6ad7a668e9afc56fd0f101a171d8@discard.email> X-Priority: 3 X-Mailer: PHPMailer 5.2.9 (https://github.com/PHPMailer/PHPMailer/) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="b1_486f6ad7a668e9afc56fd0f101a171d8" X-Spam-Score: 3.0 (+++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: I'd like to point out that when calling a function that might set errno in C, it's usually good practice to set errno to zero immediately before the call, so as to be sure that any subsequent non-zero errno value was actually a consequence of the function call: Â errno = 0; /* clear errno before the function call */ rtnval = my_func(...); if (errno != 0) {...} Â This should probably be taken into account if you're extending the FFI to provide access to errno. [...] Content analysis details: (3.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 3.0 BAD_MAILER X-Mailer is often used for spam -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 HTML_MESSAGE BODY: HTML included in message X-Debbugs-Envelope-To: 18592 X-Mailman-Approved-At: Sun, 25 Jan 2015 20:06:38 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: guile@discard.email List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 3.0 (+++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: I'd like to point out that when calling a function that might set errno in C, it's usually good practice to set errno to zero immediately before the call, so as to be sure that any subsequent non-zero errno value was actually a consequence of the function call: Â errno = 0; /* clear errno before the function call */ rtnval = my_func(...); if (errno != 0) {...} Â This should probably be taken into account if you're extending the FFI to provide access to errno. [...] Content analysis details: (3.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 3.0 BAD_MAILER X-Mailer is often used for spam -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 HTML_MESSAGE BODY: HTML included in message --b1_486f6ad7a668e9afc56fd0f101a171d8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I'd like to point out that when calling a function that might set errno in = C, it's usually good practice to set errno to zero immediately before the call= , so as to be sure that any subsequent non-zero errno value was actually a consequence of the function call: =C2=A0 errno =3D 0; /* clear errno before the function call */ rtnval =3D my_func(...); if (errno !=3D 0) {...} =C2=A0 This should probably be taken into account if you're extending the FFI to provide access to errno. --b1_486f6ad7a668e9afc56fd0f101a171d8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

I'd like to point out that when calling a function that might set errno = in C,

it's usually good practice to set errno to zero immediately before the c= all,

so as to be sure that any subsequent non-zero errno value was actually

a consequence of the function call:

 

errno =3D 0; /* clear errno before the function call */

rtnval =3D my_func(...);

if (errno !=3D 0) {...}

 

This should probably be taken into account if you're extending

the FFI to provide access to errno.

--b1_486f6ad7a668e9afc56fd0f101a171d8-- From debbugs-submit-bounces@debbugs.gnu.org Thu Dec 31 07:34:00 2015 Received: (at 18592) by debbugs.gnu.org; 31 Dec 2015 12:34:00 +0000 Received: from localhost ([127.0.0.1]:50986 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aEcQZ-0005wW-On for submit@debbugs.gnu.org; Thu, 31 Dec 2015 07:34:00 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:34161) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aEcQY-0005wJ-JL for 18592@debbugs.gnu.org; Thu, 31 Dec 2015 07:33:59 -0500 Received: by mail-pa0-f47.google.com with SMTP id uo6so130595807pac.1 for <18592@debbugs.gnu.org>; Thu, 31 Dec 2015 04:33:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version; bh=sUZqaTMuZwxvJGmQqs2+HiVRc7XUUoWMlXpk4OrNU3U=; b=oh8hyyEoTc2nzONNJ8UAU17uZ7JtlkiPbR5GneDF3d36Ga72YYx+FbIczdtUjPdrF0 ffv66GFPlaqsiAJNTtTW7dsCBnFgM+nPKn4cOt0zRyoCfIcnmfXeD5xgRrUtHjDPJUMV eWsKcAtwZgDXwkwCumcozMFNecIj3MvwS90KX5Mu8npeK1/oDKqmt3AYanUJjjcNk0kO JPX4RJ1LDzCo1VNvjAXM/27cBSOpfz07XqrQrUIeiiHqM+kbcM8CTU6gJb8yrNjlhlQM RTwyFbBkPBAshFA2xrdY5Nwdij/GJqd5iIeLkhJHQqHuTKkbTE9dx61HOQO6V8EP/9zF Iwtg== X-Received: by 10.66.237.102 with SMTP id vb6mr100182792pac.133.1451565232630; Thu, 31 Dec 2015 04:33:52 -0800 (PST) Received: from [147.2.147.24] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id 71sm7358530pfh.4.2015.12.31.04.33.50 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 31 Dec 2015 04:33:51 -0800 (PST) Message-ID: <1451565229.3594.59.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Ludovic =?ISO-8859-1?Q?Court=E8s?= Date: Thu, 31 Dec 2015 20:33:49 +0800 In-Reply-To: <87r3uko4c9.fsf@gnu.org> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> Organization: HFG Content-Type: multipart/mixed; boundary="=-1VEnwe9Z1mpPAHI9svww" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: Mark H Weaver , Chaos Eternal , 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --=-1VEnwe9Z1mpPAHI9svww Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Hi folks! Here're patches (based on stable-2.0) to fix this issue according to proposal 1. Please review them, I'm going to write a new CFFI parser with nyacc, so these patches is important for this plan. Thanks! On Sat, 2015-01-24 at 11:33 +0100, Ludovic Courtès wrote: > Mark H Weaver skribis: > > > ludo@gnu.org (Ludovic Courtès) writes: > > > >> Chaos Eternal skribis: > >> > >>> Proposals to solve this bug: > >>> > >>> Proposal 1. > >>> > >>> Adding a keyword argument to pointer->procedure, if set to true, the > >>> generated wrapper will check 'errno' immediately after ffi_call and > >>> return the errno as second value. > >>> > >>> the proposed pointer->procedure maybe like this: > >>> pointer->procedure return_type func_ptr arg_types #:return-errno > I agree #1 is now the best option so far. > > Ludo’. --=-1VEnwe9Z1mpPAHI9svww Content-Disposition: attachment; filename*0=0001-Add-option-to-pointer-procedure-to-return-errno-if-n.pat; filename*1=ch Content-Type: text/x-patch; name="0001-Add-option-to-pointer-procedure-to-return-errno-if-n.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 88a99af4b5db9096c3cde51c72eb371b6be76754 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Thu, 31 Dec 2015 20:27:59 +0800 Subject: [PATCH 1/2] Add option to pointer->procedure to return errno if necessary --- libguile/foreign.c | 33 ++++++++++++++++++++++++--------- libguile/foreign.h | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libguile/foreign.c b/libguile/foreign.c index 29cfc73..6909023 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -85,7 +85,7 @@ null_pointer_error (const char *func_name) } -static SCM cif_to_procedure (SCM cif, SCM func_ptr); +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); static SCM pointer_weak_refs = SCM_BOOL_F; @@ -753,24 +753,29 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) } #undef FUNC_NAME -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, - (SCM return_type, SCM func_ptr, SCM arg_types), +SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 1, 0, + (SCM return_type, SCM func_ptr, SCM arg_types, SCM return_errno), "Make a foreign function.\n\n" "Given the foreign void pointer @var{func_ptr}, its argument and\n" "return types @var{arg_types} and @var{return_type}, return a\n" "procedure that will pass arguments to the foreign function\n" "and return appropriate values.\n\n" "@var{arg_types} should be a list of foreign types.\n" - "@code{return_type} should be a foreign type.") + "@code{return_type} should be a foreign type.\n" + "@var{return_errno} is @code{#f} in default, if set to #t, then\n" + "the @var{errno} will be returned as the second value.") #define FUNC_NAME s_scm_pointer_to_procedure { ffi_cif *cif; SCM_VALIDATE_POINTER (2, func_ptr); + if (SCM_UNLIKELY (SCM_UNBNDP (return_errno))) + return_errno = SCM_BOOL_F; + cif = make_cif (return_type, arg_types, FUNC_NAME); - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, return_errno); } #undef FUNC_NAME @@ -940,7 +945,7 @@ get_objcode_trampoline (unsigned int nargs) } static SCM -cif_to_procedure (SCM cif, SCM func_ptr) +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) { ffi_cif *c_cif; SCM objcode, table, ret; @@ -949,7 +954,8 @@ cif_to_procedure (SCM cif, SCM func_ptr) objcode = get_objcode_trampoline (c_cif->nargs); table = scm_c_make_vector (2, SCM_UNDEFINED); - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); + SCM_SIMPLE_VECTOR_SET (table, 0, + scm_cons (cif, scm_cons (func_ptr, return_errno))); SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ ret = scm_make_program (objcode, table, SCM_BOOL_F); @@ -1116,9 +1122,11 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) unsigned i; size_t arg_size; scm_t_ptrdiff off; + SCM return_errno; cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); + return_errno = SCM_CDDR (foreign); /* Argument pointers. */ args = alloca (sizeof (void *) * cif->nargs); @@ -1153,9 +1161,16 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, max (sizeof (void *), cif->rtype->alignment)); + errno = 0; /* off we go! */ ffi_call (cif, func, rvalue, args); + if (SCM_LIKELY (scm_is_true (return_errno))) + { + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), + scm_from_int (errno))); + } + return pack (cif->rtype, rvalue, 1); } diff --git a/libguile/foreign.h b/libguile/foreign.h index 41c0b65..8541526 100644 --- a/libguile/foreign.h +++ b/libguile/foreign.h @@ -93,7 +93,7 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); */ SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, - SCM arg_types); + SCM arg_types, SCM return_errno); SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, SCM arg_types); SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); -- 1.7.10.4 --=-1VEnwe9Z1mpPAHI9svww Content-Disposition: attachment; filename="0002-updated-pointer-procedure-in-document.patch" Content-Type: text/x-patch; name="0002-updated-pointer-procedure-in-document.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 71151759513f8163e45c328e5bcae8e89ebbf614 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Thu, 31 Dec 2015 20:28:36 +0800 Subject: [PATCH 2/2] updated pointer->procedure in document --- doc/ref/api-foreign.texi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi index c2c49ec..9fd09f5 100644 --- a/doc/ref/api-foreign.texi +++ b/doc/ref/api-foreign.texi @@ -813,8 +813,8 @@ tightly packed structs and unions by hand. See the code for Of course, the land of C is not all nouns and no verbs: there are functions too, and Guile allows you to call them. -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types [return_errno=#f] +@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types, return_errno) Make a foreign function. Given the foreign void pointer @var{func_ptr}, its argument and @@ -825,6 +825,9 @@ and return appropriate values. @var{arg_types} should be a list of foreign types. @code{return_type} should be a foreign type. @xref{Foreign Types}, for more information on foreign types. +@var{return_errno} is @code{#f} in default, if set to @code{#t}, then @var{errno} +will be returned as the second value. + @end deffn Here is a better definition of @code{(math bessel)}: -- 1.7.10.4 --=-1VEnwe9Z1mpPAHI9svww-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 07:04:17 2016 Received: (at 18592) by debbugs.gnu.org; 4 Jan 2016 12:04:17 +0000 Received: from localhost ([127.0.0.1]:37173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aG3s0-000731-SF for submit@debbugs.gnu.org; Mon, 04 Jan 2016 07:04:17 -0500 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33082) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aG3rz-00072o-5h for 18592@debbugs.gnu.org; Mon, 04 Jan 2016 07:04:15 -0500 Received: by mail-pa0-f41.google.com with SMTP id cy9so196622632pac.0 for <18592@debbugs.gnu.org>; Mon, 04 Jan 2016 04:04:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version; bh=AwAMeqVyuRNlphwHr+9Vt+e0N45Cr9SAGwMCIGDL6G4=; b=xxnNyRGMZOONmx6q1w8LWDTwl5N7Rg3kUhxtSWYCKr9f+oS70rZB0WQ4p5YZzyerGQ n60kStCxkz3ZtNl8WxPlrRWZmtqP1c6flNp17+T8YoIfqsa6lLXqeGwFaLr2b/fpeF7k 9wtUa88e5le/uDjrZWMH7VYPDhtPVYM95ete9quAKYy4GtoiH/3kiRMPFYBXlkWIx6Sd UOvsfXE6xlSGhfTwPaaesK9pdObWRLQz5blBodtuU/WVMskIsCbN3+zjMh/TPnirT2kT 4VzveN2fjZxD+MtF4N5N0JBMO0KoRAKWVaZ9Nfn1USMf+wcVRLNeP7YJpuER6grp8uQ8 YEVw== X-Received: by 10.66.235.36 with SMTP id uj4mr45862687pac.85.1451909049362; Mon, 04 Jan 2016 04:04:09 -0800 (PST) Received: from [147.2.147.24] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id dz6sm125890149pab.19.2016.01.04.04.04.07 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 04 Jan 2016 04:04:08 -0800 (PST) Message-ID: <1451909046.3594.135.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Ludovic =?ISO-8859-1?Q?Court=E8s?= Date: Mon, 04 Jan 2016 20:04:06 +0800 In-Reply-To: <1451565229.3594.59.camel@Renee-desktop.suse> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> Organization: HFG Content-Type: multipart/mixed; boundary="=-lBAtszpwkM3ZVmydrCgS" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: Mark H Weaver , Chaos Eternal , 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --=-lBAtszpwkM3ZVmydrCgS Content-Type: text/plain Content-Transfer-Encoding: 7bit Resubmit since errno should be stored after ffi_call. --=-lBAtszpwkM3ZVmydrCgS Content-Disposition: attachment; filename*0=0001-Add-option-to-pointer-procedure-to-return-errno-if-n.pat; filename*1=ch Content-Type: text/x-patch; name="0001-Add-option-to-pointer-procedure-to-return-errno-if-n.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 88a99af4b5db9096c3cde51c72eb371b6be76754 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Thu, 31 Dec 2015 20:27:59 +0800 Subject: [PATCH 1/2] Add option to pointer->procedure to return errno if necessary --- libguile/foreign.c | 33 ++++++++++++++++++++++++--------- libguile/foreign.h | 2 +- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/libguile/foreign.c b/libguile/foreign.c index 29cfc73..6909023 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -85,7 +85,7 @@ null_pointer_error (const char *func_name) } -static SCM cif_to_procedure (SCM cif, SCM func_ptr); +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); static SCM pointer_weak_refs = SCM_BOOL_F; @@ -753,24 +753,29 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) } #undef FUNC_NAME -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, - (SCM return_type, SCM func_ptr, SCM arg_types), +SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 1, 0, + (SCM return_type, SCM func_ptr, SCM arg_types, SCM return_errno), "Make a foreign function.\n\n" "Given the foreign void pointer @var{func_ptr}, its argument and\n" "return types @var{arg_types} and @var{return_type}, return a\n" "procedure that will pass arguments to the foreign function\n" "and return appropriate values.\n\n" "@var{arg_types} should be a list of foreign types.\n" - "@code{return_type} should be a foreign type.") + "@code{return_type} should be a foreign type.\n" + "@var{return_errno} is @code{#f} in default, if set to #t, then\n" + "the @var{errno} will be returned as the second value.") #define FUNC_NAME s_scm_pointer_to_procedure { ffi_cif *cif; SCM_VALIDATE_POINTER (2, func_ptr); + if (SCM_UNLIKELY (SCM_UNBNDP (return_errno))) + return_errno = SCM_BOOL_F; + cif = make_cif (return_type, arg_types, FUNC_NAME); - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, return_errno); } #undef FUNC_NAME @@ -940,7 +945,7 @@ get_objcode_trampoline (unsigned int nargs) } static SCM -cif_to_procedure (SCM cif, SCM func_ptr) +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) { ffi_cif *c_cif; SCM objcode, table, ret; @@ -949,7 +954,8 @@ cif_to_procedure (SCM cif, SCM func_ptr) objcode = get_objcode_trampoline (c_cif->nargs); table = scm_c_make_vector (2, SCM_UNDEFINED); - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); + SCM_SIMPLE_VECTOR_SET (table, 0, + scm_cons (cif, scm_cons (func_ptr, return_errno))); SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ ret = scm_make_program (objcode, table, SCM_BOOL_F); @@ -1116,9 +1122,11 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) unsigned i; size_t arg_size; scm_t_ptrdiff off; + SCM return_errno; cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); + return_errno = SCM_CDDR (foreign); /* Argument pointers. */ args = alloca (sizeof (void *) * cif->nargs); @@ -1153,9 +1161,16 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, max (sizeof (void *), cif->rtype->alignment)); + errno = 0; /* off we go! */ ffi_call (cif, func, rvalue, args); + if (SCM_LIKELY (scm_is_true (return_errno))) + { + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), + scm_from_int (errno))); + } + return pack (cif->rtype, rvalue, 1); } diff --git a/libguile/foreign.h b/libguile/foreign.h index 41c0b65..8541526 100644 --- a/libguile/foreign.h +++ b/libguile/foreign.h @@ -93,7 +93,7 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); */ SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, - SCM arg_types); + SCM arg_types, SCM return_errno); SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, SCM arg_types); SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); -- 1.7.10.4 --=-lBAtszpwkM3ZVmydrCgS Content-Disposition: attachment; filename="0002-updated-pointer-procedure-in-document.patch" Content-Type: text/x-patch; name="0002-updated-pointer-procedure-in-document.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 71151759513f8163e45c328e5bcae8e89ebbf614 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Thu, 31 Dec 2015 20:28:36 +0800 Subject: [PATCH 2/2] updated pointer->procedure in document --- doc/ref/api-foreign.texi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi index c2c49ec..9fd09f5 100644 --- a/doc/ref/api-foreign.texi +++ b/doc/ref/api-foreign.texi @@ -813,8 +813,8 @@ tightly packed structs and unions by hand. See the code for Of course, the land of C is not all nouns and no verbs: there are functions too, and Guile allows you to call them. -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types [return_errno=#f] +@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types, return_errno) Make a foreign function. Given the foreign void pointer @var{func_ptr}, its argument and @@ -825,6 +825,9 @@ and return appropriate values. @var{arg_types} should be a list of foreign types. @code{return_type} should be a foreign type. @xref{Foreign Types}, for more information on foreign types. +@var{return_errno} is @code{#f} in default, if set to @code{#t}, then @var{errno} +will be returned as the second value. + @end deffn Here is a better definition of @code{(math bessel)}: -- 1.7.10.4 --=-lBAtszpwkM3ZVmydrCgS-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 11:12:41 2016 Received: (at 18592) by debbugs.gnu.org; 4 Jan 2016 16:12:41 +0000 Received: from localhost ([127.0.0.1]:37756 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aG7kP-0006P9-74 for submit@debbugs.gnu.org; Mon, 04 Jan 2016 11:12:41 -0500 Received: from world.peace.net ([50.252.239.5]:52609 ident=hope7) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aG7kN-0006P0-Lm for 18592@debbugs.gnu.org; Mon, 04 Jan 2016 11:12:40 -0500 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aG7kC-0002Ii-O2; Mon, 04 Jan 2016 11:12:28 -0500 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> Date: Mon, 04 Jan 2016 11:12:27 -0500 In-Reply-To: <1451909046.3594.135.camel@Renee-desktop.suse> (Nala Ginrut's message of "Mon, 04 Jan 2016 20:04:06 +0800") Message-ID: <8760z9gw7o.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, Ludovic =?utf-8?Q?Court=C3=A8s?= , Chaos Eternal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Hi Nala, Thanks for working on this :) Please see below for comments. Nala Ginrut writes: > From 88a99af4b5db9096c3cde51c72eb371b6be76754 Mon Sep 17 00:00:00 2001 > From: Nala Ginrut > Date: Thu, 31 Dec 2015 20:27:59 +0800 > Subject: [PATCH 1/2] Add option to pointer->procedure to return errno if > necessary > > --- > libguile/foreign.c | 33 ++++++++++++++++++++++++--------- > libguile/foreign.h | 2 +- > 2 files changed, 25 insertions(+), 10 deletions(-) > > diff --git a/libguile/foreign.c b/libguile/foreign.c > index 29cfc73..6909023 100644 > --- a/libguile/foreign.c > +++ b/libguile/foreign.c > @@ -1,4 +1,4 @@ > -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. > +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Lesser General Public License > @@ -85,7 +85,7 @@ null_pointer_error (const char *func_name) > } > > > -static SCM cif_to_procedure (SCM cif, SCM func_ptr); > +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); > > > static SCM pointer_weak_refs = SCM_BOOL_F; > @@ -753,24 +753,29 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) > } > #undef FUNC_NAME > > -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, > - (SCM return_type, SCM func_ptr, SCM arg_types), > +SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 1, 0, > + (SCM return_type, SCM func_ptr, SCM arg_types, SCM return_errno), Is this patch intended for 2.0.x? Unfortunately, we cannot change the signature of a C API function in 2.0.x, because it would change the ABI and thus break any C code compiled against guile-2.0.11 that calls scm_pointer_to_procedure. Also, the proposal that we agreed upon was to add a #:return-errno? keyword argument, not an optional positional argument. We didn't discuss what the C API should look like. We cannot change the signature of 'scm_pointer_to_procedure' in 2.0.x, and I guess it would be better to leave it unchanged in 2.2+ as well, to avoid incompatibilities between C code written for 2.0 vs 2.2. One possibility is to keep 'scm_pointer_to_procedure' as it is, and add a new C API function 'scm_pointer_to_procedure_with_errno' that accepts the same arguments but implies #:return-errno? #t. If we adopt this approach, then this C function defined with SCM_DEFINE, which accepts keyword arguments and corresponds to 'pointer->procedure', will not be part of the public C API and thus not declared in foreign.h. Thoughts? I suggest that you look at commit 3ace9a8e4e, which added keyword arguments to 'open-file' while keeping the API of 'scm_open_file' unchanged. It shows the preferred approach for handling keyword arguments from C. > "Make a foreign function.\n\n" > "Given the foreign void pointer @var{func_ptr}, its argument and\n" > "return types @var{arg_types} and @var{return_type}, return a\n" > "procedure that will pass arguments to the foreign function\n" > "and return appropriate values.\n\n" > "@var{arg_types} should be a list of foreign types.\n" > - "@code{return_type} should be a foreign type.") > + "@code{return_type} should be a foreign type.\n" > + "@var{return_errno} is @code{#f} in default, if set to #t, then\n" > + "the @var{errno} will be returned as the second value.") "If @var{return_errno} is true, then @code{errno} will be returned as a second return value." Also, please use spaces instead of tabs to indent here, for consistency with the existing code. > #define FUNC_NAME s_scm_pointer_to_procedure > { > ffi_cif *cif; > > SCM_VALIDATE_POINTER (2, func_ptr); > > + if (SCM_UNLIKELY (SCM_UNBNDP (return_errno))) > + return_errno = SCM_BOOL_F; > + Please remove SCM_UNLIKELY here. SCM_UNBNDP (return_errno) is not unlikely. > cif = make_cif (return_type, arg_types, FUNC_NAME); > > - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); > + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, return_errno); Please keep lines within 80 columns. > } > #undef FUNC_NAME > > @@ -940,7 +945,7 @@ get_objcode_trampoline (unsigned int nargs) > } > > static SCM > -cif_to_procedure (SCM cif, SCM func_ptr) > +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) > { > ffi_cif *c_cif; > SCM objcode, table, ret; > @@ -949,7 +954,8 @@ cif_to_procedure (SCM cif, SCM func_ptr) > objcode = get_objcode_trampoline (c_cif->nargs); > > table = scm_c_make_vector (2, SCM_UNDEFINED); > - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); > + SCM_SIMPLE_VECTOR_SET (table, 0, > + scm_cons (cif, scm_cons (func_ptr, return_errno))); You could use 'scm_cons2' here: scm_cons2 (cif, func_ptr, return_errno) is equivalent to the code above. Also, before storing 'return_errno', it would be good to convert it to a simple boolean. For example, if a user does this: (pointer->procedure ... #:return-errno? (assoc 'errno options)) then 'return_errno' will be a pair, and in general it could be a large data structure which is simply meant to be interpreted as #t, but it would be wasteful to retain a reference to that object and prevent it from being garbage collected. So, how about putting something like the following code near the beginning of the function? /* Convert 'return_errno' to a simple boolean, to avoid retaining references to non-boolean objects. */ return_errno = scm_from_bool (scm_is_true (return_errno)); > SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ > ret = scm_make_program (objcode, table, SCM_BOOL_F); > > @@ -1116,9 +1122,11 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) > unsigned i; > size_t arg_size; > scm_t_ptrdiff off; > + SCM return_errno; > > cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); > - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); > + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); > + return_errno = SCM_CDDR (foreign); > > /* Argument pointers. */ > args = alloca (sizeof (void *) * cif->nargs); > @@ -1153,9 +1161,16 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) > rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, > max (sizeof (void *), cif->rtype->alignment)); > > + errno = 0; Please do not touch 'errno' unless scm_is_true (return_errno). To avoid testing scm_is_true (return_errno) twice, I would recommend calling 'ffi_call' within both branches of the 'if' statement. > /* off we go! */ > ffi_call (cif, func, rvalue, args); > > + if (SCM_LIKELY (scm_is_true (return_errno))) Please remove SCM_LIKELY. > + { > + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), > + scm_from_int (errno))); Please copy 'errno' to a local variable immediately after the call to 'ffi_call'. In the code above, 'pack' and 'scm_list_2' are called before 'errno' is read. 'scm_list_2' does GC allocation, and thus could trigger a garbage collection which I guess would change 'errno'. 'pack' might also do so. > + } > + > return pack (cif->rtype, rvalue, 1); > } > > diff --git a/libguile/foreign.h b/libguile/foreign.h > index 41c0b65..8541526 100644 > --- a/libguile/foreign.h > +++ b/libguile/foreign.h Please add 2016 to this file's copyright dates. > @@ -93,7 +93,7 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); > */ > > SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, > - SCM arg_types); > + SCM arg_types, SCM return_errno); This will need to be updated to account for the C API issues discussed above. > SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, > SCM arg_types); > SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); > -- > 1.7.10.4 > > > From 71151759513f8163e45c328e5bcae8e89ebbf614 Mon Sep 17 00:00:00 2001 > From: Nala Ginrut > Date: Thu, 31 Dec 2015 20:28:36 +0800 > Subject: [PATCH 2/2] updated pointer->procedure in document > > --- > doc/ref/api-foreign.texi | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi > index c2c49ec..9fd09f5 100644 > --- a/doc/ref/api-foreign.texi > +++ b/doc/ref/api-foreign.texi > @@ -813,8 +813,8 @@ tightly packed structs and unions by hand. See the code for > Of course, the land of C is not all nouns and no verbs: there are > functions too, and Guile allows you to call them. > > -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types > -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) > +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types [return_errno=#f] > +@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types, return_errno) This will also need to be updated to account for the C API issues discussed above. > Make a foreign function. > > Given the foreign void pointer @var{func_ptr}, its argument and > @@ -825,6 +825,9 @@ and return appropriate values. > @var{arg_types} should be a list of foreign types. > @code{return_type} should be a foreign type. @xref{Foreign Types}, for > more information on foreign types. > +@var{return_errno} is @code{#f} in default, if set to @code{#t}, then @var{errno} > +will be returned as the second value. If @var{return_errno} is true, then @code{errno} will be returned as the second return value. > + > @end deffn > > Here is a better definition of @code{(math bessel)}: Thanks! Mark From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 11:21:27 2016 Received: (at 18592) by debbugs.gnu.org; 4 Jan 2016 16:21:27 +0000 Received: from localhost ([127.0.0.1]:37769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aG7st-0006d9-Mc for submit@debbugs.gnu.org; Mon, 04 Jan 2016 11:21:27 -0500 Received: from world.peace.net ([50.252.239.5]:52616 ident=hope8) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aG7sr-0006d1-J1 for 18592@debbugs.gnu.org; Mon, 04 Jan 2016 11:21:25 -0500 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aG7sm-0002Kc-5u; Mon, 04 Jan 2016 11:21:20 -0500 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> Date: Mon, 04 Jan 2016 11:21:18 -0500 In-Reply-To: <1451909046.3594.135.camel@Renee-desktop.suse> (Nala Ginrut's message of "Mon, 04 Jan 2016 20:04:06 +0800") Message-ID: <871t9xgvsx.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, Ludovic =?utf-8?Q?Court=C3=A8s?= , Chaos Eternal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) One more thing I forgot to mention: These two commits should be combined into a single commit. Thanks! Mark From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 14:14:47 2016 Received: (at 18592) by debbugs.gnu.org; 4 Jan 2016 19:14:47 +0000 Received: from localhost ([127.0.0.1]:37863 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGAac-0002Pe-JM for submit@debbugs.gnu.org; Mon, 04 Jan 2016 14:14:47 -0500 Received: from mail-pa0-f66.google.com ([209.85.220.66]:34952) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGAaZ-0002PQ-Ub for 18592@debbugs.gnu.org; Mon, 04 Jan 2016 14:14:44 -0500 Received: by mail-pa0-f66.google.com with SMTP id gi1so22820656pac.2 for <18592@debbugs.gnu.org>; Mon, 04 Jan 2016 11:14:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version; bh=2JDB1Rz54jdHPorhsi7p9FGmhpnB+zFkDs8sVVLMNNg=; b=jyQt2DsJVkdxJHRJj7SIAmUlFDmD+FT8vhjlZw5T040ZQlLWywWRR1DexzJjkn3NBP jeG1dnFIoXAGE9kGhAUqg/3OOcBuQyv9gtcEqfrH7BeUoWJvkmKTyzFWYrsvZgu39R1Z Vh4YQbZc1jMvIO9TMGhGw0wHNjvOS65ZgyO9KQhqRM0L2UzPAXTEXbrbtMvF63lJjlu2 T4/aov0FVs1tuDjRZZmSq7o022oMN4bM2CVUoFzSu5MvArmI4ash6ksWa+Mf3IzVw/Ka 9KF+9CtkkaWzRKgaZRWyV0fNrDw4AwFUFBfBtcDfWlWp1932llrQwnXucNO1czRw+no1 aSTw== X-Received: by 10.66.164.70 with SMTP id yo6mr128988005pab.36.1451934878221; Mon, 04 Jan 2016 11:14:38 -0800 (PST) Received: from [127.0.0.1] (li88-185.members.linode.com. [74.207.246.185]) by smtp.gmail.com with ESMTPSA id v16sm68887855pfa.49.2016.01.04.11.14.34 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 04 Jan 2016 11:14:37 -0800 (PST) Message-ID: <1451934872.3594.150.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Mark H Weaver Date: Tue, 05 Jan 2016 03:14:32 +0800 In-Reply-To: <8760z9gw7o.fsf@netris.org> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> Organization: HFG Content-Type: multipart/mixed; boundary="=-wDd7srkmZIS3ETp3klHQ" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, Ludovic =?ISO-8859-1?Q?Court=E8s?= , Chaos Eternal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --=-wDd7srkmZIS3ETp3klHQ Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Hi Mark! Thanks for all the advices. Here's the new patch according to your advices. Include: 1. Added new procedure pointer->procedure-with-errno with #:return-errno? Question: Should we make #:return-errno? true in default? This would make the name *-with-errno more reasonable. At present, it's false in default. 2. Used scm_cons2 3. Store errno to a local var after ffi_call immediately. 4. Set errno=0 only when #:return-errno? is true. 5. Merged all modifications into one patch. Comments please. Best regards. --=-wDd7srkmZIS3ETp3klHQ Content-Disposition: attachment; filename*0=0001-Added-new-function-pointer-procedure-with-errno-to-r.pat; filename*1=ch Content-Type: text/x-patch; name="0001-Added-new-function-pointer-procedure-with-errno-to-r.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 500b8b1f5079a56e3cd5c0a8386b3f880f396e01 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Tue, 5 Jan 2016 03:04:47 +0800 Subject: [PATCH] Added new function pointer->procedure-with-errno to return errno properly * doc/ref/api-foreign.texi (Dynamic FFI): Update documentation. * libguile/foreign.c (scm_pointer_to_procedure_with_errno): New API function to return errno properly after calling foreign function. (cif_to_procedure): Support return_errno option. * libguile/foreign.h (scm_pointer_to_procedure_with_errno): Add prototypes. * module/system/foreign.scm: Export pointer->procedure-with-errno. --- doc/ref/api-foreign.texi | 17 +++++ libguile/foreign.c | 168 +++++++++++++++++++++++++++++---------------- libguile/foreign.h | 8 ++- module/system/foreign.scm | 1 + 4 files changed, 132 insertions(+), 62 deletions(-) diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi index c2c49ec..a7e9fc1 100644 --- a/doc/ref/api-foreign.texi +++ b/doc/ref/api-foreign.texi @@ -827,6 +827,23 @@ and return appropriate values. more information on foreign types. @end deffn +@deffn {Scheme Procedure} pointer->procedure-with-errno return_type func_ptr arg_types @ + [#:return-errno?=#f] +@deffnx {C Procedure} scm_pointer_to_procedure_with_errno (return_type, func_ptr, @ + keyword_args) +Make a foreign function with errno. + +Given the foreign void pointer @var{func_ptr}, its argument and +return types @var{arg_types} and @var{return_type}, return a +procedure that will pass arguments to the foreign function +and return appropriate values. If @var{#:return-errno?} is true, then @code{errno} will be +returned as the second return value. + +@var{arg_types} should be a list of foreign types. +@code{return_type} should be a foreign type. @xref{Foreign Types}, for +more information on foreign types. +@end deffn + Here is a better definition of @code{(math bessel)}: @example diff --git a/libguile/foreign.c b/libguile/foreign.c index 29cfc73..137c34d 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -81,11 +81,11 @@ static void null_pointer_error (const char *func_name) { scm_error (sym_null_pointer_error, func_name, - "null pointer dereference", SCM_EOL, SCM_EOL); + "null pointer dereference", SCM_EOL, SCM_EOL); } -static SCM cif_to_procedure (SCM cif, SCM func_ptr); +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); static SCM pointer_weak_refs = SCM_BOOL_F; @@ -108,9 +108,9 @@ pointer_finalizer_trampoline (void *ptr, void *data) } SCM_DEFINE (scm_pointer_p, "pointer?", 1, 0, 0, - (SCM obj), - "Return @code{#t} if @var{obj} is a pointer object, " - "@code{#f} otherwise.\n") + (SCM obj), + "Return @code{#t} if @var{obj} is a pointer object, " + "@code{#f} otherwise.\n") #define FUNC_NAME s_scm_pointer_p { return scm_from_bool (SCM_POINTER_P (obj)); @@ -118,11 +118,11 @@ SCM_DEFINE (scm_pointer_p, "pointer?", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_make_pointer, "make-pointer", 1, 1, 0, - (SCM address, SCM finalizer), - "Return a foreign pointer object pointing to @var{address}. " - "If @var{finalizer} is passed, it should be a pointer to a " - "one-argument C function that will be called when the pointer " - "object becomes unreachable.") + (SCM address, SCM finalizer), + "Return a foreign pointer object pointing to @var{address}. " + "If @var{finalizer} is passed, it should be a pointer to a " + "one-argument C function that will be called when the pointer " + "object becomes unreachable.") #define FUNC_NAME s_scm_make_pointer { void *c_finalizer; @@ -170,8 +170,8 @@ scm_from_pointer (void *ptr, scm_t_pointer_finalizer finalizer) } SCM_DEFINE (scm_pointer_address, "pointer-address", 1, 0, 0, - (SCM pointer), - "Return the numerical value of @var{pointer}.") + (SCM pointer), + "Return the numerical value of @var{pointer}.") #define FUNC_NAME s_scm_pointer_address { SCM_VALIDATE_POINTER (1, pointer); @@ -181,9 +181,9 @@ SCM_DEFINE (scm_pointer_address, "pointer-address", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_pointer_to_scm, "pointer->scm", 1, 0, 0, - (SCM pointer), - "Unsafely cast @var{pointer} to a Scheme object.\n" - "Cross your fingers!") + (SCM pointer), + "Unsafely cast @var{pointer} to a Scheme object.\n" + "Cross your fingers!") #define FUNC_NAME s_scm_pointer_to_scm { SCM_VALIDATE_POINTER (1, pointer); @@ -193,8 +193,8 @@ SCM_DEFINE (scm_pointer_to_scm, "pointer->scm", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_scm_to_pointer, "scm->pointer", 1, 0, 0, - (SCM scm), - "Return a foreign pointer object with the @code{object-address}\n" + (SCM scm), + "Return a foreign pointer object with the @code{object-address}\n" "of @var{scm}.") #define FUNC_NAME s_scm_scm_to_pointer { @@ -209,18 +209,18 @@ SCM_DEFINE (scm_scm_to_pointer, "scm->pointer", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_pointer_to_bytevector, "pointer->bytevector", 2, 2, 0, - (SCM pointer, SCM len, SCM offset, SCM uvec_type), - "Return a bytevector aliasing the @var{len} bytes pointed\n" - "to by @var{pointer}.\n\n" + (SCM pointer, SCM len, SCM offset, SCM uvec_type), + "Return a bytevector aliasing the @var{len} bytes pointed\n" + "to by @var{pointer}.\n\n" "The user may specify an alternate default interpretation for\n" "the memory by passing the @var{uvec_type} argument, to indicate\n" "that the memory is an array of elements of that type.\n" "@var{uvec_type} should be something that\n" "@code{uniform-vector-element-type} would return, like @code{f32}\n" "or @code{s16}.\n\n" - "When @var{offset} is passed, it specifies the offset in bytes\n" - "relative to @var{pointer} of the memory region aliased by the\n" - "returned bytevector.") + "When @var{offset} is passed, it specifies the offset in bytes\n" + "relative to @var{pointer} of the memory region aliased by the\n" + "returned bytevector.") #define FUNC_NAME s_scm_pointer_to_bytevector { SCM ret; @@ -273,17 +273,17 @@ SCM_DEFINE (scm_pointer_to_bytevector, "pointer->bytevector", 2, 2, 0, blen = scm_to_size_t (len); ret = scm_c_take_typed_bytevector ((signed char *) ptr + boffset, - blen, btype); + blen, btype); register_weak_reference (ret, pointer); return ret; } #undef FUNC_NAME SCM_DEFINE (scm_bytevector_to_pointer, "bytevector->pointer", 1, 1, 0, - (SCM bv, SCM offset), - "Return a pointer pointer aliasing the memory pointed to by\n" + (SCM bv, SCM offset), + "Return a pointer pointer aliasing the memory pointed to by\n" "@var{bv} or @var{offset} bytes after @var{bv} when @var{offset}\n" - "is passed.") + "is passed.") #define FUNC_NAME s_scm_bytevector_to_pointer { SCM ret; @@ -337,9 +337,9 @@ scm_i_pointer_print (SCM pointer, SCM port, scm_print_state *pstate) (heap allocation overhead, Scheme/C round trips, etc.) */ SCM_DEFINE (scm_dereference_pointer, "dereference-pointer", 1, 0, 0, - (SCM pointer), - "Assuming @var{pointer} points to a memory region that\n" - "holds a pointer, return this pointer.") + (SCM pointer), + "Assuming @var{pointer} points to a memory region that\n" + "holds a pointer, return this pointer.") #define FUNC_NAME s_scm_dereference_pointer { void **ptr; @@ -355,9 +355,9 @@ SCM_DEFINE (scm_dereference_pointer, "dereference-pointer", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_string_to_pointer, "string->pointer", 1, 1, 0, - (SCM string, SCM encoding), - "Return a foreign pointer to a nul-terminated copy of\n" - "@var{string} in the given @var{encoding}, defaulting to\n" + (SCM string, SCM encoding), + "Return a foreign pointer to a nul-terminated copy of\n" + "@var{string} in the given @var{encoding}, defaulting to\n" "the current locale encoding. The C string is freed when\n" "the returned foreign pointer becomes unreachable.\n\n" "This is the Scheme equivalent of @code{scm_to_stringn}.") @@ -394,14 +394,14 @@ SCM_DEFINE (scm_string_to_pointer, "string->pointer", 1, 1, 0, #undef FUNC_NAME SCM_DEFINE (scm_pointer_to_string, "pointer->string", 1, 2, 0, - (SCM pointer, SCM length, SCM encoding), - "Return the string representing the C string pointed to by\n" + (SCM pointer, SCM length, SCM encoding), + "Return the string representing the C string pointed to by\n" "@var{pointer}. If @var{length} is omitted or @code{-1}, the\n" "string is assumed to be nul-terminated. Otherwise\n" "@var{length} is the number of bytes in memory pointed to by\n" "@var{pointer}. The C string is assumed to be in the given\n" "@var{encoding}, defaulting to the current locale encoding.\n\n" - "This is the Scheme equivalent of @code{scm_from_stringn}.") + "This is the Scheme equivalent of @code{scm_from_stringn}.") #define FUNC_NAME s_scm_pointer_to_string { size_t len; @@ -482,19 +482,19 @@ SCM_DEFINE (scm_alignof, "alignof", 1, 0, 0, (SCM type), else if (scm_is_pair (type)) { /* TYPE is a structure. Section 3-3 of the i386, x86_64, PowerPC, - and SPARC P.S. of the System V ABI all say: "Aggregates - (structures and arrays) and unions assume the alignment of - their most strictly aligned component." */ + and SPARC P.S. of the System V ABI all say: "Aggregates + (structures and arrays) and unions assume the alignment of + their most strictly aligned component." */ size_t max; for (max = 0; scm_is_pair (type); type = SCM_CDR (type)) - { - size_t align; + { + size_t align; - align = scm_to_size_t (scm_alignof (SCM_CAR (type))); - if (align > max) - max = align; - } + align = scm_to_size_t (scm_alignof (SCM_CAR (type))); + if (align > max) + max = align; + } return scm_from_size_t (max); } @@ -708,12 +708,12 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) /* then ffi_type pointers: one for each arg, one for each struct element, and one for each struct (for null-termination) */ cif_len = (ROUND_UP (cif_len, alignof_type (void *)) - + (nargs + n_structs + n_struct_elts)*sizeof(void*)); + + (nargs + n_structs + n_struct_elts)*sizeof(void*)); /* then the ffi_type structs themselves, one per arg and struct element, and one for the return val */ cif_len = (ROUND_UP (cif_len, alignof_type (ffi_type)) - + (nargs + n_struct_elts + 1)*sizeof(ffi_type)); + + (nargs + n_struct_elts + 1)*sizeof(ffi_type)); mem = scm_gc_malloc_pointerless (cif_len, "foreign"); /* ensure all the memory is initialized, even the holes */ @@ -724,8 +724,8 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) cif_len = ROUND_UP (sizeof (ffi_cif), alignof_type (void *)); type_ptrs = (ffi_type**)(mem + cif_len); cif_len = ROUND_UP (cif_len - + (nargs + n_structs + n_struct_elts)*sizeof(void*), - alignof_type (ffi_type)); + + (nargs + n_structs + n_struct_elts)*sizeof(void*), + alignof_type (ffi_type)); types = (ffi_type*)(mem + cif_len); /* whew. now knit the pointers together. */ @@ -746,7 +746,7 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) cif->flags = 0; if (FFI_OK != ffi_prep_cif (cif, FFI_DEFAULT_ABI, cif->nargs, cif->rtype, - cif->arg_types)) + cif->arg_types)) SCM_MISC_ERROR ("ffi_prep_cif failed", SCM_EOL); return cif; @@ -770,7 +770,39 @@ SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, cif = make_cif (return_type, arg_types, FUNC_NAME); - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, SCM_BOOL_F); +} +#undef FUNC_NAME + +SCM_KEYWORD (k_return_errno, "return-errno?"); + +SCM_DEFINE (scm_pointer_to_procedure_with_errno, + "pointer->procedure-with-errno", 3, 0, 1, + (SCM return_type, SCM func_ptr, SCM arg_types, SCM keyword_args), + "Make a foreign function.\n\n" + "Given the foreign void pointer @var{func_ptr}, its argument and\n" + "return types @var{arg_types} and @var{return_type}, return a\n" + "procedure that will pass arguments to the foreign function\n" + "and return appropriate values.\n\n" + "@var{arg_types} should be a list of foreign types.\n" + "@code{return_type} should be a foreign type.\n" + "If @var{#:return-errno?} is true, then the @var{errno} will be\n" + "returned as the second value.") +#define FUNC_NAME s_scm_pointer_to_procedure_with_errno +{ + ffi_cif *cif; + SCM return_errno = SCM_BOOL_F; + + SCM_VALIDATE_POINTER (2, func_ptr); + + scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0, + k_return_errno, &return_errno, + SCM_UNDEFINED); + + cif = make_cif (return_type, arg_types, FUNC_NAME); + + return cif_to_procedure (scm_from_pointer (cif, NULL), + func_ptr, return_errno); } #undef FUNC_NAME @@ -940,16 +972,20 @@ get_objcode_trampoline (unsigned int nargs) } static SCM -cif_to_procedure (SCM cif, SCM func_ptr) +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) { ffi_cif *c_cif; SCM objcode, table, ret; + /* Convert 'return_errno' to a simple boolean, to avoid retaining + references to non-boolean objects. */ + return_errno = scm_from_bool (scm_is_true (return_errno)); + c_cif = (ffi_cif *) SCM_POINTER_VALUE (cif); objcode = get_objcode_trampoline (c_cif->nargs); table = scm_c_make_vector (2, SCM_UNDEFINED); - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); + SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons2 (cif, func_ptr, return_errno)); SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ ret = scm_make_program (objcode, table, SCM_BOOL_F); @@ -1116,9 +1152,12 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) unsigned i; size_t arg_size; scm_t_ptrdiff off; + SCM return_errno; + int reterr; cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); + return_errno = SCM_CDDR (foreign); /* Argument pointers. */ args = alloca (sizeof (void *) * cif->nargs); @@ -1153,10 +1192,21 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, max (sizeof (void *), cif->rtype->alignment)); - /* off we go! */ - ffi_call (cif, func, rvalue, args); - - return pack (cif->rtype, rvalue, 1); + if (scm_is_true (return_errno)) + { + errno = 0; + /* off we go! */ + ffi_call (cif, func, rvalue, args); + reterr = errno; + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), + scm_from_int (reterr))); + } + else + { + /* off we go! */ + ffi_call (cif, func, rvalue, args); + return pack (cif->rtype, rvalue, 1); + } } diff --git a/libguile/foreign.h b/libguile/foreign.h index 41c0b65..060bd24 100644 --- a/libguile/foreign.h +++ b/libguile/foreign.h @@ -1,7 +1,7 @@ #ifndef SCM_FOREIGN_H #define SCM_FOREIGN_H -/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. +/* Copyright (C) 2010, 2011, 2012, 2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -93,9 +93,11 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); */ SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, - SCM arg_types); + SCM arg_types); +SCM_API SCM scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, + SCM arg_types, SCM keyword_args); SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, - SCM arg_types); + SCM arg_types); SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); diff --git a/module/system/foreign.scm b/module/system/foreign.scm index 55ab014..4436f1f 100644 --- a/module/system/foreign.scm +++ b/module/system/foreign.scm @@ -50,6 +50,7 @@ pointer->string pointer->procedure + pointer->procedure-with-errno ;; procedure->pointer (see below) make-c-struct parse-c-struct -- 1.7.10.4 --=-wDd7srkmZIS3ETp3klHQ-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jan 04 21:24:42 2016 Received: (at 18592) by debbugs.gnu.org; 5 Jan 2016 02:24:42 +0000 Received: from localhost ([127.0.0.1]:37998 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGHIg-0005e3-G7 for submit@debbugs.gnu.org; Mon, 04 Jan 2016 21:24:42 -0500 Received: from mail-io0-f178.google.com ([209.85.223.178]:34351) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGHIf-0005dq-Fe for 18592@debbugs.gnu.org; Mon, 04 Jan 2016 21:24:41 -0500 Received: by mail-io0-f178.google.com with SMTP id 1so127347481ion.1 for <18592@debbugs.gnu.org>; Mon, 04 Jan 2016 18:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shlug-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=obCIXb+9fMzE0xjGLvJ3A+toStcIfcFWi32Raut5OIs=; b=scYOI0cqoq3na/orR8lO0mEERQU72vI5ULFTRk6hd1/RBVuoTS3QbE9RrehWiyxzW9 AZpCXUtlvnu4mezEkkd8dn616bcjjAUKeKvd2xkc9u/cUBULlILzknT9t7rKAhnAWY6p uWJOBmcAPI1JXowJyM+I0QfphZpIQI5KtTr4b+iV9C9+Ax9n6gpXqxBQDkDFGRKhZZk8 AUWveaXc8tTDjtmD+7xLKX3rbwhRYrhhsLkUsWZJjSPNTdbNHbS5ZGD4+VECHUDjaeqi BmXUbx+pIC7NFLDibrYQ0z2TugW0119bpuWPxMCddWaQuxJdM9pOFOC70Jk68sRbF919 hbDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=obCIXb+9fMzE0xjGLvJ3A+toStcIfcFWi32Raut5OIs=; b=RHzTy6xLbNpNr9eplkT6j9RxPmJDjp8QhfsWet8KISTl3N0RionB618z7hQJyKmLZ6 qI1AJ3Iy2uHH5zOPgD3GqQNmJWK7FK13PGBp7hGLDnXQPo92OOhsifEPiPkCS4GjjMQi LC0AQVL5585gDzMUiLk1d1cIlhbyAGWQ6bdMMdKbuB9XjsCnTk/f5g15h38uIleSocbn ZOkT8awSRo1vFjhzYhogjC8T7zS297E3VuSiXUtbdprUDEBm+jWK6c0MqfdMpTfcjr4W OFUnJNxLKs/SOxXiiT2Fx3hjcb6T6Xmtzm/GYtUAVcsrcqNw4NuWSRjSf9AsMKhOe3fz ARog== X-Gm-Message-State: ALoCoQkkSf9bpWFOYXx/1E4ath1TRf3uM4CIgz2wDfVzG9snfKRmbeSJ54zC1WHkeg+GnBDsVfLkMPZnLS4NTu49S6c8Nuqm0w== MIME-Version: 1.0 X-Received: by 10.107.164.145 with SMTP id d17mr71397220ioj.162.1451960675849; Mon, 04 Jan 2016 18:24:35 -0800 (PST) Received: by 10.64.148.72 with HTTP; Mon, 4 Jan 2016 18:24:35 -0800 (PST) In-Reply-To: <1451934872.3594.150.camel@Renee-desktop.suse> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> Date: Tue, 5 Jan 2016 10:24:35 +0800 Message-ID: Subject: =?UTF-8?Q?Re=3A_bug=2318592=3A_FFI_should_have_portable_access_to_?= =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Chaos Eternal To: Nala Ginrut Content-Type: text/plain; charset=UTF-8 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: Mark H Weaver , =?UTF-8?Q?Ludovic_Court=C3=A8s?= , 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On Tue, Jan 5, 2016 at 3:14 AM, Nala Ginrut wrote: > Hi Mark! > Thanks for all the advices. > > Here's the new patch according to your advices. > Include: > 1. Added new procedure pointer->procedure-with-errno with > #:return-errno? > > Question: Should we make #:return-errno? true in default? This would > make the name *-with-errno more reasonable. At present, it's false in > default. > I suggest that if we have this new procedure, we don't need keyword option "#:return-errno?" since the procedure name itself implies it. Also if old behavior is needed, the old procedure pointer->procedure still can be employed. > 2. Used scm_cons2 > > 3. Store errno to a local var after ffi_call immediately. > > 4. Set errno=0 only when #:return-errno? is true. > > 5. Merged all modifications into one patch. > > Comments please. > > Best regards. > From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 03:24:21 2016 Received: (at submit) by debbugs.gnu.org; 5 Jan 2016 08:24:21 +0000 Received: from localhost ([127.0.0.1]:38098 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGMuj-0000rh-Ho for submit@debbugs.gnu.org; Tue, 05 Jan 2016 03:24:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50706) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGMuh-0000rU-Ab for submit@debbugs.gnu.org; Tue, 05 Jan 2016 03:24:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGMub-0000bk-6m for submit@debbugs.gnu.org; Tue, 05 Jan 2016 03:24:14 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:38463) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGMub-0000bg-3P for submit@debbugs.gnu.org; Tue, 05 Jan 2016 03:24:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGMua-0001eR-1T for bug-guile@gnu.org; Tue, 05 Jan 2016 03:24:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGMuW-0000bN-SL for bug-guile@gnu.org; Tue, 05 Jan 2016 03:24:11 -0500 Received: from mail.tuxteam.de ([5.199.139.25]:45631 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGMuW-0000bI-Lu for bug-guile@gnu.org; Tue, 05 Jan 2016 03:24:08 -0500 Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1aGMMu-00066K-5r for bug-guile@gnu.org; Tue, 05 Jan 2016 08:49:24 +0100 Date: Tue, 5 Jan 2016 08:49:24 +0100 To: bug-guile@gnu.org Subject: Re: bug#18592: FFI should have =?utf-8?Q?p?= =?utf-8?B?b3J0YWJsZSBhY2Nlc3MgdG8g4oCYZXJybm/igJk=?= Message-ID: <20160105074924.GA23165@tuxteam.de> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) From: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, Jan 05, 2016 at 10:24:35AM +0800, Chaos Eternal wrote: > On Tue, Jan 5, 2016 at 3:14 AM, Nala Ginrut wrote: > > Hi Mark! > > Thanks for all the advices. > > > > Here's the new patch according to your advices. > > Include: > > 1. Added new procedure pointer->procedure-with-errno with > > #:return-errno? > > > > Question: Should we make #:return-errno? true in default? This would > > make the name *-with-errno more reasonable. At present, it's false in > > default. Sorry for intervening from the peanut gallery, but if I understood Mark correctly, he only was proposing to introduce a second function for the C API (to keep backward compatibility at the linking-to-C level). At the Guile source level, I guess all can be subsumed under one function. regards - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlaLdYQACgkQBcgs9XrR2kYBUQCfXIbqu8h/fhM/PyM9NXI1tR9M thIAnjSo00Ts4P39cTdwGOIIXIzELU9A =cCFX -----END PGP SIGNATURE----- From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 03:38:54 2016 Received: (at 18592) by debbugs.gnu.org; 5 Jan 2016 08:38:54 +0000 Received: from localhost ([127.0.0.1]:38103 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGN8n-0001DB-QU for submit@debbugs.gnu.org; Tue, 05 Jan 2016 03:38:53 -0500 Received: from mail-pa0-f42.google.com ([209.85.220.42]:34837) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGN8m-0001D0-VO for 18592@debbugs.gnu.org; Tue, 05 Jan 2016 03:38:53 -0500 Received: by mail-pa0-f42.google.com with SMTP id do7so2146357pab.2 for <18592@debbugs.gnu.org>; Tue, 05 Jan 2016 00:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version:content-transfer-encoding; bh=OmYXJC4UlXL9nMuHSsmtjnP4tx33DCIqUQalPnT9O1w=; b=TEr/IOA4q1h91GiwbRlkOwfrNX/xL0+y/k0kLYfQLeF/Fn4yLiKxjNAQubFrzm10l4 vURWPx8LXG5Ut2ycbTp+2fI5LK8zgd9C/IswAt/obEz2rHLeCBdR2mhpvL5GSdA8LRkZ X1EbZmiZKWOx4B3Oxq8I06FazaqdLTM0KEA8jibOn9vDYFABXDXPSVh9EUSFWsZaQeGo ojPvKl/+MIfNkybRQtKrqsVaRdHJaDj/QQgRSZ0VVk52Jj+ZXEy8FQeWpKmqpn6eXdkf Zxfc7aGQp9OIsOeEgMEUwc6hlCwO2GMao5FRzTzkXJWb7RslcUKUjDGg/g+4Xonnwmkr kZAg== X-Received: by 10.67.5.2 with SMTP id ci2mr132554887pad.47.1451983127152; Tue, 05 Jan 2016 00:38:47 -0800 (PST) Received: from [147.2.147.24] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id tv6sm77181460pab.4.2016.01.05.00.38.45 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jan 2016 00:38:46 -0800 (PST) Message-ID: <1451983123.3594.156.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: tomas@tuxteam.de Date: Tue, 05 Jan 2016 16:38:43 +0800 In-Reply-To: <20160105074924.GA23165@tuxteam.de> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> Organization: HFG Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) On Tue, 2016-01-05 at 08:49 +0100, tomas@tuxteam.de wrote: > Sorry for intervening from the peanut gallery, but if I understood Mark > correctly, he only was proposing to introduce a second function for the > C API (to keep backward compatibility at the linking-to-C level). At the > Guile source level, I guess all can be subsumed under one function. > If we want to combine them in Scheme level, we have to change the name "pointer->procedure" in C level, since it's registered with SCM_DEFINE. Dunno if it breaks the ABI too. I think it's fine to make it two. And maybe keep pointer->procedure-with-errno in future version (say, 3.0), which may change ABI a lot. It's inevitable to change ABI in major version number change usually. From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 10:08:20 2016 Received: (at 18592) by debbugs.gnu.org; 5 Jan 2016 15:08:20 +0000 Received: from localhost ([127.0.0.1]:38961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGTDg-0005Wf-ED for submit@debbugs.gnu.org; Tue, 05 Jan 2016 10:08:20 -0500 Received: from world.peace.net ([50.252.239.5]:43388 ident=hope9) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGTDe-0005WX-Bd for 18592@debbugs.gnu.org; Tue, 05 Jan 2016 10:08:18 -0500 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aGTDX-0002gG-DO; Tue, 05 Jan 2016 10:08:11 -0500 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> Date: Tue, 05 Jan 2016 10:08:09 -0500 In-Reply-To: <1451983123.3594.156.camel@Renee-desktop.suse> (Nala Ginrut's message of "Tue, 05 Jan 2016 16:38:43 +0800") Message-ID: <87vb78jc86.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, tomas@tuxteam.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Nala Ginrut writes: > On Tue, 2016-01-05 at 08:49 +0100, tomas@tuxteam.de wrote: >> Sorry for intervening from the peanut gallery, but if I understood Mark >> correctly, he only was proposing to introduce a second function for the >> C API (to keep backward compatibility at the linking-to-C level). At the >> Guile source level, I guess all can be subsumed under one function. Yes, Tom=C3=A1s is correct. For the Scheme API, I would prefer to keep just one procedure 'pointer->procedure' that accepts an optional #:return-errno? keyword argument, as we had previously agreed. > If we want to combine them in Scheme level, we have to change the name > "pointer->procedure" in C level, since it's registered with SCM_DEFINE. That's right, the C function name in the SCM_DEFINE construct would need to have a different name and be private, perhaps something like 'scm_i_pointer_to_procedure_with_keywords'. > Dunno if it breaks the ABI too. As long as there still exists a 'scm_pointer_to_procedure' function with the same signature and semantics as it has now, that will preserve ABI compatibility. More specifically, here's what I'd suggest: * A new, static, 'pointer_to_procedure' C function that inherits the signature and body of 'scm_pointer_to_procedure' but with a new and required 'return_errno' argument. The other functions below would be wrappers for this function. * A new private 'scm_i_pointer_to_procedure_with_keywords' C function, defined using SCM_DEFINE and bound to 'pointer->procedure' in Scheme, that uses 'scm_c_bind_keyword_arguments' and calls 'pointer_to_procedure'. * The C API function 'scm_pointer_to_procedure', which has the same arguments as in Guile 2.0.11 and calls 'pointer_to_procedure' with 'return_errno' set to SCM_BOOL_F. * A new C API function 'scm_pointer_to_procedure_with_errno', which is identical to 'scm_pointer_to_procedure' except that it calls 'pointer_to_procedure' with 'return_errno' set to SCM_BOOL_T. The only change to foreign.h would be to add a prototype for 'scm_pointer_to_procedure_with_errno'. What do you think? Regards, Mark From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 10:40:25 2016 Received: (at 18592) by debbugs.gnu.org; 5 Jan 2016 15:40:25 +0000 Received: from localhost ([127.0.0.1]:38973 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGTij-0006Hd-8O for submit@debbugs.gnu.org; Tue, 05 Jan 2016 10:40:25 -0500 Received: from world.peace.net ([50.252.239.5]:43531 ident=hope2) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGTih-0006HW-K8 for 18592@debbugs.gnu.org; Tue, 05 Jan 2016 10:40:23 -0500 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aGTib-0002yh-1G; Tue, 05 Jan 2016 10:40:17 -0500 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> Date: Tue, 05 Jan 2016 10:40:15 -0500 In-Reply-To: <1451934872.3594.150.camel@Renee-desktop.suse> (Nala Ginrut's message of "Tue, 05 Jan 2016 03:14:32 +0800") Message-ID: <87k2nojaqo.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, Ludovic =?utf-8?Q?Court=C3=A8s?= , Chaos Eternal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Hi Nala, In addition to the API issues raised in my previous mail, the other problem with this new patch is that it seems that you converted all tabs to spaces in foreign.c. Please do not change whitespace in lines that would otherwise be unchanged by your patch. I only meant to use spaces in new lines that you added, but it's not important. Thanks, Mark From debbugs-submit-bounces@debbugs.gnu.org Tue Jan 05 14:21:54 2016 Received: (at 18592) by debbugs.gnu.org; 5 Jan 2016 19:21:54 +0000 Received: from localhost ([127.0.0.1]:39138 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGXB3-0008D1-C4 for submit@debbugs.gnu.org; Tue, 05 Jan 2016 14:21:54 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:35023) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGXB2-0008Cm-3i for 18592@debbugs.gnu.org; Tue, 05 Jan 2016 14:21:52 -0500 Received: by mail-pf0-f175.google.com with SMTP id 78so227490868pfw.2 for <18592@debbugs.gnu.org>; Tue, 05 Jan 2016 11:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version; bh=BkP7Rk24HNHtzoSVC279qa2UqStTi5IDwWEOB7v9A+M=; b=S5cCBOKW/u7ZGT7uMUYVjUUiQWThqEH/b568eAnpxxeXz85dvQs1VZyxU/4gTNzGN8 uynvoC1zVEf0FztnCgw3EDRYknahHAEQf+XS7QwL2I5T9jQwaSkMYw02niuSTBM5KN9I iOesO1ERAH8y14QrTRsTnVRsK25Dqu1lAxyKUrCIpsVa0Vi/bgRzlHYNTdDZ70JfRHvM t0YMuMW6e+X8+pLXQzo8QC3iKTNdDeeD6fZd1LPKSuSiQV0w37y0DNeJrQPj/pxIHEBf vK4uNA+hZvqxu3IfEHleGzZkOBt4Ys/AlVRsR2ukmOZKVwGudGG1Zo3JfvD9bx8THbV7 H1hA== X-Received: by 10.98.76.72 with SMTP id z69mr136016823pfa.35.1452021706455; Tue, 05 Jan 2016 11:21:46 -0800 (PST) Received: from [127.0.0.1] (li88-185.members.linode.com. [74.207.246.185]) by smtp.gmail.com with ESMTPSA id ix2sm135244628pac.15.2016.01.05.11.21.43 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jan 2016 11:21:45 -0800 (PST) Message-ID: <1452021701.3594.160.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Mark H Weaver Date: Wed, 06 Jan 2016 03:21:41 +0800 In-Reply-To: <87vb78jc86.fsf@netris.org> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> Organization: HFG Content-Type: multipart/mixed; boundary="=-ZasfTEdCEpgU4VH3gLZA" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, tomas@tuxteam.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) --=-ZasfTEdCEpgU4VH3gLZA Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Here's updated patch Thanks! On Tue, 2016-01-05 at 10:08 -0500, Mark H Weaver wrote: > More specifically, here's what I'd suggest: > > * A new, static, 'pointer_to_procedure' C function that inherits the > signature and body of 'scm_pointer_to_procedure' but with a new and > required 'return_errno' argument. The other functions below would be > wrappers for this function. > > * A new private 'scm_i_pointer_to_procedure_with_keywords' C function, > defined using SCM_DEFINE and bound to 'pointer->procedure' in Scheme, > that uses 'scm_c_bind_keyword_arguments' and calls > 'pointer_to_procedure'. > > * The C API function 'scm_pointer_to_procedure', which has the same > arguments as in Guile 2.0.11 and calls 'pointer_to_procedure' with > 'return_errno' set to SCM_BOOL_F. > > * A new C API function 'scm_pointer_to_procedure_with_errno', which is > identical to 'scm_pointer_to_procedure' except that it calls > 'pointer_to_procedure' with 'return_errno' set to SCM_BOOL_T. > > The only change to foreign.h would be to add a prototype for > 'scm_pointer_to_procedure_with_errno'. > > What do you think? > > Regards, > Mark --=-ZasfTEdCEpgU4VH3gLZA Content-Disposition: attachment; filename*0=0001-Added-new-function-pointer-procedure-with-errno-to-r.pat; filename*1=ch Content-Type: text/x-patch; name="0001-Added-new-function-pointer-procedure-with-errno-to-r.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From faa6371c3251a488e4245bf4835529009a1a7b88 Mon Sep 17 00:00:00 2001 From: Nala Ginrut Date: Tue, 5 Jan 2016 03:04:47 +0800 Subject: [PATCH] Added new function pointer->procedure-with-errno to return errno properly * doc/ref/api-foreign.texi (Dynamic FFI): Update documentation. * libguile/foreign.c (scm_pointer_to_procedure_with_errno): New API function to return errno properly after calling foreign function. (pointer_to_procedure): New internal function to support return_errno option. * libguile/foreign.h (scm_pointer_to_procedure_with_errno): Add prototypes. * module/system/foreign.scm: Export pointer->procedure-with-errno. --- doc/ref/api-foreign.texi | 23 +++++- libguile/foreign.c | 199 +++++++++++++++++++++++++++++++-------------- libguile/foreign.h | 8 +- module/system/foreign.scm | 1 + 4 files changed, 165 insertions(+), 66 deletions(-) diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi index c2c49ec..52184e2 100644 --- a/doc/ref/api-foreign.texi +++ b/doc/ref/api-foreign.texi @@ -813,14 +813,31 @@ tightly packed structs and unions by hand. See the code for Of course, the land of C is not all nouns and no verbs: there are functions too, and Guile allows you to call them. -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types @ + [#:return-errno?=#f] +@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types, keyword_args) Make a foreign function. Given the foreign void pointer @var{func_ptr}, its argument and return types @var{arg_types} and @var{return_type}, return a procedure that will pass arguments to the foreign function -and return appropriate values. +and return appropriate values. If @var{#:return-errno?} is true, then @code{errno} will be +returned as the second return value. + +@var{arg_types} should be a list of foreign types. +@code{return_type} should be a foreign type. @xref{Foreign Types}, for +more information on foreign types. +@end deffn + +@deffn {Scheme Procedure} pointer->procedure-with-errno return_type func_ptr arg_types +@deffnx {C Procedure} scm_pointer_to_procedure_with_errno (return_type, func_ptr, arg_types) +Make a foreign function with errno. + +Given the foreign void pointer @var{func_ptr}, its argument and +return types @var{arg_types} and @var{return_type}, return a +procedure that will pass arguments to the foreign function +and return appropriate values. The @code{errno} will be +returned as the second return value. @var{arg_types} should be a list of foreign types. @code{return_type} should be a foreign type. @xref{Foreign Types}, for diff --git a/libguile/foreign.c b/libguile/foreign.c index 29cfc73..b0fd2dd 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -81,11 +81,11 @@ static void null_pointer_error (const char *func_name) { scm_error (sym_null_pointer_error, func_name, - "null pointer dereference", SCM_EOL, SCM_EOL); + "null pointer dereference", SCM_EOL, SCM_EOL); } -static SCM cif_to_procedure (SCM cif, SCM func_ptr); +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); static SCM pointer_weak_refs = SCM_BOOL_F; @@ -108,9 +108,9 @@ pointer_finalizer_trampoline (void *ptr, void *data) } SCM_DEFINE (scm_pointer_p, "pointer?", 1, 0, 0, - (SCM obj), - "Return @code{#t} if @var{obj} is a pointer object, " - "@code{#f} otherwise.\n") + (SCM obj), + "Return @code{#t} if @var{obj} is a pointer object, " + "@code{#f} otherwise.\n") #define FUNC_NAME s_scm_pointer_p { return scm_from_bool (SCM_POINTER_P (obj)); @@ -118,11 +118,11 @@ SCM_DEFINE (scm_pointer_p, "pointer?", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_make_pointer, "make-pointer", 1, 1, 0, - (SCM address, SCM finalizer), - "Return a foreign pointer object pointing to @var{address}. " - "If @var{finalizer} is passed, it should be a pointer to a " - "one-argument C function that will be called when the pointer " - "object becomes unreachable.") + (SCM address, SCM finalizer), + "Return a foreign pointer object pointing to @var{address}. " + "If @var{finalizer} is passed, it should be a pointer to a " + "one-argument C function that will be called when the pointer " + "object becomes unreachable.") #define FUNC_NAME s_scm_make_pointer { void *c_finalizer; @@ -170,8 +170,8 @@ scm_from_pointer (void *ptr, scm_t_pointer_finalizer finalizer) } SCM_DEFINE (scm_pointer_address, "pointer-address", 1, 0, 0, - (SCM pointer), - "Return the numerical value of @var{pointer}.") + (SCM pointer), + "Return the numerical value of @var{pointer}.") #define FUNC_NAME s_scm_pointer_address { SCM_VALIDATE_POINTER (1, pointer); @@ -181,9 +181,9 @@ SCM_DEFINE (scm_pointer_address, "pointer-address", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_pointer_to_scm, "pointer->scm", 1, 0, 0, - (SCM pointer), - "Unsafely cast @var{pointer} to a Scheme object.\n" - "Cross your fingers!") + (SCM pointer), + "Unsafely cast @var{pointer} to a Scheme object.\n" + "Cross your fingers!") #define FUNC_NAME s_scm_pointer_to_scm { SCM_VALIDATE_POINTER (1, pointer); @@ -193,8 +193,8 @@ SCM_DEFINE (scm_pointer_to_scm, "pointer->scm", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_scm_to_pointer, "scm->pointer", 1, 0, 0, - (SCM scm), - "Return a foreign pointer object with the @code{object-address}\n" + (SCM scm), + "Return a foreign pointer object with the @code{object-address}\n" "of @var{scm}.") #define FUNC_NAME s_scm_scm_to_pointer { @@ -209,18 +209,18 @@ SCM_DEFINE (scm_scm_to_pointer, "scm->pointer", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_pointer_to_bytevector, "pointer->bytevector", 2, 2, 0, - (SCM pointer, SCM len, SCM offset, SCM uvec_type), - "Return a bytevector aliasing the @var{len} bytes pointed\n" - "to by @var{pointer}.\n\n" + (SCM pointer, SCM len, SCM offset, SCM uvec_type), + "Return a bytevector aliasing the @var{len} bytes pointed\n" + "to by @var{pointer}.\n\n" "The user may specify an alternate default interpretation for\n" "the memory by passing the @var{uvec_type} argument, to indicate\n" "that the memory is an array of elements of that type.\n" "@var{uvec_type} should be something that\n" "@code{uniform-vector-element-type} would return, like @code{f32}\n" "or @code{s16}.\n\n" - "When @var{offset} is passed, it specifies the offset in bytes\n" - "relative to @var{pointer} of the memory region aliased by the\n" - "returned bytevector.") + "When @var{offset} is passed, it specifies the offset in bytes\n" + "relative to @var{pointer} of the memory region aliased by the\n" + "returned bytevector.") #define FUNC_NAME s_scm_pointer_to_bytevector { SCM ret; @@ -273,17 +273,17 @@ SCM_DEFINE (scm_pointer_to_bytevector, "pointer->bytevector", 2, 2, 0, blen = scm_to_size_t (len); ret = scm_c_take_typed_bytevector ((signed char *) ptr + boffset, - blen, btype); + blen, btype); register_weak_reference (ret, pointer); return ret; } #undef FUNC_NAME SCM_DEFINE (scm_bytevector_to_pointer, "bytevector->pointer", 1, 1, 0, - (SCM bv, SCM offset), - "Return a pointer pointer aliasing the memory pointed to by\n" + (SCM bv, SCM offset), + "Return a pointer pointer aliasing the memory pointed to by\n" "@var{bv} or @var{offset} bytes after @var{bv} when @var{offset}\n" - "is passed.") + "is passed.") #define FUNC_NAME s_scm_bytevector_to_pointer { SCM ret; @@ -337,9 +337,9 @@ scm_i_pointer_print (SCM pointer, SCM port, scm_print_state *pstate) (heap allocation overhead, Scheme/C round trips, etc.) */ SCM_DEFINE (scm_dereference_pointer, "dereference-pointer", 1, 0, 0, - (SCM pointer), - "Assuming @var{pointer} points to a memory region that\n" - "holds a pointer, return this pointer.") + (SCM pointer), + "Assuming @var{pointer} points to a memory region that\n" + "holds a pointer, return this pointer.") #define FUNC_NAME s_scm_dereference_pointer { void **ptr; @@ -355,9 +355,9 @@ SCM_DEFINE (scm_dereference_pointer, "dereference-pointer", 1, 0, 0, #undef FUNC_NAME SCM_DEFINE (scm_string_to_pointer, "string->pointer", 1, 1, 0, - (SCM string, SCM encoding), - "Return a foreign pointer to a nul-terminated copy of\n" - "@var{string} in the given @var{encoding}, defaulting to\n" + (SCM string, SCM encoding), + "Return a foreign pointer to a nul-terminated copy of\n" + "@var{string} in the given @var{encoding}, defaulting to\n" "the current locale encoding. The C string is freed when\n" "the returned foreign pointer becomes unreachable.\n\n" "This is the Scheme equivalent of @code{scm_to_stringn}.") @@ -394,14 +394,14 @@ SCM_DEFINE (scm_string_to_pointer, "string->pointer", 1, 1, 0, #undef FUNC_NAME SCM_DEFINE (scm_pointer_to_string, "pointer->string", 1, 2, 0, - (SCM pointer, SCM length, SCM encoding), - "Return the string representing the C string pointed to by\n" + (SCM pointer, SCM length, SCM encoding), + "Return the string representing the C string pointed to by\n" "@var{pointer}. If @var{length} is omitted or @code{-1}, the\n" "string is assumed to be nul-terminated. Otherwise\n" "@var{length} is the number of bytes in memory pointed to by\n" "@var{pointer}. The C string is assumed to be in the given\n" "@var{encoding}, defaulting to the current locale encoding.\n\n" - "This is the Scheme equivalent of @code{scm_from_stringn}.") + "This is the Scheme equivalent of @code{scm_from_stringn}.") #define FUNC_NAME s_scm_pointer_to_string { size_t len; @@ -482,19 +482,19 @@ SCM_DEFINE (scm_alignof, "alignof", 1, 0, 0, (SCM type), else if (scm_is_pair (type)) { /* TYPE is a structure. Section 3-3 of the i386, x86_64, PowerPC, - and SPARC P.S. of the System V ABI all say: "Aggregates - (structures and arrays) and unions assume the alignment of - their most strictly aligned component." */ + and SPARC P.S. of the System V ABI all say: "Aggregates + (structures and arrays) and unions assume the alignment of + their most strictly aligned component." */ size_t max; for (max = 0; scm_is_pair (type); type = SCM_CDR (type)) - { - size_t align; + { + size_t align; - align = scm_to_size_t (scm_alignof (SCM_CAR (type))); - if (align > max) - max = align; - } + align = scm_to_size_t (scm_alignof (SCM_CAR (type))); + if (align > max) + max = align; + } return scm_from_size_t (max); } @@ -708,12 +708,12 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) /* then ffi_type pointers: one for each arg, one for each struct element, and one for each struct (for null-termination) */ cif_len = (ROUND_UP (cif_len, alignof_type (void *)) - + (nargs + n_structs + n_struct_elts)*sizeof(void*)); + + (nargs + n_structs + n_struct_elts)*sizeof(void*)); /* then the ffi_type structs themselves, one per arg and struct element, and one for the return val */ cif_len = (ROUND_UP (cif_len, alignof_type (ffi_type)) - + (nargs + n_struct_elts + 1)*sizeof(ffi_type)); + + (nargs + n_struct_elts + 1)*sizeof(ffi_type)); mem = scm_gc_malloc_pointerless (cif_len, "foreign"); /* ensure all the memory is initialized, even the holes */ @@ -724,8 +724,8 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) cif_len = ROUND_UP (sizeof (ffi_cif), alignof_type (void *)); type_ptrs = (ffi_type**)(mem + cif_len); cif_len = ROUND_UP (cif_len - + (nargs + n_structs + n_struct_elts)*sizeof(void*), - alignof_type (ffi_type)); + + (nargs + n_structs + n_struct_elts)*sizeof(void*), + alignof_type (ffi_type)); types = (ffi_type*)(mem + cif_len); /* whew. now knit the pointers together. */ @@ -746,14 +746,21 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) cif->flags = 0; if (FFI_OK != ffi_prep_cif (cif, FFI_DEFAULT_ABI, cif->nargs, cif->rtype, - cif->arg_types)) + cif->arg_types)) SCM_MISC_ERROR ("ffi_prep_cif failed", SCM_EOL); return cif; } #undef FUNC_NAME -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, +static SCM pointer_to_procedure (ffi_cif *cif, SCM func_ptr, SCM return_errno); +static SCM pointer_to_procedure (ffi_cif *cif, SCM func_ptr, SCM return_errno) +{ + return cif_to_procedure (scm_from_pointer (cif, NULL), + func_ptr, return_errno); +} + +SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure0", 3, 0, 0, (SCM return_type, SCM func_ptr, SCM arg_types), "Make a foreign function.\n\n" "Given the foreign void pointer @var{func_ptr}, its argument and\n" @@ -770,7 +777,61 @@ SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, cif = make_cif (return_type, arg_types, FUNC_NAME); - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); + return pointer_to_procedure (cif, func_ptr, SCM_BOOL_F); +} +#undef FUNC_NAME + +SCM_KEYWORD (k_return_errno, "return-errno?"); + +SCM_DEFINE (scm_i_pointer_to_procedure_with_keywords, + "pointer->procedure", 3, 0, 1, + (SCM return_type, SCM func_ptr, SCM arg_types, SCM keyword_args), + "Make a foreign function.\n\n" + "Given the foreign void pointer @var{func_ptr}, its argument and\n" + "return types @var{arg_types} and @var{return_type}, return a\n" + "procedure that will pass arguments to the foreign function\n" + "and return appropriate values.\n\n" + "@var{arg_types} should be a list of foreign types.\n" + "@code{return_type} should be a foreign type.\n" + "If @var{#:return-errno?} is true, then the @var{errno} will be\n" + "returned as the second value.") +#define FUNC_NAME s_scm_i_pointer_to_procedure_with_keywords +{ + ffi_cif *cif; + SCM return_errno = SCM_BOOL_F; + + SCM_VALIDATE_POINTER (2, func_ptr); + + scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0, + k_return_errno, &return_errno, + SCM_UNDEFINED); + + cif = make_cif (return_type, arg_types, FUNC_NAME); + + return pointer_to_procedure (cif, func_ptr, return_errno); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_pointer_to_procedure_with_errno, + "pointer->procedure-with-errno", 3, 0, 0, + (SCM return_type, SCM func_ptr, SCM arg_types), + "Make a foreign function.\n\n" + "Given the foreign void pointer @var{func_ptr}, its argument and\n" + "return types @var{arg_types} and @var{return_type}, return a\n" + "procedure that will pass arguments to the foreign function\n" + "and return appropriate values.\n" + "The errno will be the second value\n\n" + "@var{arg_types} should be a list of foreign types.\n" + "@code{return_type} should be a foreign type.") +#define FUNC_NAME s_scm_pointer_to_procedure_with_errno +{ + ffi_cif *cif; + + SCM_VALIDATE_POINTER (2, func_ptr); + + cif = make_cif (return_type, arg_types, FUNC_NAME); + + return pointer_to_procedure (cif, func_ptr, SCM_BOOL_T); } #undef FUNC_NAME @@ -940,16 +1001,20 @@ get_objcode_trampoline (unsigned int nargs) } static SCM -cif_to_procedure (SCM cif, SCM func_ptr) +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) { ffi_cif *c_cif; SCM objcode, table, ret; + /* Convert 'return_errno' to a simple boolean, to avoid retaining + references to non-boolean objects. */ + return_errno = scm_from_bool (scm_is_true (return_errno)); + c_cif = (ffi_cif *) SCM_POINTER_VALUE (cif); objcode = get_objcode_trampoline (c_cif->nargs); table = scm_c_make_vector (2, SCM_UNDEFINED); - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); + SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons2 (cif, func_ptr, return_errno)); SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ ret = scm_make_program (objcode, table, SCM_BOOL_F); @@ -1116,9 +1181,12 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) unsigned i; size_t arg_size; scm_t_ptrdiff off; + SCM return_errno; + int reterr; cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); + return_errno = SCM_CDDR (foreign); /* Argument pointers. */ args = alloca (sizeof (void *) * cif->nargs); @@ -1153,10 +1221,21 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, max (sizeof (void *), cif->rtype->alignment)); - /* off we go! */ - ffi_call (cif, func, rvalue, args); - - return pack (cif->rtype, rvalue, 1); + if (scm_is_true (return_errno)) + { + errno = 0; + /* off we go! */ + ffi_call (cif, func, rvalue, args); + reterr = errno; + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), + scm_from_int (reterr))); + } + else + { + /* off we go! */ + ffi_call (cif, func, rvalue, args); + return pack (cif->rtype, rvalue, 1); + } } diff --git a/libguile/foreign.h b/libguile/foreign.h index 41c0b65..561b9f8 100644 --- a/libguile/foreign.h +++ b/libguile/foreign.h @@ -1,7 +1,7 @@ #ifndef SCM_FOREIGN_H #define SCM_FOREIGN_H -/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. +/* Copyright (C) 2010, 2011, 2012, 2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -93,9 +93,11 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); */ SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, - SCM arg_types); + SCM arg_types); +SCM_API SCM scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, + SCM arg_types); SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, - SCM arg_types); + SCM arg_types); SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); diff --git a/module/system/foreign.scm b/module/system/foreign.scm index 55ab014..4436f1f 100644 --- a/module/system/foreign.scm +++ b/module/system/foreign.scm @@ -50,6 +50,7 @@ pointer->string pointer->procedure + pointer->procedure-with-errno ;; procedure->pointer (see below) make-c-struct parse-c-struct -- 1.7.10.4 --=-ZasfTEdCEpgU4VH3gLZA-- From debbugs-submit-bounces@debbugs.gnu.org Thu Feb 18 03:25:56 2016 Received: (at 18592) by debbugs.gnu.org; 18 Feb 2016 08:25:56 +0000 Received: from localhost ([127.0.0.1]:60171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWJuO-0005dQ-7k for submit@debbugs.gnu.org; Thu, 18 Feb 2016 03:25:56 -0500 Received: from mail-pf0-f178.google.com ([209.85.192.178]:33673) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWJuM-0005dE-Oh for 18592@debbugs.gnu.org; Thu, 18 Feb 2016 03:25:55 -0500 Received: by mail-pf0-f178.google.com with SMTP id q63so27304420pfb.0 for <18592@debbugs.gnu.org>; Thu, 18 Feb 2016 00:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version:content-transfer-encoding; bh=dJwHK2jMnDoSAIfutqoeqwpen3D9F25Q6zfhl4U2uT4=; b=HNFgy2gDN3vgvg0Rz5F0NW4UxKcgERkFuVuEDifVDRJ+glOTwgo4YK1xt9jjFCBHU0 0BRrf7fFlBNSunITYfq1N0nH55p0TANfol1DX57/jDhEaGf3QYY+X3lXsZdzpyCc1KDx sNQy48NDd/cn98+NQj4+/5trVdH9XJ72HMq+h2p/DI0T9O0VzjwyTQnc5qcRhr+6XJWM 9D+y1lLtkiZA4ChPIckUxOrpcrlAbEPsZsOCO0wGaePzGiGNX87oE5H/xC+kKj04AjYE Q3B+cvsemaP5frWjUR+LmCSsQbQkfqn2OlnVGsWM52oPCLVAyeS19nKM7u/M//1FAO4y WbiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:content-type:mime-version :content-transfer-encoding; bh=dJwHK2jMnDoSAIfutqoeqwpen3D9F25Q6zfhl4U2uT4=; b=e4AEbVqrzKSxHCDif9bvTJjWP8x2r2f52FVukiEbb/vB2g7x8YKjTKtXuapA92DUSS hUTv9XLPmGv/swQV3lo0ywzasN2CUIGs8crUG7ZK4h/L+viL9QIyjCIB7I+47e6MjdBE XUrMHLREW9YxvuONBvLiQ69UF2MQQRXTLQlTtaSZaKgUu4CBnJ7j9y5QS8dWYDHI3ZdT a1EVRSHvShplIOGYzXfCiXcgNhEzQ4ZsRa5YerTRwvCtiXFOwNuPtLZNREI7jBZn3DDD 2bQmzbC8ONduo+6Nt/ovH7b1oBeApsiv3Far7uSlP56fFLMpqbaTkQKmhCjbpJk0uCI+ fAwQ== X-Gm-Message-State: AG10YOTbSapCzhGa4wCqQeES/82UwMetS1EdUP1SNlVVLSZyvirMqKdcqrZD+zAJBCbv5g== X-Received: by 10.98.2.21 with SMTP id 21mr8327357pfc.11.1455783948764; Thu, 18 Feb 2016 00:25:48 -0800 (PST) Received: from [147.2.147.24] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id o10sm7985806pap.37.2016.02.18.00.25.45 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 18 Feb 2016 00:25:47 -0800 (PST) Message-ID: <1455783943.3838.16.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Mark H Weaver Date: Thu, 18 Feb 2016 16:25:43 +0800 In-Reply-To: <1452021701.3594.160.camel@Renee-desktop.suse> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> Organization: HFG Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org, tomas@tuxteam.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) Hi folks! Is there still any problem with the previous patch? Could it be applied now? If anyone think there's problem in it, I'm glad to work for it. Please don't hesitate to tell, since I need this feature very much. Thanks! From debbugs-submit-bounces@debbugs.gnu.org Thu Feb 18 08:30:35 2016 Received: (at 18592) by debbugs.gnu.org; 18 Feb 2016 13:30:35 +0000 Received: from localhost ([127.0.0.1]:60284 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWOfC-0001Ah-VG for submit@debbugs.gnu.org; Thu, 18 Feb 2016 08:30:35 -0500 Received: from world.peace.net ([50.252.239.5]:44922 ident=hope1) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWOfB-0001AZ-Bj for 18592@debbugs.gnu.org; Thu, 18 Feb 2016 08:30:33 -0500 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1aWOez-0002Xi-HB; Thu, 18 Feb 2016 08:30:21 -0500 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> Date: Thu, 18 Feb 2016 08:30:19 -0500 In-Reply-To: <1455783943.3838.16.camel@Renee-desktop.suse> (Nala Ginrut's message of "Thu, 18 Feb 2016 16:25:43 +0800") Message-ID: <871t8af8no.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) --=-=-= Content-Type: text/plain Nala Ginrut writes: > Is there still any problem with the previous patch? Yes. I'm sorry, but we were failing to communicate and I did not have time to continue trying, so instead I made my own patch, attached below. Can you try this patch, and tell me if it does what you need? Thanks, Mark --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-PRELIMINARY-Add-support-for-errno-to-Dynamic-FFI.patch Content-Description: [PATCH] PRELIMINARY: Add support for errno to Dynamic FFI >From 17a3ee8c255e06ea7ee805401c94853fb48cbf12 Mon Sep 17 00:00:00 2001 From: Mark H Weaver Date: Tue, 5 Jan 2016 16:30:41 -0500 Subject: [PATCH] PRELIMINARY: Add support for errno to Dynamic FFI. --- doc/ref/api-foreign.texi | 15 +++++--- libguile/foreign.c | 89 ++++++++++++++++++++++++++++++++++++++---------- libguile/foreign.h | 4 ++- 3 files changed, 85 insertions(+), 23 deletions(-) diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi index c2c49ec..25eaabf 100644 --- a/doc/ref/api-foreign.texi +++ b/doc/ref/api-foreign.texi @@ -1,7 +1,7 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2007, 2008, -@c 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. +@c Copyright (C) 1996, 1997, 2000-2004, 2007-2014, 2016 +@c Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @node Foreign Function Interface @@ -813,8 +813,11 @@ tightly packed structs and unions by hand. See the code for Of course, the land of C is not all nouns and no verbs: there are functions too, and Guile allows you to call them. -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types @ + [#:return-errno?=#f] +@deffnx {C Function} scm_pointer_to_procedure (return_type, func_ptr, arg_types) +@deffnx {C Function} scm_pointer_to_procedure_with_errno (return_type, func_ptr, arg_types) + Make a foreign function. Given the foreign void pointer @var{func_ptr}, its argument and @@ -825,6 +828,10 @@ and return appropriate values. @var{arg_types} should be a list of foreign types. @code{return_type} should be a foreign type. @xref{Foreign Types}, for more information on foreign types. + +If @var{return-errno?} is true, or when calling +@code{scm_pointer_to_procedure_with_errno}, the returned procedure will +return two values, with @code{errno} as the second value. @end deffn Here is a better definition of @code{(math bessel)}: diff --git a/libguile/foreign.c b/libguile/foreign.c index 29cfc73..f770100 100644 --- a/libguile/foreign.c +++ b/libguile/foreign.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -26,6 +26,7 @@ #include #include #include +#include #include "libguile/_scm.h" #include "libguile/bytevectors.h" @@ -85,7 +86,7 @@ null_pointer_error (const char *func_name) } -static SCM cif_to_procedure (SCM cif, SCM func_ptr); +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); static SCM pointer_weak_refs = SCM_BOOL_F; @@ -753,24 +754,58 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) } #undef FUNC_NAME -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, - (SCM return_type, SCM func_ptr, SCM arg_types), +static SCM +pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types, + SCM return_errno) +#define FUNC_NAME "pointer->procedure" +{ + ffi_cif *cif; + + SCM_VALIDATE_POINTER (2, func_ptr); + + cif = make_cif (return_type, arg_types, FUNC_NAME); + + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, + return_errno); +} +#undef FUNC_NAME + +SCM +scm_pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types) +{ + return pointer_to_procedure (return_type, func_ptr, arg_types, SCM_BOOL_F); +} + +SCM +scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, + SCM arg_types) +{ + return pointer_to_procedure (return_type, func_ptr, arg_types, SCM_BOOL_T); +} + +SCM_KEYWORD (k_return_errno, "return-errno?"); + +SCM_DEFINE (scm_i_pointer_to_procedure, "pointer->procedure", 3, 0, 1, + (SCM return_type, SCM func_ptr, SCM arg_types, SCM keyword_args), "Make a foreign function.\n\n" "Given the foreign void pointer @var{func_ptr}, its argument and\n" "return types @var{arg_types} and @var{return_type}, return a\n" "procedure that will pass arguments to the foreign function\n" "and return appropriate values.\n\n" "@var{arg_types} should be a list of foreign types.\n" - "@code{return_type} should be a foreign type.") -#define FUNC_NAME s_scm_pointer_to_procedure + "@code{return_type} should be a foreign type.\n" + "If the @code{#:return-errno?} keyword argument is provided and\n" + "its value is true, then the returned procedure will return two\n" + "values, with @code{errno} as the second value.") +#define FUNC_NAME "pointer->procedure" { - ffi_cif *cif; + SCM return_errno = SCM_BOOL_F; - SCM_VALIDATE_POINTER (2, func_ptr); - - cif = make_cif (return_type, arg_types, FUNC_NAME); + scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0, + k_return_errno, &return_errno, + SCM_UNDEFINED); - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); + return pointer_to_procedure (return_type, func_ptr, arg_types, return_errno); } #undef FUNC_NAME @@ -940,16 +975,20 @@ get_objcode_trampoline (unsigned int nargs) } static SCM -cif_to_procedure (SCM cif, SCM func_ptr) +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) { ffi_cif *c_cif; SCM objcode, table, ret; c_cif = (ffi_cif *) SCM_POINTER_VALUE (cif); objcode = get_objcode_trampoline (c_cif->nargs); - + + /* Convert 'return_errno' to a simple boolean, to avoid retaining + references to non-boolean objects. */ + return_errno = scm_from_bool (scm_is_true (return_errno)); + table = scm_c_make_vector (2, SCM_UNDEFINED); - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); + SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons2 (cif, func_ptr, return_errno)); SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ ret = scm_make_program (objcode, table, SCM_BOOL_F); @@ -1116,9 +1155,11 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) unsigned i; size_t arg_size; scm_t_ptrdiff off; + SCM return_errno; cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); + return_errno = SCM_CDDR (foreign); /* Argument pointers. */ args = alloca (sizeof (void *) * cif->nargs); @@ -1153,10 +1194,22 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, max (sizeof (void *), cif->rtype->alignment)); - /* off we go! */ - ffi_call (cif, func, rvalue, args); + if (scm_is_true (return_errno)) + { + int errno_save; + + errno = 0; + ffi_call (cif, func, rvalue, args); + errno_save = errno; - return pack (cif->rtype, rvalue, 1); + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), + scm_from_int (errno_save))); + } + else + { + ffi_call (cif, func, rvalue, args); + return pack (cif->rtype, rvalue, 1); + } } diff --git a/libguile/foreign.h b/libguile/foreign.h index 41c0b65..f8a176b 100644 --- a/libguile/foreign.h +++ b/libguile/foreign.h @@ -1,7 +1,7 @@ #ifndef SCM_FOREIGN_H #define SCM_FOREIGN_H -/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. +/* Copyright (C) 2010, 2011, 2012, 2016 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -94,6 +94,8 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types); +SCM_API SCM scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, + SCM arg_types); SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, SCM arg_types); SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); -- 2.6.3 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 19 00:02:50 2016 Received: (at 18592) by debbugs.gnu.org; 19 Feb 2016 05:02:50 +0000 Received: from localhost ([127.0.0.1]:33380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWdDN-00083i-Gb for submit@debbugs.gnu.org; Fri, 19 Feb 2016 00:02:49 -0500 Received: from mail-pf0-f171.google.com ([209.85.192.171]:35541) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aWdDM-00083U-1Z for 18592@debbugs.gnu.org; Fri, 19 Feb 2016 00:02:48 -0500 Received: by mail-pf0-f171.google.com with SMTP id c10so45797797pfc.2 for <18592@debbugs.gnu.org>; Thu, 18 Feb 2016 21:02:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:content-type:mime-version:content-transfer-encoding; bh=L94P1ojbssPCI4LP9Dd2wlw+Z85bhQWsjeKccUroSJM=; b=0zyGm+nS3nnzoviHLw+hVatXvypyUX0ip/GL8GAQjNPHQTa5LxAMoTVlIYjF3KpL9j Nzks+WhZkViz4kUUWuPyMAhegL9y+7ksfq2S3OJ+YMbNEuv3qV1j81eadJKvlAZL5uGP jrgJl1mmwHHaAqJC8+8aS96eU4a8wHWr9NEYmuS6ce7uZyJIbDXTV3pT/JzIoDicyAaQ cJSOtK2emOb0VdGKdDfxL01i+hpFtfRLqUCZ4vkrVKy9fcNGsTDOpiPX44vSfHwXW822 CIz3kNuJ80bfr4KjcHSvBiIPD4KTC1lwSHhYiHHFZY2W5C3CR3Zjl4PNHNxq8c0clH8P TPKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:content-type:mime-version :content-transfer-encoding; bh=L94P1ojbssPCI4LP9Dd2wlw+Z85bhQWsjeKccUroSJM=; b=O5fqm4xeVqSxxReZ22bpg1YeHwS8nRZ5NkC+FUqCdHVSvT1u1R74FSqZxFwT13JYvx DLZJA+G6oSVB1F3wYbXEo9BhhS4mvfoqZjnyGJnR0fJdPh+kP7uC+ITnimshKAPYLhZU Xyhq5Ycp4s2PiAzMNzTPl5lVGQDRbJu/J793MhxOetRuTDluwT2OiGQOw+eBFVImFeYr a4C/OKn02cnhLVg/rMImrWDUTJClDgBJAoUJfy3+sxnksDqrVH3fxSVtKc6DmvH6wPd9 8IAobERA6J/Z2IFDVAMpGeo2eLQFEwGyLAKCt4lIWv2tPqHX7S+n7idwcUoCBQMmA/to w+OQ== X-Gm-Message-State: AG10YOTQL2gLB6V8/SKSXqjlCWoyPkpi0EeFkXUk5fSKOu7wPsbI+bP8wOTvZGYuDroENg== X-Received: by 10.98.32.5 with SMTP id g5mr15458123pfg.74.1455858162106; Thu, 18 Feb 2016 21:02:42 -0800 (PST) Received: from [147.2.147.24] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id dg1sm14078332pad.18.2016.02.18.21.02.39 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 18 Feb 2016 21:02:41 -0800 (PST) Message-ID: <1455858156.3838.21.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Mark H Weaver Date: Fri, 19 Feb 2016 13:02:36 +0800 In-Reply-To: <871t8af8no.fsf@netris.org> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> <871t8af8no.fsf@netris.org> Organization: HFG Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) I think it's OK to try this: (pointer->procedure int (dynamic-func "epoll_create" (dynamic-link)) '() #:return-errno? #t) And I'm fine with the patch, could you push it please? Thank you very much! On Thu, 2016-02-18 at 08:30 -0500, Mark H Weaver wrote: > Nala Ginrut writes: > > Is there still any problem with the previous patch? > > Yes. I'm sorry, but we were failing to communicate and I did not have > time to continue trying, so instead I made my own patch, attached below. > > Can you try this patch, and tell me if it does what you need? > > Thanks, > Mark > > > differences between files attachment > (0001-PRELIMINARY-Add-support-for-errno-to-Dynamic-FFI.patch), > "[PATCH] PRELIMINARY: Add support for errno to Dynamic FFI" > From 17a3ee8c255e06ea7ee805401c94853fb48cbf12 Mon Sep 17 00:00:00 2001 > From: Mark H Weaver > Date: Tue, 5 Jan 2016 16:30:41 -0500 > Subject: [PATCH] PRELIMINARY: Add support for errno to Dynamic FFI. > > --- > doc/ref/api-foreign.texi | 15 +++++--- > libguile/foreign.c | 89 ++++++++++++++++++++++++++++++++++++++---------- > libguile/foreign.h | 4 ++- > 3 files changed, 85 insertions(+), 23 deletions(-) > > diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi > index c2c49ec..25eaabf 100644 > --- a/doc/ref/api-foreign.texi > +++ b/doc/ref/api-foreign.texi > @@ -1,7 +1,7 @@ > @c -*-texinfo-*- > @c This is part of the GNU Guile Reference Manual. > -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2007, 2008, > -@c 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. > +@c Copyright (C) 1996, 1997, 2000-2004, 2007-2014, 2016 > +@c Free Software Foundation, Inc. > @c See the file guile.texi for copying conditions. > > @node Foreign Function Interface > @@ -813,8 +813,11 @@ tightly packed structs and unions by hand. See the code for > Of course, the land of C is not all nouns and no verbs: there are > functions too, and Guile allows you to call them. > > -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types > -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) > +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types @ > + [#:return-errno?=#f] > +@deffnx {C Function} scm_pointer_to_procedure (return_type, func_ptr, arg_types) > +@deffnx {C Function} scm_pointer_to_procedure_with_errno (return_type, func_ptr, arg_types) > + > Make a foreign function. > > Given the foreign void pointer @var{func_ptr}, its argument and > @@ -825,6 +828,10 @@ and return appropriate values. > @var{arg_types} should be a list of foreign types. > @code{return_type} should be a foreign type. @xref{Foreign Types}, for > more information on foreign types. > + > +If @var{return-errno?} is true, or when calling > +@code{scm_pointer_to_procedure_with_errno}, the returned procedure will > +return two values, with @code{errno} as the second value. > @end deffn > > Here is a better definition of @code{(math bessel)}: > diff --git a/libguile/foreign.c b/libguile/foreign.c > index 29cfc73..f770100 100644 > --- a/libguile/foreign.c > +++ b/libguile/foreign.c > @@ -1,4 +1,4 @@ > -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. > +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Lesser General Public License > @@ -26,6 +26,7 @@ > #include > #include > #include > +#include > > #include "libguile/_scm.h" > #include "libguile/bytevectors.h" > @@ -85,7 +86,7 @@ null_pointer_error (const char *func_name) > } > > > -static SCM cif_to_procedure (SCM cif, SCM func_ptr); > +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); > > > static SCM pointer_weak_refs = SCM_BOOL_F; > @@ -753,24 +754,58 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) > } > #undef FUNC_NAME > > -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, > - (SCM return_type, SCM func_ptr, SCM arg_types), > +static SCM > +pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types, > + SCM return_errno) > +#define FUNC_NAME "pointer->procedure" > +{ > + ffi_cif *cif; > + > + SCM_VALIDATE_POINTER (2, func_ptr); > + > + cif = make_cif (return_type, arg_types, FUNC_NAME); > + > + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, > + return_errno); > +} > +#undef FUNC_NAME > + > +SCM > +scm_pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types) > +{ > + return pointer_to_procedure (return_type, func_ptr, arg_types, SCM_BOOL_F); > +} > + > +SCM > +scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, > + SCM arg_types) > +{ > + return pointer_to_procedure (return_type, func_ptr, arg_types, SCM_BOOL_T); > +} > + > +SCM_KEYWORD (k_return_errno, "return-errno?"); > + > +SCM_DEFINE (scm_i_pointer_to_procedure, "pointer->procedure", 3, 0, 1, > + (SCM return_type, SCM func_ptr, SCM arg_types, SCM keyword_args), > "Make a foreign function.\n\n" > "Given the foreign void pointer @var{func_ptr}, its argument and\n" > "return types @var{arg_types} and @var{return_type}, return a\n" > "procedure that will pass arguments to the foreign function\n" > "and return appropriate values.\n\n" > "@var{arg_types} should be a list of foreign types.\n" > - "@code{return_type} should be a foreign type.") > -#define FUNC_NAME s_scm_pointer_to_procedure > + "@code{return_type} should be a foreign type.\n" > + "If the @code{#:return-errno?} keyword argument is provided and\n" > + "its value is true, then the returned procedure will return two\n" > + "values, with @code{errno} as the second value.") > +#define FUNC_NAME "pointer->procedure" > { > - ffi_cif *cif; > + SCM return_errno = SCM_BOOL_F; > > - SCM_VALIDATE_POINTER (2, func_ptr); > - > - cif = make_cif (return_type, arg_types, FUNC_NAME); > + scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0, > + k_return_errno, &return_errno, > + SCM_UNDEFINED); > > - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); > + return pointer_to_procedure (return_type, func_ptr, arg_types, return_errno); > } > #undef FUNC_NAME > > @@ -940,16 +975,20 @@ get_objcode_trampoline (unsigned int nargs) > } > > static SCM > -cif_to_procedure (SCM cif, SCM func_ptr) > +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) > { > ffi_cif *c_cif; > SCM objcode, table, ret; > > c_cif = (ffi_cif *) SCM_POINTER_VALUE (cif); > objcode = get_objcode_trampoline (c_cif->nargs); > - > + > + /* Convert 'return_errno' to a simple boolean, to avoid retaining > + references to non-boolean objects. */ > + return_errno = scm_from_bool (scm_is_true (return_errno)); > + > table = scm_c_make_vector (2, SCM_UNDEFINED); > - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); > + SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons2 (cif, func_ptr, return_errno)); > SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ > ret = scm_make_program (objcode, table, SCM_BOOL_F); > > @@ -1116,9 +1155,11 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) > unsigned i; > size_t arg_size; > scm_t_ptrdiff off; > + SCM return_errno; > > cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); > - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); > + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); > + return_errno = SCM_CDDR (foreign); > > /* Argument pointers. */ > args = alloca (sizeof (void *) * cif->nargs); > @@ -1153,10 +1194,22 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) > rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, > max (sizeof (void *), cif->rtype->alignment)); > > - /* off we go! */ > - ffi_call (cif, func, rvalue, args); > + if (scm_is_true (return_errno)) > + { > + int errno_save; > + > + errno = 0; > + ffi_call (cif, func, rvalue, args); > + errno_save = errno; > > - return pack (cif->rtype, rvalue, 1); > + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), > + scm_from_int (errno_save))); > + } > + else > + { > + ffi_call (cif, func, rvalue, args); > + return pack (cif->rtype, rvalue, 1); > + } > } > > > diff --git a/libguile/foreign.h b/libguile/foreign.h > index 41c0b65..f8a176b 100644 > --- a/libguile/foreign.h > +++ b/libguile/foreign.h > @@ -1,7 +1,7 @@ > #ifndef SCM_FOREIGN_H > #define SCM_FOREIGN_H > > -/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. > +/* Copyright (C) 2010, 2011, 2012, 2016 Free Software Foundation, Inc. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Lesser General Public License > @@ -94,6 +94,8 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); > > SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, > SCM arg_types); > +SCM_API SCM scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, > + SCM arg_types); > SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, > SCM arg_types); > SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 26 06:19:05 2016 Received: (at 18592) by debbugs.gnu.org; 26 Feb 2016 11:19:05 +0000 Received: from localhost ([127.0.0.1]:46959 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aZGQL-0005QB-5C for submit@debbugs.gnu.org; Fri, 26 Feb 2016 06:19:05 -0500 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36143) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aZGQJ-0005Ph-EE for 18592@debbugs.gnu.org; Fri, 26 Feb 2016 06:19:03 -0500 Received: by mail-pf0-f170.google.com with SMTP id e127so50909459pfe.3 for <18592@debbugs.gnu.org>; Fri, 26 Feb 2016 03:19:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=GZhhAfwSqNmdaIbD5hhmJNDANSY7riC3vhxNgHoOPHA=; b=lWKt3Uktjrfdvg15+BaFXAqEqGWE9O/wQidLBNDlVZeuWZLYfYYJrSl07cInr28EGF 0qpe24UQrUJrc9OEByhYJwt9kQlUDuMKhs5UMV1zAElqFfpIYpP5lhFLmkIxeP5JJrcq icPuJn3GaSMYM3ftHPwvsASoKWySedqjKJmMnRTuq5tMX0mHd3hvwpWvmn58BW4Op1CX 9MfdJd/4AVaL3FzrkJCgJM6IN+sTE1m/WhH0IloomDXnO4uUwc1ADpO+9zFt3BQPxF4B Xm2Jtd4Y8epJ8InTzuuJ9RQSupybSlN3HZ8DIv1tnwODSG/mfRDsd4a7nteNOm18m2x2 5wxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=GZhhAfwSqNmdaIbD5hhmJNDANSY7riC3vhxNgHoOPHA=; b=LbAtqy+z1v6z20GwbRta+QgamwqW0smrZ4s7H7e+N6efxLgsS6dNWdMgjcJH2AvYUL GvotzWIPhicOJBDa20B2XIJ8dj8lUeHPVxlqzs5wdn3f5ALaeMRwJDEwbifXS7fmACOy n0oI0jheYqhFm5jB2/j/ivqg0FWPzFNyCXAq2tS9JQj292yVjtW+7ocZSBN1gwtdtSrX 0saEt+XG8DY6NOfbZnY3AXgmgFnhgyBDQIcwV8pVKXV+/U0b9/3BhTQiNueeu/Kj4Vs2 lvs0QSjqzoxAgG5jpVio5STyjr2UeEPa2viHwuw1nGMuqMu9tfdMx3QBIdd4nX7OCiCJ dkcg== X-Gm-Message-State: AD7BkJITiBirbyL1MuyO1ve+O0WbBkVHBcXBx+5rgS1H8g/F6UjkxviLZizL43LEt+cIwg== X-Received: by 10.98.72.133 with SMTP id q5mr1253689pfi.166.1456485537604; Fri, 26 Feb 2016 03:18:57 -0800 (PST) Received: from [147.2.147.24] ([203.192.156.9]) by smtp.gmail.com with ESMTPSA id ml5sm18758996pab.2.2016.02.26.03.18.55 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 26 Feb 2016 03:18:56 -0800 (PST) Message-ID: <1456485534.7330.63.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Mark H Weaver Date: Fri, 26 Feb 2016 19:18:54 +0800 In-Reply-To: <1455858156.3838.21.camel@Renee-desktop.suse> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> <871t8af8no.fsf@netris.org> <1455858156.3838.21.camel@Renee-desktop.suse> Organization: HFG Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Is there still problem? I'm fine with the patch, and I'm expecting to merge it ASAP. Anyway, please don't hesitate to tell me if there's still any problem, I'm glad to help to do it better. I really need it. Thanks! On Fri, 2016-02-19 at 13:02 +0800, Nala Ginrut wrote: > I think it's OK to try this: > (pointer->procedure int (dynamic-func "epoll_create" (dynamic-link)) '() > #:return-errno? #t) > > And I'm fine with the patch, could you push it please? > > Thank you very much! > > On Thu, 2016-02-18 at 08:30 -0500, Mark H Weaver wrote: > > Nala Ginrut writes: > > > Is there still any problem with the previous patch? > > > > Yes. I'm sorry, but we were failing to communicate and I did not have > > time to continue trying, so instead I made my own patch, attached below. > > > > Can you try this patch, and tell me if it does what you need? > > > > Thanks, > > Mark > > > > > > differences between files attachment > > (0001-PRELIMINARY-Add-support-for-errno-to-Dynamic-FFI.patch), > > "[PATCH] PRELIMINARY: Add support for errno to Dynamic FFI" > > From 17a3ee8c255e06ea7ee805401c94853fb48cbf12 Mon Sep 17 00:00:00 2001 > > From: Mark H Weaver > > Date: Tue, 5 Jan 2016 16:30:41 -0500 > > Subject: [PATCH] PRELIMINARY: Add support for errno to Dynamic FFI. > > > > --- > > doc/ref/api-foreign.texi | 15 +++++--- > > libguile/foreign.c | 89 ++++++++++++++++++++++++++++++++++++++---------- > > libguile/foreign.h | 4 ++- > > 3 files changed, 85 insertions(+), 23 deletions(-) > > > > diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi > > index c2c49ec..25eaabf 100644 > > --- a/doc/ref/api-foreign.texi > > +++ b/doc/ref/api-foreign.texi > > @@ -1,7 +1,7 @@ > > @c -*-texinfo-*- > > @c This is part of the GNU Guile Reference Manual. > > -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2007, 2008, > > -@c 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. > > +@c Copyright (C) 1996, 1997, 2000-2004, 2007-2014, 2016 > > +@c Free Software Foundation, Inc. > > @c See the file guile.texi for copying conditions. > > > > @node Foreign Function Interface > > @@ -813,8 +813,11 @@ tightly packed structs and unions by hand. See the code for > > Of course, the land of C is not all nouns and no verbs: there are > > functions too, and Guile allows you to call them. > > > > -@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types > > -@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types) > > +@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types @ > > + [#:return-errno?=#f] > > +@deffnx {C Function} scm_pointer_to_procedure (return_type, func_ptr, arg_types) > > +@deffnx {C Function} scm_pointer_to_procedure_with_errno (return_type, func_ptr, arg_types) > > + > > Make a foreign function. > > > > Given the foreign void pointer @var{func_ptr}, its argument and > > @@ -825,6 +828,10 @@ and return appropriate values. > > @var{arg_types} should be a list of foreign types. > > @code{return_type} should be a foreign type. @xref{Foreign Types}, for > > more information on foreign types. > > + > > +If @var{return-errno?} is true, or when calling > > +@code{scm_pointer_to_procedure_with_errno}, the returned procedure will > > +return two values, with @code{errno} as the second value. > > @end deffn > > > > Here is a better definition of @code{(math bessel)}: > > diff --git a/libguile/foreign.c b/libguile/foreign.c > > index 29cfc73..f770100 100644 > > --- a/libguile/foreign.c > > +++ b/libguile/foreign.c > > @@ -1,4 +1,4 @@ > > -/* Copyright (C) 2010-2015 Free Software Foundation, Inc. > > +/* Copyright (C) 2010-2016 Free Software Foundation, Inc. > > * > > * This library is free software; you can redistribute it and/or > > * modify it under the terms of the GNU Lesser General Public License > > @@ -26,6 +26,7 @@ > > #include > > #include > > #include > > +#include > > > > #include "libguile/_scm.h" > > #include "libguile/bytevectors.h" > > @@ -85,7 +86,7 @@ null_pointer_error (const char *func_name) > > } > > > > > > -static SCM cif_to_procedure (SCM cif, SCM func_ptr); > > +static SCM cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno); > > > > > > static SCM pointer_weak_refs = SCM_BOOL_F; > > @@ -753,24 +754,58 @@ make_cif (SCM return_type, SCM arg_types, const char *caller) > > } > > #undef FUNC_NAME > > > > -SCM_DEFINE (scm_pointer_to_procedure, "pointer->procedure", 3, 0, 0, > > - (SCM return_type, SCM func_ptr, SCM arg_types), > > +static SCM > > +pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types, > > + SCM return_errno) > > +#define FUNC_NAME "pointer->procedure" > > +{ > > + ffi_cif *cif; > > + > > + SCM_VALIDATE_POINTER (2, func_ptr); > > + > > + cif = make_cif (return_type, arg_types, FUNC_NAME); > > + > > + return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr, > > + return_errno); > > +} > > +#undef FUNC_NAME > > + > > +SCM > > +scm_pointer_to_procedure (SCM return_type, SCM func_ptr, SCM arg_types) > > +{ > > + return pointer_to_procedure (return_type, func_ptr, arg_types, SCM_BOOL_F); > > +} > > + > > +SCM > > +scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, > > + SCM arg_types) > > +{ > > + return pointer_to_procedure (return_type, func_ptr, arg_types, SCM_BOOL_T); > > +} > > + > > +SCM_KEYWORD (k_return_errno, "return-errno?"); > > + > > +SCM_DEFINE (scm_i_pointer_to_procedure, "pointer->procedure", 3, 0, 1, > > + (SCM return_type, SCM func_ptr, SCM arg_types, SCM keyword_args), > > "Make a foreign function.\n\n" > > "Given the foreign void pointer @var{func_ptr}, its argument and\n" > > "return types @var{arg_types} and @var{return_type}, return a\n" > > "procedure that will pass arguments to the foreign function\n" > > "and return appropriate values.\n\n" > > "@var{arg_types} should be a list of foreign types.\n" > > - "@code{return_type} should be a foreign type.") > > -#define FUNC_NAME s_scm_pointer_to_procedure > > + "@code{return_type} should be a foreign type.\n" > > + "If the @code{#:return-errno?} keyword argument is provided and\n" > > + "its value is true, then the returned procedure will return two\n" > > + "values, with @code{errno} as the second value.") > > +#define FUNC_NAME "pointer->procedure" > > { > > - ffi_cif *cif; > > + SCM return_errno = SCM_BOOL_F; > > > > - SCM_VALIDATE_POINTER (2, func_ptr); > > - > > - cif = make_cif (return_type, arg_types, FUNC_NAME); > > + scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0, > > + k_return_errno, &return_errno, > > + SCM_UNDEFINED); > > > > - return cif_to_procedure (scm_from_pointer (cif, NULL), func_ptr); > > + return pointer_to_procedure (return_type, func_ptr, arg_types, return_errno); > > } > > #undef FUNC_NAME > > > > @@ -940,16 +975,20 @@ get_objcode_trampoline (unsigned int nargs) > > } > > > > static SCM > > -cif_to_procedure (SCM cif, SCM func_ptr) > > +cif_to_procedure (SCM cif, SCM func_ptr, SCM return_errno) > > { > > ffi_cif *c_cif; > > SCM objcode, table, ret; > > > > c_cif = (ffi_cif *) SCM_POINTER_VALUE (cif); > > objcode = get_objcode_trampoline (c_cif->nargs); > > - > > + > > + /* Convert 'return_errno' to a simple boolean, to avoid retaining > > + references to non-boolean objects. */ > > + return_errno = scm_from_bool (scm_is_true (return_errno)); > > + > > table = scm_c_make_vector (2, SCM_UNDEFINED); > > - SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons (cif, func_ptr)); > > + SCM_SIMPLE_VECTOR_SET (table, 0, scm_cons2 (cif, func_ptr, return_errno)); > > SCM_SIMPLE_VECTOR_SET (table, 1, SCM_BOOL_F); /* name */ > > ret = scm_make_program (objcode, table, SCM_BOOL_F); > > > > @@ -1116,9 +1155,11 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) > > unsigned i; > > size_t arg_size; > > scm_t_ptrdiff off; > > + SCM return_errno; > > > > cif = SCM_POINTER_VALUE (SCM_CAR (foreign)); > > - func = SCM_POINTER_VALUE (SCM_CDR (foreign)); > > + func = SCM_POINTER_VALUE (SCM_CADR (foreign)); > > + return_errno = SCM_CDDR (foreign); > > > > /* Argument pointers. */ > > args = alloca (sizeof (void *) * cif->nargs); > > @@ -1153,10 +1194,22 @@ scm_i_foreign_call (SCM foreign, const SCM *argv) > > rvalue = (void *) ROUND_UP ((scm_t_uintptr) data + off, > > max (sizeof (void *), cif->rtype->alignment)); > > > > - /* off we go! */ > > - ffi_call (cif, func, rvalue, args); > > + if (scm_is_true (return_errno)) > > + { > > + int errno_save; > > + > > + errno = 0; > > + ffi_call (cif, func, rvalue, args); > > + errno_save = errno; > > > > - return pack (cif->rtype, rvalue, 1); > > + return scm_values (scm_list_2 (pack (cif->rtype, rvalue, 1), > > + scm_from_int (errno_save))); > > + } > > + else > > + { > > + ffi_call (cif, func, rvalue, args); > > + return pack (cif->rtype, rvalue, 1); > > + } > > } > > > > > > diff --git a/libguile/foreign.h b/libguile/foreign.h > > index 41c0b65..f8a176b 100644 > > --- a/libguile/foreign.h > > +++ b/libguile/foreign.h > > @@ -1,7 +1,7 @@ > > #ifndef SCM_FOREIGN_H > > #define SCM_FOREIGN_H > > > > -/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc. > > +/* Copyright (C) 2010, 2011, 2012, 2016 Free Software Foundation, Inc. > > * > > * This library is free software; you can redistribute it and/or > > * modify it under the terms of the GNU Lesser General Public License > > @@ -94,6 +94,8 @@ SCM_INTERNAL SCM scm_pointer_to_string (SCM pointer, SCM length, SCM encoding); > > > > SCM_API SCM scm_pointer_to_procedure (SCM return_type, SCM func_ptr, > > SCM arg_types); > > +SCM_API SCM scm_pointer_to_procedure_with_errno (SCM return_type, SCM func_ptr, > > + SCM arg_types); > > SCM_API SCM scm_procedure_to_pointer (SCM return_type, SCM func_ptr, > > SCM arg_types); > > SCM_INTERNAL SCM scm_i_foreign_call (SCM foreign, const SCM *argv); > From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 03 12:36:38 2016 Received: (at 18592) by debbugs.gnu.org; 3 Mar 2016 17:36:38 +0000 Received: from localhost ([127.0.0.1]:60414 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1abXB0-0005LO-Cj for submit@debbugs.gnu.org; Thu, 03 Mar 2016 12:36:38 -0500 Received: from world.peace.net ([50.252.239.5]:38189 ident=hope5) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1abXAz-0005LG-Ac for 18592@debbugs.gnu.org; Thu, 03 Mar 2016 12:36:37 -0500 Received: from pool-71-174-32-69.bstnma.east.verizon.net ([71.174.32.69] helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1abXAp-0005E1-OZ; Thu, 03 Mar 2016 12:36:27 -0500 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> <871t8af8no.fsf@netris.org> <1455858156.3838.21.camel@Renee-desktop.suse> <1456485534.7330.63.camel@Renee-desktop.suse> Date: Thu, 03 Mar 2016 12:36:15 -0500 In-Reply-To: <1456485534.7330.63.camel@Renee-desktop.suse> (Nala Ginrut's message of "Fri, 26 Feb 2016 19:18:54 +0800") Message-ID: <87si07sbu8.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Nala Ginrut writes: > Is there still problem? I'm fine with the patch, and I'm expecting to > merge it ASAP. Anyway, please don't hesitate to tell me if there's still > any problem, I'm glad to help to do it better. I really need it. Sorry for the delay, but I'm having second thoughts about whether this is the right approach. Perhaps we should instead make a set of commitments that certain basic operations like scheme evaluation, heap allocation, and basic scheme procedures will leave 'errno' unchanged. At the API level, the idea would be that if you write Scheme code that makes a reasonable effort to avoid non-trivial operations between the FFI call and the call to (errno) or (set-errno! ), this would be sufficient. At an implementation level, it would require us to save and restore 'errno' around C library calls that are made by Guile's runtime system without the user's knowledge, most notably when running GC (during allocation) or when running asyncs and things like that. What do you think? Mark From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 03 16:07:36 2016 Received: (at submit) by debbugs.gnu.org; 3 Mar 2016 21:07:36 +0000 Received: from localhost ([127.0.0.1]:60547 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1abaTA-0002J3-ER for submit@debbugs.gnu.org; Thu, 03 Mar 2016 16:07:36 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58906) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1abaT9-0002Is-Gk for submit@debbugs.gnu.org; Thu, 03 Mar 2016 16:07:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abaT3-0004k7-AK for submit@debbugs.gnu.org; Thu, 03 Mar 2016 16:07:30 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:44674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abaT3-0004k3-7J for submit@debbugs.gnu.org; Thu, 03 Mar 2016 16:07:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abaT2-0001oo-BM for bug-guile@gnu.org; Thu, 03 Mar 2016 16:07:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abaSx-0004jc-BB for bug-guile@gnu.org; Thu, 03 Mar 2016 16:07:28 -0500 Received: from mail.tuxteam.de ([5.199.139.25]:46054 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abaSx-0004jX-5a for bug-guile@gnu.org; Thu, 03 Mar 2016 16:07:23 -0500 Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1abZvN-0001kw-Vl for bug-guile@gnu.org; Thu, 03 Mar 2016 21:32:42 +0100 Date: Thu, 3 Mar 2016 21:32:41 +0100 To: bug-guile@gnu.org Subject: Re: bug#18592: FFI should have =?utf-8?Q?p?= =?utf-8?B?b3J0YWJsZSBhY2Nlc3MgdG8g4oCYZXJybm/igJk=?= Message-ID: <20160303203241.GC5413@tuxteam.de> References: <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> <871t8af8no.fsf@netris.org> <1455858156.3838.21.camel@Renee-desktop.suse> <1456485534.7330.63.camel@Renee-desktop.suse> <87si07sbu8.fsf@netris.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: 8bit In-Reply-To: <87si07sbu8.fsf@netris.org> User-Agent: Mutt/1.5.21 (2010-09-15) From: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, Mar 03, 2016 at 12:36:15PM -0500, Mark H Weaver wrote: > Nala Ginrut writes: > > > Is there still problem? I'm fine with the patch, and I'm expecting to > > merge it ASAP. Anyway, please don't hesitate to tell me if there's still > > any problem, I'm glad to help to do it better. I really need it. > > Sorry for the delay, but I'm having second thoughts about whether this > is the right approach. Perhaps we should instead make a set of > commitments that certain basic operations like scheme evaluation, heap > allocation, and basic scheme procedures will leave 'errno' unchanged. A shout from the peanut gallery (again ;) but this sounds scary. Of course, clobbering errno by things out of the user's control sounds scary too. Nala's interface feels to me more... right. regards - -- tomás -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAlbYn2kACgkQBcgs9XrR2kbhiwCfXq45vAYA5LVcWIcIvyQ1+GKF ZdwAn2QJVVDz/OoS/NUJ7y6R+GCwdxnc =xFmg -----END PGP SIGNATURE----- From debbugs-submit-bounces@debbugs.gnu.org Sun Mar 13 13:06:44 2016 Received: (at 18592) by debbugs.gnu.org; 13 Mar 2016 17:06:44 +0000 Received: from localhost ([127.0.0.1]:47154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1af9TY-0000Et-9k for submit@debbugs.gnu.org; Sun, 13 Mar 2016 13:06:44 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:35753) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1af9TW-0000Eg-AS for 18592@debbugs.gnu.org; Sun, 13 Mar 2016 13:06:42 -0400 Received: by mail-pf0-f182.google.com with SMTP id n5so80118852pfn.2 for <18592@debbugs.gnu.org>; Sun, 13 Mar 2016 10:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:in-reply-to:references :organization:mime-version:content-transfer-encoding; bh=WN7dnx+Y4tIl7XMc7u6YyLs93UQYoJvxbQJwT5M5eOA=; b=v8dlABOejISXCAlciAmmxPxuPckDm/fL1rtns7p7QttoDI/9zaTw25xke+oMH/iDFn AoGCYW9ANxfqofDAj9f/zR50JnZ8ZG24xdL7khqvotbrk32XVpBZQAdrOSNPPglHctpl hIMvJ6dYwqdjQnQSw7yuxfyKYcZd19fy4zjVhgj6Clw/mxS3Yb1RtQQqeKyD0bph1416 u6cLXiVdPepClYOYqgkh/TqSDD+owjBxI0D0XDIdfqQIy2ZyJ6t68JOvw1fU3QbBbgra 9yHqvoKYgowfwewu/f7DwpEik1irUPjF+QGl2xh7Kyt2MwaOj3w33x63soZO3jZE3RnW MeTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=WN7dnx+Y4tIl7XMc7u6YyLs93UQYoJvxbQJwT5M5eOA=; b=YEOdrSXjJEOEY893BEOJSHIx6L8/mG5/6yJEoxyzI4xgyegS/ASsofx2ZcaM+HpDYN xoN0ML13jzSStK9oD3xNINKhlKcOSo6wH7fis6EGPQkYk7Y/2vcMpHRV4RNzvLx5dIYa tXeJQ/XuuyhFhMBwpzMHwGOS2XTIUxBNvlCd+dKoKXbRjiWZ6JsbbcZmi3kvRyPkQ32x glyjHC4e8QHeBK2NWZnzQKVIC2ZJq7gyIce5o08uVYOP06+cOFG6Kcc+fCClQe4j8H3s yhCbKYus7k1d7i80bYEaUdae6/pl4CiHJgdwFh/KtyDq849BCgwGbnGtPEzvXcxFLY1w 7kVw== X-Gm-Message-State: AD7BkJLcfbrH3hbu1r6KP7JB+sRRjFdHQz6nVyZUuyHiL5caCtfdyoXBIQUXxTU2fvcUNg== X-Received: by 10.98.71.9 with SMTP id u9mr12996923pfa.7.1457888796702; Sun, 13 Mar 2016 10:06:36 -0700 (PDT) Received: from [127.0.0.1] (li88-185.members.linode.com. [74.207.246.185]) by smtp.gmail.com with ESMTPSA id 87sm26223523pfq.93.2016.03.13.10.06.34 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 13 Mar 2016 10:06:35 -0700 (PDT) Message-ID: <1457888792.30981.16.camel@Renee-desktop.suse> Subject: Re: bug#18592: FFI should have portable access to =?UTF-8?Q?=E2=80=98errno=E2=80=99?= From: Nala Ginrut To: Mark H Weaver Date: Mon, 14 Mar 2016 01:06:32 +0800 In-Reply-To: <87si07sbu8.fsf@netris.org> References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> <871t8af8no.fsf@netris.org> <1455858156.3838.21.camel@Renee-desktop.suse> <1456485534.7330.63.camel@Renee-desktop.suse> <87si07sbu8.fsf@netris.org> Organization: HFG Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.4.4 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 18592 Cc: 18592@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.7 (/) hi Mark! Fairly speaking, your new proposal sounds cool. But is it necessary to do redundant rework if there's no obvious problem in the first proposed patch? Besides, I think the new proposal may introduce extra complexity to implement. That's what I actually concern about. IMHO, it is better to avoid introducing more complexities, the simple way is better for debugging and maintaining. And it is better for us to have such feature soon, since we need to make more cool projects to enhance Guile usability in real world. Anyway, you have the big picture in mind for Guile, maybe you have your reason for that? Best regards. On Thu, 2016-03-03 at 12:36 -0500, Mark H Weaver wrote: > Nala Ginrut writes: > > > Is there still problem? I'm fine with the patch, and I'm expecting to > > merge it ASAP. Anyway, please don't hesitate to tell me if there's still > > any problem, I'm glad to help to do it better. I really need it. > > Sorry for the delay, but I'm having second thoughts about whether this > is the right approach. Perhaps we should instead make a set of > commitments that certain basic operations like scheme evaluation, heap > allocation, and basic scheme procedures will leave 'errno' unchanged. > > At the API level, the idea would be that if you write Scheme code that > makes a reasonable effort to avoid non-trivial operations between the > FFI call and the call to (errno) or (set-errno! ), this would be > sufficient. > > At an implementation level, it would require us to save and restore > 'errno' around C library calls that are made by Guile's runtime system > without the user's knowledge, most notably when running GC (during > allocation) or when running asyncs and things like that. > > What do you think? > > Mark From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 20 15:55:43 2016 Received: (at 18592-done) by debbugs.gnu.org; 20 Jun 2016 19:55:43 +0000 Received: from localhost ([127.0.0.1]:48034 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bF5IN-0001fz-7S for submit@debbugs.gnu.org; Mon, 20 Jun 2016 15:55:43 -0400 Received: from world.peace.net ([50.252.239.5]:36866) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bF5IJ-0001fk-Dv for 18592-done@debbugs.gnu.org; Mon, 20 Jun 2016 15:55:41 -0400 Received: from c-73-253-48-168.hsd1.ma.comcast.net ([73.253.48.168] helo=jojen) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bF5ID-0000KH-F5; Mon, 20 Jun 2016 15:55:33 -0400 From: Mark H Weaver To: Nala Ginrut Subject: Re: bug#18592: FFI should have portable access to =?utf-8?B?4oCY?= =?utf-8?B?ZXJybm/igJk=?= References: <87fvf8oocf.fsf@ft.bewatermyfriend.org> <87h9vmy0zw.fsf@gnu.org> <87twzgeh3c.fsf@yeeloong.lan> <87r3uko4c9.fsf@gnu.org> <1451565229.3594.59.camel@Renee-desktop.suse> <1451909046.3594.135.camel@Renee-desktop.suse> <8760z9gw7o.fsf@netris.org> <1451934872.3594.150.camel@Renee-desktop.suse> <20160105074924.GA23165@tuxteam.de> <1451983123.3594.156.camel@Renee-desktop.suse> <87vb78jc86.fsf@netris.org> <1452021701.3594.160.camel@Renee-desktop.suse> <1455783943.3838.16.camel@Renee-desktop.suse> <871t8af8no.fsf@netris.org> <1455858156.3838.21.camel@Renee-desktop.suse> <1456485534.7330.63.camel@Renee-desktop.suse> <87si07sbu8.fsf@netris.org> Date: Mon, 20 Jun 2016 15:55:21 -0400 In-Reply-To: <87si07sbu8.fsf@netris.org> (Mark H. Weaver's message of "Thu, 03 Mar 2016 12:36:15 -0500") Message-ID: <87eg7rtz2u.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.95 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 18592-done Cc: 18592-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Mark H Weaver writes: > Nala Ginrut writes: > >> Is there still problem? I'm fine with the patch, and I'm expecting to >> merge it ASAP. Anyway, please don't hesitate to tell me if there's still >> any problem, I'm glad to help to do it better. I really need it. > > Sorry for the delay, but I'm having second thoughts about whether this > is the right approach. Perhaps we should instead make a set of > commitments that certain basic operations like scheme evaluation, heap > allocation, and basic scheme procedures will leave 'errno' unchanged. Okay, I finally decided to go ahead and add 'errno' support to the FFI directly. Pushed in commit ee3381c94d389d923591dcb610bac9ecfd68e6a4 to stable-2.0. If you could make sure it works for your use cases, I'd be grateful. I'm closing this bug now, but feel free to reopen if there are issues. Thanks, Mark From unknown Sat Jun 21 10:42:35 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 19 Jul 2016 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator