From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: taylanbayirli@gmail.com (Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Guile bugs Date: Fri, 21 Jul 2017 18:33:58 +0200 Message-ID: <87eft94umh.fsf@gmail.com> References: <87lgtajpkc.fsf@web.de> <87h8y7ruuz.fsf_-_@gnu.org> <877ez384eu.fsf@elektro.pacujo.net> <87k2333qx9.fsf@gmail.com> <87pocvc5ya.fsf@elektro.pacujo.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500654535 28414 195.159.176.226 (21 Jul 2017 16:28:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 21 Jul 2017 16:28:55 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , guile-user@gnu.org To: Marko Rauhamaa Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jul 21 18:28:48 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYanC-0006hb-RY for guile-user@m.gmane.org; Fri, 21 Jul 2017 18:28:43 +0200 Original-Received: from localhost ([::1]:44053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYanH-0002lL-Vu for guile-user@m.gmane.org; Fri, 21 Jul 2017 12:28:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYamw-0002lB-F7 for guile-user@gnu.org; Fri, 21 Jul 2017 12:28:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYamv-0001uq-5D for guile-user@gnu.org; Fri, 21 Jul 2017 12:28:26 -0400 Original-Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:37370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dYamu-0001uJ-Ui; Fri, 21 Jul 2017 12:28:25 -0400 Original-Received: by mail-wm0-x242.google.com with SMTP id m4so7526928wmi.4; Fri, 21 Jul 2017 09:28:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=kgoMRHIDLQ7sXl8zj4xkQ/yvDHVO+LmxyElKnL91w/0=; b=YXVtnWHNmUpMrJLs4eG9nPu8fgfvusmAv6FKl4r+SRjidIxPtq0LeU7SmWbghIpfj6 Onw4qjvMXd6TinVEHzevwu56a0HOxWJiPkwjp+AmBR21VQPu5+toNzT0dAaGIZsAyIx9 gfwnX1Rv5XIdciX10YVwJ8TJzXc6fAnj5tmZysk5uoKKmRGFNw8zO1DMxVO61sXiS8QS QASC8ORB1zmEShxHScqW4A+bUch+oCMsNYS4VEEH3rAD6wP2XCjk3w2FWYmK0YLu+/NZ JCSYMIU37gV0OfUiPkXs7rWzssiOckGj3/XVZjYogSGzlA8g7ii5UScyo5VwdGOPRokP m26w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=kgoMRHIDLQ7sXl8zj4xkQ/yvDHVO+LmxyElKnL91w/0=; b=XTo1LZ6EpcsgvOkuEq+U1Fslbw/5gRyCrHyJPAu+ObfxlzSLz8zx/QC8HDl2kOPpS1 8pXRWt1nkHYrLdDGjBtr81dQP9pIPoSBs8BpEoWAif4B0uj9NFKezm1LNQ7MT6/Pz6lj V7s0Od+Ttb4hK8CqriWgrvmyIk0NT/UFzrkp/iWKZreZlxuxa9m/jDcuPggWyEg8WvgV IRt8qYHW7OqvMbK3HQ6dGAQDQk4n7DDjtQeXPWKw0M2PX4cgC8mNS/WW018vZFW4z1mY 7dDWX4SldGMtxy4ED0VGtn+yyWbcG7x+h3K3puenMQS/7f6AVezlyVLQxXJ62Xm6Bzz+ ASmQ== X-Gm-Message-State: AIVw1100dbQiCOB9tHJtjvUqjLwUODtu1A2psPm6+U3jCWdxb38aYOAS R/HTInkTV81ud4c5 X-Received: by 10.28.20.76 with SMTP id 73mr5451485wmu.66.1500654503339; Fri, 21 Jul 2017 09:28:23 -0700 (PDT) Original-Received: from T420 ([2a02:908:c30:6ec0:221:ccff:fe66:68f0]) by smtp.gmail.com with ESMTPSA id b80sm1508715wmf.10.2017.07.21.09.28.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Jul 2017 09:28:22 -0700 (PDT) In-Reply-To: <87pocvc5ya.fsf@elektro.pacujo.net> (Marko Rauhamaa's message of "Thu, 20 Jul 2017 21:35:09 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13970 Archived-At: Marko Rauhamaa writes: >>> 1. Does Guile offer mmap to Scheme code? >> >> It's pretty easy to call C functions from Scheme. > > Not good enough. I would have to precompile libraries for different > target platforms (or require the target environment to have a C > compiler). Besides, the need is quite generic and shouldn't require an > extension. One can also call standard C functions through the same Guile interface that I used in my example, so one can e.g. turn mmap() into a Scheme procedure. open() already happens to exist in the form of 'open-fdes', and to get the file size one can use (stat:size (stat "filepath")). The only remaining problem is that mmap's flag constants like PROT_READ, MAP_SHARED, etc. don't exist in Guile, and can't be reached through FFI since they're #define constants. Sans that problem, this works: )> ,use (system foreign) )> ,use (rnrs bytevectors) )> (define mmap (pointer->procedure '* (dynamic-func "mmap" (dynamic-link)) ;[1] (list '* size_t int int int size_t))) )> (define fd (open-fdes "/home/taylan/todo" O_RDONLY)) )> (define size (stat:size (stat fd))) )> (define file-ptr (mmap (make-pointer 0) size 1 2 fd 0)) ;[2] )> (define file-bv (pointer->bytevector file-ptr size)) )> (integer->char (bytevector-u8-ref file-bv 0)) $1 = #\- [1] When dynamic-link is called with no argument, it returns a "global symbol handle" that contains the lib bindings of the Guile process. A Guile process is sure to have "mmap" linked in. [2] The numbers 1 and 2 happen to correspond to PROT_READ and MAP_PRIVATE on my system. As a temporary workaround to the problem that mmap flag constants don't exist in Guile, one could define them manually for the systems one intends to support in the foreseeable future. >>> 3. How do I efficiently encode information in a bytevector in Scheme >>> code? >> >> What sort of data? >> >> I have a library called bytestructures that imitates the C type system >> within Scheme, to be used on bytevectors that contain data structures >> generated by C code, though the library is built upon a generic core >> with which other structures can be declared as well. Not sure if this >> helps you: >> >> https://github.com/TaylanUB/scheme-bytestructures/ > > That's precisely it. It would be nice to have it as part of standard > Guile. Maybe one day. These days I don't have much time to work on it. Maybe I'll see that I provide a GNU-compliant build system first so people can install it easily. In case you use Guix, someone made a package for it, so you could install it through there too. > I wonder, though, if doing that is fast enough in Scheme code. Since Guile supports syntax-case, the "macro API" of the library can be used so the library itself adds absolutely zero runtime overhead. (This API puts a few limits on the full feature set, but the standard modules that mimic C types don't use those features.) Taylan