Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error with nfs4.x #17

Open
messense opened this issue Jan 16, 2022 · 7 comments · May be fixed by #83
Open

Parsing error with nfs4.x #17

messense opened this issue Jan 16, 2022 · 7 comments · May be fixed by #83

Comments

@messense
Copy link
Contributor

messense commented Jan 16, 2022

https://github.com/sahlberg/libnfs/blob/master/nfs4/nfs4.x

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { variant: ParsingError { positives: [EOI, constant, enum_type, struct_type, union, typedef], negatives: [] }, location: Pos(55941), line_col: Pos((2088, 1)), path: None, line: "program NFS4_PROGRAM {␊", continued_line: None }', build.rs:10:14

Removing all program statements results in another error:

thread 'main' panicked at 'non-i32 enum variant value: ParseIntError { kind: InvalidDigit }', /Users/messense/.cargo/registry/src/github.com-1ecc6299db9ec823/fastxdr-1.0.2/src/ast/enumeration.rs:47:18

Using the master branch of fastxdr results in another error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "unresolvable type unsigned"', build.rs:10:14

build.rs:

fn main() {
    // Tell Cargo to regenerate the types if the XDR spec changes
    println!("cargo:rerun-if-changed=src/nfs4.x");

    // Read from nfs4.x, writing the generated code to out.rs
    std::fs::write(
        std::path::Path::new(std::env::var("OUT_DIR").unwrap().as_str()).join("out.rs"),
        fastxdr::Generator::default()
            .generate(include_str!("src/nfs4.x"))
            .unwrap(),
    )
    .unwrap();
}
@messense
Copy link
Contributor Author

messense commented Jan 16, 2022

Modified two unsigned to unsigned int makes the build work:

  1. https://github.com/sahlberg/libnfs/blob/f85c21755e5de76f8f622cdd71f60b49c0751eaa/nfs4/nfs4.x#L2153
  2. https://github.com/sahlberg/libnfs/blob/f85c21755e5de76f8f622cdd71f60b49c0751eaa/nfs4/nfs4.x#L2159

But the generated code doesn't compile:

error[E0308]: mismatched types
    --> /Users/messense/Projects/nfs/target/debug/build/nfs-b8a3ecb314bc087c/out/out.rs:1673:22
     |
1673 | LAYOUTRETURN4_FILE = LAYOUT4_RET_REC_FILE,
     |                      ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `u32`

error[E0308]: mismatched types
    --> /Users/messense/Projects/nfs/target/debug/build/nfs-b8a3ecb314bc087c/out/out.rs:1674:22
     |
1674 | LAYOUTRETURN4_FSID = LAYOUT4_RET_REC_FSID,
     |                      ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `u32`

error[E0308]: mismatched types
    --> /Users/messense/Projects/nfs/target/debug/build/nfs-b8a3ecb314bc087c/out/out.rs:1675:21
     |
1675 | LAYOUTRETURN4_ALL = LAYOUT4_RET_REC_ALL,
     |                     ^^^^^^^^^^^^^^^^^^^ expected `isize`, found `u32`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `nfs` due to 3 previous errors

Related code in out.rs

pub const LAYOUT4_RET_REC_ALL: u32 = 3;
pub const LAYOUT4_RET_REC_FILE: u32 = 1;
pub const LAYOUT4_RET_REC_FSID: u32 = 2;

#[derive(Debug, PartialEq)]
pub enum layoutreturn_type4 {
LAYOUTRETURN4_FILE = LAYOUT4_RET_REC_FILE,
LAYOUTRETURN4_FSID = LAYOUT4_RET_REC_FSID,
LAYOUTRETURN4_ALL = LAYOUT4_RET_REC_ALL,
}

@akitaSummer
Copy link

@messense Hello, my friend. Have you found a solution to this issue? I'm currently looking to develop a high-performance NFSv4 server and came across a similar problem. Do you have any good suggestions or solutions that could help me?

@messense messense linked a pull request Dec 17, 2023 that will close this issue
@messense
Copy link
Contributor Author

messense commented Dec 17, 2023

@akitaSummer I think #83 should fix #17 (comment).

@akitaSummer
Copy link

error: expected one of `(`, `,`, `=`, `{`, or `}`, found `:`
    --> src/out.rs:1742:19
     |
1741 | pub enum layoutreturn_type4 {
     |          ------------------ while parsing this enum
1742 | LAYOUTRETURN4_FILE: u32 = LAYOUT4_RET_REC_FILE,
     |                   ^ expected one of `(`, `,`, `=`, `{`, or `}`
     |
     = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
help: perhaps you meant to use `struct` here
     |
1741 | pub struct layoutreturn_type4 {
     |     ~~~~~~

@messense enum doesn't seem to support this syntax

@messense
Copy link
Contributor Author

Oops, I think #[repr(u32)] should work. But there are still many more errors.

@akitaSummer
Copy link

@messense Are you still studying nfs4.x related things now? I followed you on X and hope to ask you some questions.

@messense
Copy link
Contributor Author

Nope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants