[vala/0.56] vala: Avoid problems with '\' in #line directives on Windows



commit 548fb2bd2de8aa78518fe4f46e44db742cec8207
Author: 星外之神 <wszqkzqk qq com>
Date:   Sat Aug 27 23:26:41 2022 +0800

    vala: Avoid problems with '\' in #line directives on Windows
    
    Replace '\' with '/' in SourceFile.relative_path like in CodeContext.realpath().
    
      F:/msys64/home/x/test/test.vala.c: In function '_vala_main':
      F:/msys64/home/x/test/test.vala.c:12:9: warning: unknown escape sequence: '\M'
         12 | #line 3 "C:\MyFiles\test.vala"
            |         ^~~~~~~~~~~~~~~~~~~~~~
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1353

 vala/valasourcefile.vala | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/vala/valasourcefile.vala b/vala/valasourcefile.vala
index 8f4175cde..c4ac064a7 100644
--- a/vala/valasourcefile.vala
+++ b/vala/valasourcefile.vala
@@ -33,7 +33,14 @@ public class Vala.SourceFile {
 
        public string? relative_filename {
                set {
-                       this._relative_filename = value;
+                       if (Path.DIR_SEPARATOR != '/') {
+                               // don't use backslashes internally,
+                               // to avoid problems in #line / #include directives
+                               string[] components = value.split ("\\");
+                               _relative_filename = string.joinv ("/", components);
+                       } else {
+                               _relative_filename = value;
+                       }
                }
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]