This is the mail archive of the gdb-prs@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]

[Bug python/20620] New: Working with C++ variadic templates in Python API is inconvenient


https://sourceware.org/bugzilla/show_bug.cgi?id=20620

            Bug ID: 20620
           Summary: Working with C++ variadic templates in Python API is
                    inconvenient
           Product: gdb
           Version: 7.8
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: jwakely.gcc at gmail dot com
  Target Milestone: ---

Access to template arguments only seems to be possible through the
gdb.Type.template_argument(N) method. For a variadic template you might not
know how many arguments there are, and so to build a list of all arguments you
have to do something like (adapted from libstdc++ printers):

    def _template_args(self, val):
        n = 0
        args = []
        while True:
            try:
                args.append(val.type.template_argument(n))
            except:
                return args
            n += 1

It would be simpler if TYPE_N_TEMPLATE_ARGUMENTS was exposed through the API,
so you could do:

    def _template_args(self, val):
        nargs = val.type.num_template_arguments()
        return [val.type.template_argument(n) for n in range(0, nargs)]

Even better would be a gdb.Value.template_arguments() method which returned the
list. That would be much more efficient than building the list in Python, and
my _template_args() method would be:

    def _template_args(self, val):
        if hasattr(val.type, 'template_arguments'):
            return val.type.template_arguments()
        nargs = val.type.num_template_arguments()
        return [val.type.template_argument(n) for n in range(0, nargs)]

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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