[Git][ghc/ghc][wip/js-rename-getcwd] JS: Implement missing C functions `rename`, `realpath`, and `getcwd` (#23806)

Josh Meredith (@JoshMeredith) gitlab at gitlab.haskell.org
Tue Aug 8 13:39:02 UTC 2023



Josh Meredith pushed to branch wip/js-rename-getcwd at Glasgow Haskell Compiler / GHC


Commits:
125ea3cd by Josh Meredith at 2023-08-08T23:38:37+10:00
JS: Implement missing C functions `rename`, `realpath`, and `getcwd` (#23806)

- - - - -


3 changed files:

- libraries/base/jsbits/base.js
- testsuite/tests/ghc-api/downsweep/all.T
- testsuite/tests/rename/prog006/all.T


Changes:

=====================================
libraries/base/jsbits/base.js
=====================================
@@ -264,6 +264,55 @@ function h$rmdir(file, file_off) {
     h$unsupported(-1);
 }
 
+function h$rename(old_path, old_path_off, new_path, new_path_off) {
+  TRACE_IO("rename")
+#ifndef GHCJS_BROWSER
+  if (h$isNode()) {
+    try {
+      fs.renameSync(h$decodeUtf8z(old_path, old_path_off), h$decodeUtf8z(new_path, new_path_off));
+      return 0;
+    } catch(e) {
+      h$setErrno(e);
+      return -1;
+    }
+  } else
+#endif
+    h$unsupported(-1);
+}
+
+function h$getcwd(buf, off, buf_size) {
+  TRACE_IO("getcwd")
+#ifndef GHCJS_BROWSER
+  if (h$isNode()) {
+    try {
+      var cwd = h$encodeUtf8(process.cwd());
+      h$copyMutableByteArray(cwd, 0, buf, off, cwd.len);
+      RETURN_UBX_TUP2(cwd, 0);
+    } catch (e) {
+      h$setErrno(e);
+      return -1;
+    }
+  } else
+#endif
+    h$unsupported(-1);
+}
+
+function h$realpath(path,off) {
+  TRACE_IO("realpath")
+#ifndef GHCJS_BROWSER
+  if (h$isNode()) {
+    try {
+      var rp = h$encodeUtf8(fs.realpathSync(h$decodeUtf8z(path,off)));
+      RETURN_UBX_TUP2(rp, 0);
+    } catch (e) {
+      h$setErrno(e);
+      return -1;
+    }
+  } else
+#endif
+    h$unsupported(-1);
+}
+
 function h$base_open(file, file_off, how, mode, c) {
 #ifndef GHCJS_BROWSER
     if(h$isNode()) {


=====================================
testsuite/tests/ghc-api/downsweep/all.T
=====================================
@@ -8,7 +8,6 @@ test('PartialDownsweep',
 
 test('OldModLocation',
      [ extra_run_opts('"' + config.libdir + '"')
-     , js_broken(22362)
      , when(opsys('mingw32'), expect_broken(16772))
      ],
      compile_and_run,


=====================================
testsuite/tests/rename/prog006/all.T
=====================================
@@ -1 +1 @@
-test('rn.prog006', [extra_files(['A.hs', 'B/', 'Main.hs', 'pwd.hs']), js_broken(22261)], makefile_test, [])
+test('rn.prog006', [extra_files(['A.hs', 'B/', 'Main.hs', 'pwd.hs'])], makefile_test, [])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/125ea3cde4e533ecde15e86145fd45bb9c99d405

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/125ea3cde4e533ecde15e86145fd45bb9c99d405
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230808/4e16f3b1/attachment-0001.html>


More information about the ghc-commits mailing list