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 ms5.migadu.com with LMTPS id mO0lIqbjEWOnewEAbAwnHQ (envelope-from ) for ; Fri, 02 Sep 2022 13:06:14 +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 AGYdIqbjEWPzTgEA9RJhRA (envelope-from ) for ; Fri, 02 Sep 2022 13:06:14 +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 1C80112E6E for ; Fri, 2 Sep 2022 13:06:14 +0200 (CEST) Received: from localhost ([::1]:58258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU4V1-0008Q3-QT for larch@yhetil.org; Fri, 02 Sep 2022 07:06:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58792) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4R9-0008Mo-IH for emacs-orgmode@gnu.org; Fri, 02 Sep 2022 07:02:11 -0400 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]:26710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU4R7-00010Z-6h for emacs-orgmode@gnu.org; Fri, 02 Sep 2022 07:02:11 -0400 Received: from [IPv6:2a01:e35:39f3:4610:8057:6f64:f7cf:4745] (unknown [IPv6:2a01:e35:39f3:4610:8057:6f64:f7cf:4745]) (Authenticated sender: tbanelwebmin@free.fr) by smtp4-g21.free.fr (Postfix) with ESMTPSA id 81F3D19F73D for ; Fri, 2 Sep 2022 13:02:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1662116524; bh=qnGdoxQRUKd9XaZNmPxr4Z6BC94Tr/OcYGyR9rzeZeI=; h=Subject:To:References:From:Date:In-Reply-To:From; b=lSFou6ENot2NEiEmDS20YnBP/JcIaUe3q5ypNlWvGUKfLz8/wmD8G9ZcssGYvmTdD D8gZ7YbXvbYJpOTxaIP/0Y5tDmErsY8oKFIKBncNMOyp0ZJd3almQok+pSbm3ur4dw tucWj1vBzF1SCwuJpprATwomFmB4sgLLvKrmoSDPdplPpPhTunfz8u86n49zWOTFXr alZga8gh1QyGP2rlUptZCakRHu7J6QdwCchMzc8qS22NjgkPWONhKIUpnPQ4Q6WYgw V/G/MulHdOaHFmHdGMEqLMR+/2hQsOAoOjDk8j64rROBLSSl0lGpBq3h9mNaUoRbel 96Iaw/ecN21Uw== Subject: Re: Babel C-mode corrupts double-quoted strings in output To: emacs-orgmode@gnu.org References: From: tbanelwebmin Message-ID: <34af937c-f80e-9664-b29e-a767f62ba89e@free.fr> Date: Fri, 2 Sep 2022 13:02:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/html; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a01:e0c:1:1599::13; envelope-from=tbanelwebmin@free.fr; helo=smtp4-g21.free.fr X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 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, HTML_MESSAGE=0.001, MIME_HTML_ONLY=0.1, NICE_REPLY_A=-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=1662116774; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=JkndM1G4cjqIcQoD3LVoIH4QkU3uDDeF6L4+2hLzw0U=; b=GQ3F//lbtwW5jq9Ooi2ArhEM9zdPzPX6eABzJph1JiIK1OsmGIJKoEECzhh88xfHwgPC66 TPc6M0Rh6NqXmpQ+WUelRWkOy2QgW35VHZWd4s/RrxqKCjiqn9TizB8Rs7B2WHLAzqeJSQ oIC4Ah8LYmRdkQPBF6mcBMvrCWPYyvzMCjJpgIZ64MRN2UQaVC92WkfPe+puhOVTa1Z56S N8q+03VwfOgBGgdLVGt8GbSbaKQX4/yrSNYGfPJRRe0ElNJSQiK77QcTbBw562fAeioKmJ P3eHUJkjCa7XeWLIBta8m+IXCKheDkmistcA2ZoyIHoqwbHO2PFSK/4+VG06Uw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1662116774; a=rsa-sha256; cv=none; b=OrHt6c4vjae+FcQNIPaLj1fy2C8Diw9v45x0aATfHZ4zEsFvHy5QOmSnvRP98OvwVbxVi/ +QtM7H0Ib3yiFWX29McHkl9iBUaI51z/MmvebhfrwKiR6QGpOfHLucK4ZlgLgtjyETdIGh vgDGt5Krc2OY8GSjATXb8oXU0RaJkNbYaulMDvzqc3oVvaU0tfQNjmSBxYSsEaT8V1tS7G 3lDNLUOs/XMMXCAY7Fy4ElRQJ2OPhKIXpY/D7hjFCKN6+kAVTS+hvJKLCHFyq6hdGEDj91 WznJytF3tLxhP4hx4NSjhp1yvaaUHo2yrUvXXdNvWhLGktoWBFZn6xcCBUEIag== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=free.fr header.s=smtp-20201208 header.b=lSFou6EN; dmarc=pass (policy=none) header.from=free.fr; 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: -5.47 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=free.fr header.s=smtp-20201208 header.b=lSFou6EN; dmarc=pass (policy=none) header.from=free.fr; 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: 1C80112E6E X-Spam-Score: -5.47 X-Migadu-Scanner: scn0.migadu.com X-TUID: rwpGQe74x14c This looks like a bug in ob-C.el

Around line 196 we should replace
  (org-babel-read results t)
with
  results

In this way, ob-C.el will look more like ob-shell.el

Let me see what are the consequences with such a fix.

Thanks Martin for investigating deep in the sources!

Regards


Le 31/08/2022 à 18:35, Martin Jerabek a écrit :
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 <iostream> :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 it 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++ program. 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 passed to read which reads only the first string and also removes the double quotes, resulting in the observed output.

The original version of this piece of code was added with the following commit:

commit 60a8ba556d682849eafb0f84e689967cd2965549
Author: Eric Schulte <schulte.eric@gmail.com>
Date:   Wed Mar 2 07:55:39 2011 -0700

    ob: read string variable values wrapped in double quotes, removing the 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 "[Orgmode] 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 -0700" 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-babel-read also for the output.

I assumed that ":results output verbatim raw" would prevent any postprocessing 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-babel-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