From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id mNmJBJa0bGTQWgEASxT56A (envelope-from ) for ; Tue, 23 May 2023 14:41:58 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id KDmLBJa0bGSkBwAA9RJhRA (envelope-from ) for ; Tue, 23 May 2023 14:41:58 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E4FE4389B7 for ; Tue, 23 May 2023 14:41:57 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q1RK9-0001iV-Bl; Tue, 23 May 2023 08:41:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RK3-0001gA-Un for bug-guix@gnu.org; Tue, 23 May 2023 08:41:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q1RK3-0003Vg-Mi for bug-guix@gnu.org; Tue, 23 May 2023 08:41:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q1RK3-00035d-J7 for bug-guix@gnu.org; Tue, 23 May 2023 08:41:03 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#63516: [PATCH Guile-Netlink 03/11] connection: Throw upon errors in FFI bindings. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Tue, 23 May 2023 12:41:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63516 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 63516@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 63516-submit@debbugs.gnu.org id=B63516.168484562511732 (code B ref 63516); Tue, 23 May 2023 12:41:03 +0000 Received: (at 63516) by debbugs.gnu.org; 23 May 2023 12:40:25 +0000 Received: from localhost ([127.0.0.1]:38533 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1RJR-000339-3Y for submit@debbugs.gnu.org; Tue, 23 May 2023 08:40:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44330) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q1RJJ-00031j-6O for 63516@debbugs.gnu.org; Tue, 23 May 2023 08:40:17 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RJ9-0003Af-Af; Tue, 23 May 2023 08:40:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=ej7mfhboHb9U79Nt3rKXKtleDDIvybI9C0rOeRDnAgU=; b=M63dnaoYH6D6iny/b5W/ hkuVFi4RmC+AEJfPgcP7WV2Ji/NjicoP78+LbRVAhsKUUaaEz8/G7cdVgdoC5OsanxKwpw0Epks43 Wv/ffz4YRkzofanuirdGCCcN4zyXyYGeRYIwCGkKl4lk6q2uFcba72PCA4ywOk1wVnPVjlL3QdnHg /0RLTMobRJFpDhXuT9Zwk6zadXtu1HzTvy9SAcmn/RiGr3/EwmPamf0aG/nLUFjO+gDi8BAYwUBMi cnScYBK9/zpPNJnRdSiTXyO2tSD+6QHLhBcmztep0Fo/BWw/fx7KpPZ8kBysQ/XMDi5YSVzmiwXew hW5MfO7HaW4iqQ==; Received: from [193.50.110.247] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q1RJ7-00081G-ML; Tue, 23 May 2023 08:40:06 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 23 May 2023 14:39:43 +0200 Message-Id: <20230523123951.6225-4-ludo@gnu.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230523123951.6225-1-ludo@gnu.org> References: <871qjawqpt.fsf@gnu.org> <20230523123951.6225-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Seal: i=1; s=key1; d=yhetil.org; t=1684845717; a=rsa-sha256; cv=none; b=gkHaSxDB3aD7SPeFB7E9r5T2Qim4UwDqW3cjx0M7YVlH/t01VshaXB4e5QKDMSK45ycSnn WLADSzwviNKMs4NKzqg1/CPakz69sw/2IvX9t72+PmNoWX9CVK0dCRpPZgKAE7wbuFwoPV YJeBpAGS5FB9dvkIcCghw4ja6Joneh9VkxFbR8WbJL5bzs14lugd2gAcTNXqATyp78xcIY xOvd1G7u+AOe0/Z044YTSNoVz8HVFqcuQLy2zGhv/e3IOhLIt0Gwgy0gK0HhnvF6xGBN0j KngIDnLRIWNCdX375uT74qC+MhnjfYMIvKXTWRfWF8HGfe9/1N1ilqSNGONrDg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=M63dnaoY; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1684845717; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=ej7mfhboHb9U79Nt3rKXKtleDDIvybI9C0rOeRDnAgU=; b=GEZWmwNHM5NaGvWey//7cyAg9uOsc8/VuA/hZ1NbzI4ZsKJVfRfgupDVC70b43Y5+Ix3lH In3EXp3l5Jx7rmp+zcFRPQGUYq26KWN+d/lBhKlpe99SLHdVZnDBo4FTUUF1IOmEDUkOz8 8Nuc5wwRNsD9etrS6cDiuPsaBjU/l4dCcSag0CfXj8p2bt/P4UiajjwdrRq8MeFd1n99mV +wQZuI1uv3ERxafiMEKUYEZuvT2hpG+u5CGkBydmQM9vLK9Y1+DgUZsPJ+S2Q5x8JNfzSH zGIHCaAY76dXct9U6GX0RxeiSY6Y43WMlCwtN6lsYXK/RIlntQ56bS3XKTZUXw== X-Migadu-Scanner: scn1.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=M63dnaoY; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.57 X-Spam-Score: -1.57 X-Migadu-Queue-Id: E4FE4389B7 X-TUID: iCVQiZ+j/mnd * netlink/connection.scm (syscall->procedure): New procedure. (ffi-sendto, ffi-recvmsg, ffi-bind): Use it. --- netlink/connection.scm | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/netlink/connection.scm b/netlink/connection.scm index 6f41ef8..f4a5cc6 100644 --- a/netlink/connection.scm +++ b/netlink/connection.scm @@ -1,7 +1,8 @@ ;;;; This file is part of Guile Netlink ;;;; ;;;; Copyright (C) 2021 Julien Lepiller -;;;; +;;;; Copyright (C) 2023 Ludovic Courtès +;;;; ;;;; This library is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or @@ -24,6 +25,7 @@ #:use-module (system foreign) #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) + #:use-module (srfi srfi-71) #:export (connect connect-route close-socket @@ -34,16 +36,27 @@ (define libc (dynamic-link)) -(define ffi-sendto (pointer->procedure int - (dynamic-func "sendto" libc) - (list int '* size_t int '* int) - #:return-errno? #t)) -(define ffi-recvmsg (pointer->procedure int - (dynamic-func "recvmsg" libc) - (list int '* int))) -(define ffi-bind (pointer->procedure int - (dynamic-func "bind" libc) - (list int '* int))) +(define (syscall->procedure return-type function + argument-types) + "Return a procedure that calls FUNCTION, a syscall wrapper from the C library +with the given RETURN-TYPE and ARGUMENT-TYPES." + (let ((proc (pointer->procedure return-type + (dynamic-func function libc) + argument-types + #:return-errno? #t))) + (lambda args + (let ((ret errno (apply proc args))) + (when (< ret 0) + (throw 'system-error function "~A" + (list (strerror errno)) (list errno))) + ret)))) + +(define ffi-sendto + (syscall->procedure int "sendto" (list int '* size_t int '* int))) +(define ffi-recvmsg + (syscall->procedure int "recvmsg" (list int '* int))) +(define ffi-bind + (syscall->procedure int "bind" (list int '* int))) ;; define simple functions to open/close sockets (define (open-socket proto) -- 2.40.1