Re: [PATCH] perf python: Set error messages on call failure

From: Jinli Xiao
Date: Tue May 02 2023 - 22:33:25 EST


Thanks for the prompt response!

On Tue, May 2, 2023 at 4:37 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> Nice! Would it be possible to test this? We could do a shell test

All my changes in this patch is just setting the error message that
can be interpreted by Python just before the bindings return.

I am not sure about shell test, but I can do something like

[root@nyu-lexis linux]# export PYTHONPATH=~jinli/linux/tools/perf/python/
[root@nyu-lexis linux]# python3
Python 3.11.2 (main, Feb 8 2023, 00:00:00) [GCC 12.2.1 20221121 (Red
Hat 12.2.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import perf
>>> thread_map = perf.thread_map(9999) # a non-existent pid in /proc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory

whereas the original output is

>>> thread_map = perf.thread_map(9999)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: <class 'perf.thread_map'> returned NULL without setting
an exception

Upon testing I did find some of the changes unnecessary. I will submit
a new patch to this.

This is my first time contributing so please let me know if I did
anything wrong :)

Best wishes,
Jinli