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: [Patch] PR python/15464 and python/16113


Attached is a new version of the patch which addresses Tom's comments.

Siva> +   if (name_obj != Py_None)
Siva> +     {
Siva> +       field = python_string_to_host_string (name_obj);
Siva> +       Py_DECREF (name_obj);
Siva> +       name_obj = NULL;
Siva> +       if (field == NULL)
Siva> +         return NULL;
Siva> +     }
Siva> +
Siva> +   if (name_obj == Py_None || field[0] == '\0')
Siva> +     {
Siva> +       PyObject *bitpos_obj;
Siva> +       int valid;
Siva> +
Siva> +       Py_XDECREF (name_obj);

Tom> I think that if name_obj is the Python string "", then it will be
Tom> decref'd twice.

I had "name_obj = NULL" in the first if block with the second decref
an x-decref to avoid decref-ing twice.  This is irrelevant now as I
have modified to make the name 'None' if the name is "".

Siva> + res_val = value_struct_elt_bitpos (&tmp, bitpos, "struct/class/union");

Tom> I think this approach will fail in the situation where multiple
Tom> anonymous sub-objects appear at the same bitpos.  I think this happens
Tom> with inheritance, typically at bitpos 0 but perhaps elsewhere with
Tom> multiple inheritance.

I apologize for not being thorough here.  Even a simple union with two
un-named fields can show the problem.

Tom> It may be sufficient to also pass in an expected type, which could be
Tom> extracted from the Field object.

The attached patch takes this route.

2014-12-07  Siva Chandra Reddy  <sivachandra@google.com>

        PR python/15464
        PR python/16133
        * valops.c (value_struct_elt_bitpos): New function
        * py-type.c (convert_field): Set 'name' attribute of a gdb.Field
        object to 'None' if the field name is an empty string ("").
        * python/py-value.c (valpy_getitem): Use 'bitpos' and 'type'
        attribute to look for a field when 'name' is 'None'.
        (get_field_type): New function

        testsuite/
        * gdb.python/py-type.c: Enhance test case.
        * gdb.python/py-value-cc.cc: Likewise
        * gdb.python/py-type.exp: Add new tests.
        * gdb.python/py-value-cc.exp: Likewise

Attachment: value_field_subscript_patch_v3.txt
Description: Text document


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