Skip to content
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

why \v is getting converted into \u000b during asr_to_c conversion #2375

Closed
Agent-Hellboy opened this issue Oct 8, 2023 · 5 comments · Fixed by #2373
Closed

why \v is getting converted into \u000b during asr_to_c conversion #2375

Agent-Hellboy opened this issue Oct 8, 2023 · 5 comments · Fixed by #2373

Comments

@Agent-Hellboy
Copy link
Contributor

Agent-Hellboy commented Oct 8, 2023

I got below error while using ch=='\v'

/home/runner/work/lpython/lpython/integration_tests/_lpython-tmp-test-c/test_str_attributes.c: In function ‘__lpython_overloaded_0___lpython_str_isspace’:
/home/runner/work/lpython/lpython/integration_tests/_lpython-tmp-test-c/test_str_attributes.c:1991:167: error: \u000b is not a valid universal character
 1991 |         if (strcmp(ch, " ")  !=  0 && strcmp(ch, "\t")  !=  0 && strcmp(ch, "\n")  !=  0 && strcmp(ch, "\r")  !=  0 && strcmp(ch, "\\f")  !=  0 && strcmp(ch, "\u000b")  !=  0) {
      |     

please debug why?

Edit: isspace issue was related to name mangling, so I removed it.

@Shaikh-Ubaid
Copy link
Collaborator

The following might fix it:

diff --git a/src/libasr/string_utils.cpp b/src/libasr/string_utils.cpp
index 073167d16..55e5a6b2a 100644
--- a/src/libasr/string_utils.cpp
+++ b/src/libasr/string_utils.cpp
@@ -142,6 +142,7 @@ std::string str_escape_c(const std::string &s) {
             case '\n': o << "\\n"; break;
             case '\r': o << "\\r"; break;
             case '\t': o << "\\t"; break;
+            case '\v': o << "\\v"; break;
             default:
                 if ('\x00' <= *c && *c <= '\x1f') {
                     o << "\\u"

@Thirumalai-Shaktivel
Copy link
Collaborator

MRE:

from sympy import pi, Symbol, S

def main0():
    x: str = 'Hel\vlo'
    print(x)

main0()

LLVM

$ lpython examples/expr2.py
Hel
   lo

C

$ lpython examples/expr2.py --backend=c
expr2__tmp__generated__.c:17:30: error: universal character name refers to a control character
    _lfortran_strcpy(&x, "Hel\u000blo", 1);
                             ^~~~~~
1 error generated.
The command 'gcc -o expr2.out expr2__tmp__generated__.c  -I /Users/thirumalai/Open_Source/lpython/src/bin/../libasr/runtime -L"/Users/thirumalai/Open_Source/lpython/src/bin/../runtime" -Wl,-rpath,"/Users/thirumalai/Open_Source/lpython/src/bin/../runtime" -llpython_runtime -lm' failed.

@Agent-Hellboy
Copy link
Contributor Author

The following might fix it:

diff --git a/src/libasr/string_utils.cpp b/src/libasr/string_utils.cpp
index 073167d16..55e5a6b2a 100644
--- a/src/libasr/string_utils.cpp
+++ b/src/libasr/string_utils.cpp
@@ -142,6 +142,7 @@ std::string str_escape_c(const std::string &s) {
             case '\n': o << "\\n"; break;
             case '\r': o << "\\r"; break;
             case '\t': o << "\\t"; break;
+            case '\v': o << "\\v"; break;
             default:
                 if ('\x00' <= *c && *c <= '\x1f') {
                     o << "\\u"

should I add a PR for the same and revert my changes?

@Shaikh-Ubaid
Copy link
Collaborator

should I add a PR for the same and revert my changes?

Since it is just a one-line change, I would include it in existing PR #2373.

@Agent-Hellboy
Copy link
Contributor Author

should I add a PR for the same and revert my changes?

Since it is just a one-line change, I would include it in existing PR #2373.

okay

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

Successfully merging a pull request may close this issue.

3 participants