File handling

5 views
Skip to first unread message

Waldek Hebisch

unread,
Dec 7, 2024, 1:45:13 PM12/7/24
to fricas...@googlegroups.com
Part of file handling is now moved to Spad. In the process I did
a few simplifications, so format of NRLIB-s and KAF files is slightly
different. Affected code is also used for saving history and
by Spad compiler, so there were changes in several places. I
added a test file for file operations and checked that history
still works for me after changes, but there is some potential
for breakage.

--
Waldek Hebisch

Grégory Vanuxem

unread,
Dec 8, 2024, 6:47:31 AM12/8/24
to fricas...@googlegroups.com
Hello Waldek,

That compiles fine on WSL Linux and MSYS2/Windows x86_64 but
files.input does not pass checks on Windows because writeable? returns
false even if I can 'touch' (and write in) a file in /tmp/. Some
investigations lead to (|writeablep| ..) called from nlib.lisp returns
-1 whereas it returns 1 on Linux. I guess the root cause is to find in
writeablep in cfuns-c.c.

Greg

Windows:
(5) -> writable?("/tmp/test")
1<enter fnameDirectory : "/tmp/test"
1>exit fnameDirectory : "/tmp"
1<enter writeablep : "/tmp"
1>exit writeablep : -1

(5) false

Linux:
(1) -> )tr writeablep

Function traced: writeablep
(1) -> writable?("/tmp/teste")
1<enter writeablep : "/tmp"
1>exit writeablep : 1

(1) true
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/Z1SXtT7WTTfMSv74%40fricas.org.

Grégory Vanuxem

unread,
Dec 8, 2024, 6:51:29 AM12/8/24
to fricas...@googlegroups.com
I can experiment with some code changes on Windows if necessary.

Waldek Hebisch

unread,
Dec 8, 2024, 8:04:21 AM12/8/24
to fricas...@googlegroups.com
On Sun, Dec 08, 2024 at 12:46:53PM +0100, Grégory Vanuxem wrote:
> Hello Waldek,
>
> That compiles fine on WSL Linux and MSYS2/Windows x86_64 but
> files.input does not pass checks on Windows because writeable? returns
> false even if I can 'touch' (and write in) a file in /tmp/.

There are two 'open'-s for writing in 'files.input'. Do both fail?
Or maybe only one?

--
Waldek Hebisch

Grégory Vanuxem

unread,
Dec 8, 2024, 9:12:31 AM12/8/24
to fricas...@googlegroups.com
Looking more carefully it seems this is caused by SBCL on Windows
which uses a mixed Windows/Linux path scheme:

(1) -> )lisp (truename "tt")

Value = #P"C:/msys64/home/gregv/build/tt"

Above it is just after a ')sys touch tt' in the build directory.
Checking more deeper in cfuns-c.c, writeablep:
In this piece of code:
code = stat(path, &buf);
if (code == -1) {
/** The file does not exist, so check to see
if the directory is writable *****/
if (make_path_from_file(newpath, path) == -1 ||
stat(newpath, &buf) == -1) {
return (-1);
}
}

the path-s can't indeed be stat-ed, the two returned values are -1. On
my Windows 11 I haven't a C:\Tmp directory by default, see the
attached file to see the errors returned (particularly the second
'open'):

So just /tmp is not accessible by default on Windows 11 with SBCL even
if I start FriCAS from MSYS2 (linux paths).
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/Z1WZUUgmuasz-VYQ%40fricas.org.
files.output

Grégory Vanuxem

unread,
Dec 8, 2024, 9:16:56 AM12/8/24
to fricas...@googlegroups.com
Quick note: writable?("tt") from above returns true so the code is
correct from what I see (the code takes into account the working
directory).

Grégory Vanuxem

unread,
Dec 9, 2024, 1:48:33 PM12/9/24
to fricas...@googlegroups.com
Hello,

Thinking about that, and since the TMP or TEMP environment variables
in Linux contrary to Windows don't exist by default apparently, what
about creating the temporary files in src/input like some other
temporary files. And for information the mostlyclean-local target in
Makefile.in is

mostlyclean-local:
-rm -f *.output
-rm -rf *.NRLIB
-rm -rf $(OUT)
-rm -f redo.input
-rm -f sieve.asy sieve.lsp simple.asy simple.lsp
-rm -f *.fn *.data *.lib *.$(LISPOBJEXT)

I just checked with just Git cloned FriCAS on MSYS2/MINGW64, all
files.input checks pass without the use of '/tmp/'.

Greg

Waldek Hebisch

unread,
Dec 9, 2024, 7:21:51 PM12/9/24
to fricas...@googlegroups.com
On Mon, Dec 09, 2024 at 07:47:54PM +0100, Grégory Vanuxem wrote:
> Hello,
>
> Thinking about that, and since the TMP or TEMP environment variables
> in Linux contrary to Windows don't exist by default apparently, what
> about creating the temporary files in src/input like some other
> temporary files.

<snip>

> I just checked with just Git cloned FriCAS on MSYS2/MINGW64, all
> files.input checks pass without the use of '/tmp/'.

There are to separate things that we can do:
- 'writable?' is essentially impossible to implement correctly
on modern systems. Namely, the only way to know that file
is writable is to write to it. When it works file is (or
rather was at time of write) writable. So I think that we
should not use 'writable?' for opening files.
- from what you wrote it seems that actial problem is that
'/tmp'/ is not writable from FriCAS. This can be fixed
by creating files in build directory.

I am not sure what you tried, but the attached patch works for
me on Linux and should fix problem on Windows.

--
Waldek Hebisch
sum6a1.diff

Grégory Vanuxem

unread,
Dec 10, 2024, 2:34:50 AM12/10/24
to fricas...@googlegroups.com
This is exactly what I tested, i.e. do not use the Unix-like /tmp/
directory but create the files in src/input directly. That works
effectively on Windows (just tested your patch on Windows).

- Greg
Reply all
Reply to author
Forward
0 new messages