ext/redrat_ext/redrat_ext.c
/*
 * redrat_builtin_mapping - The Root of All Things
 *
 * Retrieves a PythonValue that supports the dictionary protocol to access the
 * builtins.
 *
 * From here, just about everything is possible because of the existence of
 * __import__.  An annotated example of what this C code is intended to enable
 * follows:
 *
 *     # Access the builtins, available as a dictionary
 *
 *     >>> __builtins__
 *     <module '__builtin__' (built-in)>
 *
 *     # __import__ is the low-level method used for importing modules
 *
 *     >>> __builtins__.__import__
 *     <built-in function __import__>
 *
 *     # Any available module can be imported, yielding another module
 *     # PyObject; furthermore, those modules can be delegated messages from
 *     # Ruby, as Python modules are just PyObjects.
 *
 *     >>> __builtins__.__import__('argparse')
 *     <module 'argparse' from '/usr/lib/python2.7/argparse.pyc'>
 */
The Root of All Things
Retrieves a PythonValue that supports the dictionary protocol to access the
builtins.

From here, just about everything is possible because of the existence of
import__.  An annotated example of what this C code is intended to enable
follows.

# Access the builtins, available as a dictionary



# __import__ is the low-level method used for importing modules



# Any available module can be imported, yielding another module
# PyObject; furthermore, those modules can be delegated messages from
# Ruby, as Python modules are just PyObjects.


The Root of All Things Retrieves a PythonValue that supports the dictionary protocol to access the builtins . From here just about everything is possible because of the existence of import__ . An annotated example of what this C code is intended to enable follows . # Access the builtins available as a dictionary # __import__ is the low - level method used for importing modules # Any available module can be imported yielding another module # PyObject ; furthermore those modules can be delegated messages from # Ruby as Python modules are just PyObjects .
static VALUE
redrat_builtin_mapping(VALUE self)
{
    PyGILState_STATE     gstate;
    PyObject *pBuiltins;
    VALUE rExcGetBuiltin = Qnil;
    VALUE rReturn;
    gstate = PyGILState_Ensure();
    pBuiltins = PyEval_GetBuiltins();
    REDRAT_ERRJMP_PYEXC(rExcGetBuiltin, pBuiltins);
    Py_INCREF(pBuiltins);
    Assert_PyMapping(pBuiltins);
    rReturn = redrat_ruby_handoff(pBuiltins);
    PyGILState_Release(gstate);
    return rReturn;
py_rb_error:
    Py_XDECREF(pBuiltins);
    PyGILState_Release(gstate);
    if (rExcGetBuiltin != Qnil)
        redrat_rb_exc_raise(rExcGetBuiltin,
                            "redrat_ext: couldn't read Python builtins, "
                            "RedRat cannot initialize");
    else
        rb_fatal("redrat_ext: report this bug in redrat_builtin_mapping");
    Assert(false);
}
static VALUE redrat_builtin_mapping ( VALUE self ) { PyGILState_STATE gstate ; PyObject * pBuiltins ; VALUE rExcGetBuiltin = Qnil ; VALUE rReturn ; gstate = PyGILState_Ensure ( ) ; pBuiltins = PyEval_GetBuiltins ( ) ; REDRAT_ERRJMP_PYEXC ( rExcGetBuiltin , pBuiltins ) ; Py_INCREF ( pBuiltins ) ; Assert_PyMapping ( pBuiltins ) ; rReturn = redrat_ruby_handoff ( pBuiltins ) ; PyGILState_Release ( gstate ) ; return rReturn ; py_rb_error : Py_XDECREF ( pBuiltins ) ; PyGILState_Release ( gstate ) ; if ( rExcGetBuiltin != Qnil ) redrat_rb_exc_raise ( rExcGetBuiltin , " " " " ) ; else rb_fatal ( " " ) ; Assert ( false ) ; }
redrat_builtin_mapping - The Root of All Things
 Retrieves a PythonValue that supports the dictionary protocol to access the
 builtins.
redrat_builtin_mapping - The Root of All Things Retrieves a PythonValue that supports the dictionary protocol to access the builtins .
/*
     * A failure to return the builtin mapping to Ruby, which makes it
     * seemingly impossible to bootstrap access to richer Python functionality.
     * That's bad news so early in the game, but faithfully clean up and raise
     * an exception.
     *
     * These Py_XDECREF calls have to be carefully checked that they do not
     * cause over-decref-ing should a procedure returns a "borrowed" reference
     * and yet winds up in this error path.  In the above, PyEval_GetBuiltins()
     * is such an example.
     */