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

len attribute should be an int literal #265

Merged
merged 2 commits into from
Sep 3, 2019
Merged

Conversation

emillon
Copy link
Contributor

@emillon emillon commented Sep 2, 2019

Closes #264

This rejects things like [@len ""] and [@len 1l] which were previously silently ignored.

Closes mirage#264

This rejects things like `[@len ""]` and `[@len 1l]` which were
previously silently ignored.
@emillon
Copy link
Contributor Author

emillon commented Sep 2, 2019

ppxlib has some combinators to avoid this kind of boilerplate - might be worth investigating if we split the ppx out of the main cstruct package.

@avsm
Copy link
Member

avsm commented Sep 2, 2019

I'd be delighted to get a ppx/ppxlib port of ppx_cstruct..

Copy link
Member

@avsm avsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except the request to tighten up the length parsing (unless that is done later -- in which case just having a test case for a negative length attribute would be great)

ppx/ppx_cstruct.ml Outdated Show resolved Hide resolved
; _}])] ->
Some (int_of_string sz)
| [{txt = "len"; loc}, _ ] ->
loc_err loc "[@len] argument should be an integer"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
loc_err loc "[@len] argument should be an integer"
loc_err loc "[@len] argument should be a positive, non-zero integer"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are two check sites so I used this more specific version only when needed, how does that look?

@avsm
Copy link
Member

avsm commented Sep 3, 2019

Looks good to me! Unrelated to this PR, but the tests fail on 4.08 since ppx_cstruct generates references to stdlib. I'll fix that in a separate PR.

@avsm avsm merged commit 5af8b1b into mirage:master Sep 3, 2019
@emillon
Copy link
Contributor Author

emillon commented Sep 3, 2019

Yes that's #263 - the environment variable should do it. Thanks!

@emillon emillon deleted the len-not-int branch September 3, 2019 15:53
avsm added a commit to avsm/opam-repository that referenced this pull request Nov 24, 2019
…uct-sexp and cstruct-lwt (5.1.0)

CHANGES:

- Do not issue deprecation warnings when using OCaml 4.08.0
  and cstruct-ppx with enums due to `Pervasives` (mirage/ocaml-cstruct#269 @cypheon @hannesm)

- Tighten parsing of the `[@len]` attribute to ensure it is a
  valid, positive integer (mirage/ocaml-cstruct#265 @emillon)

- Update JavaScript bindings to latest `Js_of_ocaml` 3.5.0
  interfaces (@hhugo mirage/ocaml-cstruct#268)
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 this pull request may close these issues.

silent failure on variable/expressions in [@len]
2 participants