← 输入框|github.com|刷新
Skip to content

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

Closed

Description

@Agent-Hellboy

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.

Activity

  1. ubaidsk commented on Oct 8, 2023

    @ubaidsk
    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"
  2. Thirumalai-Shaktivel commented on Oct 8, 2023

    @Thirumalai-Shaktivel
    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.
  3. Agent-Hellboy commented on Oct 8, 2023

    @Agent-Hellboy
    ContributorAuthor

    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?

  4. ubaidsk commented on Oct 8, 2023

    @ubaidsk
    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.

  5. Agent-Hellboy commented on Oct 8, 2023

    @Agent-Hellboy
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions