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 v19 1/4] Add xmethod documentation and NEWS entry


Siva Chandra <sivachandra@google.com> writes:

> 2014-05-30  Siva Chandra Reddy  <sivachandra@google.com>
>
>         * NEWS (Python Scripting): Add entry about the new xmethods
>         feature.
>
>         doc/
>         *  python.texi (Xmethods In Python, XMethod API)
>         (Writing an Xmethod): New nodes.
>         (Python API): New menu entries "Xmethods In Python",
>         "Xmethod API", "Writing an Xmethod".
>
> [...]
>
> +@node Writing an Xmethod
> +@subsubsection Writing an Xmethod
> +@cindex writing xmethods in Python
> +
> +Implementing xmethods in Python will require implementing xmethod
> +matchers and xmethod workers (@pxref{Xmethods In Python}).  Consider
> +the following C@t{++} class:
> +
> +@smallexample
> +class MyClass
> +@{
> +public:
> +  MyClass (int a) : a_(a) @{ @}
> +
> +  int geta (void) @{ return a_; @}
> +  int operator+ (int b);

The corresponding python method takes a MyClass object for "b", not an int.
Either they should match, or the docs should say why they're different.
[There's no reason the user can't add new methods to an object with
xmethods, but at the moment I think the reader will find the difference
confusing unless there's an explanation of why.]

> +class MyClassWorker_plus(gdb.xmethod.XMethodWorker):
> +    def get_arg_types(self):
> +        return gdb.lookup_type('MyClass')
> + 
> +    def __call__(self, obj, other):
> +        return obj['a_'] + other['a_']
> +@end smallexample

LGTM with that fixed.


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