From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: paul Newsgroups: gmane.lisp.guile.user Subject: Difficulty integrating with Swift/Objective-C Date: Sun, 05 Sep 2021 16:03:24 +1000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29758"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 27.2 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 05 08:04:21 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mMlGO-0007Ur-Gv for guile-user@m.gmane-mx.org; Sun, 05 Sep 2021 08:04:20 +0200 Original-Received: from localhost ([::1]:37072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mMlGM-00021F-Ut for guile-user@m.gmane-mx.org; Sun, 05 Sep 2021 02:04:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mMlFm-000217-Un for guile-user@gnu.org; Sun, 05 Sep 2021 02:03:43 -0400 Original-Received: from aibo.runbox.com ([91.220.196.211]:38938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mMlFj-0005FN-Eh for guile-user@gnu.org; Sun, 05 Sep 2021 02:03:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=inktvis.org ; s=selector1; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Message-ID:Date:Subject:To:From; bh=e3nvE7e/k6D6nux92QTBf0/eKMPMrvXhIaWnvzwW2A8=; b=jRz8Qe9m19IVqDtwFjunozDgv+ RP0P3LzRcdi/8dhMdn5Z/Y+tRX06jvkdQDXavRdy6RotHBLMR6eZR2uHCoz7dQlBDwHi57O/VztZ2 49Kj4NlyzG/ORpJo2ucDewTfa78HOZZWTYIozbbsuUKQcXFzigK2UpM6LVficdIDNx7FfJ4mnNQvO yjXyb0waDfUdEl1drSW9xay1dSdZKqtfq9kWe4jIfAiVEs04p2jJcMFYkHhvF+AAAP6kFU8EPKe32 Q/SAqo9unf//7SMLGr19Hd5gGuEDHWaauooAFkrrQC7Dhe/l/XGXO2W2Z/zp1J0kYB31NY81zSQFT TuPTuYiQ==; Original-Received: from [10.9.9.72] (helo=submission01.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1mMlFg-0007Zy-EV for guile-user@gnu.org; Sun, 05 Sep 2021 08:03:36 +0200 Original-Received: by submission01.runbox with esmtpsa [Authenticated ID (826552)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1mMlFa-0008LB-JM for guile-user@gnu.org; Sun, 05 Sep 2021 08:03:31 +0200 Received-SPF: pass client-ip=91.220.196.211; envelope-from=paul@inktvis.org; helo=aibo.runbox.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17712 Archived-At: Good day, I have an existing app which is written in Swift and runs on macOS=20 10.15. I would like to provide users a way of customising the app=20 (initially just simple things like modifying keybindings for=20 example, later hopefully more) and as a keen Emacs user, i'm=20 inspired by the idea of providing a Schemey/Lispy interface for=20 such extensions. Guile looks like it'd be great for this. If i=20 understand correctly, it'd be best if i could bundle the Guile=20 runtime as a static library with the app, and call out to it to=20 evaluate user-provided code. I haven't thought deeply about this=20 interface yet; i thought i'd get a proof-of-concept working first.=20 I wonder if i might humbly ask for some guidance on how to get it=20 working, because after a couple of days i seem to have failed.=20 I'm no C/threads/low-level guru, so my apologies if i'm doing=20 something very dumb. I had some difficulty getting my app to compile against Guile, but=20 i eventually managed to link against a version of Guile installed=20 with Homebrew (guile: stable 3.0.7 (bottled)), however when trying=20 to boot it up i seemed to run into the same issue described by=20 Jeffrey Walton [1]. My app would boot, and as soon as it hit the=20 Guile initialisation calls, it would error with "allocating JIT=20 code buffer failed: Permission denied, jit.c:5804: fatal:=20 assertion failed". While that person seems to imply the problem=20 is with Apple's M1 silicon, i'm actually running an older machine=20 (2.9 GHz Dual-Core Intel Core i5, macOS 11.5.2). I then managed=20 to get further by downloading the Guile release tarball version=20 3.0.7 and and building with `./configure --enable-jit=3Dno`; this=20 got me a bit further, however it still didn't work: i think it is=20 because some assumption Guile has about the thread it runs on, or=20 when it's invoked, is violated.. but i'm unsure how to find out. What i currently have, is this snippet. It's being called from=20 Swift land, in the `applicationDidFinishLaunching(_ aNotification:=20 Notification)` function. As far as i can tell, that _is_ the main=20 thread. ``` #include "libguile.h" static void* register_functions (void* data) { SCM test =3D scm_c_eval_string("(+ 3 5)"); int foo =3D scm_to_int(test); printf("foo =3D %d\n", foo); return NULL; } void run_guile() { printf("hello from C, before Guile\n"); scm_init_guile(); //scm_with_guile(®ister_functions, NULL); // i've tried=20 only having this line uncommented, too, but that also causes=20 immediate crashes //scm_shell(0, NULL); } ``` This compiles fine, and i see the "hello from C" line printed, but=20 then it crashes. The error seems to vary, here are some i've=20 seen: 1. "Thread 1: EXC_BAD_ACCESS (code=3D1, address=3D0x0)" at line 182 of=20 pairs.h, 2. "Pre-boot error; key: misc-error, args: ("%search-path" "path=20 is not a proper list: ~a" (("/usr/local/share/guile/3.0"=20 "/usr/local/share/guile/site/3.0" "/usr/local/share/guile/site"=20 . #)) #f)", "Thread 1: signal=20 SIGABRT", line 260 of throw.c 3. "Thread 1: EXC_BAD_ACCESS (code=3D1, address=3D0x9)", at line 585=20 of weak-set.c. 4. I've also sometimes seen this one,=20 https://lists.gnu.org/archive/html/emacs-bug-tracker/2020-01/msg00365.html,= =20 although perhaps that's indeed related to closed stdout. Because these errors are different all the time i guess it's some=20 race condition or threading issue? I wonder if someone knows an=20 avenue i can attempt to use to debug what's going on? =F0=9F=99=8F All the best, paul 1. https://mail.gnu.org/archive/html/bug-guile/2021-03/msg00012.html