 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Paul Drummond Guest
|
Posted: Tue Nov 29, 2005 4:07 pm Post subject: f_locals is NULL inside a method |
|
|
Hi all,
I am developing a new python debugger which is coming on quite nicely
except that f_locals always becomes NULL when entering new functions.
Can anyone help with this? Someone else has posted earlier with a
similar problem but there are no replies. I can't understand why
f_locals would be NULL - it works fine at the module level but as soon
as I "step into" a function, the contents of frame->f_locals when
converted to a string is null. The conversion is as follows:
int tracer(PyObject*, PyFrameObject* frame, int what, PyObject* arg)
{
PyObject* locals = PyObject_Str(frame->f_locals);
std::cout << "LOCALS: " << PyString_AsString(locals) << std::endl;
Py_DECREF(locals);
}
Is there anything wrong with this or can I assume f_locals is actually
NULL?
Note: I have ran the same test module in PDB and it's f_locals is fine!
|
|
| Back to top |
|
 |
Howard Guest
|
Posted: Tue Nov 29, 2005 4:53 pm Post subject: Re: f_locals is NULL inside a method |
|
|
"Paul Drummond" <paul.drummond (AT) dsl (DOT) pipex.com> wrote
| Quote: | Hi all,
I am developing a new python debugger which is coming on quite nicely
except that f_locals always becomes NULL when entering new functions.
|
You don't provide any declaration for the class which contains this f_locals
variable, or a declaration for what that variable is. Perhaps you're just
encountering some problems with copy constructors?
| Quote: | Can anyone help with this? Someone else has posted earlier with a
similar problem but there are no replies. I can't understand why
f_locals would be NULL - it works fine at the module level but as soon
as I "step into" a function, the contents of frame->f_locals when
converted to a string is null. The conversion is as follows:
int tracer(PyObject*, PyFrameObject* frame, int what, PyObject* arg)
{
PyObject* locals = PyObject_Str(frame->f_locals);
std::cout << "LOCALS: " << PyString_AsString(locals) << std::endl;
Py_DECREF(locals);
}
|
Is frame->f_locals NULL immediately upon entering this function, or after
executing PyObject_Str (whatever that is)? Or does it just APPEAR to be
NULL when output via that PyString_AsString function?
We have no was of knowing what any of that code is doing, or how the data
was created or passed to this function, so it would be pretty hard to guess.
| Quote: |
Note: I have ran the same test module in PDB and it's f_locals is fine!
|
I take it that's some kind of debugger? When you see the problem you're
describing above, how exactly are you determining that frame->f_locals is
NULL? Are you using another debugger? Perhaps it's a problem with that
debugger? No way for us to know, unfortunately.
-Howard
|
|
| Back to top |
|
 |
Paul Drummond Guest
|
Posted: Wed Nov 30, 2005 9:28 am Post subject: Re: f_locals is NULL inside a method |
|
|
Hi Howard,
The tracer function is a callback provided by the python interpreter by
PyEval_SetTrace() and all parameters are provided by Python, hence the
problem - python is providing frame->f_locals as a null when it should
be a dictionary to all the current locals.
I have solved the problem anyway for anyone who is interested, a call
PyFrame_FastToLocals(frame) will update f_locals to be correct. As far
as I can tell you also need to call PyFrame_LocalsToFast(frame, 0) when
you are finished with f_locals.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|