Feature #15777
closed
autoload?(cname, inherit=true)
Added by fxn (Xavier Noria) over 5 years ago.
Updated over 5 years ago.
Description
Zeitwerk needs to be able to check if a given class or module has an autoload defined for a certain constant name, that would be autoload?(cname, false)
, similar to const_defined?(cname, false)
.
- Description updated (diff)
Changing the signature of rb_autoload_p
could break API compatibility.
I think we'll need another function for it.
Maybe rb_autoload_at_p
like as rb_const_defined_at
?
Is it necessary to export rb_autoload_at_p
?
Do you have the plan to use it in extension libraries?
byroot (Jean Boussier) wrote:
Let me know if you desire further changes.
Fix the bug first.
In rb_autoload_at_p
, this condition is wrong.
- while (!autoload_defined_p(mod, id)) {
+ while (RTEST(recur) && autoload_defined_p(mod, id)) {
Leave it unchanged but return nil
if not recur
in that loop.
Is it necessary to export rb_autoload_at_p?
Do you have the plan to use it in extension libraries?
No I have no such plan. I did so because it's defined in variable.c
but called from load.c
so without that declaration it won't compile:
load.c:1180:12: error: implicit declaration of function 'rb_autoload_at_p' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
return rb_autoload_at_p(mod, id, recur);
I'm quite a MRI & C beginner though, so if there is a better way to do it I'll gladly change it.
@Eregon (Benoit Daloze) told me which place to declare internal functions. It's now in internal.h
return nil if not recur in that loop.
Done.
- Assignee set to nobu (Nobuyoshi Nakada)
- Status changed from Open to Closed
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0