Skip to content

rdstdin (linenoise) breaks the C++ backend #16449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HJarausch opened this issue Dec 23, 2020 · 7 comments
Closed

rdstdin (linenoise) breaks the C++ backend #16449

HJarausch opened this issue Dec 23, 2020 · 7 comments

Comments

@HJarausch
Copy link

HJarausch commented Dec 23, 2020

import rdstdin
echo "Merry Christmas"
let ans= readLineFromStdin("do you follow the Corona rules ")
if ans != "yes" :
  echo "but you should!"
else :
  echo "fine"

#[
Compiling this with nim cpp -r Hello.nim
gives
/usr/lib/nim/wrappers/linenoise/linenoise.c: In function 'void abAppend(abuf*, const char*, int)':
/usr/lib/nim/wrappers/linenoise/linenoise.c:462:11: error: expected unqualified-id before 'new'
462 | char *new = realloc(ab->b,ab->len+len);
| ^~~
/usr/lib/nim/wrappers/linenoise/linenoise.c:464:13: error: expected type-specifier before '==' token
464 | if (new == NULL) return;
| ^~
/usr/lib/nim/wrappers/linenoise/linenoise.c:465:15: error: expected type-specifier before '+' token
465 | memcpy(new+ab->len,s,len);
| ^
]#


**new** is a keyword in C++ and must not be used as an identifier.
linenoise.c should be fixed to be valid C++ .
e.g. by applying the attached patch
[linenoise.c.diff.txt](https://github.com/nim-lang/Nim/files/5735670/linenoise.c.diff.txt)

Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2020-12-23
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: b1c3dab2089bb4327627c2152a1148b299f1a930
active boot switches: -d:release
5

@ringabout
Copy link
Member

see #3720
and antirez/linenoise#87

@ringabout
Copy link
Member

Note that

This module contains code for reading from stdin:idx:. On UNIX the
linenoise library is wrapped and set up to provide default key bindings
(e.g. you can navigate with the arrow keys). On Windows system.readLine
is used. This suffices because Windows' console already provides the
wanted functionality.

nim cpp works in windows since system.readLine is used.

@ringabout
Copy link
Member

PR is welcome

@timotheecour
Copy link
Member

timotheecour commented Dec 26, 2020

proposed approach to fix this: see #16451 (comment)

@timotheecour
Copy link
Member

timotheecour commented Jan 14, 2021

@HJarausch I can't reproduce

on osx: works
(fee5fbc 1.5.1 and also 1.4.2 work)

on linux: works

ya works for me on linux too w 1.5.1
d34d023
g++
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

command:
nim r -b:cpp main

@krux02
Copy link
Contributor

krux02 commented Feb 8, 2021

I have a déjà vu here. This discussion has been there in the past. It had been resolved. The problem was fixed. This is a regression.
#5357 (comment)

@ringabout
Copy link
Member

If someone can reproduce this issue, feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants