Skip to content

C parser drops docs under namespace variables defined in another file #1744

Description

@st0012

C parser drops docs for entries under a namespace variable defined in another file

RDoc's C parser appears unable to resolve extension namespace variables across C files for constants and methods.

Example:

/* foo.c */
VALUE mFoo;

void Init_foo(void) {
    mFoo = rb_define_module("Foo");
}
/* constants.c */
rb_define_const(mFoo, "VERSION", rb_str_new_cstr("1.0.0"));

In this shape, RDoc does not know what mFoo means while parsing constants.c, so Foo::VERSION is not documented.

There is partial cross-file support for _under definitions, such as:

/* bar.c */
VALUE cBar = rb_define_class_under(mFoo, "Bar", rb_cObject);

That can work because rb_define_class_under / rb_define_module_under goes through a store-backed enclosure lookup. In other words, when RDoc is creating a class or module, it has a special path that can sometimes find the enclosing C variable from another parsed file or cache.

Constants and methods do not appear to use the same path. They only check the parser-local @known_classes map, and if mFoo is missing, the entry is silently skipped.

A workaround is to add a fake seed comment in each C file:

/* RDoc parses C files independently: mFoo = rb_define_module("Foo") */

Because RDoc scans block comments for rb_define_* patterns, this seeds mFoo => Foo for that file and documentation is generated.

Expected behavior: once mFoo is defined in one parsed C file, later C files should be able to document constants and methods under Foo, or RDoc should provide a documented way to seed cross-file C namespace variables.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions