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: Thu, 20 Jul 2017 20:26:58 +0200 Message-ID: <87k2333qx9.fsf@gmail.com> References: <87lgtajpkc.fsf@web.de> <87h8y7ruuz.fsf_-_@gnu.org> <877ez384eu.fsf@elektro.pacujo.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1500575003 1485 195.159.176.226 (20 Jul 2017 18:23:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Jul 2017 18:23:23 +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 Thu Jul 20 20:23:17 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 1dYG6T-0008Ij-Iy for guile-user@m.gmane.org; Thu, 20 Jul 2017 20:23:13 +0200 Original-Received: from localhost ([::1]:39418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYG6Z-0000wN-4s for guile-user@m.gmane.org; Thu, 20 Jul 2017 14:23:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYG49-0008GU-3R for guile-user@gnu.org; Thu, 20 Jul 2017 14:20:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYG48-0007F4-2g for guile-user@gnu.org; Thu, 20 Jul 2017 14:20:49 -0400 Original-Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:37349) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dYG47-0007ES-R3; Thu, 20 Jul 2017 14:20:48 -0400 Original-Received: by mail-wr0-x243.google.com with SMTP id 12so2838245wrb.4; Thu, 20 Jul 2017 11:20:46 -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:content-transfer-encoding; bh=xINQjaSlIRJiRX4UBkh0x3wdGWqVLnccQscQv3cvNZs=; b=I5SpHChm70CBE2Bud3jRU0xAMok9I6TQalFvdfuA0UGnvsabtM1G8IGg1je1S16q/+ JMYP2OtopnmNz+aGHw67vbYP6G7L1ghiCT9CVYhCwv9AYVQn3Khe94aY8ZG60QuOluOO X/Jf14bjKYX/VALkO8JkuK120oHIJauNts3cKU5uKOW9AGqRMTCsl4wGPZJrUshJu3j2 EFt8ikx/dQmN5oE7VYwOTrPfqHS3zqbsWBUY1plsOtf451FMqgxIQKAgguEgGMcqOWr2 zQGddsmM9Tzbr5QS3Gvej+xir8mhRRwZN5S6NWD+3JfF7h8pZmX2I9PNtYUWr39P3Sls isFA== 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:content-transfer-encoding; bh=xINQjaSlIRJiRX4UBkh0x3wdGWqVLnccQscQv3cvNZs=; b=mFgG6e5eD8KbaJjz6hyc9uH6ezf5U8WgZ9vuGOoptvzrzShd96kE4eMntjXNA4ynCt NhybIFtGJCdaophGzSGwZkw0EVbn/wc1dd/iGijykI+DXTqndvgre9yUZIMhc6VopMzr rAymUvmvq+zwmaTvzDHqsgvZoHcgv067cLdZmOnCZurrSbccFmSfDrUKgxtyI6hrUtJI 3UrFz2FbOVwnBjsxgOUY7zfHxfxKbTN1TsCaNwv1tA4GhmrKc4/iAiDp7tNLLv1MpVaT w8bRQoR0aLE9/KVpByTc+aaOL+w5emOQ9s+ln2/Lg3DWB+vBv0EldY83UyuC2ML+WzMu 0GuA== X-Gm-Message-State: AIVw113hjvysrEwi5d6L22Ky2L/YGd6fGrjenRmCyT89Liz8ZbfYZTxM W6NIjM2vvN3NLja9 X-Received: by 10.223.146.164 with SMTP id 33mr7575197wrn.134.1500574844782; Thu, 20 Jul 2017 11:20:44 -0700 (PDT) Original-Received: from T420 ([2a02:908:c30:6ec0:221:ccff:fe66:68f0]) by smtp.gmail.com with ESMTPSA id l46sm7930178wrl.15.2017.07.20.11.20.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Jul 2017 11:20:43 -0700 (PDT) In-Reply-To: <877ez384eu.fsf@elektro.pacujo.net> (Marko Rauhamaa's message of "Thu, 20 Jul 2017 19:22:01 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 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:13953 Archived-At: Marko Rauhamaa writes: > ludo@gnu.org (Ludovic Court=C3=A8s): > >> I=E2=80=99m very skeptical about this use case (I=E2=80=99d use =E2=80= =98mmap=E2=80=99 and get a >> bytevector.) > > Please elaborate. > > 1. Does Guile offer mmap to Scheme code? It's pretty easy to call C functions from Scheme. Here's a trivial example. $ cat map_file.c #include #include #include #include #include void *map_file(char *file) { int fd =3D open(file, O_RDONLY); off_t size =3D lseek(fd, 0, SEEK_END); return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); } $ gcc -shared -o map_file.so -fPIC map_file.c $ guile )> ,use (system foreign) )> (define map-file (pointer->procedure '* (dynamic-func "map_file" (dynamic-link "./map_file")) (list '*))) )> (define file-ptr (map-file (string->pointer "/home/taylan/todo"))) )> (define file-bv (pointer->bytevector file-ptr 100)) ;see note below )> file-bv $3 =3D #vu8(45 42 45 32 111 114 103 32 45 42 45 10 10 ...) That's ASCII for "-*- org -*-\n\n", which is what my todo file begins with. :-) (It's a file mode marker for Emacs, for those who don't know.) Note: The second argument to pointer->bytevector defines the size of the bytevector. I passed 100 because I was too lazy to get the size of the file. You should pass the size of the file in bytes. > 2. What would prevent Guile's GC from scanning the mmapped area for > pointers? I don't know the details but AFAIK this is no problem with Boehm GC. > 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/ > Marko Hope I could help, Taylan