changeset 58909:619a2c6f3d02 foreign+vector

Automatic merge with foreign
author mcimadamore
date Thu, 11 Apr 2019 12:09:39 +0200
parents fa2e9c39d939 2dc0507dfb5d
children c94042f0aff8
files
diffstat 5 files changed, 59 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jextract/share/classes/com/sun/tools/jextract/JavaSourceBuilder.java	Wed Apr 10 16:39:22 2019 +0200
+++ b/src/jdk.jextract/share/classes/com/sun/tools/jextract/JavaSourceBuilder.java	Thu Apr 11 12:09:39 2019 +0200
@@ -146,7 +146,7 @@
             Object value = fields.get(key);
             if (value instanceof String) {
                 sb.append('"');
-                sb.append(value.toString());
+                sb.append(Utils.quote(value.toString()));
                 sb.append('"');
             } else if (value instanceof Enum) {
                 sb.append(value.getClass().getSimpleName());
@@ -160,7 +160,7 @@
                 String[] strs = (String[])value;
                 for (int i = 0; i < strs.length; i++) {
                     sb.append('"');
-                    sb.append(strs[i]);
+                    sb.append(Utils.quote(strs[i]));
                     sb.append('"');
                     if (i != strs.length - 1) {
                         sb.append(", ");
--- a/src/jdk.jextract/share/classes/com/sun/tools/jextract/JavaSourceFactory.java	Wed Apr 10 16:39:22 2019 +0200
+++ b/src/jdk.jextract/share/classes/com/sun/tools/jextract/JavaSourceFactory.java	Thu Apr 11 12:09:39 2019 +0200
@@ -99,7 +99,7 @@
         global_jsb.addPackagePrefix(headerFile.pkgName);
 
         Map<String, Object> header = new HashMap<>();
-        header.put("path", headerFile.path.toAbsolutePath().toString().replace("\\", "\\\\"));
+        header.put("path", headerFile.path.toAbsolutePath().toString());
         if (!libraryNames.isEmpty()) {
             header.put("libraries", libraryNames.toArray(new String[0]));
             if (libraryPaths != null && !libraryPaths.isEmpty()) {
@@ -168,7 +168,7 @@
             SourceLocation.Location loc = src.getFileLocation();
             Path p = loc.path();
             Map<String, Object> fields = new HashMap<>();
-            fields.put("file", p == null ? "<builtin>" :  p.toAbsolutePath().toString().replace("\\", "\\\\"));
+            fields.put("file", p == null ? "<builtin>" :  p.toAbsolutePath().toString());
             fields.put("line", loc.line());
             fields.put("column", loc.column());
             jsb.addAnnotation(align, NATIVE_LOCATION, fields);
--- a/src/jdk.jextract/share/classes/com/sun/tools/jextract/Utils.java	Wed Apr 10 16:39:22 2019 +0200
+++ b/src/jdk.jextract/share/classes/com/sun/tools/jextract/Utils.java	Thu Apr 11 12:09:39 2019 +0200
@@ -252,4 +252,50 @@
                 map(p -> p.resolve(System.mapLibraryName(libName))).
                 filter(Files::isRegularFile).map(Path::toAbsolutePath).findFirst();
     }
+
+    /*
+     * FIXME: when we add jdk.compiler dependency from jdk.jextract module, revisit
+     * the following. The following methods 'quote', 'quote' and 'isPrintableAscii'
+     * are from javac source. See also com.sun.tools.javac.util.Convert.java.
+     */
+
+    /**
+     * Escapes each character in a string that has an escape sequence or
+     * is non-printable ASCII.  Leaves non-ASCII characters alone.
+     */
+    public static String quote(String s) {
+        StringBuilder buf = new StringBuilder();
+        for (int i = 0; i < s.length(); i++) {
+            buf.append(quote(s.charAt(i)));
+        }
+        return buf.toString();
+    }
+
+    /**
+     * Escapes a character if it has an escape sequence or is
+     * non-printable ASCII.  Leaves non-ASCII characters alone.
+     */
+    public static String quote(char ch) {
+        switch (ch) {
+        case '\b':  return "\\b";
+        case '\f':  return "\\f";
+        case '\n':  return "\\n";
+        case '\r':  return "\\r";
+        case '\t':  return "\\t";
+        case '\'':  return "\\'";
+        case '\"':  return "\\\"";
+        case '\\':  return "\\\\";
+        default:
+            return (isPrintableAscii(ch))
+                ? String.valueOf(ch)
+                : String.format("\\u%04x", (int) ch);
+        }
+    }
+
+    /**
+     * Is a character printable ASCII?
+     */
+    private static boolean isPrintableAscii(char ch) {
+        return ch >= ' ' && ch <= '~';
+    }
 }
--- a/test/jdk/com/sun/tools/jextract/test8221154/SrcGenTest.java	Wed Apr 10 16:39:22 2019 +0200
+++ b/test/jdk/com/sun/tools/jextract/test8221154/SrcGenTest.java	Thu Apr 11 12:09:39 2019 +0200
@@ -43,7 +43,7 @@
 
 /*
  * @test
- * @bug 8221154 8221228 8221336 8221419 8221443 8222274
+ * @bug 8221154 8221228 8221336 8221419 8221443 8222274 8222288
  * @summary jextract should generate java source files
  * @library ..
  * @run testng SrcGenTest
--- a/test/jdk/com/sun/tools/jextract/test8221154/srcgentest.h	Wed Apr 10 16:39:22 2019 +0200
+++ b/test/jdk/com/sun/tools/jextract/test8221154/srcgentest.h	Thu Apr 11 12:09:39 2019 +0200
@@ -38,6 +38,14 @@
 
 #include <stdbool.h>
 
+// The following macro is inspired from a macro from
+// /usr/include/net/route.h. Make sure that jextract
+// generates proper String literal
+
+#define PROBLEM_STRING \
+    "\020\1UP\2GATEWAY\3HOST\4REJECT\5DYNAMIC\6MODIFIED\7DONE" \
+    "\10DELCLONE\11CLONING\12XRESOLVE\13LLINFO\14STATIC\15BLACKHOLE"
+
 enum {
     R, G, B
 };