From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id CBLxJsISbGCEUQAAgWs5BA (envelope-from ) for ; Tue, 06 Apr 2021 09:50:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id GJXcIMISbGAbSwAAB5/wlQ (envelope-from ) for ; Tue, 06 Apr 2021 07:50:26 +0000 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 B37301568F for ; Tue, 6 Apr 2021 09:50:25 +0200 (CEST) Received: from localhost ([::1]:34000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lTgTf-0003wr-HZ for larch@yhetil.org; Tue, 06 Apr 2021 03:50:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lTgT6-0003wk-If for emacs-orgmode@gnu.org; Tue, 06 Apr 2021 03:49:48 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]:13215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lTgT0-0004vF-TW for emacs-orgmode@gnu.org; Tue, 06 Apr 2021 03:49:47 -0400 Received: from [IPv6:2a01:e35:39f3:4610:a4fb:6759:bf1c:882a] (unknown [IPv6:2a01:e35:39f3:4610:a4fb:6759:bf1c:882a]) by smtp2-g21.free.fr (Postfix) with ESMTPS id 536772003E8 for ; Tue, 6 Apr 2021 09:49:39 +0200 (CEST) Subject: Re: Bug: Incompatible return type in org-babel C when using a table of doubles with a header as a variable [9.4.4 (release_9.4.4-272-ga9f38b @ /home/richard/.emacs.d/straight/build/org/)] To: emacs-orgmode@gnu.org References: From: tbanelwebmin Message-ID: <80bf5e0b-37ef-e750-793a-f37630de0bf7@free.fr> Date: Tue, 6 Apr 2021 09:49:38 +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/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Received-SPF: pass client-ip=212.27.42.2; envelope-from=tbanelwebmin@free.fr; helo=smtp2-g21.free.fr X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1617695426; 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; bh=NqtxGR+0NKho0YqmzymWVBB6P21DypfsiwBd6tTmbMA=; b=s1gSYG69mOd0P3YaZGBy+hTwDNLjcTXdf9nbUt60A7znx1Q1P5FMAGy8Aic3u+klu7qVhB GkDsjo2ef+ec5En/KLhILm8iRpeq8CEdqHgPGVoh4PEk4AzCP2Hf0wLZNwgxXyO7RXR3s8 YO432iz3Nb2RV62mSAzPGSvZFAkNA2jeRT9yXUP0tvv56E5PSKN3E6xpVr3WGcpm5YoKgR PiWTgcxtRTHN0HMK5FazTvU79gXajoHu8VCNIoBDGt/iHZmI664ohxfmEDiU18HL+3azsy 9fiMQDbxKgZJRwEwXQwyPUkQ0l9Cb9waTxt+PqhP8sg95Vn4nNl5pVN4aZDBZg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1617695426; a=rsa-sha256; cv=none; b=neVCfaUYYwDIIa0WbmT0BbIt5yJDFXtW8enuSwcEBSd32PvRJoc4vDxOHYnYuG48xEJdBY ogoc8GfQkJNyUzXebSaWkUxHaigfeC0XfzVa5df9hGMWD3bX7rORC5YV93+1LLmyrPSq0c 9RwuSRRS7IvxQFAhR6DSuS4ID/+E076Vc1JkMxMu/qzrebAW33RShE+uuuGc7bzDEp1QSc ruMDMwc4YbZlbGyIF57l31dRvxWuv67k+SorVDxbuAjaSE5JlpsTxhaAyyUwDChcOQBGKU D2yu7pEkJFn4L9jBOHASv9kYeKVp1xBXmxD/aPKj6d9v+EZwA3PwfXL/67R70w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=free.fr (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -0.84 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=free.fr (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: B37301568F X-Spam-Score: -0.84 X-Migadu-Scanner: scn0.migadu.com X-TUID: N/fhW6AfiYO/ Richard, yourbug submission uncovered 3 problems. From minor to major: 1. Missing delimitersin your example change   :includes stdio.h to       :includes 2. The function strcmp() is undefined A patch has already been committed to fix that, in early January. 3. A mess between char* and double in automatically generated code. This is a regression. I am investigating it. Stay connected for an update. Thanks for reporting! Cheers Thierry Le 02/04/2021 à 19:40, Richard Sent via General discussions about Org-mode. a écrit : > When a table of floating pointer numbers that contains a header row is > set as a variable to a C source block, the generated header file > contains an invalid return type, causing the program to not compile. > > For example, if I have a table that looks like > > #+NAME: tbl-doubles-org-bug-report > #+begin_src C :includes :results table :colnames '("i" "val") >   for (int i = 0; i < 5; i++) { >     printf("%f %f\n", (double)i, i * 2.0); >   } > #+end_src > > #+RESULTS: tbl-doubles-org-bug-report > |   i | val | > |-----+-----| > | 0.0 | 0.0 | > | 1.0 | 2.0 | > | 2.0 | 4.0 | > | 3.0 | 6.0 | > | 4.0 | 8.0 | > > And then attempt to include that table as a variable called data > > #+begin_src C :includes stdio.h :var data=tbl-doubles-org-bug-report >   printf("No errors!"); > #+end_src > > Nothing is printed, and *Org-Babel Error Output* will display > > /tmp/babel-NQHi51/C-src-lsA892.c: In function ‘data_h’: > /tmp/babel-NQHi51/C-src-lsA892.c:24:65: error: incompatible types when > returning type ‘double’ but ‘const char *’ was expected >    24 | const char* data_h (int row, const char* col) { return > data[row][get_column_num(2,data_header,col)]; } >       |                                                        > ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > /bin/bash: line 1: /tmp/babel-NQHi51/C-bin-90Zk27: Permission denied > > If we look in the /tmp file mentioned, it's easy to see the > inconsistency. > > double data[5][2] = { > {0.000000,0.000000}, > {1.000000,2.000000}, > {2.000000,4.000000}, > {3.000000,6.000000}, > {4.000000,8.000000} > }; > const int data_rows = 5; > const int data_cols = 2; > int get_column_num (int nbcols, const char** header, const char* column) > { >   int c; >   for (c=0; c     if (strcmp(header[c],column)==0) >       return c; >   return -1; > } > const char* data_header[2] = {"i","val"}; > const char* data_h (int row, const char* col) { return > data[row][get_column_num(2,data_header,col)]; } > int main() { > printf("No errors!"); > return 0; > } > > data_h() should not return a const char*, but a double. > > I've also tested this with $ emacs -Q and the issue is still present. It > does not occur if the table contains integer values instead of floats > or if a header row is omitted. Seeing as how the header row is processed > differently from the data, I don't think the presence of a header row is > meant to cause this error. > > > > Emacs  : GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version > 3.24.22, cairo version 1.17.3) > of 2020-08-28 > Package: Org mode version 9.4.4 (release_9.4.4-272-ga9f38b @ > /home/richard/.emacs.d/straight/build/org/) > > current state: > ============== > (setq > org-src-mode-hook '(org-src-babel-configure-edit-buffer > org-src-mode-configure-edit-buffer doom-modeline-set-org-src-modeline) > org-link-shell-confirm-function 'yes-or-no-p > org-blank-before-new-entry '((heading . t) (plain-list-item . t)) > org-metadown-hook '(org-babel-pop-to-session-maybe) > org-clock-out-hook '(org-clock-remove-empty-clock-drawer) > org-html-format-inlinetask-function > 'org-html-format-inlinetask-default-function > org-odt-format-headline-function 'org-odt-format-headline-default-function > org-agenda-files '("~/org") > org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default > org-startup-folded t > org-mode-hook '(#[0 "\301\211\207" [imenu-create-index-function > org-imenu-get-tree] 2] > #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook > org-show-all append local] 5] > #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook > org-babel-show-result-all append local] 5] > org-babel-result-hide-spec org-babel-hide-all-hashes turn-on-auto-fill > mixed-pitch-mode org-superstar-mode > highlight-parentheses-mode) > org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"] > org-archive-hook '(org-attach-archive-delete-maybe) > org-confirm-elisp-link-function 'yes-or-no-p > org-agenda-before-write-hook '(org-agenda-add-entry-text) > org-metaup-hook '(org-babel-load-in-session-maybe) > org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3 > "\n\n(fn ENTRY)"] > org-adapt-indentation nil > org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"] > org-babel-pre-tangle-hook '(save-buffer) > org-file-apps '(("\\.pdf\\'" . emacs) (auto-mode . emacs) (directory . > emacs) ("\\.mm\\'" . default) ("\\.x?html?\\'" . default) > ("\\.pdf\\'" . default)) > org-tab-first-hook '(org-babel-hide-result-toggle-maybe > org-babel-header-arg-expand) > org-hide-leading-stars t > org-babel-load-languages '((C . t) (emacs-lisp . t)) > org-log-done 'time > org-superstar-leading-bullet 32 > org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME > CONTENTS WIDTH)"] > org-agenda-loop-over-headlines-in-active-region nil > org-occur-hook '(org-first-headline-recenter) > org-cycle-separator-lines 1 > org-export-before-processing-hook > '(org-blackfriday--reset-org-blackfriday--code-block-num-backticks) > org-cycle-hook '(org-cycle-hide-archived-subtrees > org-cycle-hide-drawers org-cycle-show-empty-lines >   org-optimize-window-after-visibility-change) > org-speed-command-hook '(org-speed-command-activate > org-babel-speed-command-activate) > org-clock-persist-file "/home/richard/.emacs.d/var/org/clock-persist.el" > org-superstar-leading-fallback 8229 > org-odt-format-inlinetask-function > 'org-odt-format-inlinetask-default-function > org-latex-prefer-user-labels t > org-babel-tangle-lang-exts '(("D" . "d") ("C++" . "cpp") ("emacs-lisp" > . "el") ("elisp" . "el")) > org-publish-timestamp-directory > "/home/richard/.emacs.d/var/org/timestamps/" > org-export-before-parsing-hook '(org-attach-expand-links) > org-id-locations-file "/home/richard/.emacs.d/var/org/id-locations.el" > org-confirm-shell-link-function 'yes-or-no-p > org-link-parameters '(("attachment" :follow org-attach-follow > :complete org-attach-complete-link) ("id" :follow org-id-open) >        ("eww" :follow org-eww-open :store org-eww-store-link) ("rmail" > :follow org-rmail-open :store org-rmail-store-link) >        ("mhe" :follow org-mhe-open :store org-mhe-store-link) >        ("irc" :follow org-irc-visit :store org-irc-store-link :export > org-irc-export) >        ("info" :follow org-info-open :export org-info-export :store > org-info-store-link) >        ("gnus" :follow org-gnus-open :store org-gnus-store-link) >        ("docview" :follow org-docview-open :export org-docview-export > :store org-docview-store-link) >        ("bibtex" :follow org-bibtex-open :store org-bibtex-store-link) >        ("bbdb" :follow org-bbdb-open :export org-bbdb-export :complete > org-bbdb-complete-link :store org-bbdb-store-link) >        ("w3m" :store org-w3m-store-link) ("file+sys") ("file+emacs") > ("shell" :follow org-link--open-shell) >        ("news" :follow #[514 "\301\300\302Q\"\207" ["news" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("mailto" :follow #[514 "\301\300\302Q\"\207" ["mailto" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("https" :follow #[514 "\301\300\302Q\"\207" ["https" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("http" :follow #[514 "\301\300\302Q\"\207" ["http" > browse-url ":"] 6 "\n\n(fn URL ARG)"]) >        ("ftp" :follow #[514 "\301\300\302Q\"\207" ["ftp" browse-url > ":"] 6 "\n\n(fn URL ARG)"]) >        ("help" :follow org-link--open-help) ("file" :complete > org-link-complete-file) >        ("elisp" :follow org-link--open-elisp) ("doi" :follow > org-link--open-doi)) > org-latex-format-headline-function > 'org-latex-format-headline-default-function > org-latex-logfiles-extensions '("lof" "lot" "tex~" "aux" "idx" "log" > "out" "toc" "nav" "snm" "vrb" "dvi" "fdb_latexmk" "blg" "brf" "fls" > "entoc" "ps" "spl" "bbl") > org-link-elisp-confirm-function 'yes-or-no-p > org-latex-format-inlinetask-function > 'org-latex-format-inlinetask-default-function > org-html-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME > CONTENTS)"] > org-html-format-headline-function > 'org-html-format-headline-default-function > org-confirm-babel-evaluate nil > org-fontify-whole-block-delimiter-line nil > ) >