Project

General

Profile

Feature #15338

Provide way for C extensions to query if global variable is defined

Added by graywolf (Gray Wolf) 6 months ago. Updated 6 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:90046]

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

0001-Add-rb_gv_defined.patch (3.42 KB) 0001-Add-rb_gv_defined.patch graywolf (Gray Wolf), 11/24/2018 08:21 PM

History

Updated by normalperson (Eric Wong) 6 months ago

https://bugs.ruby-lang.org/issues/15338

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?

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) 6 months ago

As for the implementation, this rb_gv_defined will add new ID just by asking if the gv is defined.

Also available in: Atom PDF