]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Avoid problems with '\' in #line directives on Windows
author星外之神 <wszqkzqk@qq.com>
Sat, 27 Aug 2022 15:26:41 +0000 (23:26 +0800)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 28 Aug 2022 15:17:06 +0000 (17:17 +0200)
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

index 8f4175cdef7d1ecb4932d5b505b9de958a5b2218..c4ac064a7a2cc10fd1c995b5c986474e94d54b38 100644 (file)
@@ -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;
+                       }
                }
        }