Feature #15338
openProvide way for C extensions to query if global variable is defined
Description
As far as I can tell, there is no way for C extension to check if global variable is defined. I can rb_gv_get
, but that produces warning when $VERBOSE = true
.
Let's introduce third function rb_gv_defined
to complement rb_gv_get
and rb_gv_set
.
PS: At the moment I'm doing if (RTEST(rb_eval_string("defined?($XX) && $XX"))) { ... }
but there's got to be a better way, right?
Files
Updated by normalperson (Eric Wong) almost 6 years ago
Let's introduce third function
rb_gv_defined
to complementrb_gv_get
andrb_gv_set
.
PS: At the moment I'm doing
if (RTEST(rb_eval_string("defined?($XX) && $XX"))) { ... }
but
there's got to be a better way, right?
I prefer we avoid adding more bloat to the public C API unless
it's a performance critical case. This doesn't seem
performance-critical to me.
Updated by nobu (Nobuyoshi Nakada) almost 6 years ago
As for the implementation, this rb_gv_defined
will add new ID just by asking if the gv is defined.