Hi Hongwei,
On Sun, Feb 22, 2015 at 11:36 PM, Hongwei Xi <
gmh...@gmail.com> wrote:
>>>extern fun vfs_ustat_ats (dev: dev_t): Option_vt(@(uint64_t, uint64_t)) =
>>> "sta#"
>
> Using option_vt causes memory allocation. Using 'opt' does not:
>
> typedef res = @(uint64_t, uint64_t)
> extern fun vfs_ustat_ats (dev: dev_t, res? >> opt(res, b)): #[b:bool] bool(b) = "sta#"
I try to use opt at following code.
https://github.com/metasepi/linux-bohai-s2/blob/774767d22125f39b3eb6f1aa3290707029dfa679/metasepi/fs/DATS/statfs.dats#L27
```
extern fun vfs_ustat
(dev: dev_t, sbuf: &kstatfs_t? >> opt (kstatfs_t, i==0)): #[i:int | i
!= 0] int(i) = "mac#"
extern fun syscall_ustat_ats (dev: dev_t, ubuf: ustat_t_p): int = "sta#"
implement syscall_ustat_ats (dev, ubuf) = r where {
fun copy_tmp (sbuf: &kstatfs_t): int = r where {
var tmp: ustat_t
val _ = memset0(addr@tmp, 0, sizeof<ustat_t>)
val () = tmp.f_tfree := $UN.cast(sbuf.f_bfree)
val () = tmp.f_tinode := $UN.cast(sbuf.f_ffree)
val r = if copy_to_user0($UN.cast ubuf, addr@tmp, $UN.cast
sizeof<ustat_t>) != 0
then (~ EFAULT) else 0
}
var sbuf: kstatfs_t
val e = vfs_ustat(new_decode_dev(dev), sbuf)
val r = (if e != 0 then let
prval () = opt_unnone(sbuf)
in
e:int
end else let
prval () = opt_unsome(sbuf)
in
copy_tmp(sbuf)
end):int
}
```
However it cause following compile error:
https://travis-ci.org/metasepi/linux-bohai-s2/builds/52234547#L1937
/home/kiwamu/src/ATS-Postiats/bin/patsopt -o fs/statfs_dats.c -d
metasepi/fs/DATS/statfs.dats
/home/kiwamu/src/linux-bohai-s2/metasepi/fs/DATS/statfs.dats:
1570(line=39, offs=27) -- 1634(line=43, offs=8): error(3): mismatch of
static terms (tyleq):
The actual term is: S2Etop(knd=0; S2Eapp(S2Ecst(g0int_t0ype);
S2Ecst(lint_kind)))
The needed term is: S2Eapp(S2Ecst(g0int_t0ype); S2Ecst(lint_kind))
/home/kiwamu/src/linux-bohai-s2/metasepi/fs/DATS/statfs.dats:
1570(line=39, offs=27) -- 1634(line=43, offs=8): error(3): mismatch of
static terms (tyleq):
--snip--
How to fix it?
Best regards,