[capi-sig] scopes and PyEval_EvalCode()
sndive at gmail.com
Fri Nov 9 22:55:32 CET 2007
On Nov 6, 8:25 pm, snd... at gmail.com wrote:
> 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);
> and later on in a function for a module that i defined
> expected to extract that handle:
> PyObject *dict = PyEval_GetGlobals(); // or GetLocals
> depending on where
> // execcontext ended up in PyEval_EvalCode
> PyObject *co = PyDict_GetItemString(dict, "interp");
> but i get null co either way and the dict does not match execcontext
> that is passed into PyEval_EvalCode.
> any ideas how to fix this?
in other words: is there a scope more global than a module scope?
something that won't change for a given PyEval_EvalCode or a similar call.
i stuffed my CObject into __main__ but in case of multiple threads or
nested PyEval_EvalCode i'd have a problem with this approach.
i somehow just need to get to the pointer to the same dictionary that
i passed to PyEval_EvalCode for global scope to retrieve my handle
in a method of a new python type defined in C space.
More information about the capi-sig