[CM] bug in s7 keyword handling?

Gregg Reynolds dev at mobileink.com
Sat Jul 17 13:25:31 PDT 2021


Hi,

There's no obvious cause of this in my code so I wonder what you make of it.

Background: my library is for parsing Starlark code (that's the language
Bazel uses). I'm using the object "applicator" capability to support
predicates and pseudo attributes, so I can do things like:

(node :<nodetype>?)

which returns true if the AST node has that type. E.g.  (node :list-expr?)

An example of a pseudo attribute is (node :@deps), which when applied to a
node of type :call-expr (that is, a Bazel rule application), reaches down
into the subnodes to get the "deps" attribute.  The Bazel code would look
like:

cc_library(
    name = "foobar",
    deps  = [":baz"]
)

So when applied to the cc_library node, it would return the nodelist for
"deps = [":baz"]".

It's been working great so far (just getting started) but I've run into the
following problem.  This works, returning true for the test node:

  (display (format #f "(node :stmt-list?): ~A" (node :stmt-list?)))

However, if I run it a second time, it fails.  The problem is that
s7_keyword_to_symbol strips the trailing question mark - but only the
second time thru!

Here's a fragment from my code:

    s7_pointer op = s7_car(rest);  /* op is the kw :stmt-list? */
    if (s7_is_keyword(op)) {
        log_debug("KWdump: %s", s7_object_to_c_string(s7, op));
        s7_pointer sym = s7_keyword_to_symbol(s7, op);
        log_debug("SYMdump: %s", s7_object_to_c_string(s7, sym));
        char *kw = (char*)s7_symbol_name(sym);
        log_debug("KW: %s", kw);
        ... handle kw ...
      ....

When I eval this:

  (display (format #f "(node :stmt-list?): ~A" (node :stmt-list?)))
(newline)
  (display (format #f "(node :stmt-list?): ~A" (node :stmt-list?)))
(newline)

This is the log output:

ast_node_s7.c:445: g_ast_node_object_applicator
ast_node_s7.c:1329: APPLICATOR ARGS:
ast_node_s7.c:1330: (:stmt-list?)
ast_node_s7.c:459: KWdump: :stmt-list?
ast_node_s7.c:461: SYMdump: stmt-list?   <<=========== ? retained
ast_node_s7.c:463: KW: stmt-list?
ast_node_s7.c:479: KW PREDICATE stmt-list?
ast_node_s7.c:338: ast_node_type_kw_pred: stmt-list?
nodes.c:317: lookup: TK-Stmt-List
(node :stmt-list?): #t
ast_node_s7.c:445: g_ast_node_object_applicator
ast_node_s7.c:1329: APPLICATOR ARGS:
ast_node_s7.c:1330: (:stmt-list?)
ast_node_s7.c:459: KWdump: :stmt-list?
ast_node_s7.c:461: SYMdump: stmt-list          <<======= ? disappeared
ast_node_s7.c:463: KW: stmt-list
ast_node_s7.c:385: g_ast_node_ref_specialized
ast_node_s7.c:289: ast_node_property_lookup

;ast-node-ref argument 1, :stmt-list?, is a symbol but should be one of :c,
:str, :i, etc.

(The error is correct since the actual lookup is based on stmt-list not
stmt-list?)

It looks to me like it might be a bug in s7, but I would not be surprised
if my code has managed to corrupt the memory somehow.  Any help would be
appreciated.

Gregg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20210717/1f2dfd55/attachment.html>


More information about the Cmdist mailing list