'Fill a remotely allocated dict with values from the Cython C stack'

def _fill_locals_dict(self, executor, local_dict_pointer):

    cython_func = self.get_cython_function()
    for (name, cyvar) in cython_func.locals.items():
        if ((cyvar.type == PythonObject) and self.is_initialized(cython_func, name)):
            try:
                val = gdb.parse_and_eval(cyvar.cname)
            except RuntimeError:
                continue
            else:
                if val.is_optimized_out:
                    continue
            pystringp = executor.alloc_pystring(name)
            code = ('\n                                                                                (PyObject    *)    PyDict_SetItem(\n                                                                                                (PyObject    *)    %d,\n                                                                                                (PyObject    *)    %d,\n                                                                                                (PyObject    *)    %s)\n                                                                ' % (local_dict_pointer, pystringp, cyvar.cname))
            try:
                if (gdb.parse_and_eval(code) < 0):
                    gdb.parse_and_eval('PyErr_Print()')
                    raise gdb.GdbError('Unable    to    execute    Python    code.')
            finally:
                executor.xdecref(pystringp)
