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?


On Wed, Mar 28, 2012 at 8:56 PM,  <Paul_Koning@dell.com> wrote:
> 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.

I agree that the overall refcounting scheme is correct.  However, I
still think that on the Python side, my example should print 1 and not
2 as there are no references to the Objfile object other than that
from the argument to getrefcount.  Actually, having a refcount of 2
does not affect the functionality in any way.  But, when I was trying
something with symtabs and objfiles, and while debugging, I spent a
good amount of time feeling that I was doing something wrong with my
changes.

I have attached a patch now which I feel correctly fixes the 'issue'
that I report.  The changelog is as follows:

2012-03-28  Siva Chandra Reddy  <sivachandra@google.com>

        * python/py-newobjfileevent.c (create_new_objfile_event_object):
        Adjust reference counting scheme for Python gdb.Objfile so that
        reference counts seem correct on the Python side.
        * python/py-objfile.c (objfpy_dealloc): Likewise
        (py_free_objfile): Likewise
        (objfile_to_objfile_object): Likewise
        * python/py-prettyprint.c (find_pretty_printer_from_objfiles):
        Likewise
        * python/py-symtab.c (stpy_get_objfile): Likewise
        * python/python.c (gdbpy_get_current_objfile): Likewise
        (gdbpy_objfiles): Likewise

Siva> Load any program and do the following:
Siva>
Siva> python
Siva> import sys
Siva> print sys.getrefcount(gdb.lookup_global_symbol("main").symtab.objfile)
Siva> end

Thanks,
Siva Chandra

Attachment: refcount_patch_v2.txt
Description: Text document


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