Bug 780501 - Path types for OS.File;r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Thu, 16 Aug 2012 22:05:30 -0400
changeset 102602 277e7c231f1a8314a46e756aae7cbbf2b0061091
parent 102601 e953b3f9ddd6869da67150689b9c2f7e3507e7fa
child 102603 4c0f3d35933baa763ad0046a3855c33dc030fa5f
push id13545
push userryanvm@gmail.com
push dateFri, 17 Aug 2012 02:05:42 +0000
treeherdermozilla-inbound@4c0f3d35933b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs780501
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 780501 - Path types for OS.File;r=froydnj
toolkit/components/osfile/osfile_unix_allthreads.jsm
toolkit/components/osfile/osfile_unix_back.jsm
toolkit/components/osfile/osfile_win_allthreads.jsm
toolkit/components/osfile/osfile_win_back.jsm
--- a/toolkit/components/osfile/osfile_unix_allthreads.jsm
+++ b/toolkit/components/osfile/osfile_unix_allthreads.jsm
@@ -142,9 +142,21 @@ if (typeof Components != "undefined") {
 
   exports.OS.Shared.Unix.Error = OSError;
 
   // Special constants that need to be defined on all platforms
 
    Object.defineProperty(exports.OS.Shared, "POS_START", { value: exports.OS.Constants.libc.SEEK_SET });
    Object.defineProperty(exports.OS.Shared, "POS_CURRENT", { value: exports.OS.Constants.libc.SEEK_CUR });
    Object.defineProperty(exports.OS.Shared, "POS_END", { value: exports.OS.Constants.libc.SEEK_END });
+
+  // Special types that need to be defined for communication
+  // between threads
+  let Types = exports.OS.Shared.Type;
+
+   /**
+    * Native paths
+    *
+    * Under Unix, expressed as C strings
+    */
+  Types.path = Types.cstring.withName("[in] path");
+  Types.out_path = Types.out_cstring.withName("[out] path");
 })(this);
--- a/toolkit/components/osfile/osfile_unix_back.jsm
+++ b/toolkit/components/osfile/osfile_unix_back.jsm
@@ -88,25 +88,16 @@
        /**
         * A C integer holding -1 in case of error or a positive integer
         * in case of success.
         */
        Types.negativeone_or_ssize_t =
          Types.ssize_t.withName("negativeone_or_ssize_t");
 
        /**
-        * A C string
-        */
-       Types.null_or_string =
-         Types.char.in_ptr.withName("null_or_string");
-
-       Types.string =
-         Types.char.in_ptr.withName("string");
-
-       /**
         * Various libc integer types
         */
        Types.mode_t =
          Types.intn_t(OS.Constants.libc.OSFILE_SIZEOF_MODE_T).withName("mode_t");
        Types.uid_t =
          Types.intn_t(OS.Constants.libc.OSFILE_SIZEOF_UID_T).withName("uid_t");
        Types.gid_t =
          Types.intn_t(OS.Constants.libc.OSFILE_SIZEOF_GID_T).withName("gid_t");
@@ -179,17 +170,16 @@
          stat.add_field_at(OS.Constants.libc.OSFILE_OFFSETOF_STAT_ST_CTIME,
                           "st_ctime", Types.time_t.implementation);
 
          stat.add_field_at(OS.Constants.libc.OSFILE_OFFSETOF_STAT_ST_SIZE,
                         "st_size", Types.size_t.implementation);
          Types.stat = stat.getType();
        }
 
-
        // Declare libc functions as functions of |OS.Unix.File|
 
        // Finalizer-related functions
        let _close =
          libc.declare("close", ctypes.default_abi,
                         /*return */ctypes.int,
                         /*fd*/     ctypes.int);
 
@@ -212,54 +202,54 @@
          libc.declare("free", ctypes.default_abi,
                        /*return*/ ctypes.void_t,
                        /*ptr*/    ctypes.voidptr_t);
 
        // Other functions
        UnixFile.access =
          declareFFI("access", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string,
+                    /*path*/   Types.path,
                     /*mode*/   Types.int);
 
        UnixFile.chdir =
          declareFFI("chdir", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string);
+                    /*path*/   Types.path);
 
        UnixFile.chmod =
          declareFFI("chmod", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string,
+                    /*path*/   Types.path,
                     /*mode*/   Types.mode_t);
 
        UnixFile.chown =
          declareFFI("chown", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string,
+                    /*path*/   Types.path,
                     /*uid*/    Types.uid_t,
                     /*gid*/    Types.gid_t);
 
        UnixFile.copyfile =
          declareFFI("copyfile", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*source*/ Types.string,
-                    /*dest*/   Types.string,
+                    /*source*/ Types.path,
+                    /*dest*/   Types.path,
                     /*state*/  Types.void_t.in_ptr, // Ignored atm
                     /*flags*/  Types.uint32_t);
 
        UnixFile.dup =
          declareFFI("dup", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_fd,
                     /*fd*/     Types.fd);
 
        UnixFile.chdir =
          declareFFI("chdir", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string);
+                    /*path*/   Types.path);
 
        UnixFile.fchdir =
          declareFFI("fchdir", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
                     /*fd*/     Types.fd);
 
        UnixFile.fchown =
          declareFFI("fchown", ctypes.default_abi,
@@ -270,38 +260,38 @@
 
        UnixFile.fsync =
          declareFFI("fsync", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
                     /*fd*/     Types.fd);
 
        UnixFile.getcwd =
          declareFFI("getcwd", ctypes.default_abi,
-                    /*return*/ Types.null_or_string,
-                    /*buf*/    Types.char.out_ptr,
+                    /*return*/ Types.out_path,
+                    /*buf*/    Types.out_path,
                     /*size*/   Types.size_t);
 
        UnixFile.getwd =
          declareFFI("getwd", ctypes.default_abi,
-                    /*return*/ Types.null_or_string,
-                    /*buf*/    Types.char.out_ptr);
+                    /*return*/ Types.out_path,
+                    /*buf*/    Types.out_path);
 
        // Two variants of |getwd| which allocate the memory
        // dynamically.
 
        // Linux/Android version
        UnixFile.get_current_dir_name =
          declareFFI("get_current_dir_name", ctypes.default_abi,
-                    /*return*/ Types.null_or_string.releaseWith(UnixFile.free));
+                    /*return*/ Types.out_path.releaseWith(UnixFile.free));
 
        // MacOS/BSD version (will return NULL on Linux/Android)
        UnixFile.getwd_auto =
          declareFFI("getwd", ctypes.default_abi,
-                    /*return*/ Types.null_or_string.releaseWith(UnixFile.free),
-                    /*buf*/    Types.void_t.in_ptr);
+                    /*return*/ Types.out_path.releaseWith(UnixFile.free),
+                    /*buf*/    Types.void_t.out_ptr);
 
        UnixFile.fdatasync =
          declareFFI("fdatasync", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
                     /*fd*/     Types.fd); // Note: MacOS/BSD-specific
 
        UnixFile.ftruncate =
          declareFFI("ftruncate", ctypes.default_abi,
@@ -323,77 +313,77 @@
                       /*path*/   Types.fd,
                       /*buf*/    Types.stat.out_ptr
                      );
        }
 
        UnixFile.lchown =
          declareFFI("lchown", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string,
+                    /*path*/   Types.path,
                     /*uid_t*/  Types.uid_t,
                     /*gid_t*/  Types.gid_t);
 
        UnixFile.link =
          declareFFI("link", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*source*/ Types.string,
-                    /*dest*/   Types.string);
+                    /*source*/ Types.path,
+                    /*dest*/   Types.path);
 
        UnixFile.lseek =
          declareFFI("lseek", ctypes.default_abi,
                     /*return*/ Types.off_t,
                     /*fd*/     Types.fd,
                     /*offset*/ Types.off_t,
                     /*whence*/ Types.int);
 
        UnixFile.mkdir =
          declareFFI("mkdir", ctypes.default_abi,
                     /*return*/ Types.int,
-                    /*path*/ Types.string,
+                    /*path*/ Types.path,
                     /*mode*/ Types.int);
 
        UnixFile.mkstemp =
          declareFFI("mkstemp", ctypes.default_abi,
-                    /*return*/ Types.null_or_string,
-                    /*template*/Types.string);
+                    /*return*/ Types.out_path,
+                    /*template*/Types.out_path);
 
        UnixFile.open =
          declareFFI("open", ctypes.default_abi,
                     /*return*/Types.negativeone_or_fd,
-                    /*path*/  Types.string,
+                    /*path*/  Types.path,
                     /*oflags*/Types.int,
                     /*mode*/  Types.int);
 
        UnixFile.opendir =
          declareFFI("opendir", ctypes.default_abi,
                     /*return*/ Types.null_or_DIR_ptr,
-                    /*path*/   Types.string);
+                    /*path*/   Types.path);
 
        UnixFile.pread =
          declareFFI("pread", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_ssize_t,
                     /*fd*/     Types.fd,
-                    /*buf*/    Types.char.out_ptr,
+                    /*buf*/    Types.void_t.out_ptr,
                     /*nbytes*/ Types.size_t,
                     /*offset*/ Types.off_t);
 
        UnixFile.pwrite =
          declareFFI("pwrite", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_ssize_t,
                     /*fd*/     Types.fd,
-                    /*buf*/    Types.char.in_ptr,
+                    /*buf*/    Types.void_t.in_ptr,
                     /*nbytes*/ Types.size_t,
                     /*offset*/ Types.off_t);
 
        UnixFile.read =
          declareFFI("read", ctypes.default_abi,
                     /*return*/Types.negativeone_or_ssize_t,
                     /*fd*/    Types.fd,
-                    /*buf*/   Types.char.out_ptr,
+                    /*buf*/   Types.void_t.out_ptr,
                     /*nbytes*/Types.size_t);
 
        if (OS.Constants.libc._DARWIN_FEATURE_64_BIT_INODE) {
          // Special case for MacOS X 10.5+
          // Symbol name "readdir" still exists but is used for a
          // deprecated function that does not match the
          // constants of |OS.Constants.libc|.
          UnixFile.readdir =
@@ -405,96 +395,96 @@
            declareFFI("readdir", ctypes.default_abi,
                       /*return*/Types.null_or_dirent_ptr,
                       /*dir*/   Types.DIR.in_ptr); // Other Unices
        }
 
        UnixFile.rename =
          declareFFI("rename", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*old*/    Types.string,
-                    /*new*/    Types.string);
+                    /*old*/    Types.path,
+                    /*new*/    Types.path);
 
        UnixFile.rmdir =
          declareFFI("rmdir", ctypes.default_abi,
                     /*return*/ Types.int,
-                    /*path*/   Types.string);
+                    /*path*/   Types.path);
 
        UnixFile.splice =
          declareFFI("splice", ctypes.default_abi,
                     /*return*/ Types.long,
                     /*fd_in*/  Types.fd,
                     /*off_in*/ Types.off_t.in_ptr,
                     /*fd_out*/ Types.fd,
                     /*off_out*/Types.off_t.in_ptr,
                     /*len*/    Types.size_t,
                     /*flags*/  Types.unsigned_int); // Linux/Android-specific
 
        UnixFile.symlink =
          declareFFI("symlink", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*source*/ Types.string,
-                    /*dest*/   Types.string);
+                    /*source*/ Types.path,
+                    /*dest*/   Types.path);
 
        UnixFile.truncate =
          declareFFI("truncate", ctypes.default_abi,
                     /*return*/Types.negativeone_or_nothing,
-                    /*path*/  Types.string,
+                    /*path*/  Types.path,
                     /*length*/ Types.off_t);
 
        UnixFile.unlink =
          declareFFI("unlink", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_nothing,
-                    /*path*/   Types.string);
+                    /*path*/ Types.path);
 
        UnixFile.write =
          declareFFI("write", ctypes.default_abi,
                     /*return*/ Types.negativeone_or_ssize_t,
                     /*fd*/     Types.fd,
-                    /*buf*/    Types.char.in_ptr,
+                    /*buf*/    Types.void_t.in_ptr,
                     /*nbytes*/ Types.size_t);
 
        // Weird cases that require special treatment
 
        // OSes use a variety of hacks to differentiate between
        // 32-bits and 64-bits versions of |stat|, |lstat|, |fstat|.
        if (OS.Constants.libc._DARWIN_FEATURE_64_BIT_INODE) {
          // MacOS X 64-bits
          UnixFile.stat =
            declareFFI("stat$INODE64", ctypes.default_abi,
                       /*return*/ Types.negativeone_or_nothing,
-                      /*path*/   Types.string,
+                      /*path*/   Types.path,
                       /*buf*/    Types.stat.out_ptr
                      );
          UnixFile.lstat =
            declareFFI("lstat$INODE64", ctypes.default_abi,
                       /*return*/ Types.negativeone_or_nothing,
-                      /*path*/   Types.string,
+                      /*path*/   Types.path,
                       /*buf*/    Types.stat.out_ptr
                      );
          UnixFile.fstat =
            declareFFI("fstat$INODE64", ctypes.default_abi,
                       /*return*/ Types.negativeone_or_nothing,
                       /*path*/   Types.fd,
                       /*buf*/    Types.stat.out_ptr
                      );
        } else if (OS.Constants.libc._STAT_VER != undefined) {
          const ver = OS.Constants.libc._STAT_VER;
          // Linux, all widths
          let xstat =
            declareFFI("__xstat", ctypes.default_abi,
                       /*return*/    Types.negativeone_or_nothing,
                       /*_stat_ver*/ Types.int,
-                      /*path*/      Types.string,
+                      /*path*/      Types.path,
                       /*buf*/       Types.stat.out_ptr);
          let lxstat =
            declareFFI("__lxstat", ctypes.default_abi,
                       /*return*/    Types.negativeone_or_nothing,
                       /*_stat_ver*/ Types.int,
-                      /*path*/      Types.string,
+                      /*path*/      Types.path,
                       /*buf*/       Types.stat.out_ptr);
          let fxstat =
            declareFFI("__fxstat", ctypes.default_abi,
                       /*return*/    Types.negativeone_or_nothing,
                       /*_stat_ver*/ Types.int,
                       /*fd*/        Types.fd,
                       /*buf*/       Types.stat.out_ptr);
 
@@ -507,23 +497,23 @@
          UnixFile.fstat = function stat(fd, buf) {
            return fxstat(ver, fd, buf);
          };
        } else {
          // Mac OS X 32-bits, other Unix
          UnixFile.stat =
            declareFFI("stat", ctypes.default_abi,
                       /*return*/ Types.negativeone_or_nothing,
-                      /*path*/   Types.string,
+                      /*path*/   Types.path,
                       /*buf*/    Types.stat.out_ptr
                      );
          UnixFile.lstat =
            declareFFI("lstat", ctypes.default_abi,
                       /*return*/ Types.negativeone_or_nothing,
-                      /*path*/   Types.string,
+                      /*path*/   Types.path,
                       /*buf*/    Types.stat.out_ptr
                      );
          UnixFile.fstat =
            declareFFI("fstat", ctypes.default_abi,
                       /*return*/ Types.negativeone_or_nothing,
                       /*fd*/     Types.fd,
                       /*buf*/    Types.stat.out_ptr
                      );
--- a/toolkit/components/osfile/osfile_win_allthreads.jsm
+++ b/toolkit/components/osfile/osfile_win_allthreads.jsm
@@ -152,9 +152,21 @@ if (typeof Components != "undefined") {
 
   exports.OS.Shared.Win.Error = OSError;
 
   // Special constants that need to be defined on all platforms
 
   Object.defineProperty(exports.OS.Shared, "POS_START", { value: exports.OS.Constants.Win.FILE_BEGIN });
   Object.defineProperty(exports.OS.Shared, "POS_CURRENT", { value: exports.OS.Constants.Win.FILE_CURRENT });
   Object.defineProperty(exports.OS.Shared, "POS_END", { value: exports.OS.Constants.Win.FILE_END });
+
+  // Special types that need to be defined for communication
+  // between threads
+  let Types = exports.OS.Shared.Type;
+
+  /**
+   * Native paths
+   *
+   * Under Windows, expressed as wide strings
+   */
+  Types.path = Types.wstring.withName("[in] path");
+  Types.out_path = Types.out_wstring.withName("[out] path");
 })(this);
--- a/toolkit/components/osfile/osfile_win_back.jsm
+++ b/toolkit/components/osfile/osfile_win_back.jsm
@@ -192,106 +192,106 @@
          return handle.dispose(); // Returns the value of |CloseHandle|.
        };
 
        // Declare libc functions as functions of |OS.Win.File|
 
        WinFile.CopyFile =
          declareFFI("CopyFileW", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
-                    /*sourcePath*/ Types.jschar.in_ptr,
-                    /*destPath*/   Types.jschar.in_ptr,
+                    /*sourcePath*/ Types.path,
+                    /*destPath*/   Types.path,
                     /*bailIfExist*/Types.bool);
 
        WinFile.CreateFile =
          declareFFI("CreateFileW", ctypes.winapi_abi,
                     /*return*/  Types.maybe_HANDLE,
-                    /*name*/    Types.jschar.in_ptr,
+                    /*name*/    Types.path,
                     /*access*/  Types.DWORD,
                     /*share*/   Types.DWORD,
                     /*security*/Types.void_t.in_ptr,// FIXME: Implement?
                     /*creation*/Types.DWORD,
                     /*flags*/   Types.DWORD,
                     /*template*/Types.HANDLE);
 
        WinFile.DeleteFile =
          declareFFI("DeleteFileW", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
-                    /*path*/   Types.jschar.in_ptr);
+                    /*path*/   Types.path);
 
        WinFile.FileTimeToSystemTime =
          declareFFI("FileTimeToSystemTime", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
                     /*filetime*/Types.FILETIME.in_ptr,
                     /*systime*/ Types.SystemTime.out_ptr);
 
        WinFile.FindFirstFile =
          declareFFI("FindFirstFileW", ctypes.winapi_abi,
                     /*return*/ Types.maybe_find_HANDLE,
-                    /*pattern*/Types.jschar.in_ptr,
+                    /*pattern*/Types.path,
                     /*data*/   Types.FindData.out_ptr);
 
        WinFile.FindNextFile =
          declareFFI("FindNextFileW", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
                     /*prev*/   Types.HANDLE,
                     /*data*/   Types.FindData.out_ptr);
 
        WinFile.FormatMessage =
          declareFFI("FormatMessageW", ctypes.winapi_abi,
                     /*return*/ Types.DWORD,
                     /*flags*/  Types.DWORD,
                     /*source*/ Types.void_t.in_ptr,
                     /*msgid*/  Types.DWORD,
                     /*langid*/ Types.DWORD,
-                    /*buf*/    Types.jschar.out_ptr,
+                    /*buf*/    Types.out_wstring,
                     /*size*/   Types.DWORD,
                     /*Arguments*/Types.void_t.in_ptr
                    );
 
        WinFile.GetCurrentDirectory =
          declareFFI("GetCurrentDirectoryW", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_DWORD,
                     /*length*/ Types.DWORD,
-                    /*buf*/    Types.jschar.out_ptr
+                    /*buf*/    Types.out_path
                    );
 
        WinFile.GetFileInformationByHandle =
          declareFFI("GetFileInformationByHandle", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
                     /*handle*/ Types.HANDLE,
                     /*info*/   Types.FILE_INFORMATION.out_ptr);
 
        WinFile.MoveFileEx =
          declareFFI("MoveFileExW", ctypes.winapi_abi,
                     /*return*/   Types.zero_or_nothing,
-                    /*sourcePath*/ Types.jschar.in_ptr,
-                    /*destPath*/ Types.jschar.in_ptr,
+                    /*sourcePath*/ Types.path,
+                    /*destPath*/ Types.path,
                     /*flags*/    Types.DWORD
                    );
 
        WinFile.ReadFile =
          declareFFI("ReadFile", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
                     /*file*/   Types.HANDLE,
                     /*buffer*/ Types.char.out_ptr,
                     /*nbytes*/ Types.DWORD,
                     /*nbytes_read*/Types.DWORD.out_ptr,
                     /*overlapped*/Types.void_t.inout_ptr // FIXME: Implement?
          );
 
        WinFile.RemoveDirectory =
          declareFFI("RemoveDirectoryW", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
-                    /*path*/   Types.jschar.in_ptr);
+                    /*path*/   Types.path);
 
        WinFile.SetCurrentDirectory =
          declareFFI("SetCurrentDirectoryW", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
-                    /*path*/   Types.jschar.in_ptr
+                    /*path*/   Types.path
                    );
 
        WinFile.SetEndOfFile =
          declareFFI("SetEndOfFile", ctypes.winapi_abi,
                     /*return*/ Types.zero_or_nothing,
                     /*file*/   Types.HANDLE);
 
        WinFile.SetFilePointer =