diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2010-05-15 04:53:48 -0400 |
---|---|---|
committer | Johannes Berg <johannes@sipsolutions.net> | 2010-05-25 07:17:03 -0400 |
commit | 0ab540c4b72e3bdebfcbe7af84a70fa757ab3bf8 (patch) | |
tree | 2a09919d7585b9701cf873d44486406b66f48a24 | |
parent | ce91ba442d8d909a7a9fc554338a9576d23e9239 (diff) |
swig: properly wrap output parameters
By using %apply rather than overriding, we
can make the swig code smaller, generate
less code and fewer warnings.
Acked-by: Darren Hart <dvhltc@us.ibm.com>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
-rw-r--r-- | ctracecmd.i | 28 | ||||
-rw-r--r-- | tracecmd.py | 4 |
2 files changed, 5 insertions, 27 deletions
diff --git a/ctracecmd.i b/ctracecmd.i index 51e98d5..f3daad2 100644 --- a/ctracecmd.i +++ b/ctracecmd.i | |||
@@ -5,38 +5,14 @@ | |||
5 | 5 | ||
6 | %apply Pointer NONNULL { struct tracecmd_input *handle }; | 6 | %apply Pointer NONNULL { struct tracecmd_input *handle }; |
7 | %apply Pointer NONNULL { struct pevent *pevent }; | 7 | %apply Pointer NONNULL { struct pevent *pevent }; |
8 | 8 | %apply unsigned long long *OUTPUT {unsigned long long *} | |
9 | /* return a (rec,cpu) tuple in python */ | 9 | %apply int *OUTPUT {int *} |
10 | extern struct record *tracecmd_read_at(struct tracecmd_input *handle, | ||
11 | unsigned long long offset, | ||
12 | int *OUTPUT); | ||
13 | 10 | ||
14 | 11 | ||
15 | %{ | 12 | %{ |
16 | #include "trace-cmd.h" | 13 | #include "trace-cmd.h" |
17 | %} | 14 | %} |
18 | 15 | ||
19 | |||
20 | /* return python longs from unsigned long long functions */ | ||
21 | %typemap(out) unsigned long long { | ||
22 | $result = PyLong_FromUnsignedLongLong((unsigned long long) $1); | ||
23 | } | ||
24 | |||
25 | |||
26 | %inline %{ | ||
27 | PyObject *pevent_read_number_field_py(struct format_field *f, void *data) | ||
28 | { | ||
29 | unsigned long long val; | ||
30 | int ret; | ||
31 | |||
32 | ret = pevent_read_number_field(f, data, &val); | ||
33 | if (ret) | ||
34 | Py_RETURN_NONE; | ||
35 | else | ||
36 | return PyLong_FromUnsignedLongLong(val); | ||
37 | } | ||
38 | %} | ||
39 | |||
40 | %ignore trace_seq_vprintf; | 16 | %ignore trace_seq_vprintf; |
41 | 17 | ||
42 | /* SWIG can't grok these, define them to nothing */ | 18 | /* SWIG can't grok these, define them to nothing */ |
diff --git a/tracecmd.py b/tracecmd.py index cf0a275..26f3ac2 100644 --- a/tracecmd.py +++ b/tracecmd.py | |||
@@ -71,7 +71,9 @@ class Event(object): | |||
71 | 71 | ||
72 | def num_field(self, name): | 72 | def num_field(self, name): |
73 | f = pevent_find_any_field(self._format, name) | 73 | f = pevent_find_any_field(self._format, name) |
74 | val = pevent_read_number_field_py(f, record_data_get(self._record)) | 74 | ret, val = pevent_read_number_field(f, record_data_get(self._record)) |
75 | if ret: | ||
76 | return None | ||
75 | return val | 77 | return val |
76 | 78 | ||
77 | 79 | ||