[Python-Dev] Accessing value stack

Maciej Fijalkowski fijall at gmail.com
Mon Jan 7 21:43:06 CET 2013


On Mon, Jan 7, 2013 at 10:40 PM, PJ Eby <pje at telecommunity.com> wrote:
> On Mon, Jan 7, 2013 at 11:32 AM, Brett Cannon <brett at python.org> wrote:
>> On Mon, Jan 7, 2013 at 10:46 AM, Maciej Fijalkowski <fijall at gmail.com> wrote:
>>> On Mon, Jan 7, 2013 at 4:22 PM, Oleg Broytman <phd at phdru.name> wrote:
>>>> On Mon, Jan 07, 2013 at 03:06:51PM +0100, Dima Tisnek <dimaqq at gmail.com> wrote:
>>>>> Hi, is it possible to access the values stored on the stack in Python stack
>>>>> machine from Python?
>>>>
>>>>    In short: it's possible but very much discouraged. Don't hack into
>>>> python internals.
>>>
>>> Is it possible? I claim it's not (from *Python* because obviously data
>>> is in memory).
>>
>> Nope, it's not.
>
> I took that as a challenge, and just tried to do it using
> gc.get_referents().  ;-)
>
> Didn't work though...  which actually makes me wonder if that's a bug
> in gc.get_referents(), or whether I'm making a bad assumption about
> when you'd have to run gc.get_referents() on a frame in order to see
> items from the value stack included.  Could this actually be a bug in
> frames' GC implementation, or are value stack items not supposed to
> count for GC purposes?

valustack is a static list in C (it's not a Python list at all) that's
stored on the frame. You can't do it that way. gc.get_referrers
returns you only python objects (and in fact should return you only
python objects that are accessible otherwise, but those details are
really implementation-dependent)


More information about the Python-Dev mailing list