From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id EA3HJRSjD2NfygAAbAwnHQ (envelope-from ) for ; Wed, 31 Aug 2022 20:06:12 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id kKPoJBSjD2PTUAEAG6o9tA (envelope-from ) for ; Wed, 31 Aug 2022 20:06:12 +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 226B0829C for ; Wed, 31 Aug 2022 20:06:12 +0200 (CEST) Received: from localhost ([::1]:41726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTS6N-0006LG-7X for larch@yhetil.org; Wed, 31 Aug 2022 14:06:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTS4g-0006IA-SW for emacs-orgmode@gnu.org; Wed, 31 Aug 2022 14:04:27 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]:37737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTS4e-0000WS-Un for emacs-orgmode@gnu.org; Wed, 31 Aug 2022 14:04:26 -0400 Received: by mail-lj1-x22e.google.com with SMTP id x10so15434834ljq.4 for ; Wed, 31 Aug 2022 11:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=oooVVYdXAvv9epSb9TB27qS2t4NnBKxxlp1MyguhVjs=; b=mcCGiI3tone8ZH9qcrHC+abBrQCyeL3KzdY+T/vSL1KXUGMa23wGyNyZBArh/t042L gscw3S4VojgoI3mzm0ud4v6c9k/JCfHH/dO+7NUqms6FoX6AU88ylfDizaMaNSqI2a88 9eDwJDGSsxnMxY16jVxgr/w5MJM7irWIcRlegHhJF9WjssuPwIQBM2Drt1hHbCaEFmQH IAfHEAa63arAAslxDNZxMkU7flKfdn6rtullsZB4rNevjOwMP148+I+YKRJROG0jUvlz MujajaO26KLpFz5S09Mwvmdh4mRC48TdCMy2gA6vDHFNHQ/rNi0nvMgbaNWdEwJ0jZuM nNSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=oooVVYdXAvv9epSb9TB27qS2t4NnBKxxlp1MyguhVjs=; b=Pu4xsh3FflhQD7Vn9dOWM49vHHXNKF5Z4YYe/JMz9u6M8ttld3Bj31J/rRkbSfKLLI BkGLyrttNcOaO5mwOv4LdDh8m2Fcj2/thTCPg0GQ/teo/Ot1fCRoPCSfA2ttBrtqqC5o ci6W5HLr7X7iYlpdY+TUsSZ0phQrz+SNsN2swPSGASmBoHHB4Ng3zxne9IHFL8JdaghR 5AeWkCFj5wIVCjOV5Rn4TpaEGVzuDeiHwC4LDRhnA+3WZ9BtxHvTb9KnqXXp3hc17ETl ewfuTrL1fupjLHukXeNvJ24sdt6Y56PjETLDm+ozwHklC1oEWAdBIJ/1itc4+rgO70Yc P3XQ== X-Gm-Message-State: ACgBeo2bLXwoLrkXXvjLJU5xqm9rtVLT0mT/NcgdXuH5R+9BD3ygM2rO oCEYY5HMau7Qnf5ACNGL/eP328Kb9bM/WVaQyn2l9+4= X-Google-Smtp-Source: AA6agR4fRZ0y84wcy+tnjbcqSqfrpU+liqA7t8r3vDKPJmnU5JnWi7YBeyYqyLFZesCbH+xVNhc5UqKBqSyaYzNeaOA= X-Received: by 2002:a05:651c:1587:b0:261:b558:b6ab with SMTP id h7-20020a05651c158700b00261b558b6abmr8445532ljq.204.1661969060176; Wed, 31 Aug 2022 11:04:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Immanuel Litzroth Date: Wed, 31 Aug 2022 20:03:43 +0200 Message-ID: Subject: Re: Babel C-mode corrupts double-quoted strings in output To: Martin Jerabek Cc: emacs-orgmode@gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::22e; envelope-from=immanuel.litzroth@gmail.com; helo=mail-lj1-x22e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1661969172; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=oooVVYdXAvv9epSb9TB27qS2t4NnBKxxlp1MyguhVjs=; b=B/pC9jExX/GUvjhBud6Er2Pl7c59glXM1E9JiVYG75ukPoC3EoRtznxJi76SFjk2YdxP02 Z23M+B1yf7+h6Xw/r5jyLwGgg8ntvSAMWsGPtM9blgUGzbZ/y+tGh2St9OFz0b9Rt/3l7L b9cip0Tm7izf6nNLqPDcZRmioWEn7AI1HgweowH8j564t/tvTbFr33Tvk5b5aQdYAIUz9R 66DhcoySJwQH9ehkggyukeFoLrhCqekEqMX9qv13bma9BQlLHf5yOZQZc14BvvqANUceE2 OlFbXu5175UIzIVx0lYgK/Vd+VzpoZbIjrFRqWUbGEw9UDdf2HSnGgoV9Meh+A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1661969172; a=rsa-sha256; cv=none; b=E0NMC41gVf5gaOQb7NMeRcoD7jgksy66TpEmy4rkAd/C9JBoahrcXV8Fj+Y1xBIldfC3C0 puKaWTjd+YiGmixyYMjhvEPpGaxDFaOSfhaA8JYQNEIEGES/glAhSX3pKzDRFB8pMHaKpl 8vVK/wJj1Vt3BYFPA4IZsK9uETQtjwth43ki87VZOFv1Qw+ILABq7mEMGGJW7qAMO9biKX uHiAp14KpGFkn7PP0ASj6Bt902ALy9+/eA6cXBBwGMgnTNE8tjx2l34mmZVhXVcOPIqfGk u/J+PbG7JtIIaPgWXKjiMPVvsnze0QUG9fHWtZBalb1hahYhd5p6qp6wbe5B7w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mcCGiI3t; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.28 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mcCGiI3t; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 226B0829C X-Spam-Score: -2.28 X-Migadu-Scanner: scn1.migadu.com X-TUID: 2VtL5umC/HRR I would advise you not to use org babel for compiled languages. There is just too much stuff that doesn't work well and multifile dependencies & build systems are just plain hard to get right. Debugging is annoying and getting org babel to tell you compiler where the source actually came from is impossible, if the lang= uage even supports #line and #file directives (Rust still doesn't). Immanuel Litzroth On Wed, Aug 31, 2022 at 6:38 PM Martin Jerabek wrote: > > Hi! > > I recently started to use Org Babel for C++ programs. One of the programs= outputs several lines with double-quoted strings, similar to this: > > #+NAME: doublequotes_cpp > #+begin_src cpp :includes :results output verbatim raw > std::cout << "\"line 1\"\n"; > std::cout << "\"line 2\"\n"; > std::cout << "\"line 3\"\n"; > #+end_src > > #+RESULTS: doublequotes_cpp > line 1 > > As you can see, only the first line is copied to the RESULTS block, and i= t is stripped of the double quotes. > > I tracked down the problem to org-babel-read (in ob-core.el). org-babel-C= -execute (in ob-C.el) calls this function with the output of the C++ progra= m. The problem is the following line: > > ((eq (string-to-char cell) ?\") (read cell)) > > i.e. if the output of the program starts with a double quote, it is passe= d to read which reads only the first string and also removes the double quo= tes, resulting in the observed output. > > The original version of this piece of code was added with the following c= ommit: > > commit 60a8ba556d682849eafb0f84e689967cd2965549 > Author: Eric Schulte > Date: Wed Mar 2 07:55:39 2011 -0700 > > ob: read string variable values wrapped in double quotes, removing th= e quotes > > * lisp/ob.el (org-babel-read): Read string variable values wrapped in > double quotes, removing the quotes. > > AFAICT this modification was done in response to the email thread "[Orgmo= de] org-babel-read should have option NOT to interpret as elisp" started on= 2011-02-27, more specifically the email on "Wed, 02 Mar 2011 07:56:45 -070= 0" from Eric Schulte. This was obviously done for parsing variables in the = header line, not for the program output, but the Babel C mode uses org-babe= l-read also for the output. > > I assumed that ":results output verbatim raw" would prevent any postproce= ssing of the output but this is not the case for C mode. > > I am not sure how to fix this without breaking backward compatibility. I = assume it should be fixed directly in org-babel-C-execute, not in a central= function like org-babel-read to minimize the impact. Surprisingly (for me)= the equivalent shell script works as expected: > > #+NAME: doublequotes > #+begin_src shell :results output verbatim raw > echo '"line 1"' > echo '"line 2"' > echo '"line 3"' > #+end_src > > #+RESULTS: doublequotes > "line 1" > "line 2" > "line 3" > > because org-babel-execute:shell does not process the output with org-babe= l-read. I do not know if languages other than the C family (C, C++, D) are = affected. > > At the very least, the documentation of org-babel-read should be expanded= to document the fact that if the CELL parameter starts with a double quote= , it is processed by the read function. > > Best regards > Martin Jerabek > --=20 -- A man must either resolve to point out nothing new or to become a slave to defend it. -- Sir Isaac Newton