This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [RFC - Python Scripting] Unnecessary Py_XINCREF?


Siva,

I think the code is correct as it stands.  The objfile_to_objfile_object function says that it returns a borrowed reference.  So the function you were looking at does need the INCREF because it is supposed to return a new (not borrowed) reference.  It looks like the new object (when a new one needs to be created) is remembered in the object->objfile field, so the reference count should indeed be 2 in the example you mentioned -- one for the reference coming into the sys.getreferencecount function, and one for the pointer held in the object struct.

	paul

-----Original Message-----
From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-owner@sourceware.org] On Behalf Of Siva Chandra
Sent: Wednesday, March 28, 2012 8:13 AM
To: gdb-patches@sourceware.org
Subject: Re: [RFC - Python Scripting] Unnecessary Py_XINCREF?

I take back my simple fix. I think this is not as simple as removing the Py_XINCREF. I am working on the proper fix.

Thanks,
Siva Chandra

On Wed, Mar 28, 2012 at 3:55 PM, Siva Chandra <sivachandra@google.com> wrote:
> Hello,
>
> I find something which to my understanding looks like an unnecessary 
> Py_XINCREF in py-symtab.c:stpy_get_objfile. I support it by this
> experiment:
>
> Load any program and do the following:
>
> python
> import sys
> print sys.getrefcount(gdb.lookup_global_symbol("main").symtab.objfile)
> end
>
> The above Python snippet prints 2 without the patch applied. With the 
> patch applied, it prints 1 which I think is what it should be. Am I 
> missing something (real bad) here?
>
> ChangeLog:
>
> 2012-03-28 ?Siva Chandra Reddy ?<sivachandra@google.com>
>
> ? ? ? ?* python/py-symtab.c (stpy_get_objfile): Remove the unnecessary
> ? ? ? ?Py_XINCREF.
>
> Thanks,
> Siva Chandra


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]