private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack

sndive at gmail.com sndive at gmail.com
Tue Nov 13 16:18:14 EST 2007


On Nov 9, 5:36 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Tue, 06 Nov 2007 23:25:17 -0300, <snd... at gmail.com> escribió:
>
> > i naively created execution context:
> >     PyObject *execcontext = PyDict_New();
> > stuffed a handle in it:
> >     PyObject *ih = PyCObject_FromVoidPtr(handle, NULL);
> >    int st= PyDict_SetItemString(res, "interp", ih);
>
> What's `res`?

duh!
it should be execcontext:
int st= PyDict_SetItemString(execcontext, "interp", ih);
then i'd
PyEval_EvalCode(somecallable, execcontext, g_maindict);
where g_maindict is a dictionary from __main__ module
...

later as part of PyEval_EvalCode
a method in a module extending python is executed by python runtime
and i want to get "interp" assuming it would be in the global context:
        PyObject *dict = PyEval_GetGlobals();
        PyObject *co = PyDict_GetItemString(dict, "interp");
but apparently PyEval_GetGlobals(); returns the dictionary
that has nothing to do with the execcontext passed into
PyEval_EvalCode higher up on the call stack
and i do not know how to get to the execcontext dictionary that
i passed in PyEval_EvalCode.
If each module has its own globals what the point of passing
global and local namespace into PyEval_EvalCode?

> One should make a lot of assumptions about your code because it's not
> complete. Please post a minimal complete example showing your problem.
>
It's a rather large program. My assumption was that just posting the
snippet around the call site and the callee pathetic attempt
to extract interp would be sufficient :(




More information about the Python-list mailing list