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

Handling of nil nodes is suboptimal #4328

Closed
vicuna opened this issue Jun 23, 2007 · 1 comment
Closed

Handling of nil nodes is suboptimal #4328

vicuna opened this issue Jun 23, 2007 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Jun 23, 2007

Original bug ID: 4328
Reporter: cstork
Assigned to: ertai
Status: closed (set by @xavierleroy on 2010-04-29T12:26:12Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.10.0
Fixed in version: 3.10+dev
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: cstork

Bug description

If I try to pretty print

<:str_item< type $t$; ... >>

where t could potentially be a nil node, ie, <:ctyp<>>, then camlp4r produces a stack overflow.

Two suggestions:

  1. CleanAst.ml could easily turn such empty str_item nodes into <:str_item<>>. Attached is a simple patch that achieves this for this case. If there's interest I'd extend this patch to cover more useful cases. This has the potential to make writing camlp4 extensions more pleasant.

  2. camlp4 shouldn't simply crash on nil nodes, but produce a meaningful error message. In case that such a nil node is not pretty printed but dump'ed the error message is

Assertion failed, file "camlp4/Camlp4/Struct/Camlp4Ast2OCamlAst.ml",
line 792, char 11

which is a bit more helpful.

Additional information

To reproduce:

$ echo << DONE
open Camlp4.PreCast.Syntax;
EXTEND Gram
GLOBAL: str_item;
str_item: [[ "type_Nil" -> <:str_item< type $ <:ctyp<>> $ >> ]];
END;
DONE > pa_type_Nil.ml
$ ocamlc -c -pp camlp4rf -I +camlp4 pa_type_Nil.ml
$ echo "type_Nil;" > type_Nil.ml
$ camlp4r pa_type_Nil.cmo type_Nil.ml
type (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
Camlp4: Uncaught exception: Stack_overflow

File attachments

@vicuna
Copy link
Author

vicuna commented Nov 21, 2007

Comment author: ertai

Thanks for your report. That's fixed in CVS.

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

No branches or pull requests

1 participant