2 * SPDX-License-Identifier: MIT
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
8 # error Unsupported output language
14 #define BT_LOG_TAG "BT2-PY"
18 * Include before `<babeltrace2/func-status.h>` because
19 * `<babeltrace2/babeltrace.h>` removes the `__BT_IN_BABELTRACE_H`
22 #include <babeltrace2/babeltrace.h>
25 * This is not part of the API, but because those bindings reside within
26 * the project, we take the liberty to use them.
28 #define __BT_IN_BABELTRACE_H
29 #include <babeltrace2/func-status.h>
31 #include "common/assert.h"
32 #include "py-common/py-common.h"
34 /* Used by some interface files */
35 #include "native_bt_bt2_objects.h"
36 #include "native_bt_log_and_append_error.h"
40 typedef uint64_t bt_listener_id;
42 /* For uint*_t/int*_t */
46 * Remove `bt_` and `BT_` prefixes from function names, global variables and
49 %rename("%(strip:[bt_])s", %$isfunction) "";
50 %rename("%(strip:[bt_])s", %$isvariable) "";
51 %rename("%(strip:[BT_])s", %$isenumitem) "";
54 * Output argument typemap for string output (always appends)
56 * We initialize the output parameter `temp_value` to an invalid but non-zero
57 * pointer value. This is to make sure we don't rely on its initial value in
58 * the epilogue (where we call SWIG_Python_str_FromChar). When they fail,
59 * functions on which we apply this typemap don't guarantee that the value of
60 * `temp_value` will be unchanged or valid.
62 %typemap(in, numinputs=0) (const char **) (char *temp_value = (void *) 1) {
66 %typemap(argout) (const char **) {
68 /* SWIG_Python_AppendOutput() steals the created object */
69 $result = SWIG_Python_AppendOutput($result, SWIG_Python_str_FromChar(*$1));
71 /* SWIG_Python_AppendOutput() steals Py_None */
73 $result = SWIG_Python_AppendOutput($result, Py_None);
77 /* Output argument typemap for value output (always appends) */
78 %typemap(in, numinputs=0) (bt_value **) (struct bt_value *temp_value = NULL) {
82 %typemap(argout) (bt_value **) {
84 /* SWIG_Python_AppendOutput() steals the created object */
85 $result = SWIG_Python_AppendOutput($result,
86 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
87 SWIGTYPE_p_bt_value, 0));
89 /* SWIG_Python_AppendOutput() steals Py_None */
91 $result = SWIG_Python_AppendOutput($result, Py_None);
95 /* Output argument typemap for initialized uint64_t output parameter (always appends) */
96 %typemap(in, numinputs=0) (uint64_t *) (uint64_t temp) {
100 %typemap(argout) uint64_t * {
101 $result = SWIG_Python_AppendOutput(resultobj,
102 SWIG_From_unsigned_SS_long_SS_long((*$1)));
105 /* Output argument typemap for initialized int64_t output parameter (always appends) */
106 %typemap(in, numinputs=0) (int64_t *) (int64_t temp) {
110 %typemap(argout) (int64_t *) {
111 $result = SWIG_Python_AppendOutput(resultobj, SWIG_From_long_SS_long((*$1)));
114 /* Output argument typemap for initialized unsigned int output parameter (always appends) */
115 %typemap(in, numinputs=0) (unsigned int *) (unsigned int temp) {
119 %typemap(argout) (unsigned int *) {
120 $result = SWIG_Python_AppendOutput(resultobj,
121 SWIG_From_unsigned_SS_long_SS_long((uint64_t) (*$1)));
124 /* Output argument typemap for initialized bt_boot output parameter (always appends) */
125 %typemap(in, numinputs=0) (bt_bool *) (bt_bool temp) {
129 %typemap(argout) bt_bool * {
130 $result = SWIG_Python_AppendOutput(resultobj,
131 SWIG_From_bool(*$1));
134 /* Input argument typemap for UUID bytes */
135 %typemap(in) bt_uuid {
136 $1 = (unsigned char *) PyBytes_AsString($input);
139 /* Output argument typemap for UUID bytes */
140 %typemap(out) bt_uuid {
145 $result = PyBytes_FromStringAndSize((const char *) $1, 16);
149 /* Input argument typemap for bt_bool */
150 %typemap(in) bt_bool {
151 $1 = PyObject_IsTrue($input);
154 /* Output argument typemap for bt_bool */
155 %typemap(out) bt_bool {
165 * Input and output argument typemaps for raw Python objects (direct).
167 * Those typemaps honor the convention of Python C function calls with
168 * respect to reference counting: parameters are passed as borrowed
169 * references, and objects are returned as new references. The wrapped
170 * C function must ensure that the return value is always a new
171 * reference, and never steal parameter references.
173 %typemap(in) PyObject * {
177 %typemap(out) PyObject * {
181 /* Native part initialization and finalization */
182 void bt_bt2_init_from_bt2(void);
183 void bt_bt2_exit_handler(void);
186 * Define `__BT_IN_BABELTRACE_H` to allow specific headers to be
187 * included. This remains defined as long as we don't include the main
188 * header, `<babeltrace2/babeltrace.h>`.
190 #define __BT_IN_BABELTRACE_H
193 * Define `__BT_ATTR_FORMAT_PRINTF` to nothing, otherwise SWIG fails to parse
194 * the included header files that use it.
196 #define __BT_ATTR_FORMAT_PRINTF(_string_index, _first_to_check)
199 %include <babeltrace2/types.h>
201 /* Common function status codes */
202 %include <babeltrace2/func-status.h>
204 /* Per-module interface files */
205 %include "native_bt_autodisc.i"
206 %include "native_bt_clock_class.i"
207 %include "native_bt_clock_snapshot.i"
208 %include "native_bt_component.i"
209 %include "native_bt_component_class.i"
210 %include "native_bt_connection.i"
211 %include "native_bt_error.i"
212 %include "native_bt_event.i"
213 %include "native_bt_event_class.i"
214 %include "native_bt_field.i"
215 %include "native_bt_field_class.i"
216 %include "native_bt_field_path.i"
217 %include "native_bt_graph.i"
218 %include "native_bt_integer_range_set.i"
219 %include "native_bt_interrupter.i"
220 %include "native_bt_logging.i"
221 %include "native_bt_message.i"
222 %include "native_bt_message_iterator.i"
223 %include "native_bt_mip.i"
224 %include "native_bt_packet.i"
225 %include "native_bt_plugin.i"
226 %include "native_bt_port.i"
227 %include "native_bt_query_exec.i"
228 %include "native_bt_stream.i"
229 %include "native_bt_stream_class.i"
230 %include "native_bt_trace.i"
231 %include "native_bt_trace_class.i"
232 %include "native_bt_value.i"
233 %include "native_bt_version.i"
238 * This function is defined by SWIG. Declare here to avoid a
239 * -Wmissing-prototypes warning.
241 PyObject *SWIG_init(void);