Project

General

Profile

Actions

Feature #15338

open

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

Added by graywolf (Gray Wolf) over 5 years ago. Updated over 5 years ago.

Status:
Open
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

Updated by normalperson (Eric Wong) over 5 years 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) over 5 years ago

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

Actions

Also available in: Atom PDF

Like0
Like0Like0